private void btnAdd_Click(object sender, EventArgs e)
        {
            int        id                 = int.Parse(textBoxId.Text);
            string     name               = textBoxName.Text;
            decimal    salary             = decimal.Parse(textBoxSalary.Text);
            Department selectedDepartment = comboBoxDepartments.SelectedItem as Department;

            Employee employee = new Employee
            {
                EmployeeId     = id,
                EmployeeName   = name,
                Salary         = salary,
                DepartmentInfo = selectedDepartment
            };

            EmployeeBusinessComponent employeeBo = new EmployeeBusinessComponent();
            bool status = employeeBo.AddRecord(employee);

            if (status)
            {
                MessageBox.Show("employee record added successfully");
            }
            else
            {
                MessageBox.Show("employee record not added");
            }
            Reset();
        }
Ejemplo n.º 2
0
        public void LoadEmployees()
        {
            var department = (comboBoxDepartments.SelectedItem as Department);
            var selectedId = department.DepartmentId;

            employeeBusinessComponent = new EmployeeBusinessComponent();
            var employees = employeeBusinessComponent.FetchEmployeeByDepartment(selectedId);

            dgvEmployees.DataSource = employees;
        }
Ejemplo n.º 3
0
        private void GetSortedRecords(EmployeeSortChoice choice)
        {
            EmployeeBusinessComponent empBo = new EmployeeBusinessComponent();
            var collection = dataGridEmployees.DataSource as List <Employee>;

            var sortedCollection = empBo.SortRecords(collection, choice);

            dataGridEmployees.DataSource = null;
            dataGridEmployees.DataSource = sortedCollection;
        }
Ejemplo n.º 4
0
 private void ComboBoxDepartments_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         var department = (comboBoxDepartments.SelectedItem as Department);
         var selectedId = department.DepartmentId;
         employeeBusinessComponent = new EmployeeBusinessComponent();
         var employees = employeeBusinessComponent.FetchEmployeeByDepartment(selectedId);
         dgvEmployees.DataSource = employees;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Ejemplo n.º 5
0
 private void DeleteSelectedEmployee(int selectedEmployeeId)
 {
     try
     {
         employeeBusinessComponent = new EmployeeBusinessComponent();
         int result = employeeBusinessComponent.RemoveEmployee(selectedEmployeeId);
         if (result > 0)
         {
             MessageBox.Show($"{result} record deleted succesfully");
             this.LoadEmployees();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Ejemplo n.º 6
0
        private void comboBoxDepartments_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedDepartment = comboBoxDepartments.SelectedItem as Department;

            if (selectedDepartment != null)
            {
                EmployeeBusinessComponent employeeDao
                    = new EmployeeBusinessComponent();
                var list = employeeDao.GetRecordById(selectedDepartment.DepartmentId);

                if (list != null && list.Count > 0)
                {
                    dataGridEmployees.AutoGenerateColumns = false;
                    dataGridEmployees.DataSource          = list;
                }
            }
        }