当前位置:文档之家› 用户管理信息系统

用户管理信息系统


加“TextBox”,对其属性“Name”分别修改
为“userID”,“Pass1”“Pass2” 3. 对该窗体依次添加公共控件“Button”,分别逐级命名为“确定”“取
消” 4. 对窗体中所有控件,调整布局,美观整洁。 代码编写如下
using System.Data.SqlClient;
namespace WindowsApplication1 {
namespace WindowsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) {
{ FormNewuser frm = new FormNewuser(); frm.ShowDialog(); Form1_Load(sender, e);
}
sender,
private void 修改密码ToolStripMenuItem_Click(object EventArgs e)
{ FormUpdate frm = new FormUpdate(); frm.ShowDialog(); Form1_Load(sender, e);
一、主窗体:
1. 运行C#编译环境,新建Windows运行程序项目,名称暂时不做修 改。
2. 在窗体设计属性里面更改窗体的属性“Text”为“用户管理信息系 统”。
3. 在主窗体上添加菜单和工具栏“MenuStrip”,为此菜单添加菜单 主项“用户管理(&A)”,添加菜单子项“新建用户”,“修改密 码”,“删除用户”。
SqlConnection conn = new SqlConnection(scsb.ConnectionString); conn.Open();
SqlCommand cmd = conn.CreateCommand(); mandText = string.Format("select count(*) from Tuser where 用户名='{0}' and 密码='{1}'",
4. 为主窗体添加数据控件“DataGridView”,修改它的属性“Dock”为 填充整个窗体剩余空间,对数据控 件“DataGridView”的“ScrollBars”属性设置为“Both”,增加滚动 条。
5. 在完成二、三、四添加附窗体后进行代码编写 编码如下:
using System.Data.SqlClient;
public partial class FormNewuser : Form {
public FormNewuser() {
InitializeComponent(); }
private void button2_Click(object sender, EventArgs e) {
this.Close(); }
}
二、添加Newuser窗体
1在解决方案资源管理器“WindowsApplication1”右键单击“添
加”—“windows窗体”,名称修改为“FormNewuser.cs”
2. 对该窗体依次添加公共控件“Lable”标签,对其属性“Text”并分别逐
级命名为“用户名”,“密码”,“确认密码”,并为“Lable”对应添
} } }
三、添加Update窗体
1. 在解决方案资源管理器“WindowsApplication1”右键单击“添 加”—“windows窗体”,名称修改为“FormUpdate.cs”,对窗体的属 性“MaximizeBox”设置为False
2. 对该窗体依次添加公共控件“Lable”标签,对其属性“Text”并分别逐 级命名为“用户名”,“原密码”,“新密码”,“确认密码”,并 为“Lable”对应添加“TextBox”,对其属性“Name”分别修改
this.textBoxPass1.Focus(); return; } SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder(); scsb.DataSource = "."; scsb.InitialCatalog = "stuDB"; scsb.IntegratedSecurity = true; SqlConnection conn = new SqlConnection(scsb.ConnectionString); conn.Open(); SqlCommand cmd = conn.CreateCommand(); mandText = string.Format("insert into Tuser values('{0}','{1}')", this.textBoxuserID.Text.Trim(), this.textBoxPass1.Text); try { cmd.ExecuteNonQuery(); } catch { MessageBox.Show("新建用户失败"); this.textBoxuserID.Focus(); conn.Close(); return; } conn.Close(); MessageBox.Show("新建用户成功");
mandText = string.Format("update Tuser set 密码='{0}' where 用户名='{1}'",
this.textBoxNewPass1.Text,this.textBoxuserID.Text.Trim());
try { cmd.ExecuteNonQuery(); } catch {
if (this.textBoxuserID.Text.Trim() == "") {
MessageBox.Show("请输入用户名"); this.textBoxuserID.Focus(); return; } if (this.textBoxOldPass.Text.Trim() == "") { MessageBox.Show("请输入用户原密码"); this.textBoxOldPass.Focus(); return; } if (this.textBoxNewPass1.Text.Trim() == "") { MessageBox.Show("请输入新密码密码"); this.textBoxNewPass1.Focus();
}
sender,
private void 删除用户ToolStripMenuItem_CliΒιβλιοθήκη k(objectsender,
EventArgs e)
{
FormDelete frm = new FormDelete();
frm.ShowDialog();
Form1_Load(sender, e);
}
}
MessageBox.Show("修改失败"); this.textBoxuserID.Focus(); conn.Close(); return; } conn.Close(); MessageBox.Show("修改成功"); } } }
四、添加Delete窗体
1. 在解决方案资源管理器“WindowsApplication1”右键单击“添 加”—“windows窗体”,名称修改为“FormDelete.cs”,对窗体的属 性“MaximizeBox”设置为False
代码编写如下
using System.Data.SqlClient;
return; } if (this.textBoxNewPass1.Text != this.textBoxNewPass2.Text) {
MessageBox.Show("新密码与确认密码不一致,请核查"); this.textBoxNewPass1.Focus(); return; } SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder(); scsb.DataSource = "."; scsb.InitialCatalog = "stuDB"; scsb.IntegratedSecurity = true;
private void button1_Click(object sender, EventArgs e) {
if (this.textBoxuserID.Text.Trim() == "") {
MessageBox.Show("请输入用户名"); this.textBoxuserID.Focus(); return; } if (this.textBoxPass1.Text.Trim() == "") { MessageBox.Show("请输入密码"); this.textBoxPass1.Focus(); return; } if (this.textBoxPass1.Text != this.textBoxPass2.Text) { MessageBox.Show("两次输入密码不一致,请核查");
DataSet ds = new DataSet(); sda.Fill(ds); this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
相关主题