Example #1
0
 private void SaveExecute()
 {
     try
     {
         if (EntryValidation.ValidateName(Worker.FirstName) == false)
         {
             MessageBox.Show("First Name can only contain letters. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateName(Worker.LastName) == false)
         {
             MessageBox.Show("Last Name can only contain letters. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateDate(Worker.DateOfBirth) == false)
         {
             MessageBox.Show("Person Must be at least 16 years of age. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidatePersonalIDNumber(Worker.PersonalIDNumber) == false)
         {
             MessageBox.Show("Personal ID nubmer you entered is not valid. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidateJmbg(Worker.JMBG) == false)
         {
             MessageBox.Show("JMBG you entered is not valid. Please try again", "Invalid input");
             return;
         }
         if (EntryValidation.ValidatePhone(Worker.PhoneNumber) == false)
         {
             MessageBox.Show("Phone number you entered is not in correct format. Please try again", "Invalid input");
             return;
         }
         Worker.GenderID   = Gender.GenderID;
         Worker.SectorID   = Sector.SectorID;
         Worker.ManagerID  = Manager.WorkerID;
         Worker.LocationID = Location.LocationID;
         _dbService.EditWorker(Worker);
         IsUpdateWorker = true;
         string logMessage = string.Format("Worker {0} {1} - JMBG:{2}, data was edited to {3} {4} JMBG:{5}.", FirstNameBeforeEdit,
                                           LastNameBeforeEdit, JMBGBeforeEdit, _worker.FirstName, _worker.LastName, _worker.JMBG);
         actionEventObject.OnActionPerformed(logMessage);
         MessageBox.Show("Worker Edited Successfully!", "Info");
         _editWorker.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
        private void ListBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key == System.Windows.Input.Key.Delete)
            {// удаление по клавише delete
                if (listBox.SelectedIndex > -1)
                {
                    int             si              = cBoxWork.SelectedIndex;
                    WorkViewModel   workViewModel   = cBoxWork.SelectedItem as WorkViewModel;
                    WorkerViewModel workerViewModel = listBox.SelectedItem as WorkerViewModel;

                    workService.RemoveWorkerFromWork(workViewModel.WorkId, workerViewModel.WorkerId);
                    works = workService.GetAll();
                    cBoxWork.DataContext   = works;
                    cBoxWork.SelectedIndex = si;
                }
            }
            if (e.Key == System.Windows.Input.Key.Insert)
            {// обновление по клавише Insert
                if (listBox.SelectedIndex > -1)
                {
                    WorkerViewModel workerViewModel = listBox.SelectedItem as WorkerViewModel;
                    var             dialog          = new EditWorker(workerViewModel);
                    var             result          = dialog.ShowDialog();
                    if (result == true)
                    {
                        workService.UpdateWorker(workerViewModel);
                        dialog.Close();
                    }
                }
            }
        }
        private void ButtonAddWorker_Click(object sender, RoutedEventArgs e)
        {
            var worker = new WorkerViewModel();

            worker.DateOfBirth = new DateTime(1990, 01, 01);
            var dialog = new EditWorker(worker);
            var result = dialog.ShowDialog();

            if (result == true)
            {
                var work = (WorkViewModel)cBoxWork.SelectedItem;
                work.Workers.Add(worker);
                workService.AddWorkerToWork(work.WorkId, worker);
                dialog.Close();
            }
        }