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;

namespace DTable_App.admin
{
	/// <summary>
	/// Admin_login 的摘要说明。
	/// </summary>
	public class Admin_login : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox Admin_User;
		protected System.Web.UI.WebControls.TextBox Admin_Pw;
		protected System.Web.UI.WebControls.TextBox Admin_yzm;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Label L_yzm;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!Page.IsPostBack)
			{
                string stryzm=sharecode.GetRndPassword(6);
				L_yzm.Text=stryzm;
				System.Web.HttpContext.Current.Session["Admin_yzm"]=stryzm;
			}

		}

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

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
		    string stryhm=Admin_User.Text;
			string strpw=Admin_Pw.Text;
			string stryzm=Admin_yzm.Text;
			string strthisyzm=sharecode.GetSessionValue("Admin_yzm");
			if(stryzm!=strthisyzm)
			{
				sharecode.OutMsgBox("验证码没有通过,请重新刷新页面再登录",true);
			}
			stryhm=stryhm.Replace("'","").Replace("--","").Replace(";","").Replace(" ","");
			strpw=strpw.Replace("'","").Replace("--","").Replace(";","").Replace(" ","");


			if(stryhm.Length<5 || stryhm.Length>25)
			{
				sharecode.OutMsgBox("请重新输入用户名",true);
			}
			if(strpw.Length<5 || strpw.Length>25)
			{
				sharecode.OutMsgBox("请重新输入密码",true);

			}
			//开始验证用户名密码
			if(!sharecode.CheckAdminLogin(stryhm,strpw))
			{
                 sharecode.OutMsgBox("用户名或密码没有通过验证",true);
			}
		//	Page.Response.Write("<script language=javascript>window.open('left.aspx','leftFrame','');</script>登录成功,请选择左侧管理项.");
			System.Web.HttpContext.Current.Session["Admin_yzm"]=null;

			Page.Response.Write("<script language=javascript>top.leftFrame.document.location.replace('left.aspx');alert('登录成功,请选择左侧管理项');</script>");
			Page.Response.End();


		}
	}
}
