Exemple #1
0
        //private void UpdateQs()
        //{

        //    //Set Q No. TO 0 if the process is completed
        //    foreach (var process in ProcessCache.GetInstance().Processes)
        //    {
        //        var q = ProcessQCache.GetInstance().GetByProcess(process);
        //        if(q == null)
        //        {
        //            //if no q entry, make a new entry.
        //            q = ProcessQCache.GetInstance().Insert(new ProcessQ
        //            {
        //                ProcessId = process.Id,
        //                QNumber = 0
        //            });
        //        }
        //        if (process.Status == Process.ProcessStatus.Completed)
        //        {
        //            q.QNumber = 0;
        //            ProcessQCache.GetInstance().Update(q);
        //        }
        //    }
        //    //For each resource,
        //    foreach (var resource in ResourceCache.GetInstance().Resources)
        //    {
        //        //get incomplete processes...
        //        var incompleteProcs = ProcessCache.GetInstance().GetByResourceId(resource.Id).FindAll(p => p.Status != Process.ProcessStatus.Completed).ToList<Process>();
        //        //order them ascending order of existing q numbers... if a ProcessQ isn't available, temporarily assign it a large value so that they get to the end of the q in next step
        //        var procsInQueueOrder = incompleteProcs.OrderBy(p => ProcessQCache.GetInstance().GetByProcess(p)?.QNumber ?? long.MaxValue);
        //        long index = 0;
        //        foreach (var process in procsInQueueOrder)
        //        {
        //            index++;
        //            var q = ProcessQCache.GetInstance().GetByProcess(process);
        //            if (q != null)
        //            {
        //                q.QNumber = index;
        //                ProcessQCache.GetInstance().Update(q);
        //            }
        //            else if (q == null)
        //            {
        //                ProcessQCache.GetInstance().Insert(
        //                    new ProcessQ
        //                    {
        //                        ProcessId = process.Id,
        //                        QNumber = index
        //                    });
        //            }
        //        }
        //    }
        //}

        private void DeleteProcessClickHandler()
        {
            //delete q number of this process first..
            ProcessQCache.GetInstance().Delete(ProcessQCache.GetInstance().GetByProcess(SelectedProcess));
            //now delete the process.
            ProcessCache.GetInstance().Delete(SelectedProcess);
            Processes.Remove(SelectedProcess);

            //Run the Q update logic now..
            CommonFunctions.UpdateQs();
            Resources = ResourceCache.GetInstance().UpdateAllQSizes();
        }
Exemple #2
0
 public static void UpdateQs()
 {
     //Set Q No. TO 0 if the process is completed
     foreach (var process in ProcessCache.GetInstance().Processes)
     {
         var q = ProcessQCache.GetInstance().GetByProcess(process);
         if (q == null)
         {
             //if no q entry, make a new entry.
             q = ProcessQCache.GetInstance().Insert(new ProcessQ
             {
                 ProcessId = process.Id,
                 QNumber   = 0
             });
         }
         if (process.Status == Process.ProcessStatus.Completed)
         {
             q.QNumber = 0;
             ProcessQCache.GetInstance().Update(q);
         }
     }
     //For each resource,
     foreach (var resource in ResourceCache.GetInstance().Resources)
     {
         //get incomplete processes...
         var incompleteProcs = ProcessCache.GetInstance().GetByResourceId(resource.Id).FindAll(p => p.Status != Process.ProcessStatus.Completed).ToList <Process>();
         //order them ascending order of existing q numbers... if a ProcessQ isn't available, temporarily assign it a large value so that they get to the end of the q in next step
         var  procsInQueueOrder = incompleteProcs.OrderBy(p => ProcessQCache.GetInstance().GetByProcess(p)?.QNumber ?? long.MaxValue);
         long index             = 0;
         foreach (var process in procsInQueueOrder)
         {
             index++;
             var q = ProcessQCache.GetInstance().GetByProcess(process);
             if (q != null)
             {
                 q.QNumber = index;
                 ProcessQCache.GetInstance().Update(q);
             }
             else if (q == null)
             {
                 ProcessQCache.GetInstance().Insert(
                     new ProcessQ
                 {
                     ProcessId = process.Id,
                     QNumber   = index
                 });
             }
         }
     }
 }
        private void DownClickHandler()
        {
            var selectedIndex = Processes.IndexOf(SelectedProcess);
            //step 1: Identify the process just below the selected process.
            var processBelow = Processes[Processes.IndexOf(SelectedProcess) + 1];
            //step 2: increase q number of selected item.
            var selectedQ = ProcessQCache.GetInstance().GetByProcess(SelectedProcess);

            selectedQ.QNumber = selectedQ.QNumber + 1;
            ProcessQCache.GetInstance().Update(selectedQ);
            //step 3: Reduce q number of item below.
            var aboveQ = ProcessQCache.GetInstance().GetByProcess(processBelow);

            aboveQ.QNumber = aboveQ.QNumber - 1;
            ProcessQCache.GetInstance().Update(aboveQ);
            //step 4. Refresh.
            Refresh();
            SelectedProcess = Processes[selectedIndex + 1]; //selected the item moved down.
        }
        private void UpClickHandler()
        {
            var selectedIndex = Processes.IndexOf(SelectedProcess);
            //step 1: Identify the process just above the selected process.
            var processAbove = Processes[Processes.IndexOf(SelectedProcess) - 1];
            //step 2: reduce q number of selected item.
            var selectedQ = ProcessQCache.GetInstance().GetByProcess(SelectedProcess);

            selectedQ.QNumber = selectedQ.QNumber - 1;
            ProcessQCache.GetInstance().Update(selectedQ);
            //step 3: increase q number of item above.
            var aboveQ = ProcessQCache.GetInstance().GetByProcess(processAbove);

            aboveQ.QNumber = aboveQ.QNumber + 1;
            ProcessQCache.GetInstance().Update(aboveQ);
            //step 4. Refresh.
            Refresh();
            SelectedProcess = Processes[selectedIndex - 1]; //select the item moved up
        }
Exemple #5
0
        private void ResourceComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var  vm            = DataContext as AddEditProjectViewModel;
            var  combobox      = sender as ComboBox;
            Grid containingRow = combobox.Parent as Grid;
            var  process       = containingRow.DataContext as Process;

            //var index = vm.Processes.IndexOf(process);
            //reset the q number of the process when resource is changed. A new Q Number will be given while saving (as the last in the q of the new resource selected)
            if (process.Id != 0)
            {
                //for new processes, (with id = 0), it won;t hve a processQ, so do this only for existing processes.
                //new processes will get a new processQ when the project is saved.
                ProcessQCache.GetInstance().GetByProcess(process).QNumber = 0;
                //update processQ of this process object
                ProcessQCache.GetInstance().Update(process);
            }
            //vm.Processes[index] = process;
        }