⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adminmanage.aspx.cs

📁 yi ge xue sheng cheng ji guan li xi tong de yuan ma .
💻 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.SqlClient;
namespace myResult
{
	/// <summary>
	/// adminmanage 的摘要说明。
	/// </summary>
	public class adminmanage : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox txtpwd;
		protected System.Web.UI.WebControls.DropDownList ddltype;
		protected System.Web.UI.WebControls.Button btninput;
		protected System.Web.UI.WebControls.TextBox txtuser;
		protected SqlConnection conn;
		protected System.Web.UI.WebControls.DataGrid dg_admin;
		protected SqlCommand myCmd;
		protected SqlDataAdapter myDa;
		protected System.Web.UI.WebControls.Button btndelete;
		protected System.Web.UI.WebControls.TextBox txtpwdRepeat;
		protected System.Web.UI.WebControls.CompareValidator cvpwd;
		protected System.Web.UI.WebControls.RegularExpressionValidator revpwd;
		protected System.Web.UI.WebControls.ValidationSummary vsShow;
		protected System.Web.UI.WebControls.RegularExpressionValidator revuser;
		protected System.Web.UI.WebControls.CustomValidator cuvuser;
		protected DataSet ds;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(Session["Auser"]==null)
			{
				Response.Redirect("adminlogin.aspx");
			}
			else
			{
				string str_type=Session["admintype"].ToString();
				if(str_type=="普通管理员")
				{
					Page.RegisterClientScriptBlock("show","<script>alert('你没有这个权限!');history.go(-1);</script>");
				}
				else
				{
					if(!Page.IsPostBack)
					{
						this.BindDg();
						this.btndelete.Attributes.Add("onclick","if(confirm('你确定要删除吗?'))return true;else return false;");
					}
				}
			}
		}
		private void ExecuteInsert()
		{
			string str_user=this.txtuser.Text.Trim().Replace("'","''");
			string str_pwd=this.txtpwd.Text.Trim().Replace("'","''");
			string str_pwdMD5=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str_pwd,"MD5").ToString();//加密后
			string str_type=this.ddltype.SelectedValue.ToString();
			conn=connDB.createConn();
			conn.Open();
			myCmd=new SqlCommand("procAdmin",conn);
			myCmd.CommandType=CommandType.StoredProcedure;
			myCmd.Parameters.Add("@Auser",SqlDbType.VarChar,50);
			myCmd.Parameters.Add("@Apwd",SqlDbType.VarChar,50);
			myCmd.Parameters.Add("@Atype",SqlDbType.VarChar,20);
			myCmd.Parameters["@Auser"].Value=str_user;
			myCmd.Parameters["@Apwd"].Value=str_pwdMD5;
			myCmd.Parameters["@Atype"].Value=str_type;
			if(ddltype.SelectedIndex<1)
			{
				Page.RegisterStartupScript("type","<script>alert('请选择用户类型!');</script>");
			}
			else
			{
				myCmd.ExecuteNonQuery();
			conn.Close();
			string Dhtmlalert="";
			Dhtmlalert += "<script language=javascript>";
			Dhtmlalert += "alert('添加成功!');";
			Dhtmlalert += "</script>";
			Page.RegisterStartupScript("alert_news",Dhtmlalert);
				}
		}
		private void BindDg()
		{
			conn=connDB.createConn();
			string str_sel="select AdminId,Users,AdminType from AdminInfo";
			myDa=new SqlDataAdapter(str_sel,conn);
			ds=new DataSet();
			myDa.Fill(ds,"AdminInfo");
			dg_admin.DataSource=ds.Tables["AdminInfo"].DefaultView;
			dg_admin.DataKeyField="AdminId";
			dg_admin.DataBind();
		}
		public void CheckAll(object sender,System.EventArgs e)
		{
			CheckBox chball=(CheckBox)sender;
			if(chball.Text=="全选")
			{
				foreach(DataGridItem dg in dg_admin.Items)
				{
					CheckBox cb=(CheckBox)dg.FindControl("chb");
					cb.Checked=chball.Checked;
				}
			}
		}

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

		}
		#endregion

		private void btninput_Click(object sender, System.EventArgs e)
		{
			if(this.txtuser.Text==""||this.txtpwd.Text=="")
			{
				Page.RegisterStartupScript("show_message","<script language='javascript'>alert('用户名和密码不能为空!');</script>");
			}
			else
			{
				this.ExecuteInsert();
				this.BindDg();
			}
		}

		private void btndelete_Click(object sender, System.EventArgs e)
		{
			if(this.IsValid)
			{
				foreach(DataGridItem dg in this.dg_admin.Items)
				{
					CheckBox chb=(CheckBox)dg.FindControl("chb");
					if(chb.Checked)
					{
						string str_id=this.dg_admin.DataKeys[dg.ItemIndex].ToString();//获得该行ID
						string str_del="delete from AdminInfo where AdminId="+str_id;
						data.ExecuteDel(str_del);
					}
				}
				this.dg_admin.CurrentPageIndex=0;
				this.BindDg();
			}
		}

		private void cuvuser_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
		{
			string str_user=args.Value;
			string str_sel="select count(Users) from AdminInfo where Users='"+str_user+"'";
			int count=data.ExecuteSel(str_sel);
			if(count>0)//用户已存在
			{
				args.IsValid=false;
			}
			else
			{
				args.IsValid=true;
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -