分享

用户控件开发:

 昵称10504424 2014-02-24

 

 

弦断有谁听
 

博客园
 首页
 博问
 闪存
 新随笔
 联系
 订阅
管理
 
随笔-3  文章-0  评论-0 

 

 


用户控件开发:

 

 

 
功能:
 
1、判断用户是否自动登录
 


有了html5,就可以在很多地方用localStorage取代cookies,sessionStorage取代Session
 
2、实现视频搜索
 
首先为TextBox控件扩展一个AutoCompleteExtender控件,实现输入字符,自动显示相关视频。
 
读者需要了解AutoCompleteExtender控件的使用方法;此实例后台WebService方法如下
 


数据库表中有videoTitle字段,通过调用存储过程selectVideoTitle
 
create proc [dbo].[selectVideoTitle]
@videoTitle nvarchar(20)
as
select * from T_videoInfo where videoTitle like '%'+@videoTitle+'%' and aduiting=0 order by clickCount desc
 
获得视频名称列表,然后传给strArray;
 
为TextBox控件添加blur事件,发生此事件时,会把TextBox控件的值传给selectVideoInfo.ashx文件,此文件负责返回视频Id,通过参数Id传给videoShow.asox;然后跳转到视频列表展示页面videoShow.aspx
 


selectVideoInfo如下:
 


也是通过调研存储过程。SqlHelp等一些公共方法在代码中
 
3.登录,注册上传视频页面的打开
 


当希望链接被蜘蛛爬到,又不希望通过链接形式打开;可以使用return false语句
 
下面javaScript用来打开注册页面:
 


大家可以去查一下window.showModalDialog()和window.open()的区别等。
 
代码
 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Diagnostics;


namespace 在线视频.CommonClass
{
    public class SqlHelp
    {
        static string connstr = ConfigurationManager.ConnectionStrings["conVedioStr"].ConnectionString;
        public static DataTable ExecuteDataTable(string str, params SqlParameter[] parameters)
        {
            using (SqlConnection conn = new SqlConnection(connstr))
            {
                using (SqlCommand com = conn.CreateCommand())
                {
                    com.CommandText = str;
                    com.Parameters.AddRange(parameters);
                    SqlDataAdapter adapter = new SqlDataAdapter(com);
                    DataTable table = new DataTable();
                    adapter.Fill(table);
                    return table;
                }
            }
        }
        public static DataTable ExecuteDataTablePro(string procName, params SqlParameter[] parameters)
        {
            using (SqlConnection conn = new SqlConnection(connstr))
            {
                using (SqlCommand com = conn.CreateCommand())
                {
                    com.CommandType = CommandType.StoredProcedure;
                    com.CommandText = procName;
                    com.Parameters.AddRange(parameters);
                    SqlDataAdapter adapter = new SqlDataAdapter(com);
                    DataTable table = new DataTable();
                    adapter.Fill(table);
                    return table;
                }
            }
        }
        public static int  ExecuteNonQuery(string str, params SqlParameter[] parameters)
        {
            using (SqlConnection conn = new SqlConnection(connstr))
            {
                conn.Open();
                using (SqlCommand com = conn.CreateCommand())
                {
                    com.CommandText = str;
                    com.Parameters.AddRange(parameters);
                   return com.ExecuteNonQuery();
                }
            }

        }
        public static int ExecuteNonQueryPro(string procName, params SqlParameter[] parameters)
        {
            using (SqlConnection con = new SqlConnection(connstr))
            {
                con.Open();
                using(SqlCommand com=con.CreateCommand())
                {
                    com.CommandType = CommandType.StoredProcedure;
                    com.CommandText = procName;
                    com.Parameters.AddRange(parameters);
                    return com.ExecuteNonQuery();
                }
            }
        }
        public static object ExecuteScalar(string str, params SqlParameter[] parameters)
        {
            using (SqlConnection conn = new SqlConnection(connstr))
            {
                conn.Open();
                using (SqlCommand com = conn.CreateCommand())
                {
                    com.CommandText = str;
                    com.Parameters.AddRange(parameters);
                    return com.ExecuteScalar();
                }

            }

        }
        public static object ExecuteScalarPro(string procName, params SqlParameter[] parameters)
        {
            using (SqlConnection conn = new SqlConnection(connstr))
            {
                conn.Open();
                using (SqlCommand com = conn.CreateCommand())
                {
                    com.CommandType = CommandType.StoredProcedure;
                    com.CommandText = procName;
                    com.Parameters.AddRange(parameters);
                    return com.ExecuteScalar();
                }

            }

        }
        public static SqlDataReader ExecuteReader(string str, params SqlParameter[] parameters)
        {
            using (SqlConnection conn = new SqlConnection(connstr))
            {
                conn.Open();
                using (SqlCommand com = conn.CreateCommand())
                {
                    com.CommandText = str;
                    com.Connection = conn;
                    com.Parameters.AddRange(parameters);
                    SqlDataReader reader = com.ExecuteReader();
                    return reader;
                }
               
            }

        }
        public static object FromDbValue(object value)
        {
            if (value == DBNull.Value)
            {
                return null;
            }
            else
            {
                return value;
            }
        }
        public static object ToDbValue(object value)
        {
            if (value == null)
            {
                return DBNull.Value;
            }
            else
            {
                return value;
            }
        }
        public static string AlertMsg(string msg)
        {
            string str = "<script type=\"text/javascript\" >alert('" + msg + "');</script>";
            return str;
        }
        public static  string getUniqueName(string tempPath)//tempPath上传路径
        {
            string strPre = tempPath.Substring(0, tempPath.LastIndexOf("."));

            string strLast = tempPath.Substring(tempPath.LastIndexOf(".") + 1);
            int i = 0;
            while (File.Exists(tempPath))
            {
                tempPath = strPre + "(" + i.ToString() + ")." + strLast;
                i++;
            }
            return tempPath;//返回唯一路径

        }
        public static void catchImg(string videoFileName, string imgSavePath)//截取图片
        {
            string fmpeg = @"F:\html\在线视频\在线视频\CommonFiles\ffmpeg.exe";
            string savePath = imgSavePath;
            string imgSize = ConfigurationManager.AppSettings["sizeofImg"];
            Process pass = new Process();
            pass.StartInfo.FileName = fmpeg;
            pass.StartInfo.Arguments = "  -i  " + videoFileName + "  -y  -f  image2   -ss 2 -vframes 1 -s " + imgSize + " " + savePath;
            pass.Start();
        }

    }
}


 前台代码:
 

 

 

 


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

 

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Header.ascx.cs" Inherits="在线视频.Header" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<link href="CSS/Header.css" rel="stylesheet" />

<script src="JS/jquery-1.7.1.js"></script>

    <script type="text/javascript">

        function showDialog(url,width,height) {

            var opensettings = "toolbar=no,menubar=no,status=no,scrollbars=no,location=no,resizable=no,center=yes";

            //var modalsettings = "center=yes;";

            var left, top;

            left = (screen.width - width) / 2;

            top = (screen.height - height) / 2;

            // opensettings = opensettings + ",left=" + left + ",top=" + top+",screenx="+left+",screeny="+top;

           var modalsettings = opensettings + ",dialogLeft=" + left + ",dialogTop=" + top;

            var d = new Object("dd");

            // window.open(url,tarert,opensettings);

            window.showModalDialog(url, d, modalsettings);

        }

        window.onload = function () {

            if (localStorage.userName != null && localStorage.userName != "")

            {

                document.getElementById("notLogin").style.display ="none";

                document.getElementById("spUerName").innerHTML = localStorage.userName;

            }

        }

        $(function () {

            $("#Header_txtSearch").blur(function () {

                $.get("Ajax/selectVideoInfo.ashx", { "videoTitle": $("#Header_txtSearch").val() }, function (data, status) {

                    if (status == 'success') {

                        window.location.href = "videoShow.aspx?Id=" + data;

                    }

                    else {

                        alert("视频获取失败");

                    }

                });

            });

            $("#spUerName").mouseover(function () {

 

            });

   });

    </script>

<div class="divHead">

        <div class="divHeader">     

                <div class="divWeatherInfo" >

                    <span id="cityName">城市:</span> 

                    <span ><img id="weaPic" src="" alt="无法显示天气图片" /></span>

                    <span id="temp">温度:</span>

                    <span>| 空气质量:</span>

                    <span id="airQuality"></span>

                </div>

                <div class="divVideoSearch">

                    <asp:TextBox ID="txtSearch" runat="server" Height="29px" Width="200px" ></asp:TextBox>

                    <asp:AutoCompleteExtender ID="txtSearch_AutoCompleteExtender" runat="server" Enabled="True" ServicePath="~/WebService/videoSearch.asmx" TargetControlID="txtSearch" ServiceMethod="GetTextString" MinimumPrefixLength="1" >

                    </asp:AutoCompleteExtender>

                <asp:Button ID="btnSearch" runat="server" Text="搜索" BackColor="#FFECDF" BorderStyle="None" BorderWidth="0px" Font-Bold="True" Font-Italic="False" Font-Size="Large" ForeColor="#FF6E0C" Height="34px" OnClick="btnSearch_Click"  Width="70px"/>            

                </div>

                <div class="divUserInfo">

                    <span id="notLogin">

                    <a href="UserLogin.html" onclick="showDialog('UserLogin.html','200','150');return false;">登录</a>

                    <a href="UserRegister.aspx" target="_blank">注册</a></span>

                    <span id="spUerName" ><button id="userCan">退出</button></span>

                    <a href="videoUpLoad.aspx">上传</a>

                </div>

        </div>

    </div>

 

 

 


绿色通道: 好文要顶 关注我 收藏该文与我联系

 


弦断有谁听
 关注 - 1
 粉丝 - 1

 

+加关注


0

0


 (请您对文章做出评价)


上一篇:验证码
下一篇:单位值控件(服务端)开发(原创由郑健前辈所写)

 
posted @ 2014-02-15 10:21 弦断有谁听 阅读(118) 评论(0) 编辑 收藏
 

 

刷新评论刷新页面返回顶部
 

注册用户登录后才能发表评论,请 登录 或 注册,访问网站首页。
 
程序员找工作,就在博客园招聘频道
 
博客园首页博问新闻闪存程序员招聘知识库
 

 

 


最新IT新闻:
 · 诺基亚 MWC 2014 发布会直播预告,Nokia X 即将揭晓
 · 网络购火车票下月起将验证身份:防止黄牛囤票
 · 谷歌智能手表或6月I/O大会发布 由LG代工
 · Mozilla发三款Firefox OS新机:最低25美元
 · 创业者自述:选择正确VC的7个关键点
更多新闻...

最新知识库文章:

 · Node.js 究竟是什么?
 · Habya'a(临时拼凑的组件)与技术债务
 · 关于在线教育和线下教育的六个问题
 · 别错把需求当市场
 · 浏览器中关于事件的那点事儿

更多知识库文章...

 


公告


昵称:弦断有谁听
园龄:13天
粉丝:1
关注:1
+加关注
 

 

 

 

<

2014年2月

>

 


 

26

27

28

29

30

31

1

 

2

3

4

5

6

7

8

 

9

10

11

12

13

14

15

 

16

17

18

19

20

21

22

 

23

24

25

26

27

28

1

 

2

3

4

5

6

7

8

 

 

搜索
 
 
 
 
 

常用链接
 我的随笔
我的评论
我的参与
最新评论
我的标签
 


随笔档案
2014年2月 (3)


最新评论

 

阅读排行榜

1. 用户控件开发:(118)
2. 验证码(64)
3. 单位值控件(服务端)开发(原创由郑健前辈所写)(29)
 

评论排行榜

1. 验证码(0)
2. 用户控件开发:(0)
3. 单位值控件(服务端)开发(原创由郑健前辈所写)(0)
 

推荐排行榜
 

 


 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约