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.SqlClient;

namespace free.admin
{
	/// <summary>
	/// Summary description for denglu.
	/// </summary>
	public class denglu : System.Web.UI.Page
	{
		protected System.Web.UI.HtmlControls.HtmlInputButton queding;
		protected System.Web.UI.HtmlControls.HtmlInputButton qingkong;
		protected System.Web.UI.WebControls.Label cuowu;
		protected System.Web.UI.HtmlControls.HtmlInputText yonghuming;
		protected System.Web.UI.HtmlControls.HtmlInputText yonghumima;
		protected System.Web.UI.WebControls.Label liu;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			cuowu.Visible=false;
		}


		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.queding.ServerClick += new System.EventHandler(this.queding_ServerClick);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void queding_ServerClick(object sender, System.EventArgs e)
		{
			if(yonghuming.Value=="")
			{
				cuowu.Visible=true;
				cuowu.Text="请输入您用户名";
			}
			else if(yonghumima.Value=="")
			{
				cuowu.Visible=true;
				cuowu.Text="请输入您的密码";
			}
			else
			{
				SqlConnection monn=new SqlConnection(Session["str_connection"].ToString());
				monn.Open();
				string mysql="select * from admin where yonghuming=@yonghuming and yonghumima=@yonghumima  ";
				SqlCommand mycommand=new SqlCommand(mysql,monn);
				mycommand.Parameters.Add(new SqlParameter("@yonghuming", SqlDbType.Char, 20));
				mycommand.Parameters["@yonghuming"].Value=yonghuming.Value.ToString();
				mycommand.Parameters.Add(new SqlParameter("@yonghumima", SqlDbType.Char, 20));
				mycommand.Parameters["@yonghumima"].Value=yonghumima.Value.ToString();
				try
				{
					SqlDataReader reader=mycommand.ExecuteReader();
					reader.Read();
					Session["free_quanxian"]=reader.GetString(2).ToString().Trim();
					Session["free_admin"]=reader.GetString(0).ToString().Trim();
					Response.Redirect("default.aspx");
					reader.Close();
					monn.Close();
				
//					else
//					{
						//cuowu.Visible=true;
						//cuowu.Text="您的密码输入有误！！";
						yonghumima.Value="";
//					}
				}
				catch
				{
					Response.Write("<script>alert('您无权使用！！')</script>");
				}
			}
		}
	}
}
