Ejemplo n.º 1
0
        private void BtnOk_Click(object sender, EventArgs e)
        {
            try
            {
                var selected = comboBoxDepartment.SelectedItem;
                employeeBusinessComponent = new EmployeeBusinessComponent();
                int result = employeeBusinessComponent
                             .UpdateEmployee(new Employee
                {
                    EmployeeId       = int.Parse(txtId.Text),
                    EmployeeName     = txtName.Text,
                    EmployeeSalary   = decimal.Parse(txtSalary.Text),
                    EmployeeLocation = txtLocation.Text,
                    DepartmentId     = comboBoxDepartment.SelectedItem != null ? (comboBoxDepartment.SelectedItem as Department).DepartmentId : employee.DepartmentId
                });

                MessageBox.Show(result > 0 ? $"{result} updated successfully" : "record updation failed");

                ReloadRecordsForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 2
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBoxDepartment.SelectedItem != null)
                {
                    if (MessageBox.Show("Sure to add?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        employeeBusinessComponent
                            = new EmployeeBusinessComponent();
                        int result = employeeBusinessComponent.AddNewEmployee(
                            new Employee
                        {
                            EmployeeName     = txtName.Text,
                            EmployeeLocation = txtLocation.Text,
                            EmployeeSalary   = decimal.Parse(txtSalary.Text),
                            DepartmentId     = (comboBoxDepartment.SelectedItem as Department).DepartmentId
                        });

                        if (result > 0)
                        {
                            MessageBox.Show($"{result} record added successfully");
                        }
                        else
                        {
                            MessageBox.Show($"record couldn't be added successfully");
                        }
                    }
                    else
                    {
                        MessageBox.Show("operation cancelled");
                    }

                    ReloadRecordsForm();
                }
                else
                {
                    MessageBox.Show("select department name");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }