📄 yhgl.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace cwgl.yjxm
{
public partial class yhgl : Form
{
public yhgl()
{
InitializeComponent();
}
SqlConnection con = new SqlConnection(global::cwgl.Properties.Settings.Default.cwglCon);
private void button1_Click(object sender, EventArgs e)
{
if (this.tabControl1.SelectedTab.Text == this.tabPage1.Text)
{
string user1 = this.textBox1.Text.ToString().Trim();
string psw11 = this.textBox2.Text.ToString().Trim();
string psw12 = this.textBox3.Text.ToString().Trim();
if (psw11 == psw12)
{
try
{
con.Open();
string sql = "insert into admin (users,password) values('" + user1 + "','" + psw11 + "')";
SqlCommand com = new SqlCommand(sql, con);
com.ExecuteNonQuery();
MessageBox.Show("用户添加成功!", "完成");
con.Close();
this.textBox1.Text = "";
this.textBox2.Text = "";
this.textBox3.Text = "";
this.Close();
}
catch (SqlException e1)
{
MessageBox.Show("用户已经存在,请重新输入!", "失败");
this.textBox1.Text = "";
this.textBox2.Text = "";
this.textBox3.Text = "";
}
finally
{
con.Close();
}
}
else
{
MessageBox.Show("两次输入密码不相同,请重新输入!", "错误");
this.textBox2.Text = "";
this.textBox3.Text = "";
}
}
else if (this.tabControl1.SelectedTab.Text == this.tabPage2.Text)
{
string user2 = this.textBox4.Text.ToString().Trim();
string psw21 = this.textBox5.Text.ToString().Trim();
string psw22 = this.textBox6.Text.ToString().Trim();
string psw23 = this.textBox7.Text.ToString().Trim();
if (psw22 == psw23)
{
try
{
con.Open();
string sql = "select * from admin";
SqlCommand com = new SqlCommand(sql, con);
SqlDataReader sdr = com.ExecuteReader();
sdr.Read();
if (Convert.ToString(sdr["password"]) == psw21 && Convert.ToString(sdr["users"]) == user2)
{
sdr.Close();
string sql1 = "update admin set password='" + psw22 + "' where users='"+user2+"' ";
SqlCommand com1 = new SqlCommand(sql1, con);
com1.ExecuteNonQuery();
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("用户密码修改成功!", "完成");
this.textBox4.Text = "";
this.textBox5.Text = "";
this.textBox6.Text = "";
this.textBox7.Text = "";
this.Close();
}
else if (Convert.ToString(sdr["users"]) != user2)
{
MessageBox.Show("用户不存在,请重新输入!", "失败");
this.textBox4.Text = "";
this.textBox5.Text = "";
this.textBox6.Text = "";
this.textBox7.Text = "";
}
else if(Convert.ToString(sdr["password"]) != psw21)
{
MessageBox.Show("旧密码错误,请重新输入!", "错误");
this.textBox5.Text = "";
}
}
catch (SqlException e1)
{
MessageBox.Show("用户不存在,请重新输入!", "失败");
this.textBox4.Text = "";
this.textBox5.Text = "";
this.textBox6.Text = "";
this.textBox7.Text = "";
}
finally
{
con.Close();
}
}
else
{
MessageBox.Show("两次输入密码不相同,请重新输入!", "错误");
this.textBox6.Text = "";
this.textBox7.Text = "";
}
}
else if (this.tabControl1.SelectedTab.Text == this.tabPage3.Text)
{
string user3 = this.textBox8.Text.ToString().Trim();
string psw31 = this.textBox9.Text.ToString().Trim();
string psw32 = this.textBox10.Text.ToString().Trim();
if (psw31 == psw32)
{
try
{
con.Open();
string sql = "DELETE FROM admin WHERE users ='" + user3 + "'";
SqlCommand com = new SqlCommand(sql, con);
com.ExecuteNonQuery();
MessageBox.Show("用户删除成功!", "完成");
con.Close();
this.textBox8.Text = "";
this.textBox9.Text = "";
this.textBox10.Text = "";
this.Close();
}
catch (SqlException e1)
{
MessageBox.Show("用户不存在,请重新输入!", "失败");
this.textBox8.Text = "";
this.textBox9.Text = "";
this.textBox10.Text = "";
}
finally
{
con.Close();
}
}
else
{
MessageBox.Show("两次输入密码不相同,请重新输入!", "错误");
this.textBox9.Text = "";
this.textBox10.Text = "";
}
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -