62,041
社区成员
发帖
与我相关
我的任务
分享
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.Web.Security;
using Socut.Data ;
namespace CHINAESL
{
/// <summary>
/// _default 的摘要说明。
/// </summary>
public class _default : System.Web.UI.Page
{
public CReader dr;//实例化DataReader阅读器的类
public CReader drLogin;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.TextBox TextBox6;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Button Button4;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.HtmlControls.HtmlTable T1;
protected System.Web.UI.HtmlControls.HtmlTable T2;
protected System.Web.UI.WebControls.RegularExpressionValidator name;
protected System.Web.UI.WebControls.RegularExpressionValidator key;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.TextBox TextBox5;
protected System.Web.UI.WebControls.RegularExpressionValidator tbox4;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
public CData myData=new CData ();//此类包含统计的过程
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
if(Session["UserName"]==null)
{
//如果用户未登陆
T2.Visible =false;//隐藏表格二
}
else if(Session["UserName"].ToString().Equals("worldlink"))//管理员登录
{
T1.Visible =false;//隐藏表格一
Label1.Text =Session["UserName"].ToString();//显示用户名
Button3.Visible=true;
}
else//如果登陆
{
T1.Visible =false;//隐藏表格一
Label1.Text =Session["UserName"].ToString();//显示用户名
}
}
}
public string GetList()
{
string strBody=null;//新闻主体
dr=new CReader ("SELECT TOP 50 * FROM socut_news ORDER BY n_time DESC");//提取前10条新闻
while(dr.Read ())//循环读取
{
strBody+="<a href='news/view.aspx?id="+dr["n_id"]+"' target=''>"+dr["n_title"]+"</a><br>";
}
dr.Close ();//切记一定要关闭阅读器
return strBody;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Button4.Click += new System.EventHandler(this.Button4_Click);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
string SHA1 =FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox2.Text,"MD5");
drLogin=new CReader("SELECT * FROM socut_user WHERE u_name='"+TextBox1.Text+"' AND u_pass='"+SHA1+"'");
if(drLogin.Read ())//如果用户名,密码都正确
{
Session["UserName"]=TextBox1.Text ;//生成用户的Session
Response.Redirect ("default.aspx");
}
else
{
Label2.Text ="Wrong username or password";
}
drLogin.Close ();//一切读取行为结束后,一定要关闭阅读器
}
public string GetCount()//得到统计
{
int intCount=(int)myData.GetExecuteScalar("SELECT COUNT(*) FROM socut_news",1);//统计行数,整型用1
return intCount.ToString ();
}
private void Button2_Click(object sender, System.EventArgs e)
{
Response.Redirect ("User/Reg.aspx");
}
private void Button3_Click(object sender, System.EventArgs e)
{
Response.Redirect("News/manage.aspx");
}
private void Button4_Click(object sender, System.EventArgs e)
{
string strID=System.Guid.NewGuid().ToString();//GUID编号ID
string strTime=System.DateTime.Now.ToString();//当前时间
myData.GetExecuteNonQuery("INSERT INTO socut_news (n_id,n_title,n_content,n_email,n_name,n_time) VALUES ('"+strID+"','"+TextBox3.Text.Replace("'","")+"','"+TextBox6.Text.Replace("'","").Replace("/n","<br>")+"','"+TextBox4.Text.Replace("'","")+"','"+TextBox5.Text+"','"+strTime+"')");
Response.Write("<script language=javascript>window.alert('Message posted!');window.location.href=('News/list.aspx');</script>");
}
}
}