Beispiel #1
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;
            }
        }
Beispiel #2
0
        public void ImportData(MWTController controller, string importFromVersion, Dictionary <PreferenceName, string> loadPreferences, List <WorkItemStatus> importStatuses, XDocument xml)
        {
            MWTModel _model = controller.GetMWTModel();

            // Import any preference changes.
            // (Note that the passing method provides an empty collection if we don't want this to happen).
            if (loadPreferences.Count > 0)
            {
                foreach (PreferenceName key in loadPreferences.Keys)
                {
                    if (_model.GetAppPreferenceValue(key).Equals(loadPreferences[key]) == false)
                    {
                        controller.UpdateAppPreference(key, loadPreferences[key]);
                    }
                }
            }

            // Import any WorkItemStatus requirements.
            foreach (WorkItemStatus wis in importStatuses)
            {
                WorkItemStatus currentWIS = controller.GetWorkItemStatus(wis.Status);
                if (currentWIS != null)
                {
                    // If the two Statuses (system and import) exists, but are not the same...
                    if (currentWIS.IsSame(wis) == false)
                    {
                        wis.Status          += " (2)";
                        wis.WorkItemStatusID = controller.InsertDBWorkItemStatus(wis);
                    }
                    else
                    {
                        // The Status exists, and is the same as the existing version; set the dbID to be the same as the existing one.
                        wis.WorkItemStatusID = controller.GetWorkItemStatus(wis.Status).WorkItemStatusID;
                    }
                }
                else
                { // If the Status doesn't exist, then we want to add it.
                    wis.WorkItemStatusID = controller.InsertDBWorkItemStatus(wis);
                }
            }

            // Import the Work Items.
            var query1 = from element in xml.Descendants("WorkItem")
                         select element;

            foreach (var el3 in query1)
            {
                int      importedWorkID = Int32.Parse(el3.Attribute("WorkItem_ID").Value);
                WorkItem wi             = new WorkItem
                {
                    Title            = el3.Element("Title").Value,
                    TaskDescription  = el3.Element("Description").Value,
                    Completed        = Int32.Parse(el3.Element("Complete").Value),
                    CreationDateTime = DateTime.Parse(el3.Element("CreationDate").Value)
                };

                if ((el3.Element("DeletionDate").Value != null) && (el3.Element("DeletionDate").Value.Equals("") == false))
                {
                    wi.DeletionDateTime = DateTime.Parse(el3.Element("DeletionDate").Value);
                }

                wi.Meta.WorkItem_ID = controller.InsertDBWorkItem(wi, false);

                // Work Item Status
                var query2 = from element in el3.Descendants("StatusChange")
                             where Int32.Parse(el3.Attribute("WorkItem_ID").Value) == importedWorkID
                             select element;
                foreach (var el2 in query2)
                {
                    int statusID = Int32.Parse(el2.Element("Status_ID").Value);
                    Console.WriteLine($"-----------------------------\nImporting WI {importedWorkID}, which becomes #{wi.Meta.WorkItem_ID}, the status ID is {statusID}");
                    var wiseCreateDateTime = DateTime.Parse(el2.Element("CreationDate").Value);

                    DateTime?DeleteDateTime = null;
                    if ((el3.Element("DeletionDate").Value != null) && (el2.Element("DeletionDate").Value.Equals("") == false))
                    {
                        DeleteDateTime = DateTime.Parse(el2.Element("DeletionDate").Value);
                    }

                    WorkItemStatusEntry wise = new WorkItemStatusEntry(wi.Meta.WorkItem_ID, statusID, wiseCreateDateTime, DeleteDateTime);
                    controller.InsertDBWorkItemStatusEntry(wise);
                }

                // Due Dates
                var query3 = from element in el3.Descendants("DueDateChange")
                             where Int32.Parse(el3.Attribute("WorkItem_ID").Value) == importedWorkID
                             select element;
                foreach (var el2 in query3)
                {
                    DateTime dueDateTime    = DateTime.Parse(el2.Element("DueDateTime").Value);
                    string   changeReason   = (string)el2.Element("ChangeReason").Value;
                    DateTime?DeleteDateTime = null;
                    if ((el3.Element("DeletionDate").Value != null) && (el2.Element("DeletionDate").Value.Equals("") == false))
                    {
                        DeleteDateTime = DateTime.Parse(el2.Element("DeletionDate").Value);
                    }
                    controller.InsertDBDueDate(wi, dueDateTime, changeReason);
                }

                // Journals
                var query4 = from element in el3.Descendants("JournalEntry")
                             where Int32.Parse(el3.Attribute("WorkItem_ID").Value) == importedWorkID
                             select element;
                foreach (var el2 in query4)
                {
                    string journalHeader = "";
                    if (el2.Element("Header").Value != null)
                    {
                        journalHeader = (string)el2.Element("Header").Value;
                    }

                    string journalEntry = "";
                    if (el2.Element("Entry").Value != null)
                    {
                        journalEntry = (string)el2.Element("Entry").Value;
                    }

                    DateTime?creationDateTime = null;
                    if ((el2.Element("CreationDateTime").Value != null) && (el2.Element("CreationDateTime").Value.Equals("") == false))
                    {
                        creationDateTime = DateTime.Parse(el2.Element("CreationDateTime").Value);
                    }

                    DateTime?modificationDateTime = null;
                    if ((el2.Element("ModificationDateTime").Value != null) && (el2.Element("ModificationDateTime").Value.Equals("") == false))
                    {
                        modificationDateTime = DateTime.Parse(el2.Element("ModificationDateTime").Value);
                    }

                    DateTime?DeleteDateTime = null;
                    if ((el2.Element("JournalDeletionDateTime").Value != null) && (el2.Element("JournalDeletionDateTime").Value.Equals("") == false))
                    {
                        DeleteDateTime = DateTime.Parse(el2.Element("JournalDeletionDateTime").Value);
                    }
                    JournalEntry journal = new JournalEntry(journalHeader, journalEntry, creationDateTime, modificationDateTime, DeleteDateTime);
                    controller.InsertDBJournalEntry(wi.Meta.WorkItem_ID, journal);
                }
            } // end - foreach (var el3 in query3)
        }