private void EditWorker_Click(object sender, RoutedEventArgs e) { // Worker to be edited var w = WorkersView.SelectedItem as IWorker; if (w == null) { return; } // Get currently selected department from the Tree View var tvis = AppleTree.SelectedItem as TreeViewItem; if (tvis == null) { return; } var d = tvis.Tag as IDepartmentDTO; // Check if deparment has director. // This is necessary to calculate salaries in EditWorker Window bool hasDirector = true; if ((Apple as IRetrieve).Director(d) == null) { hasDirector = false; } // For each hierarchy level provide proper list of available positions // i.e. you can't add Head of the Division at the Department level bool keepDirector = false; if (w is IDirector) { keepDirector = true; } var availablePositionsList = Apple.Available(d, keepDirector); // Open Edit Worker dialog window DateTime orgCreationDate = (Apple as IRetrieve).RootDepartment().CreatedOn; EditWorkerMenu editWorkerWin = new EditWorkerMenu(w, d, hasDirector, availablePositionsList, orgCreationDate); bool?result = editWorkerWin.ShowDialog(); if (result != true) { return; } // Pass new data of worker to back-end method to update the worker UI.Workers.EditWorker(editWorkerWin.wCopy); UpdateMainWindow(); }
/// <summary> /// Creates new worker /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddWorker_Click(object sender, RoutedEventArgs e) { // Get currently selected department from the Tree View var tvis = AppleTree.SelectedItem as TreeViewItem; if (tvis == null) { return; } var d = tvis.Tag as IDepartmentDTO; // For each hierarchy level provide proper list of available positions // i.e. you can't add Head of the Division at the Department level var availablePositionsList = Apple.Available(d, false); // Invoke Add Worker Menu window AddWorkerMenu addWorkerWin = new AddWorkerMenu(d.DeptName, availablePositionsList); bool?result = addWorkerWin.ShowDialog(); if (result != true) { return; } // Pass collected worker's information to the back-end worker adding method // Cast interface values to back-end types int addResult = UI.Workers.AddWorker( addWorkerWin.FirstNameEntryBox.Text, // First Name addWorkerWin.LastNameEntryBox.Text, // Last Name (DateTime)addWorkerWin.DateOfBirthPicker.SelectedDate, // Date of birth d, // Department (addWorkerWin.PositionEntryBox.SelectedItem as IPositionTuple).Pos // Position ); // Check if adding was successful if not display a warning message if (addResult != 0) { addWorkerWin.AddingMistakeWarning(addResult); return; } UpdateMainWindow(); }