Пример #1
0
        /// <summary>
        /// Adds the employee when the Ok button is clicked.
        /// </summary>
        /// <param name="sender">The button that is clicked.</param>
        /// <param name="e">Additional event information.</param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (IsValidData())
                {
                    Employee employee = employeeDA.GetEmployeeByEmployeeId(txtEmployeeId.Text);

                    if (employee == null)
                    {
                        employee = new Employee(txtEmployeeId.Text, txtFullName.Text,
                                                (Department)cboDepartment.SelectedItem, dtpWeekStartDate.Value, updSalary.Value);
                        employeeDA.AddEmployee(employee);
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        MessageBox.Show("Employee is already on list.", "Add Employee",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtEmployeeId.SelectAll();
                        txtEmployeeId.Focus();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.GetType().ToString() +
                                "\n" + ex.StackTrace, "Exception Caught",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }