Ejemplo n.º 1
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (comboBox1.SelectedIndex > -1)
     {
         Staff staff = new Staff();
         staff.ID        = ((Product)comboBox1.SelectedItem).ID;
         staff.姓名        = textBox1.Text.Trim();
         staff.性别        = (性别)Enum.ToObject(typeof(性别), comboBox2.SelectedIndex);
         staff.Depart    = comboBox3.SelectedItem as Department;
         staff.Condition = comboBox3.SelectedItem as StaffCondition;
         staff.生日        = DateTime.Parse(textBox3.Text.Trim());
         staff.电话        = textBox5.Text.Trim();
         staff.宿舍        = textBox4.Text.Trim();
         staff.备注        = textBox6.Text.Trim();
         staff.钥匙数       = (int)numericUpDown1.Value;
         staff.工衣数       = (int)numericUpDown2.Value;
         staff.工牌数       = (int)numericUpDown3.Value;
         staff.是否全部回收    = checkBox1.Checked;
         StaffLogic ml = StaffLogic.GetInstance();
         if (ml.ExistsNameOther(staff.姓名, staff.ID))
         {
             if (MessageBox.Show("系统中已经存在该员工,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
             {
                 if (ml.UpdateStaff(staff))
                 {
                     LoadStaffs();
                     MessageBox.Show("修改成功!");
                 }
             }
             else
             {
                 textBox1.Focus();
                 textBox1.SelectAll();
             }
         }
         else
         {
             if (ml.UpdateStaff(staff))
             {
                 LoadStaffs();
                 MessageBox.Show("修改成功!");
             }
         }
     }
     else
     {
         MessageBox.Show("先选定要修改的员工!");
     }
 }