Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Staff staff = new Staff();

            staff.姓名        = textBox6.Text.Trim();
            staff.性别        = (性别)Enum.ToObject(typeof(性别), comboBox2.SelectedIndex);
            staff.Depart    = comboBox3.SelectedItem as Department;
            staff.Condition = comboBox6.SelectedItem as StaffCondition;
            staff.生日        = DateTime.Parse(textBox4.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.ExistsName(staff.姓名))
            {
                if (MessageBox.Show("系统中已经存在该员工,确定还要继续保存么?", "重名提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
                {
                    int id = ml.AddStaff(staff);
                    if (id > 0)
                    {
                        staff.ID = id;
                        LoadStaffs();
                        MessageBox.Show("添加成功!");
                    }
                }
                else
                {
                    textBox1.Focus();
                    textBox1.SelectAll();
                }
            }
            else
            {
                int id = ml.AddStaff(staff);
                if (id > 0)
                {
                    staff.ID = id;
                    LoadStaffs();
                    MessageBox.Show("添加成功!");
                }
            }
        }