Пример #1
0
        /// <summary>
        /// Добавить сотрудника
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void BtnAddEmployee_Click(object sender, RoutedEventArgs e)
        {
            int            deptId         = (mainWindow.lbDepartments.SelectedItem as Department).DepartmentId;
            EmployeeWindow employeeWindow = new EmployeeWindow();

            employeeWindow.btnCancel.Click          += (o, h) => employeeWindow.Close();
            employeeWindow.cbDepartment.ItemsSource  = org.Departments;
            employeeWindow.cbDepartment.SelectedItem = org.Departments.First(d => d.DepartmentId == deptId);
            employeeWindow.btnAddEmployee.Click     += (o, h) =>
            {
                if (!String.IsNullOrEmpty(employeeWindow.tbFirstName.Text) && !String.IsNullOrEmpty(employeeWindow.tbSecondName.Text) &&
                    employeeWindow.dpBirthDay.SelectedDate.HasValue)
                {
                    StringContent content = new StringContent(org.GetJSONEmployee(new Employee(
                                                                                      employeeWindow.tbFirstName.Text
                                                                                      , employeeWindow.tbSecondName.Text
                                                                                      , employeeWindow.dpBirthDay.SelectedDate.Value
                                                                                      , (employeeWindow.cbDepartment.SelectedItem as Department).DepartmentId
                                                                                      )), Encoding.UTF8, "application/json");
                    var r = httpClient.PostAsync(baseAddress + @"AddEmployee", content).Result;
                    employeeWindow.DialogResult = true;
                    employeeWindow.Close();
                }
                else
                {
                    MessageBox.Show("Заполните все параметры");
                }
            };
            employeeWindow.Owner = mainWindow;
            employeeWindow.ShowDialog();
            if (employeeWindow.DialogResult == true)
            {
                UpdateLbEmployees(deptId);
            }
        }
Пример #2
0
        /// <summary>
        /// Добавить сотрудника
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void BtnAddEmployee_Click(object sender, RoutedEventArgs e)
        {
            DataRow        newRow         = empDatatTable.NewRow();
            EmployeeWindow employeeWindow = new EmployeeWindow(newRow, deptDatatTable);

            employeeWindow.Owner = mainWindow;
            employeeWindow.ShowDialog();
            if (employeeWindow.DialogResult.HasValue && employeeWindow.DialogResult.Value)
            {
                empDatatTable.Rows.Add(newRow);
                sqlEmployeeAdapter.Update(empDatatTable);
            }
        }
Пример #3
0
        private static void BtnEditEmployee_Click(object sender, RoutedEventArgs e)
        {
            EmployeeWindow employeeWindow = new EmployeeWindow();

            /*employeeWindow.tbFirstName.IsEnabled = false;
             * employeeWindow.tbSecondName.IsEnabled = false;
             * employeeWindow.tbSerial.IsEnabled = false;
             * employeeWindow.tbNumber.IsEnabled = false;
             * employeeWindow.dpBirthDay.IsEnabled = false;
             * employeeWindow.cbDocumentType.IsEnabled = false;*/
            Employee curEmp = mainWindow.lbEmployees.SelectedItem as Employee;

            employeeWindow.tbFirstName.Text            = curEmp.FirstName;
            employeeWindow.tbSecondName.Text           = curEmp.SecondName;
            employeeWindow.tbSerial.Text               = curEmp.EmployeeDocument.Serial;
            employeeWindow.tbNumber.Text               = curEmp.EmployeeDocument.Number;
            employeeWindow.cbDocumentType.ItemsSource  = Enum.GetValues(typeof(Document.DocumentType));
            employeeWindow.cbDocumentType.SelectedItem = curEmp.EmployeeDocument.documentType;
            employeeWindow.dpBirthDay.SelectedDate     = curEmp.BirthDay;
            employeeWindow.cbDepartment.ItemsSource    = org.Departments;
            employeeWindow.cbDepartment.SelectedItem   = curEmp.Department;
            employeeWindow.btnCancel.Click            += (o, h) => employeeWindow.Close();
            employeeWindow.cbDocumentType.ItemsSource  = Enum.GetValues(typeof(Document.DocumentType));
            employeeWindow.btnAddEmployee.Click       += (o, h) =>
            {
                if (!String.IsNullOrEmpty(employeeWindow.tbFirstName.Text) && !String.IsNullOrEmpty(employeeWindow.tbSecondName.Text) &&
                    employeeWindow.dpBirthDay.SelectedDate.HasValue && employeeWindow.cbDocumentType.SelectedItem != null &&
                    !String.IsNullOrEmpty(employeeWindow.tbSerial.Text) && !String.IsNullOrEmpty(employeeWindow.tbNumber.Text))
                {
                    var r = curEmp.Department;
                    curEmp.ChangePersonalInfo(employeeWindow.tbFirstName.Text
                                              , employeeWindow.tbSecondName.Text
                                              , employeeWindow.dpBirthDay.SelectedDate.Value
                                              , (Document.DocumentType)employeeWindow.cbDocumentType.SelectedItem
                                              , employeeWindow.tbSerial.Text, employeeWindow.tbNumber.Text
                                              , (employeeWindow.cbDepartment.SelectedItem as Department));
                    mainWindow.lbEmployees.ItemsSource = org.GetEmployees(r);
                    employeeWindow.Close();
                }
                else
                {
                    MessageBox.Show("Заполните все параметры");
                }
            };
            employeeWindow.Owner = mainWindow;
            employeeWindow.ShowDialog();
        }
Пример #4
0
        /// <summary>
        /// Редактирование сотрудника
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void BtnEditEmployee_Click(object sender, RoutedEventArgs e)
        {
            EmployeeWindow employeeWindow = new EmployeeWindow();
            Employee       curEmp         = mainWindow.lbEmployees.SelectedItem as Employee;

            employeeWindow.tbFirstName.Text            = curEmp.FirstName;
            employeeWindow.tbSecondName.Text           = curEmp.SecondName;
            employeeWindow.tbSerial.Text               = curEmp.EmployeeDocument.Serial;
            employeeWindow.tbNumber.Text               = curEmp.EmployeeDocument.Number;
            employeeWindow.cbDocumentType.ItemsSource  = Enum.GetValues(typeof(Document.DocumentTypes));
            employeeWindow.cbDocumentType.SelectedItem = curEmp.EmployeeDocument.DocumentType;
            employeeWindow.dpBirthDay.SelectedDate     = curEmp.BirthDay;
            employeeWindow.cbDepartment.ItemsSource    = org.Departments;
            employeeWindow.cbDepartment.SelectedItem   = org.Departments.First(d => d.DepartmentId == curEmp.Departmentid);
            employeeWindow.btnCancel.Click            += (o, h) => employeeWindow.Close();
            employeeWindow.cbDocumentType.ItemsSource  = Enum.GetValues(typeof(Document.DocumentTypes));
            employeeWindow.btnAddEmployee.Click       += (o, h) =>
            {
                int currentDeptId = curEmp.Departmentid;
                if (!String.IsNullOrEmpty(employeeWindow.tbFirstName.Text) && !String.IsNullOrEmpty(employeeWindow.tbSecondName.Text) &&
                    employeeWindow.dpBirthDay.SelectedDate.HasValue && employeeWindow.cbDocumentType.SelectedItem != null &&
                    !String.IsNullOrEmpty(employeeWindow.tbSerial.Text) && !String.IsNullOrEmpty(employeeWindow.tbNumber.Text))
                {
                    curEmp.ChangePersonalInfo(employeeWindow.tbFirstName.Text
                                              , employeeWindow.tbSecondName.Text
                                              , employeeWindow.dpBirthDay.SelectedDate.Value
                                              , (Document.DocumentTypes)employeeWindow.cbDocumentType.SelectedItem
                                              , employeeWindow.tbSerial.Text, employeeWindow.tbNumber.Text
                                              , (employeeWindow.cbDepartment.SelectedItem as Department).DepartmentId);
                    // Как бы это переделать
                    if (currentDeptId != curEmp.Departmentid)
                    {
                        mainWindow.lbEmployees.ItemsSource = org.GetEmployees(currentDeptId);
                    }
                    employeeWindow.Close();
                }
                else
                {
                    MessageBox.Show("Заполните все параметры");
                }
            };
            employeeWindow.Owner = mainWindow;
            employeeWindow.ShowDialog();
        }
Пример #5
0
        /// <summary>
        /// Редактирование сотрудника
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void BtnEditEmployee_Click(object sender, RoutedEventArgs e)
        {
            DataRowView    newRow         = (DataRowView)mainWindow.lbEmployees.SelectedItem;
            EmployeeWindow employeeWindow = new EmployeeWindow(newRow.Row, deptDatatTable);

            employeeWindow.Owner = mainWindow;
            newRow.BeginEdit();
            employeeWindow.ShowDialog();
            if (employeeWindow.DialogResult.HasValue && employeeWindow.DialogResult.Value)
            {
                newRow.EndEdit();
                empDatatTable.Rows.Add(newRow);
                sqlEmployeeAdapter.Update(empDatatTable);
            }
            else
            {
                newRow.CancelEdit();
            }
        }
Пример #6
0
        /// <summary>
        /// Добавить сотрудника
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void BtnAddEmployee_Click(object sender, RoutedEventArgs e)
        {
            EmployeeWindow employeeWindow = new EmployeeWindow();

            employeeWindow.btnCancel.Click           += (o, h) => employeeWindow.Close();
            employeeWindow.cbDocumentType.ItemsSource = Enum.GetValues(typeof(Document.DocumentTypes));
            employeeWindow.cbDepartment.ItemsSource   = org.Departments;
            employeeWindow.btnAddEmployee.Click      += (o, h) =>
            {
                if (!String.IsNullOrEmpty(employeeWindow.tbFirstName.Text) && !String.IsNullOrEmpty(employeeWindow.tbSecondName.Text) &&
                    employeeWindow.dpBirthDay.SelectedDate.HasValue && employeeWindow.cbDocumentType.SelectedItem != null &&
                    !String.IsNullOrEmpty(employeeWindow.tbSerial.Text) && !String.IsNullOrEmpty(employeeWindow.tbNumber.Text))
                {
                    if (org.AddEmployee(new Employee(
                                            employeeWindow.tbFirstName.Text
                                            , employeeWindow.tbSecondName.Text
                                            , employeeWindow.dpBirthDay.SelectedDate.Value
                                            , (Document.DocumentTypes)employeeWindow.cbDocumentType.SelectedItem
                                            , employeeWindow.tbSerial.Text, employeeWindow.tbNumber.Text
                                            , (employeeWindow.cbDepartment.SelectedItem as Department).DepartmentId
                                            )))
                    {
                        mainWindow.lbEmployees.ItemsSource = org.GetEmployees((mainWindow.lbDepartments.SelectedItem as Department).DepartmentId);
                        employeeWindow.Close();
                    }
                    else
                    {
                        MessageBox.Show("Такой сотрудник уже есть");
                    }
                }
                else
                {
                    MessageBox.Show("Заполните все параметры");
                }
            };
            employeeWindow.Owner = mainWindow;
            employeeWindow.ShowDialog();
        }