Exemplo n.º 1
0
 /// <summary>
 /// Catch UI events sent from the Model.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="action"></param>
 public void ModelEventListener(Object sender, BaseNotification action)
 {
     if (action is WorkItemCreatingNotification)
     {
         Console.WriteLine("WorkItemCreatingAction in usercontrol");
         SelectedTaskTitleField.Focus();
     }
 }
Exemplo n.º 2
0
 private void ActiveWorkItemSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     // If the application is in 'add mode' (ADD_WORK_ITEM) then don't allow any selections.
     if (_model.IsApplicationInAddMode)
     {
         SelectedTaskTitleField.Focus();
     }
     else
     {
         UpdateWorkItemDBAsRequired();
         Overview.Background = Brushes.White;
         WorkItem wi = (WorkItem)(sender as ListBox).SelectedItem;
         // The ActiveWorkItemSelectionChanged may be set to null (if a Closed selection is made), so need to handle that here.
         if (wi != null)
         {
             _model.SetSelectedWorkItem(wi);
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// A listener method for the AppEvents.
        /// This method handles all of the AppEvents that are fired from the model.
        /// </summary>
        /// <param name="o"></param>
        /// <param name="args"></param>
        private void AppEventListener(Object o, AppEventArgs args)
        {
            switch (args.Action)
            {
            case AppAction.CREATE_WORK_ITEM:
                // Change the Combobox that shows the Status of the currently selected item.
                WorkItemStatusComboBox.SelectedItem = _controller.GetWorkItemStatus(_model.SelectedWorkItem.workItemStatus.Status);

                _model.IsBindingLoading = false;

                // Move the cursor to the Task Title field.
                SelectedTaskTitleField.Focus();

                _model.SetApplicationMode(DataEntryMode.ADD);
                break;

            case AppAction.SELECT_WORK_ITEM:
                // Because the UI is divided into two lists (active and closed), we need to toggle the selections of both lists.
                _model.IsBindingLoading = true;
                WorkItem wi = args.CurrentWorkItemSelection;

                // The Work Item selection is of an 'Active' status.
                // If the selection is Active, then we want to clear the Closed list selections.
                if (wi.IsConsideredActive)
                {
                    ClosedListView.SelectedItem = null;
                    // If an item isn't selected on the Overview list, and is in the list, then select it now.
                    if ((Overview.SelectedItem == null) && (Overview.Items.Contains(wi)))
                    {
                        Overview.SelectedItem = wi;
                    }
                }
                else
                {
                    // The Work Item selection is of a 'Closed' status.
                    // If the selection is Closed, then we want to clear the Active list selections.
                    Overview.SelectedItem = null;
                    if ((ClosedListView.SelectedItem == null) && (ClosedListView.Items.Contains(wi)))
                    {
                        ClosedListView.SelectedItem = wi;
                    }
                }

                // ---
                Console.WriteLine($"WorkItemStatusID = {wi.Meta.WorkItemStatus_ID}; WorkItemStatusEntryID={wi.WorkItemStatusEntry.WorkItemStatusEntryID}; FlaggedForUpdate={wi.Meta.WorkItemStatusNeedsUpdate}; Status={wi.Status}; Completion={wi.Completed};");
                Console.WriteLine($"WorkItemStatusEntryID={wi.WorkItemStatusEntry.WorkItemStatusEntryID}; StatusID={wi.WorkItemStatusEntry.StatusID}; CompletionAmount={wi.WorkItemStatusEntry.CompletionAmount} RecordExists={wi.WorkItemStatusEntry.RecordExists}");
                // WorkItemStatusID = 0; WorkItemStatusEntryID = 9; FlaggedForUpdate = False; Status = Active; Completion = 0;
                // WorkItemStatusEntryID = 9; StatusID = 1; CompletionAmount = 0 RecordExists = True
                // ---

                // Set the Work Item Status & the DueInDays control to the values of the selected WorkItem
                WorkItemStatusComboBox.SelectedItem = _controller.GetWorkItemStatus(wi.Status);
                DueInDaysTextField.Text             = DateMethods.GenerateDateDifferenceLabel(DateTime.Now, _model.SelectedWorkItem.DueDate, true);

                // Check to see if the Journal entries for this Work Item have been loaded. Load them if not.
                if (_model.SelectedWorkItem.Meta.AreJournalItemsLoaded == false)
                {
                    _controller.LoadJournalEntries(_model.SelectedWorkItem);
                }
                JournalEntryList.ItemsSource = _model.SelectedWorkItem.Journals;

                //  Check to see if the CheckList for this WorkItem have been loaded. Load them if not.
                if (_model.AreCheckListsLoaded(wi.Meta.WorkItem_ID) == false)
                {
                    _controller.LoadWorkItemCheckLists(_model.SelectedWorkItem);
                }
                WorkItemCheckList.ItemsSource = _model.CheckListItems;

                _model.SetApplicationMode(DataEntryMode.EDIT);

                _model.IsBindingLoading = false;

                break;

            case AppAction.WORK_ITEM_ADDED:

                SaveButton.Background = Brushes.SteelBlue;
                SaveButton.Content    = "Save";
                break;

            case AppAction.WORK_ITEM_STATUS_CHANGED:
                // Before processing any actions, check to see if Binding is loading.
                // If it is, then do nothing.
                if (_model.IsBindingLoading == false)
                {
                    // Unpack the event
                    WorkItem       wi2 = args.CurrentWorkItemSelection;
                    WorkItemStatus newWorkItemStatus = (WorkItemStatus)args.Object1;
                    WorkItemStatus oldWorkItemStatus = (WorkItemStatus)args.Object2;

                    // Check to see if the change in status is a change between active/closed
                    if (newWorkItemStatus.IsConsideredActive != oldWorkItemStatus.IsConsideredActive)
                    {
                        // Active-to-Closed
                        // If the status is not considered to be active, then disable the progress slider.
                        if (newWorkItemStatus.IsConsideredActive == false)
                        {
                            WorkItemProgressSlider.IsEnabled = false;
                            _model.SwapList(true, wi2);
                            //_model.SetSelectedWorkItem(null);
                        }
                        else     // Closed-to-Active
                        {
                            _model.SwapList(false, wi2);
                            OverviewAreaTabs.SelectedIndex = 0;
                            // If it's Active (i.e. not Completed) and at 100% progress then set it back to 95%
                            // (This is to prevent a Completed-then-Active being auto-set back to Completed when loaded again)
                            WorkItemProgressSlider.IsEnabled = true;
                            //if (wi2.Completed == 100)
                            if (wi2.Completed == 100)
                            {
                                string strValue = _model.GetAppPreferenceValue(PreferenceName.STATUS_ACTIVE_TO_COMPLETE_PCN);
                                wi2.Completed = int.Parse(strValue);
                            }
                        }
                    }
                    else
                    {
                        // do nothing
                    }
                }
                break;

            case AppAction.SET_APPLICATION_MODE:
                if (_model.GetApplicationMode() == DataEntryMode.ADD)
                {
                    // Make the 'New Work Item' button unavailable.
                    // TODO: Not working
                    NewWorkItemButton.IsEnabled = false;

                    Overview.Background = Brushes.WhiteSmoke;

                    SaveButton.Content = "Create Work Item";
                }
                else if (_model.GetApplicationMode() == DataEntryMode.EDIT)
                {
                    // Make the 'New Work Item' button available.
                    NewWorkItemButton.IsEnabled = true;
                    Overview.Background         = Brushes.White;
                    SaveButton.Content          = "Save";
                }
                break;

            case AppAction.PREFERENCE_CHANGED:
                // Intentionally there is no in-built protection to stop a user from editing a non-editable value. (Keeping my options open)

                // Change in memory.
                Enum.TryParse(args.Object1.ToString(), out PreferenceName preferenceName);

                _model.GetAppPreferenceCollection()[preferenceName].Value = args.Object3.ToString();

                // Change in storage.
                _controller.UpdateAppPreference(preferenceName, args.Object3.ToString());

                break;

            case AppAction.JOURNAL_ENTRY_DELETED:
                _controller.DeleteDBJournalEntry((JournalEntry)args.Object1);
                break;

            case AppAction.JOURNAL_ENTRY_ADDED:
                _controller.InsertDBJournalEntry(args.CurrentWorkItemSelection.Meta.WorkItem_ID, (JournalEntry)args.Object1);
                _controller.AddJournalEntry(args.CurrentWorkItemSelection, (JournalEntry)args.Object1);
                break;

            case AppAction.JOURNAL_ENTRY_EDITED:
                _controller.UpdateDBJournalEntry((JournalEntry)args.Object2);
                int indexOf = _model.SelectedWorkItem.Journals.IndexOf((JournalEntry)args.Object1);
                _model.SelectedWorkItem.Journals.Remove((JournalEntry)args.Object1);
                _model.SelectedWorkItem.Journals.Insert(indexOf, (JournalEntry)args.Object2);
                break;

            case AppAction.DATA_EXPORT:
                ExportWindow exportDialog = new ExportWindow(_controller.GetPreferencesBeginningWith("DATA_EXPORT"));
                exportDialog.ShowDialog();

                if (exportDialog.WasSubmitted)
                {
                    string dbConn = null;
                    if (exportDialog.ExportFromSystemFile)
                    {
                        dbConn = _controller.DBConnectionString;
                    }
                    else
                    {
                        dbConn = "data source=" + exportDialog.ExportFile;

                        // Save the last directory where the export has come from.
                        int    index           = exportDialog.ExportFile.LastIndexOf('\\');
                        string exportDirectory = exportDialog.ExportFile.Substring(0, index - 1);
                        if (_model.GetAppPreferenceValue(PreferenceName.DATA_EXPORT_LAST_DIRECTORY).Equals(exportDirectory) == false)
                        {
                            _controller.UpdateAppPreference(PreferenceName.DATA_EXPORT_LAST_DIRECTORY, exportDirectory);
                        }
                    }

                    var exportSettings = new Dictionary <ExportSetting, string>();
                    exportSettings.Add(ExportSetting.DATABASE_CONNECTION, dbConn);
                    exportSettings.Add(ExportSetting.EXPORT_TO_LOCATION, exportDialog.SaveLocation);
                    exportSettings.Add(ExportSetting.EXPORT_PREFERENCES, Convert.ToString(exportDialog.IncludePreferences));
                    exportSettings.Add(ExportSetting.EXPORT_WORK_ITEM_OPTION, exportDialog.WorkItemType);
                    exportSettings.Add(ExportSetting.EXPORT_DAYS_STALE, Convert.ToString(exportDialog.StaleNumber));
                    exportSettings.Add(ExportSetting.EXPORT_INCLUDE_DELETED, Convert.ToString(exportDialog.IncludeDeleted));
                    exportSettings.Add(ExportSetting.EXPORT_INCLUDE_LAST_STATUS_ONLY, Convert.ToString(!exportDialog.AllStatuses));
                    exportSettings.Add(ExportSetting.EXPORT_INCLUDE_LAST_DUEDATE_ONLY, Convert.ToString(!exportDialog.AllDueDates));
                    _controller.ExportToXML(exportDialog.ExportVersion, exportSettings);

                    MessageBox.Show($"Export has been saved to {exportDialog.SaveLocation}", "Export Complete");
                }
                break;

            case AppAction.DATA_IMPORT:
                string       importLastDirectory = _model.GetAppPreferenceValue(PreferenceName.DATA_IMPORT_LAST_DIRECTORY);
                ImportWindow importDialog        = new ImportWindow(_model.GetAppPreferenceValue(PreferenceName.APPLICATION_VERSION),
                                                                    importLastDirectory);
                importDialog.ShowDialog();

                if ((importDialog.WasSubmitted) && (importDialog.ImportSelectionCount > 0))
                {
                    Dictionary <PreferenceName, string> preferences = new Dictionary <PreferenceName, string>();
                    if (importDialog.ImportPreferencesSelected)
                    {
                        preferences = importDialog.LoadedPreferences;
                    }
                    _controller.ImportData(importDialog.GetImportVersion, preferences, importDialog.GetImportStatuses, importDialog.LoadedXMLDocument);
                    string directoryPortionOnly = importLastDirectory.Substring(0, importLastDirectory.LastIndexOf('\\') - 1);
                    if (importDialog.GetImportFileLocation.Equals(directoryPortionOnly) == false)
                    {
                        _controller.UpdateAppPreference(PreferenceName.DATA_IMPORT_LAST_DIRECTORY, directoryPortionOnly);
                    }
                }
                break;

            case AppAction.WORK_ITEM_DELETE_LOGICAL:
                _controller.DeleteWorkItem(args.CurrentWorkItemSelection, true);
                break;

            case AppAction.WORK_ITEM_DELETE_PHYSICAL:
                _controller.DeleteWorkItem(args.CurrentWorkItemSelection, false);
                break;

            case AppAction.CHECKLIST_ITEM_ADDED:
                CheckListItem i2 = (CheckListItem)args.Object1;
                _model.CheckListItems.Add(i2);
                _controller.SetCheckListMode(DataEntryMode.EDIT);
                WorkItemCheckList.SelectedItem = i2;
                break;

            case AppAction.CHECKLIST_ITEM_SELECTED:
                if (_model.WorkItemCheckListDBNeedsUpdating)
                {
                    Console.WriteLine("an item needs updating");
                    CheckListItem cli = (CheckListItem)args.Object1;
                    _controller.UpdateDBCheckListItem(cli, 0);
                }

                break;

            case AppAction.CHECKLIST_ITEM_MOVED:
                CheckListItem cli3 = (CheckListItem)args.Object1;
                ReloadCheckListItems();
                _model.SelectedCheckListItem = cli3;     // TODO this isn't working. The item moved up doesn't have focus in the list.
                break;

            case AppAction.CHECKLIST_MODE_CHANGED:
                if (_model.CheckListItemMode == DataEntryMode.ADD)
                {
                    AddChecklistItemButton.IsEnabled = true;
                    CheckListItem cli2 = new CheckListItem();
                    _model.SelectedCheckListItem = cli2;
                }
                else
                {
                    AddChecklistItemButton.IsEnabled = false;
                }
                break;
            }
        }