Пример #1
0
        private void buttonAddPersonal_Click(object sender, EventArgs e)
        {
            if (textBoxLastName.Text.Length == 0 || textBoxFirstName.Text.Length == 0 ||
                comboBoxGender.Text.Length == 0 || comboBoxFunction.Text.Length == 0 ||
                (dateSelected == false && Form1.AddOrEdit == AddEditOrDelete.Add))
            {
                MessageBox.Show("Вы ввели не все данные!");
                return;
            }
            Functions funcCmb = (Functions)int.Parse(comboBoxFunction.SelectedValue.ToString());

            if (emp == null)
            {
                emp = new Employee(textBoxINN.Text, textBoxFirstName.Text, textBoxSecondName.Text,
                                   textBoxLastName.Text, textBoxPassport.Text, textBoxAddress.Text, Convert.ToDateTime(date),
                                   Converter.ConvertSex(comboBoxGender.Text), textBoxNumbOfTel.Text, funcCmb);
                EmployeeMapper em = new EmployeeMapper();
                try
                {
                    emp = em.Insert(emp);
                }
                catch (Exception ex)
                {
                    emp = null;
                    MessageBox.Show("При добавлении данных произошла ошибка - " +
                                    $"{ex.Message}");
                    return;
                }
            }
            else
            {
                EmployeeMapper em = new EmployeeMapper();
                emp.INN        = textBoxINN.Text;
                emp.FirstName  = textBoxFirstName.Text;
                emp.SecondName = textBoxSecondName.Text;
                emp.LastName   = textBoxLastName.Text;
                emp.Passport   = textBoxPassport.Text;
                emp.Address    = textBoxAddress.Text;
                emp.BornDate   = Convert.ToDateTime(date);
                emp.Gender     = Converter.ConvertSex(comboBoxGender.Text);
                emp.Function   = funcCmb;
                emp.PhoneNumb  = textBoxNumbOfTel.Text;
                em.Update(emp);
            }
            Form1.AddListPersonalInGrid(mainForm.dataGridView, Queries.StaffView);
            this.Close();
            mainForm.dataGridView.ClearSelection();
            mainForm.dataGridView.Rows[Form1.SelectIndex].Selected = true;
        }