示例#1
0
        /// <summary>
        /// Client'ların bilgileri listesini günceller
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReloadScreen(object sender, EventArgs e)
        {
            //Ekrandan kaldırılacak item'lar
            List <ListViewItem> removingListItems = new List <ListViewItem>();

            //Ekrana halihazırda eklenmiş clientId'ler
            List <string> alreadyAddedClientIds = new List <string>();

            //Öncelikle ekrandakiler güncelleniyor veya kaldırılıyor
            foreach (ListViewItem listItem in lvClients.Items)
            {
                var client = Clients.Where(p => p.Id == listItem.Text).FirstOrDefault();

                //Eğer client yoksa veya timeout olduysa
                if (client == null || DateMethods.IsTimedOut(client.LastUpdate, MaxRemovingSeconds))
                {
                    removingListItems.Add(listItem);

                    //Client listesinden de kaldırılıyor
                    if (client != null)
                    {
                        Clients.Remove(client);
                    }
                }
                else
                {
                    alreadyAddedClientIds.Add(client.Id);
                    SetListItem(listItem, client);
                }
            }

            //Kaldırılacaklar ekrandan kaldırılıyor
            removingListItems.ForEach(p => lvClients.Items.Remove(p));

            /*
             * Ekranda var olmayan client'lar ekrana ekleniyor
             * ve
             * Eğer belli bir saniye süresince (MaxRemovingSeconds) client'dan bir bilgi gelmediyse
             * ekrandan ve listeden kaldırılır.
             */
            var notAddedClients = Clients.Where(client => !alreadyAddedClientIds.Contains(client.Id)).ToList();

            foreach (var client in notAddedClients)
            {
                /*
                 * Eğer belli bir saniye süresince (MaxRemovingSeconds) client'dan bir bilgi gelmediyse
                 * client'dan cevap alamadığı bilgisi düşülür.
                 */

                var newRow = new ListViewItem();

                SetListItem(newRow, client);

                lvClients.Items.Add(newRow);
            }
        }
示例#2
0
        /// <summary>
        /// تاریخ میلادی به عبارت فارسی و خوانای تاریخ شمسی
        /// </summary>
        /// <param name="date">تاریخ</param>
        /// <returns></returns>
        public static string ToPersianText(this DateTime date)
        {
            var persianDate = date.ToPersianDate();
            var year        = persianDate.Substring(0, 4);
            var month       = persianDate.Substring(5, 2);
            var day         = persianDate.Substring(8, 2);

            day   = DateMethods.DayName(day);
            month = DateMethods.MonthName(month);
            year  = year.NumberToPersianText();

            return($"{day} {month} {CommonConsts.Names.Month} {CommonConsts.Names.Year} {year} ");
        }
示例#3
0
        /// <summary>
        /// Select a new DueDate for the WorkItem.
        /// If the DueDate (from database) has been set within x mins of now, UPDATE the record instead of INSERTING it.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DueDateButton_Click(object sender, RoutedEventArgs e)
        {
            if (_model.SelectedWorkItem != null)
            {
                WorkItem selectedWI     = _model.SelectedWorkItem;
                DateTime currentDueDate = selectedWI.DueDate;
                var      ddDialog       = new DueDateDialog(currentDueDate);
                ddDialog.Owner = this;
                ddDialog.ShowDialog();

                if (ddDialog.WasDialogSubmitted)
                {
                    if (ddDialog.NewDateTime.Equals(currentDueDate))
                    {
                        // Do nothing
                    }
                    else
                    {
                        int rowID = -1;
                        // If the DueDate (from database) has been set within x mins of now, UPDATE the record instead of INSERTING it.
                        int minutesSinceLastSet = DateTime.Now.Subtract(selectedWI.Meta.DueDateUpdateDateTime).Minutes;
                        if (minutesSinceLastSet < Convert.ToInt32(_controller.GetMWTModel().GetAppPreferenceValue(PreferenceName.DUE_DATE_SET_WINDOW_MINUTES)))
                        {
                            // Update
                            rowID = _controller.UpdateDBDueDate(selectedWI, ddDialog.NewDateTime, ddDialog.ChangeReason);
                        }
                        else
                        {
                            // Insert
                            rowID = _controller.InsertDBDueDate(selectedWI, ddDialog.NewDateTime, ddDialog.ChangeReason);
                        }

                        // Update the update/record change time.
                        selectedWI.Meta.DueDate_ID            = rowID;
                        selectedWI.Meta.DueDateUpdateDateTime = DateTime.Now;
                        selectedWI.DueDate = ddDialog.NewDateTime;
                        selectedWI.Meta.DueDateUpdateDateTime = DateTime.Now;

                        // Refresh the time label
                        DueInDaysTextField.Text = DateMethods.GenerateDateDifferenceLabel(DateTime.Now, _model.SelectedWorkItem.DueDate, true);
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// ثبت خطاها
        /// </summary>
        /// <param name="ex"></param>
        /// <param name="form"> فرم جاری</param>
        public static void LogToTextFile(this Exception ex, string methodName)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(" -------------------- " + DateMethods.Hour() + "-----------------------");

            sb.AppendLine("Method : ");
            sb.AppendLine(methodName);
            sb.AppendLine();

            sb.AppendLine("User : "******"LogFiles");

            sb.ToString().ToFile(path);
        }
        public void testGetLastCheckpoint2ID()
        {
            List <FieldCheckpoint> fields = new List <FieldCheckpoint>();

            fields.Add(FieldCheckpoint.message);
            Tracking trackingGet1 = new Tracking("whatever");

            trackingGet1.id = "53d1e35405e166704ea8adb9";

            Checkpoint newCheckpoint1 = connection.getLastCheckpoint(trackingGet1, fields, "");

            Assert.AreEqual("Network movement commenced", newCheckpoint1.message);
            Assert.AreEqual("0001-01-01T00:00:00+00:00", DateMethods.ToString(newCheckpoint1.createdAt));

            fields.Add(FieldCheckpoint.created_at);
//            System.out.println("list:"+fields.toString());
            Checkpoint newCheckpoint2 = connection.getLastCheckpoint(trackingGet1, fields, "");

            Assert.AreEqual("Network movement commenced", newCheckpoint2.message);
            Assert.AreEqual("2014-07-25T04:55:49+00:00", DateMethods.ToString(newCheckpoint2.createdAt));
        }
示例#6
0
        public void testGetLastCheckpoint2ID()
        {
            List <FieldCheckpoint> fields = new List <FieldCheckpoint>();

            fields.Add(FieldCheckpoint.message);
            Tracking trackingGet1 = new Tracking("whatever");

            trackingGet1.id = "555035fe74346ecd50998680";

            Checkpoint newCheckpoint1 = connection.getLastCheckpoint(trackingGet1, fields, "");

            Assert.IsTrue(!string.IsNullOrEmpty(newCheckpoint1.message));
            Assert.AreEqual("0001-01-01T00:00:00+08:00", DateMethods.ToString(newCheckpoint1.createdAt));

            fields.Add(FieldCheckpoint.created_at);
            Checkpoint newCheckpoint2 = connection.getLastCheckpoint(trackingGet1, fields, "");

            Assert.IsTrue(!string.IsNullOrEmpty(newCheckpoint2.message));
            Assert.AreNotEqual("0001-01-01T00:00:00+00:00", DateMethods.ToString(newCheckpoint2.createdAt));
            Assert.IsTrue(!string.IsNullOrEmpty(DateMethods.ToString(newCheckpoint2.createdAt)));
        }
示例#7
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;
            }
        }
示例#8
0
        /// <summary>
        /// ListItem'ı günceller
        /// </summary>
        /// <param name="listItem"></param>
        /// <param name="client"></param>
        private void SetListItem(ListViewItem listItem, ClientData client)
        {
            listItem.SubItems.Clear();

            listItem.Text = client.Id;

            bool isTimedOutForResponding = DateMethods.IsTimedOut(client.LastUpdate, MaxRespondingSeconds);

            if (isTimedOutForResponding)
            {
                client.ClientStatusType = ClientStatusType.NotResponding;
            }

            listItem.SubItems.Add(new ListViewItem.ListViewSubItem()
            {
                Name = "status",
                Tag  = "status",
                Text = client.ClientStatusType.ToString()
            });



            if (isTimedOutForResponding)
            {
                listItem.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "message",
                    Tag  = "message",
                    Text = "Not Responding"
                });

                client.ClientStatusType = ClientStatusType.NotResponding;
            }
            else
            {
                listItem.SubItems.Add(new ListViewItem.ListViewSubItem()
                {
                    Name = "message",
                    Tag  = "message",
                    Text = client.StatusText
                });
            }

            listItem.SubItems.Add(new ListViewItem.ListViewSubItem()
            {
                Name = "lastUpdate",
                Tag  = "lastUpdate",
                Text = client.LastUpdate.ToString()
            });

            //Client'ın durumuna göre satırın rengi belirleniyor
            switch (client.ClientStatusType)
            {
            case ClientStatusType.Normal:
                listItem.BackColor = lvClients.BackColor;
                listItem.ForeColor = lvClients.ForeColor;
                break;

            case ClientStatusType.Message:
                listItem.BackColor = Color.Yellow;
                listItem.ForeColor = lvClients.ForeColor;
                break;

            case ClientStatusType.Error:
                listItem.BackColor = Color.Red;
                listItem.ForeColor = Color.White;
                break;

            case ClientStatusType.NotResponding:
                listItem.BackColor = Color.Orange;
                listItem.ForeColor = lvClients.ForeColor;
                break;

            case ClientStatusType.Attacking:
                listItem.BackColor = Color.Green;
                listItem.ForeColor = Color.White;
                break;

            default:
                break;
            }
        }