欢迎大家访问我的BLOG,我会多多的出原创文章,希望大家支持我,为我祈祷,让我实现我的三个梦想!再30岁能成为一个名优秀的软件架构师!

网络电视Default.aspx

  1using System;
  2using System.Collections;
  3using System.ComponentModel;
  4using System.Data;
  5using System.Data.SqlClient;
  6using System.Drawing;
  7using System.Web;
  8using System.Web.SessionState;
  9using System.Web.UI;
 10using System.Web.UI.WebControls;
 11using System.Web.UI.HtmlControls;
 12using JJS_BMT;
 13using System.IO;
 14using System.Configuration;
 15
 16namespace JJS_OMT
 17{
 18    /// <summary>
 19    /// _Default 的摘要说明。
 20    /// </summary>

 21    public class _Default : System.Web.UI.Page
 22    {
 23        protected System.Web.UI.HtmlControls.HtmlTableCell Nav;//小类导航容器
 24        protected System.Web.UI.HtmlControls.HtmlTableCell TvList;//网络电视列表容器
 25        NetTVFunction Fun=new NetTVFunction();
 26        int BTypeID,STypeID;
 27        string strKey=null;//初始化关键字
 28        string condition=String.Empty;//初始化条件
 29        protected System.Web.UI.HtmlControls.HtmlTableCell TVSearch;//搜索容器
 30        int TotalNumber1;//总记录条数(不包括会员登陆后个性定制的总记录条数)
 31        int TotalNumber2;//总记录条数(个性定制的记录条数)
 32        int Rows,PagerIndex1,PagerIndex2;//PagerIndex1:页次(不包括会员登陆后个性定制的页次),PagerIndex2:页次(个性定制的页次)
 33        protected System.Web.UI.HtmlControls.HtmlTableCell Pager;//分页控件容器
 34        protected System.Web.UI.HtmlControls.HtmlTableCell TypeNav;//大类导航容器
 35    
 36        private void Page_Load(object sender, System.EventArgs e)
 37        {
 38            // 在此处放置用户代码以初始化页面
 39            PagerIndex1=(Request.Params["page"]==null)?1:Convert.ToInt32(Request.Params["page"]);//得到当前页次,如果为空的话,则默认1
 40            Rows=15;//******在这里设置网络电视列表每页显示的记录数******
 41            BTypeID=(Request.Params["BTypeID"]==null)?1:Convert.ToInt32(Request.Params["BTypeID"]);//得到大类id,如果为空的话,则默认为1
 42            STypeID=(Request.Params["STypeID"]==null)?1:Convert.ToInt32(Request.Params["STypeID"]);//得到小类id,如果为空的话,则默认为1
 43            strKey=(Request.Params["key1"]==null)?String.Empty:Request.Params["key1"].Trim();//得到关键字,如果为空的话,默认为空字符串
 44            if(Request.Params["key1"]!=null&&Request.Params["key1"]!=String.Empty)//如果搜索引擎
 45            {
 46                condition="(charindex("+"\'"+strKey+"\'"+" ,a.fChannelName)<>0)";//初始化附加条件
 47                STypeID=0;//大类ID设为0
 48            }

 49            if(Request.Params["Fun"]!=null&&Request.Params["Fun"].Trim()=="Logout")//如果会员注销,登出
 50            {
 51                Fun.SetSesionEmpty();//调用清空Session函数
 52            }

 53                SetCollection();//当会员用户登陆之后,单击定制,后调用,第一把定制的数据写入数据库,第二判断用户是否重复订制某条频道
 54                string url="Default.aspx?BTypeID="+BTypeID+"&STypeID="+STypeID+"&key1="+strKey;//当前URL
 55                string strNav=Fun.GetRadioNav(BTypeID,STypeID,url+"&page="+PagerIndex1);//得到小类构造HTML,后面加上&page="+PagerIndex1,是为了当用户定制频道,提交表单不会回到第一页,而是保持在当前页次
 56                string strTvList=Fun.GetTVList(BTypeID,STypeID,condition,ref TotalNumber1,ref PagerIndex1,Rows);//得到网络电视列表构造HTML
 57                string strTVSearhc=Fun.GetTVSearch();//得到搜索构造HMTL
 58                string strTypeNav=Fun.GetTypeNav(BTypeID);//得到大类构造HTML
 59                string strPager=Fun.GetTVPager(url,ref PagerIndex1,TotalNumber1,Rows,true,true,"");//得到分页控件构造THML
 60                TVSearch.Controls.Add(new LiteralControl(strTVSearhc));
 61                TypeNav.Controls.Add(new LiteralControl(strTypeNav));
 62                if(BTypeID==3)//如果用户单击个性定制
 63                {
 64                    if(Session["UserID"]!=null)//用户已经登陆会员
 65                    {
 66                        PagerIndex2=(Request.Params["page"]==null)?1:Convert.ToInt32(Request.Params["page"]);                        
 67                        string strUserMess=Fun.SetTotalCollect();
 68                        string strTvList2=Fun.GetCollectList(ref TotalNumber2,ref PagerIndex2,Rows);
 69                        string strPager2=Fun.GetTVPager(url,ref PagerIndex2,TotalNumber2,Rows,true,true,"");
 70                        Nav.Controls.Add(new LiteralControl(strUserMess));
 71                        TvList.Controls.Add(new LiteralControl(strTvList2));
 72                        Pager.Controls.Add(new LiteralControl(strPager2));
 73                    }

 74                    else//用户没有登陆
 75                    {
 76                        Response.Write("<script language='javascript'>alert('请先登陆!');history.go(-1);</script>");
 77                    }

 78                }

 79                else
 80                {
 81                    Nav.Controls.Add(new LiteralControl(strNav));
 82                    TvList.Controls.Add(new LiteralControl(strTvList));
 83                    Pager.Controls.Add(new LiteralControl(strPager));
 84                }

 85        }

 86
 87        /// <summary>
 88        /// 用户个性定制频道
 89        /// </summary>

 90        public void SetCollection()
 91        {
 92            if(Request.Params["Check_Sel"]!=null)
 93            {
 94                string s=(Request.Params["Check_Sel"]);
 95                string[] s1=s.Split(',');
 96                string connStr=ConfigurationSettings.AppSettings["connStr"];
 97                SqlConnection conn=new SqlConnection(connStr);
 98                for(int i=0;i<s1.Length;i++)
 99                {
100                    string strSql="select count(*) from TV_Collection a INNER JOIN TV_User b ON a.UserID = b.UserID where a.fCannelId="+Convert.ToInt32(s1[i])+" and a.UserID='"+Session["UserId"].ToString()+"'";
101                    SqlCommand comm=new SqlCommand(strSql,conn);
102                    conn.Open();
103                    int count=Convert.ToInt32(comm.ExecuteScalar());
104                    conn.Close();
105                    if(count!=0)
106                    {
107                        Response.Write("<script language='javascript'>alert('你已经定制过这个频道!');history.go(-1);</script>");
108                        return;
109                    }

110                    strSql="insert into TV_Collection (UserID,fCannelId,AddDate) values(@UserID,@fCannelId,@AddDate)";
111                    comm=new SqlCommand(strSql,conn);
112                    comm.Parameters.Add("@UserID",SqlDbType.VarChar,18);
113                    comm.Parameters.Add("@fCannelId",SqlDbType.Int);
114                    comm.Parameters.Add("@AddDate",SqlDbType.DateTime);
115                    comm.Parameters["@UserID"].Value=Session["UserId"].ToString();
116                    comm.Parameters["@fCannelId"].Value=Convert.ToInt32(s1[i]);
117                    comm.Parameters["@AddDate"].Value=DateTime.Now;
118                    conn.Open();
119                    comm.ExecuteNonQuery();
120                    conn.Close();
121                }

122            }

123        }

124
125        Web 窗体设计器生成的代码
144    }

145}

146

posted on 2006-07-12 10:29  程序缘  阅读(486)  评论(0)    收藏  举报

导航