namespace temp
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using System.Data.SqlClient;
	using System.Configuration;
    

	/// <summary>
	///		WebUserControl1 的摘要说明。
	/// </summary>
	public partial class WebUserControl1 : System.Web.UI.UserControl
	{

		protected void Page_Load(object sender, System.EventArgs e)
		{
			

			// 在此处放置用户代码以初始化页面
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		设计器支持所需的方法 - 不要使用代码编辑器
		///		修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{

		}
		#endregion

	
		#region//登录按钮
		protected void Button1_Click(object sender, System.EventArgs e)
		{
			SB.ADOHelper help=new SB.ADOHelper();
			 string username=this.userid.Text.ToString();
		    DateTime dt=DateTime.Now;
			string ip=Request.UserHostAddress.ToString();
			string url=Request.Url.ToString();
			string errorlog="登录失败!";
			string accesslog="登录成功!";
			SqlDataReader read=help.getReader("Select UserName,Role from SystemUser where UserName='"+SB.ADOHelper.inputText(this.userid.Text.Trim())+"' and PassWord='"+SB.ADOHelper.Encrypt(this.userpwd.Text)+"'");
			if(read.Read())
			{
				this.Session["USERNAME"]=read["UserName"].ToString();
				this.Session["ROLE"]=read["Role"].ToString();
				read.Close();
				help.execSql("insert into FinanceLogin(Affairs,AffairsType,UserName,DataAndTime,ip,webPage,Remarks) values('3','登录','"+username+"','"+dt.ToString()+"','"+ip+"','"+url+"','"+accesslog+"')");
                help.execSql("update SystemUser set Register='" + dt.ToString() + "', RegisterIp='" + ip + "' where UserName='" + SB.ADOHelper.inputText(this.userid.Text.Trim()) + "'");
                if (help.conn.State == ConnectionState.Open)
                { help.conn.Close(); }
				Response.Redirect("main.aspx");
			}
			else
			{
				read.Close();
                Response.Write("<script>alert(\"用户名或密码有误！\")</script>");
				help.execSql("insert into FinanceLogin(AffairsType,UserName,DataAndTime,ip,webPage,Remarks) values('登录','"+SB.ADOHelper.inputText(username)+"','"+dt.ToString()+"','"+ip+"','"+url+"','"+errorlog+"')");
                if (help.conn.State == ConnectionState.Open)
                { help.conn.Close(); }
			}
          
		}
		#endregion

        #region//取消按扭
	
		protected void Button2_Click(object sender, System.EventArgs e)
		{
			this.userid.Text="";
			this.userpwd.Text="";
		}
      #endregion 
	}
}
