📄 addemployee.cs
字号:
this.Text = "对员工操作";
this.Load += new System.EventHandler(this.addemploee_Load);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
string constr = "Data Source = (local);"+
"Integrated Security = SSPI;"+
"Initial Catalog = "+"资产管理";
if (this.textBox1.Text.Trim() == "")
{
MessageBox.Show("员工号不能为空!");
this.textBox1.Focus();
}
else
{
string s1 = this.textBox1.Text.Trim();
if (s1[0]!='a'&&s1[0]!= 'b'&&s1[0] != 'c'&&s1[0] != 'A'&&s1[0] != 'B'&&s1[0] != 'C')
{
MessageBox.Show("添加管理员以a或A开头,财务员以b或B开头,维护员以c或C开头,长度为八位");
this.textBox1.Text = "";
this.textBox1.Focus();
}
else
{
if (textBox1.Text.Length == 8)
{
if (this.textBox3.Text.Trim() == "")
{
MessageBox.Show("请输入姓名!");
}
else
{
if (this.textBox8.Text.Trim() == "")
{
MessageBox.Show("请输入地址!");
}
else
{
employeeNo = textBox1.Text.Trim().ToUpper();
employeeName = textBox3.Text;
if (this.radioButton1.Checked ==true)
sex = "1";
else
sex = "0";
address = textBox8.Text;
workTel = textBox5.Text;
homeTel = textBox6.Text;
email = textBox7.Text;
salary = textBox9.Text;
bool check = true;
employee emp = new employee();
emp.Open();
string s = "select * from employee";
SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand mycommand = new SqlCommand(s,conn);
SqlDataReader dr = mycommand.ExecuteReader();
while (dr.Read())
{
string employeeno = dr.GetString(0);
//string Name = dr.GetString(2);
if (employeeno == textBox1.Text.ToString())
{
check = false;
}
}
if (check)
{
try
{
bool d = emp.addEmployee(employeeNo,employeeName,address,workTel,homeTel,email,int.Parse(sex),float.Parse(salary));
if (d)
{
MessageBox.Show("注册成功!");
}
else
{
MessageBox.Show("注册不成功!");
}
}
catch
{
MessageBox.Show("工资应为数字");
}
}
else
{
MessageBox.Show("用户号已存在!");
}
dr.Close();
conn.Close();
emp.Close();
}
}
}
else
{
MessageBox.Show("长度必须为8位");
}
}
}
}
private void addemploee_Load(object sender, System.EventArgs e)
{
if (this.ManagerNo == "1")
{
this.button1.Visible = false;
this.button4.Visible = false;
this.label12.Visible = false;
}
else
{
this.button3.Visible = false;
this.button5.Visible = false;
this.button6.Visible = false;
}
textBox1.Text = "";
// textBox2.Text = "";
textBox3.Text = "";
//textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
this.button3.Enabled = false;
}
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if (sex == "1")
this.radioButton1.Checked = true;
if (this.radioButton1.Checked ==true)
this.radioButton2.Checked = false;
if (this.radioButton2.Checked == true)
this.radioButton1.Checked = false;
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void label1_Click(object sender, System.EventArgs e)
{
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
string s = this.textBox1.Text.Trim();
if (this.textBox1.Text.Trim().Length > 8)
{
MessageBox.Show("输入无效!");
this.textBox1.Text = "";
}
}
private void textBox3_TextChanged(object sender, System.EventArgs e)
{
if (this.textBox3.Text.Trim().Length > 20)
{
MessageBox.Show("输入无效!");
this.textBox3.Text = "";
}
}
private void textBox8_TextChanged(object sender, System.EventArgs e)
{
if (this.textBox8.Text.Trim().Length > 30)
{
MessageBox.Show("输入无效!");
this.textBox8.Text = "";
}
}
private void textBox5_TextChanged(object sender, System.EventArgs e)
{
string s = "";
if (this.textBox5.Text.Trim().Length > 20)
{
MessageBox.Show("输入无效!");
this.textBox5.Text = "";
}
else
{
if (this.textBox5.Text.Trim() != "")
{
s = this.textBox5.Text.Trim();
for (int i = 0;i < s.Length;i++)
{
if (s[i] >= '0'&& s[i] <= '9')
{
continue;
}
else
{
MessageBox.Show(" 电话号码为数字!");
this.textBox5.Text = "";
this.textBox5.Focus();
}
}
}
}
}
private void textBox6_TextChanged(object sender, System.EventArgs e)
{
string s = "";
if (this.textBox6.Text.Trim().Length > 20)
{
MessageBox.Show("输入无效!");
this.textBox6.Text = "";
}
else
{
if (this.textBox6.Text.Trim() != "")
{
s = this.textBox6.Text.Trim();
for (int i = 0;i < s.Length;i++)
{
if (s[i] >= '0'&&s[i] <= '9')
{
continue;
}
else
{
MessageBox.Show(" 电话号码为数字!");
this.textBox6.Text = "";
this.textBox6.Focus();
}
}
}
}
}
private void textBox7_TextChanged(object sender, System.EventArgs e)
{
//string s = "";
if (this.textBox7.Text.Trim().Length > 30)
{
MessageBox.Show("输入无效!");
this.textBox7.Text = "";
}
}
private void textBox9_TextChanged(object sender, System.EventArgs e)
{
string s = "";
if (this.textBox9.Text.Trim().Length > 7)
{
MessageBox.Show("输入的编号无效!");
this.textBox9.Text = "";
this.textBox9.Focus();
}
else
{
if (this.textBox9.Text.Trim() != "")
{
s = this.textBox9.Text.Trim();
for (int i = 0;i < s.Length;i++)
{
if (s[i] >= '0'&&s[i] <= '9')
{
continue;
}
else
{
MessageBox.Show(" 工资应为数字!");
this.textBox9.Text = "";
this.textBox9.Focus();
}
}
if ((s.Length >= 2) && (s[0] == '0'))
{
MessageBox.Show("无效数据,请重输!");
this.textBox9.Text = "";
this.textBox9.Focus();
}
}
}
}
private void button4_Click(object sender, System.EventArgs e)
{
textBox1.Text = "";
// textBox2.Text = "";
textBox3.Text = "";
//textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
}
private void button3_Click(object sender, System.EventArgs e)
{
if (this.textBox3.Text.Trim() == "")
{
MessageBox.Show("姓名不能为空!");
this.textBox3.Focus();
}
else
{
if (this.textBox8.Text.Trim() == "")
{
MessageBox.Show("地址不能为空!");
this.textBox8.Focus();
}
else
{
Connection s = new Connection();
SqlConnection co = new SqlConnection(s.getConnectionString);
co.Open();
this.textBox1.ReadOnly = false;
employeeNo = textBox1.Text.Trim().ToUpper();
employeeName = textBox3.Text.Trim();
if (this.radioButton1.Checked ==true)
sex = "1";
else
sex = "0";
address = textBox8.Text;
workTel = textBox5.Text;
homeTel = textBox6.Text;
email = textBox7.Text;
salary = textBox9.Text;
employee en = new employee();
en.Open();
try
{
bool d = en.modifyEmployee(employeeNo,employeeName,address,workTel,homeTel,email,int.Parse(sex),float.Parse(salary));
if (d)
{
MessageBox.Show("修改成功!");
this.textBox1.ReadOnly = false;
}
else
{
MessageBox.Show("修改不成功!");
this.textBox1.ReadOnly = false;
}
}
catch
{
MessageBox.Show("工资应为数字");
this.textBox9.Text = "";
this.textBox9.Focus();
}
en.Close();
co.Close();
}
}
}
private void button5_Click(object sender, System.EventArgs e)
{
this.button3.Enabled = false;
bool check = true;
if (this.textBox1.Text.Trim() == "")
{
MessageBox.Show("请输入员工号!");
textBox3.Text = "";
//textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
}
else
{
Connection s = new Connection();
SqlConnection conn = new SqlConnection(s.getConnectionString);
conn.Open();
string ddtr = "select * from employee";
SqlCommand cmd1 = new SqlCommand(ddtr,conn);
SqlDataReader dr = cmd1.ExecuteReader();
while (dr.Read())
{
if (this.textBox1.Text.Trim() == Convert.ToString(dr["employeeNo"]))
{
this.textBox1.ReadOnly = true;
this.button3.Enabled = true;
check = false;
this.textBox3.Text = Convert.ToString(dr["employeeName"]);
this.textBox8.Text = Convert.ToString(dr["address"]);
if (Convert.ToString(dr["sex"]) == "1")
{
this.radioButton1.Checked = true;
}
else
{
this.radioButton2.Checked = true;
}
this.textBox5.Text = Convert.ToString(dr["workTelExt"]);
this.textBox6.Text = Convert.ToString(dr["homeTelNum"]);
this.textBox7.Text = Convert.ToString(dr["empEmail"]);
this.textBox9.Text = Convert.ToString(dr["salary"]);
break;
}
}
dr.Close();
conn.Close();
if (check)
{
MessageBox.Show("此员工号不存在!");
this.textBox1.Text = "";
this.textBox1.Focus();
}
}
}
private void button6_Click(object sender, System.EventArgs e)
{
this.textBox1.ReadOnly = false;
this.button3.Enabled = false;
textBox3.Text = "";
textBox1.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
this.textBox1.Focus();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -