以下是引用片段:
其关键代码实现如下: private void RyEdit_Load(object sender, EventArgs e) { //绑定显示部门列表 comboBox2.ValueMember = "部门代码"; comboBox2.DisplayMember = "部门名称"; comboBox2.DataSource = db.Get("select * from 部门"); if (m员工号 != "") { //显示当前的员工信息 DataTable dt = new DataTable(); dt = db.Get("select * from 员工信息 where 员工号='" + m员工号 + "'"); if (dt.Rows.Count > 0) { textBox1.ReadOnly = true; textBox1.Text = dt.Rows[0]["员工号"].ToString(); textBox2.Text = dt.Rows[0]["姓名"].ToString(); comboBox1.Text = dt.Rows[0]["性别"].ToString(); textBox3.Text = dt.Rows[0]["职位"].ToString(); dateTimePicker1.Value = Convert.ToDateTime(dt.Rows[0]["入职日期"].ToString()); textBox5.Text = dt.Rows[0]["联系方式"].ToString(); textBox4.Text = dt.Rows[0]["员工介绍"].ToString(); comboBox2.SelectedValue = dt.Rows[0]["部门代码"].ToString();
} } }
private void BtnAdd_Click(object sender, EventArgs e) { //根据标志 添加或修改 员工信息 if (m员工号 == "") { //添加新员工 if (db.Get("select * from 员工信息 where 员工号='" + textBox1.Text + "'").Rows.Count > 0) { MessageBox.Show("员工帐号重复"); return; } db.Exec("insert into 员工信息(员工号,姓名,性别,职位,入职日期,员工介绍,联系方式,部门代码) values('"+ textBox1.Text +"', " + " '"+ textBox2.Text +"','"+ comboBox1.Text +"','"+ textBox3.Text +"','"+ dateTimePicker1.Value +"','"+ textBox4.Text +"', " + " '"+ textBox5.Text +"',"+ comboBox2.SelectedValue +")"); } else { //修改员工信息 db.Exec("update 员工信息 set 姓名='" + textBox2.Text + "',性别='" + comboBox1.Text + "',职位='" + textBox3.Text + "'," + " 入职日期='" + dateTimePicker1.Value + "',员工介绍='" + textBox4.Text + "',联系方式='" + textBox5.Text + "', " + " 部门代码=" + comboBox2.SelectedValue + " where 员工号='" + m员工号 + "' ");
} this.Close(); }
|