public ActionListViewModel(int ProcessId, int PlaceId)
 {
     this.ProcessId      = ProcessId;
     this.PlaceId        = PlaceId;
     ProcessActionKeeper = new ProcessActionKeeper();
     PlaceActionKeeper   = new PlaceActionKeeper();
 }
Beispiel #2
0
        public async Task LoadProcessActions()
        {
            try
            {
                List <Task <List <dynamic> > > tasks = new List <Task <List <dynamic> > >();

                await ActionTypes.Refresh();

                int year = DateTime.Now.Year;
                int week = DateTime.Now.IsoWeekOfYear();

                foreach (var at in ActionTypes.Items)
                {
                    if (at.ActionsApplicable == true)
                    {
                        //let's get its stats
                        Task <List <dynamic> > getAtStats = Task.Run(() => ProcessActionKeeper.GetProcessActionStats(year, week, DivisionType, at.ActionTypeId));
                        tasks.Add(getAtStats);
                    }
                }
                if (tasks.Any())
                {
                    var results = await Task.WhenAll(tasks);


                    foreach (var r in results)
                    {
                        chartSeries.Add(r);
                    }
                    //string s = chartSeries.FirstOrDefault().FirstOrDefault().Weekday;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Wystąpił problem przy pobieraniu statystyk wykonania czynności w listach kontrolnych", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public async Task <bool> Initialize()
        {
            //get all the placeActions of this placeId and processActions for this process
            //and fill the list in

            try
            {
                CheckedItems = new ObservableCollection <ProcessAction>();
                Items        = new ObservableCollection <IActionKeeper>();

                if (ProcessId != 0)
                {
                    var processReload = Task.Run(() => ProcessActionKeeper.Reload($"ProcessId={ProcessId}"));
                    var placeReload   = Task.Run(() => PlaceActionKeeper.Reload($"PlaceId={PlaceId}"));

                    //go no further till both tasks complete
                    await Task.WhenAll(processReload, placeReload);

                    CheckedItems = new ObservableCollection <ProcessAction>(ProcessActionKeeper.Items);
                    Items        = new ObservableCollection <IActionKeeper>(CheckedItems);
                    foreach (var item in Items)
                    {
                        if ((bool)item.IsChecked)
                        {
                            //if item has been saved as checked, don't let anyone change it
                            item.IsMutable = false;
                        }
                    }
                }
                else
                {
                    var placeReload = Task.Run(() => PlaceActionKeeper.Reload($"PlaceId={PlaceId}"));

                    //go no further till task complete
                    await Task.WhenAll(placeReload);
                }


                foreach (PlaceAction p in PlaceActionKeeper.Items)
                {
                    if (!CheckedItems.Any(i => i.ActionId == p.ActionId))
                    {
                        Items.Add(p);
                    }
                }
                IsInitialized = true;
                Task.Run(() => TakeSnapshot());
                if (Items.Any())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }