📄 user.aspx.cs
字号:
using System;
using System.IO;
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 WebApplication4
{
/// <summary>
/// wfrmflow 的摘要说明。
/// </summary>
public class wfrmflow : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.DropDownList DropDownList3;
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.Label Label5;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button4;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
TextBox2.Visible=false;
if(!this.IsPostBack)
{
string ss="server=localhost;uid=sa;password=123;database=factory";
SqlConnection myconn=new SqlConnection(ss);
string strsql="select name from login";
SqlCommand mycommand=new SqlCommand(strsql,myconn);
SqlDataReader rd=null;
myconn.Open();
rd=mycommand.ExecuteReader();
while(rd.Read())
{
DropDownList1.Items.Add( new ListItem(rd["name"].ToString()));
}
rd.Close();
myconn.Close();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button4.Click += new System.EventHandler(this.Button4_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string ss="server=localhost;uid=sa;password=123;database=factory";
SqlConnection myconn=new SqlConnection(ss);
string strsql="select * from login where name='"+DropDownList1.SelectedItem.Text.Trim()+"'";
SqlCommand mycommand=new SqlCommand(strsql,myconn);
SqlDataReader rd=null;
myconn.Open();
rd=mycommand.ExecuteReader();
while(rd.Read())
{
DropDownList2.SelectedValue=rd["location"].ToString().Trim();
DropDownList3.SelectedValue=rd["authority"].ToString().Trim();
TextBox1.Text=rd["pwd"].ToString().Trim();
}
rd.Close();
myconn.Close();
}
private void Button3_Click(object sender, System.EventArgs e)
{
Button3.Attributes.Add("onclick","alert('修改后不可恢复');return false;");
string ss="server=localhost;uid=sa;password=123;database=factory";
SqlConnection myconn=new SqlConnection(ss);
string strsql="update login set pwd='"+TextBox1.Text.Trim()+"',location='"+DropDownList2.SelectedItem.Text.Trim()+"',authority='"+DropDownList3.SelectedItem.Text.Trim()+"'where name='"+DropDownList1.SelectedItem.Text.Trim()+"'" ;
SqlCommand mycommand=new SqlCommand(strsql,myconn);
myconn.Open();
int rd=mycommand.ExecuteNonQuery();
if(rd==1) {Label5.Text="修改成功";}
else { Label5.Text="修改失败";}
myconn.Close();
}
private void Button4_Click(object sender, System.EventArgs e)
{
Label5.Visible=false;
}
private void Button2_Click(object sender, System.EventArgs e)
{
Button3.Attributes.Add("onclick,cancle","alert('删除后不可恢复');return false;");
string ss="server=localhost;uid=sa;password=123;database=factory";
SqlConnection myconn=new SqlConnection(ss);
string strsql="delete from login where name='"+DropDownList1.SelectedItem.Text.Trim()+"'" ;
string ls=""+DropDownList1.SelectedItem.Text.Trim()+"";
SqlCommand mycommand=new SqlCommand(strsql,myconn);
myconn.Open();
int rd=mycommand.ExecuteNonQuery();
if(rd==1) {Label5.Text="删除成功";}
else { Label5.Text="删除失败";}
myconn.Close();
}
private void Button1_Click(object sender, System.EventArgs e)
{
TextBox2.Visible=true;
Label5.Text="请输入";
try
{
if(TextBox2.Text.Trim()=="")
Label5.Text="用户名不能为空";
else
{
string ss="server=localhost;uid=sa;password=123;database=factory";
SqlConnection myconn=new SqlConnection(ss);
string strsql="select name from login where name='"+TextBox2.Text.Trim()+"'";
SqlCommand mycommand=new SqlCommand(strsql,myconn);
myconn.Open();
int rd=mycommand.ExecuteNonQuery();
if(rd==1) {Label5.Text="此用户已存在,用户名不能重复!";}
else
{ string strsql1="insert into login values('"+TextBox2.Text.Trim()+"','"+TextBox1.Text.Trim()+"','"+DropDownList3.SelectedItem.Text.Trim()+"','"+DropDownList2.SelectedItem.Text.Trim()+"')" ;
SqlCommand mycommand1=new SqlCommand(strsql1,myconn);
int rd1=mycommand1.ExecuteNonQuery();
if(rd1==1) {Label5.Text="新建成功,新用户请重新登录。重新点击用户管理可显示新用户信息!";}
else { Label5.Text="新建失败";}
}
myconn.Close();
}
}
catch(Exception ee)
{
throw new Exception(ee.Message);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -