Beispiel #1
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            bool isValid = true;

            CheckTextBoxNotEmpty(ref isValid, txtUserName, txtRealName);
            CheckComBoNotEmpty(ref isValid, cmbDepartment, cmbGender, cmbRank);
            if (pwdPassword.Password.Length <= 0)
            {
                isValid = false;
                pwdPassword.Background = Brushes.Red;
            }
            else
            {
                pwdPassword.Background = null;
            }
            if (isValid == false)
            {
                return;
            }
            if (IsEdited == false)
            {
                Employee employee = new Employee();
                employee = (Employee)gridEdit.DataContext;
                EmployeeDAL   empDAL = new EmployeeDAL();
                DepartmentDAL dptDAL = new DepartmentDAL();
                if (empDAL.CheckExsited(employee.UserName))
                {
                    MessageBox.Show("UserName is already exsited");
                    return;
                }
                else
                {
                    if (empDAL.CheckManagerExisted(employee))
                    {
                        MessageBox.Show("Manager is already exsited, please demote existed manager first!");
                        return;
                    }
                    else
                    {
                        employee.Password = pwdPassword.Password;
                        EmployeeDAL dal = new EmployeeDAL();
                        dal.Insert(employee);
                        dal.UpdateManagerIDtoDepartmentTable(employee);
                        dal.UpLoadManagerName(employee);
                    }
                }
            }
            else
            {
                Employee employee = (Employee)gridEdit.DataContext;
                if (new EmployeeDAL().CheckManagerExisted(employee))
                {
                    MessageBox.Show("Manager is already exsited, please demote existed manager first!");
                    return;
                }
                else if (new EmployeeDAL().CheckExsited(employee.UserName))
                {
                    MessageBox.Show("UserName is already exsited");
                    return;
                }
                else
                {
                    new EmployeeDAL().Update(employee);
                }
            }
            DialogResult = true;
        }