コード例 #1
0
        private void btnAddButton_Click(object sender, EventArgs e)
        {
            Employee     employee        = new Employee();
            EmployeeForm frmEmployeeForm = new EmployeeForm(employee, Company);

            frmEmployeeForm.MdiParent = MdiParent;
            frmEmployeeForm.CompanyComboBox.Enabled = false;
            frmEmployeeForm.Show();
            frmEmployeeForm.SaveButton.Click += delegate
            {
                employee = frmEmployeeForm.Employee;
                string             errorText          = string.Empty;
                EmployeeRepository employeeRepository = new EmployeeRepository();
                if (Validation.ValidateEmployee(employee, ref errorText))
                {
                    employeeRepository.Add(employee);
                    frmEmployeeForm.Close();
                }
                else
                {
                    ShowErrorMessage(errorText);
                }
                bsEmployees.DataSource  = employeeRepository.FindByCompanyId(Company.Id);
                grdEmployees.DataSource = bsEmployees;
                grdEmployees.Refresh();
            };
        }
コード例 #2
0
        private void btnEditButton_Click(object sender, EventArgs e)
        {
            Employee employee = new Employee();

            employee = (Employee)bsEmployees.Current;
            EmployeeForm frmEmployeeForm = new EmployeeForm(employee);

            frmEmployeeForm.MdiParent = MdiParent;
            frmEmployeeForm.Show();
            frmEmployeeForm.SaveButton.Click += delegate
            {
                employee = frmEmployeeForm.Employee;
                string             errorText          = string.Empty;
                EmployeeRepository employeeRepository = new EmployeeRepository();
                if (Validation.ValidateEmployee(employee, ref errorText))
                {
                    employeeRepository.Update(employee);
                    frmEmployeeForm.Close();
                }
                else
                {
                    ShowErrorMessage(errorText);
                }
                bsEmployees.DataSource = employeeRepository.FindAll();
                grdEmployees.Refresh();
            };
            frmEmployeeForm.CancelChangesButton.Click += delegate
            {
                EmployeeRepository employeeRepository = new EmployeeRepository();
                bsEmployees.DataSource = employeeRepository.FindAll();
                grdEmployees.Refresh();
            };
        }