📄 index.aspx.cs
字号:
using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Data.OleDb;namespace Lb_news{ /// <summary> /// index 的摘要说明。 /// </summary> public class index : System.Web.UI.Page { //protected System.Web.UI.WebControls.DataGrid dg; protected System.Web.UI.WebControls.DropDownList ddl_className; protected string Lb_title; protected Conn ds1=new Conn(); protected UrlFormat urlFormat=new UrlFormat(); protected System.Web.UI.HtmlControls.HtmlInputImage Image1; protected int i=0; protected int j=0; protected System.Web.UI.WebControls.Button Submit; protected string ClassId; protected System.Web.UI.HtmlControls.HtmlInputButton Submit1; protected System.Web.UI.HtmlControls.HtmlInputText username; protected System.Web.UI.HtmlControls.HtmlInputText password; protected System.Web.UI.WebControls.DropDownList LoginTime; protected System.Web.UI.HtmlControls.HtmlInputButton Submit2; protected System.Web.UI.WebControls.TextBox keyWord; protected string LbUserName; protected string LbUserGrade; protected string Lb_scriptCode; protected string Lb_scriptName; protected OleDbDataReader rd; protected DataSet ds; private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if (Request.Cookies["UserInfo"]!=null) { HttpCookie cookie=Request.Cookies["UserInfo"]; LbUserName=cookie.Values["username"].ToString(); LbUserGrade=cookie.Values["grade"].ToString(); } if (!Page.IsPostBack) { Submit.Attributes.Add("OnClick", "return checkSearchEmpty();"); Submit1.Attributes.Add("OnClick", "return checkLoginEmpty();"); Lb_Stup(); Listddl_className(); } } private void Lb_Stup() { ds1.DBopen(); rd=ds1.ExecuteOleDbDataReader("select * from Lb_Setup"); if (rd.HasRows) { rd.Read(); Lb_title=rd.GetString(1); Lb_scriptName=(string)rd["S_ScriptName"]; Lb_scriptCode=(string)rd["S_ScriptCode"]; rd.Close(); } else { Response.Write ("暂时没有记录"); } ds1.DBclose(); } public void leftViewClass() { ds1.DBopen(); rd=ds1.ExecuteOleDbDataReader("select * from Lb_Class"); if (rd.HasRows) { Response.Write ("<tr>"); while(rd.Read()) { Response.Write ("<TD><IMG height=11 src='pic/index_left1.gif' width=11 border=0><a href="+urlFormat.ClassUrl(rd.GetInt32(0))+">"+rd.GetString(1)+"</a></TD>"); i=i+1; if (i%2==0) { Response.Write ("</tr><tr>"); } } Response.Write ("</tr>"); rd.Close(); } else { Response.Write ("暂时没有记录"); } ds1.DBclose(); } private void Listddl_className() { ds1.DBopen(); ds=ds1.CreateDataSet("select * from Lb_Class","Lb_class"); ddl_className.DataSource=ds; ddl_className.DataTextField="C_Name"; ddl_className.DataValueField="C_Id"; ddl_className.DataBind(); ListItem all=new ListItem("全部","");//增加一个空白项,并使之位于首位。 ddl_className.Items.Insert(0,all); ds1.DBclose(); } public void list_picNews() { ds1.DBopen(); rd=ds1.ExecuteOleDbDataReader("select top 8 * from Lb_news where n_check=1 and n_ispic=1 order by n_date desc"); if (rd.HasRows) { while(rd.Read()) { Response.Write ("<TD vAlign='top' width='1'><TABLE cellSpacing=0 cellPadding=0 width='100%' border='0'>"); Response.Write ("<TBODY><TR><TD width='100%'><P align='center'><TABLE borderColor='#111111' cellSpacing='0' cellPadding='0' border='0' >"); Response.Write("<TBODY><TR><TD width=5 height=5><IMG src='pic/k1_1.gif' border=0></TD><TD background='pic/k1_top.gif' height=2></TD><TD width=5 height=5><IMG src='pic/k1_2.gif' border=0></TD></TR>"); Response.Write("<TR><TD width=5 background='pic/k1_left.gif'></TD><TD align='center'><TABLE border='0'><TBODY><TR>"); Response.Write("<TD align='center'><A href='"+urlFormat.NewsUrl(rd.GetInt32(0))+"' target='_blank'><IMG height='100' alt='"+rd["n_title"]+"' src='"+rd["n_spic"]+"' width='120' border='0'></A>"); Response.Write("</TD></TR></TBODY></TABLE></TD><TD width='5' background='pic/k1_right.gif'></TD></TR><TR>"); Response.Write("<TD noWrap width='5' height='5'><IMG src='pic/k1_3.gif' border=0></TD><TD noWrap background='pic/k1_end.gif' height=5></TD>"); Response.Write("<TD noWrap width=5 height=5><IMG src='pic/k1_4.gif' border=0></TD></TR></TBODY></TABLE></P></TD></TR></TBODY></TABLE></P></TD>"); } rd.Close(); } else { Response.Write ("暂时没有记录"); } ds1.DBclose(); } public void list_hot() { ds1.DBopen(); rd=ds1.ExecuteOleDbDataReader("select top 8 * from Lb_news where n_check=1 order by n_hit desc"); if (rd.HasRows) { while(rd.Read()) { Response.Write ("·<a href='"+urlFormat.NewsUrl(rd.GetInt32(0))+"' target='_blank'>"+rd["n_title"]+"</a><br>"); } rd.Close(); } else { Response.Write ("暂时没有记录"); } ds1.DBclose(); } public void list_board() { ds1.DBopen(); rd=ds1.ExecuteOleDbDataReader("select S_Board from Lb_Setup"); if (rd.HasRows) { rd.Read(); Response.Write (rd.GetString(0)); rd.Close(); } else { Response.Write ("暂时没有记录"); } ds1.DBclose(); } public void list_link() { ds1.DBopen(); rd=ds1.ExecuteOleDbDataReader("select * from Lb_Links"); if (rd.HasRows) { Response.Write ("<tr>"); while(rd.Read()) { Response.Write ("<TD> <a href='"+rd.GetString(3)+"' target='_blank'><img width='88' border='0' height='31' src='"+rd.GetString(1)+"' alt='"+rd.GetString(2)+"'></a></TD>"); j=j+1; if (j%5==0) { Response.Write ("</tr><tr>"); } } Response.Write ("</tr>"); rd.Close(); } else { Response.Write ("暂时没有记录"); } ds1.DBclose(); } public void list_commend() { ds1.DBopen(); rd=ds1.ExecuteOleDbDataReader("select top 8 * from Lb_news where n_check=1 and n_commend=1 order by n_date desc"); if (rd.HasRows) { while(rd.Read()) { Response.Write ("·<a href='"+urlFormat.NewsUrl(rd.GetInt32(0))+"' target='_blank'>"+rd.GetString(5)+"</a><br>"); } rd.Close(); } else { Response.Write ("暂时没有记录"); } ds1.DBclose(); } public void list_news() { ds1.DBopen(); rd=ds1.ExecuteOleDbDataReader("select top 8 * from Lb_news where n_check=1 order by n_date desc"); if (rd.HasRows) { while(rd.Read()) { Response.Write ("·<a href='"+urlFormat.NewsUrl(rd.GetInt32(0))+"'target='_blank'>"+rd.GetString(5)+"</a><br>"); } rd.Close(); } else { Response.Write ("暂时没有记录"); } ds1.DBclose(); } public void list_index() { string sql1="SELECT * FROM Lb_Class"; OleDbDataAdapter cmd1=new OleDbDataAdapter(sql1,ds1.Lb_Conn); ds1.DBopen(); DataSet ds=new DataSet(); cmd1.Fill(ds,"lbClass"); string sql2="select * from Lb_News where n_check=1 and n_index=1 order by n_date desc"; OleDbDataAdapter cmd2=new OleDbDataAdapter(sql2,ds1.Lb_Conn); cmd2.Fill(ds,"lbNews"); ds.Relations.Add("myrelation",ds.Tables["lbClass"].Columns["C_Id"] ,ds.Tables["lbNews"].Columns["n_cid"]); /* --------第二种写法:foreach---------------*/ //bool BreakTrue=false; foreach ( DataRow parent in ds.Tables["lbClass"].Rows) { DataRow[] children=parent.GetChildRows("myrelation"); if (children.Length!=0) { goto DispTrue; } else { // BreakTrue=true; continue; } DispTrue: { Response.Write ("<TABLE cellSpacing='0' cellPadding=0 width='100%'><TBODY><TR>"); Response.Write ("<TD class='lframe-t-left'></TD><TD class='lframe-t-mid'><SPAN class='lframe-t-text'>"+parent["C_Name"]+"</SPAN></TD><TD class='lframe-t-right'></TD>"); Response.Write ("</TR></TBODY></TABLE>"); for(int i=0;i<children.Length && i<5; i++ ) { Response.Write ("<TABLE cellSpacing=0 cellPadding=0 width='100%'><TBODY><TR><TD class='mframe-m-left'></TD><TD class='mframe-m-mid'><TABLE cellSpacing=0 cellPadding=2 width='100%' border='0'><TBODY><tr>"); Response.Write ("<td>·<a href='"+urlFormat.NewsUrl(ds1.ChangeToInt(children[i]["n_id"].ToString()))+"' target='_blank'>"+children[i]["n_title"]+"</a>"+"</td>"); Response.Write ("</tr></TBODY></TABLE></TD><TD class='mframe-m-right'></TD></TR></TBODY></TABLE>"); } } } ds1.DBclose(); } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Submit.Click += new System.EventHandler(this.Submit_Click); this.Submit1.ServerClick += new System.EventHandler(this.Submit1_ServerClick); this.Submit2.ServerClick += new System.EventHandler(this.Submit2_ServerClick); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Submit_Click(object sender, System.EventArgs e) { string Key=keyWord.Text.Trim(); ClassId=ddl_className.SelectedItem.Value.Trim(); Response.Redirect ("search.aspx?classid="+ClassId+"&key="+Key+""); } private void Submit1_ServerClick(object sender, System.EventArgs e) { string ExpireTime=LoginTime.SelectedItem.Value.ToString(); string UserName=username.Value.ToString(); string PassWord=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password.Value.ToString(), "MD5"); ds1.DBopen(); rd=ds1.ExecuteOleDbDataReader("select * from Lb_Admin where A_Name='"+UserName+"' and A_Password='"+PassWord+"'"); if(rd.Read()==true) { if (ExpireTime=="1") { HttpCookie MyCookies; MyCookies=new HttpCookie("UserInfo"); MyCookies.Values.Add("username",rd.GetString(1).ToString()); MyCookies.Values.Add("grade",rd["A_Grade"].ToString()); Response.AppendCookie(MyCookies); } else { HttpCookie MyCookies; MyCookies=new HttpCookie("UserInfo"); MyCookies.Values.Add("username",rd.GetString(1).ToString()); MyCookies.Values.Add("grade",rd["A_Grade"].ToString()); MyCookies.Expires=DateTime.MaxValue; Response.AppendCookie(MyCookies); } Response.Redirect ("index.aspx"); } else { ds1.alert("用户名或者密码错误","index.aspx"); } rd.Close(); ds1.DBclose(); } private void Submit2_ServerClick(object sender, System.EventArgs e) { if (Request.Cookies["UserInfo"]==null) { Response.Redirect("index.aspx"); } else { HttpCookie cookie2=Request.Cookies["UserInfo"]; cookie2.Expires=DateTime.Now.AddDays(-10); Response.Cookies.Add(cookie2); Response.Redirect ("index.aspx"); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -