Beispiel #1
0
 private void RefreshListView()
 {
     using (var db = new EmployeesDBContext())
     {
         if (SearchByComboBox.Text == SalaryManagementSystem.Properties.Resources.NameStr)
         {
             searchResult = (from em in db.Employees
                             where em.Name.Contains(SearchTextBox.Text)
                             select em).ToList();
         }
         else if (SearchByComboBox.Text == SalaryManagementSystem.Properties.Resources.EGNStr)
         {
             searchResult = (from em in db.Employees
                             where em.EGN.Contains(SearchTextBox.Text)
                             select em).ToList();
         }
         else if (SearchByComboBox.Text == SalaryManagementSystem.Properties.Resources.CompanyNameStr)
         {
             searchResult = (from em in db.Employees
                             where em.CompanyName.Contains(SearchTextBox.Text)
                             select em).ToList();
         }
     }
     EmployeesListView.ItemsSource = searchResult;
 }
Beispiel #2
0
 private void DeleteEmployee(Employee employee)
 {
     using (var db = new EmployeesDBContext())
     {
         var toRemove = db.Employees.SingleOrDefault(em => em.ID == employee.ID);
         if (toRemove != null)
         {
             db.Employees.Remove(toRemove);
             db.SaveChanges();
         }
     }
 }
Beispiel #3
0
        private void EditBtn_Click(object sender, RoutedEventArgs e)
        {
            if (EmployeesListView.SelectedItems.Count > 1)
            {
                MessageBox.Show("Please select just one employee!");
                return;
            }
            Employee selectedEmployee = EmployeesListView.SelectedItem as Employee;

            if (selectedEmployee != null)
            {
                using (var db = new EmployeesDBContext())
                {
                    var toEdit = db.Employees.SingleOrDefault(em => em.ID == selectedEmployee.ID);
                    if (toEdit != null)
                    {
                        string newValue = selectedEmployee.Salary.ToString();
                        while (newValue.Length > 0)
                        {
                            newValue = Interaction.InputBox(SalaryManagementSystem.Properties.Resources.EnterSalaryMsg
                                                            , "Input"
                                                            , newValue);

                            double newValueAsDouble;
                            if (Double.TryParse(newValue, out newValueAsDouble) &&
                                newValueAsDouble >= Constants.MIN_SALARY)
                            {
                                toEdit.Salary = newValueAsDouble;
                                db.SaveChanges();
                                RefreshListView();
                                break;
                            }
                            else if (newValue.Length > 0)
                            {
                                string salaryMsg = SalaryManagementSystem.Properties.Resources.InvalidSalaryMsg;
                                salaryMsg = salaryMsg.Replace("^1", Constants.MIN_SALARY.ToString());

                                MessageBox.Show(salaryMsg
                                                , "Error"
                                                , MessageBoxButton.OK
                                                , MessageBoxImage.Error);
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show(SalaryManagementSystem.Properties.Resources.SelectEmployeeMsg);
            }
        }
        public ListEmployeeSalaryBills()
        {
            InitializeComponent();

            listViewColumnSorter = new ListViewColumnSorter(listView);

            using (var db = new EmployeesDBContext())
            {
                var employees = db.Employees.ToList();
                var bills     = db.EmployeeSalaryBills.ToList();
                salaryBills = bills;
            }
            listView.ItemsSource = salaryBills;
        }
Beispiel #5
0
        private void CreateBill(Employee employee, string targetFolderPath)
        {
            using (var db = new EmployeesDBContext())
            {
                var toExport = db.Employees.SingleOrDefault(em => em.ID == employee.ID);
                if (toExport != null)
                {
                    EmployeeSalaryBill salaryBill = new EmployeeSalaryBill(DateTime.Now, toExport);

                    if (targetFolderPath.Substring(targetFolderPath.Length - 1) == "\\")
                    {
                        targetFolderPath += "Bill_" + toExport.Name + "_" + salaryBill.Date.ToString().Replace("/", "_").Replace(":", "_") + ".xlsx";
                    }
                    else
                    {
                        targetFolderPath += "\\Bill_" + toExport.Name + "_" + salaryBill.Date.ToString().Replace("/", "_").Replace(":", "_") + ".xlsx";
                    }

                    SalaryBillToExcel.WriteSalaryBillToExcel(salaryBill, targetFolderPath);
                    db.EmployeeSalaryBills.Add(salaryBill);
                    db.SaveChanges();
                }
            }
        }
        private void SubmitBtn_Click(object sender, RoutedEventArgs e)
        {
            double salary = 0;

            if (NameTextBox.Text.Length < Employee.MIN_NAME_LENGTH)
            {
                string nameMsg = SalaryManagementSystem.Properties.Resources.InvalidNameMsg;
                nameMsg = nameMsg.Replace("^1", Employee.MIN_NAME_LENGTH.ToString());

                MessageBox.Show(nameMsg
                                , "Error"
                                , MessageBoxButton.OK
                                , MessageBoxImage.Error);
            }
            else if (!Employee.IsValidEGN(EGNTextBox.Text))
            {
                MessageBox.Show(SalaryManagementSystem.Properties.Resources.InvalidEGNMsg
                                , "Error"
                                , MessageBoxButton.OK
                                , MessageBoxImage.Error);
            }
            else if (!double.TryParse(SalaryTextBox.Text, out salary) ||
                     salary < Constants.MIN_SALARY)
            {
                string salaryMsg = SalaryManagementSystem.Properties.Resources.InvalidSalaryMsg;
                salaryMsg = salaryMsg.Replace("^1", Constants.MIN_SALARY.ToString());

                MessageBox.Show(salaryMsg
                                , "Error"
                                , MessageBoxButton.OK
                                , MessageBoxImage.Error);
            }
            else if (CompanyTextBox.Text.Length == 0)
            {
                MessageBox.Show(SalaryManagementSystem.Properties.Resources.InvalidCompanyName
                                , "Error"
                                , MessageBoxButton.OK
                                , MessageBoxImage.Error);
            }
            else
            {
                using (var db = new EmployeesDBContext())
                {
                    var query = from em in db.Employees
                                where em.EGN == EGNTextBox.Text
                                select em;

                    // EGN must be unique!
                    if (query.Count() == 0)
                    {
                        Employee newEmployee = new Employee()
                        {
                            Name        = NameTextBox.Text,
                            EGN         = EGNTextBox.Text,
                            Salary      = salary,
                            CompanyName = CompanyTextBox.Text
                        };

                        db.Employees.Add(newEmployee);
                        db.SaveChanges();

                        string addedMsg = SalaryManagementSystem.Properties.Resources.AddedEmployee;
                        addedMsg = addedMsg.Replace("^1", newEmployee.Name);
                        addedMsg = addedMsg.Replace("^2", newEmployee.EGN);

                        MessageBox.Show(addedMsg
                                        , "Information"
                                        , MessageBoxButton.OK
                                        , MessageBoxImage.Information);
                    }
                    else
                    {
                        string alreadyExistsMsg = SalaryManagementSystem.Properties.Resources.EmployeeAlreadyExists;
                        alreadyExistsMsg = alreadyExistsMsg.Replace("^1", EGNTextBox.Text);

                        MessageBox.Show(alreadyExistsMsg
                                        , "Error"
                                        , MessageBoxButton.OK
                                        , MessageBoxImage.Error);
                    }
                }
            }
        }