Beispiel #1
0
 private void ExecuteAddCommand(object obj)
 {
     addEmployeeWindow.DialogResult = true;
     addEmployeeWindow.Close();
 }
        public void SaveEmployee(AddEmployeeWindow parameter)
        {
            string sex;

            if (string.IsNullOrEmpty(parameter.txtName.Text))
            {
                parameter.txtName.Focus();
                return;
            }
            if (string.IsNullOrEmpty(parameter.txtDate.Text))
            {
                parameter.txtDate.Focus();
                return;
            }
            else
            {
            }
            if (parameter.rdoMale.IsChecked.Value == true)
            {
                sex = "Nam";
            }
            else
            {
                sex = "Nữ";
            }
            if (string.IsNullOrEmpty(parameter.txtStartDate.Text))
            {
                parameter.txtStartDate.Focus();
                return;
            }
            if (string.IsNullOrEmpty(parameter.txtPosition.Text))
            {
                parameter.txtPosition.Focus();
                return;
            }
            if (string.IsNullOrEmpty(parameter.txtTelephoneNumber.Text))
            {
                parameter.txtTelephoneNumber.Focus();
                return;
            }
            if (string.IsNullOrEmpty(parameter.txtAddress.Text))
            {
                parameter.txtAddress.Focus();
                return;
            }
            if (parameter.grdSelectImage.Background == null)
            {
                //parameter.grdSelectImage.Focus();
                //return;
            }
            try
            {
                Employee employee = new Employee(
                    int.Parse(parameter.txtIdEmployee.Text),
                    parameter.txtName.Text,
                    DateTime.Parse(parameter.txtDate.Text),
                    sex,
                    DateTime.Parse(parameter.txtStartDate.Text),
                    parameter.txtPosition.Text,
                    parameter.txtTelephoneNumber.Text,
                    parameter.txtAddress.Text,
                    sex);
                if (AorU)
                {
                    if (EmployeeDAL.Instance.AddEmployeeToDatabase(employee))
                    {
                        MessageBox.Show("Thêm thành công");
                    }
                }
                else
                {
                    if (EmployeeDAL.Instance.UpdateOnDatabase(employee))
                    {
                        MessageBox.Show("Thêm thành công");
                    }
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                LoadEmployee(homeWindow);
                parameter.Close();
            }
        }