Beispiel #1
0
        void ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Performances.Clear();
                var items = Event.Performances;
                foreach (var item in items)
                {
                    Performances.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
        protected override void ExecuteInsertPerformanceCommand(string[] commandWords)
        {
            switch (commandWords[2])
            {
            case "theatre":
                var venue   = GetVenue(commandWords[5]);
                var theatre = new Theatre(commandWords[3], decimal.Parse(commandWords[4]), venue, DateTime.Parse(commandWords[6] + " " + commandWords[7]));
                Performances.Add(theatre);
                break;

            case "concert":
                var venue2  = GetVenue(commandWords[5]);
                var concert = new Concert(commandWords[3], decimal.Parse(commandWords[4]), venue2, DateTime.Parse(commandWords[6] + " " + commandWords[7]));
                Performances.Add(concert);
                break;

            default:
                base.ExecuteInsertPerformanceCommand(commandWords);
                break;
            }
        }
        //Load Items Asynchronious
        public void LoadItems()
        {
            IList <PerformanceVM> calculateModels = new List <PerformanceVM>();

            Performances.Clear();
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += new DoWorkEventHandler((sender, args) =>
            {
                IList <Venue> venues = administrationService.GetVenues();
                foreach (Venue venue in venues)
                {
                    IList <Performance> performances = administrationService.GetPerformancesByVenueAndDay(venue, CurrentDate);
                    if (performances.Count > 4)
                    {
                        return;
                    }
                    DateTime d       = CurrentDate.Date;
                    Performance col1 = new Performance();
                    col1.StagingTime = d.AddHours(14);
                    Performance col2 = new Performance();
                    col2.StagingTime = d.AddHours(15);
                    Performance col3 = new Performance();
                    col3.StagingTime = d.AddHours(16);
                    Performance col4 = new Performance();
                    col4.StagingTime = d.AddHours(17);
                    Performance col5 = new Performance();
                    col5.StagingTime = d.AddHours(18);

                    foreach (Performance p in performances)
                    {
                        if (p.StagingTime.Hour >= 18)
                        {
                            col5 = p;
                        }
                        else if (p.StagingTime.Hour >= 17)
                        {
                            col4 = p;
                        }
                        else if (p.StagingTime.Hour >= 16)
                        {
                            col3 = p;
                        }
                        else if (p.StagingTime.Hour >= 15)
                        {
                            col2 = p;
                        }
                        else if (p.StagingTime.Hour >= 14)
                        {
                            col1 = p;
                        }
                    }

                    calculateModels.Add(new PerformanceVM(venue, col1, col2, col3, col4, col5, administrationService, this));
                }
            });
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler((sender, args) => {
                Performances.Clear();
                foreach (PerformanceVM vm in calculateModels)
                {
                    vm.GroupCheckBox();
                    Performances.Add(vm);
                }
                RaisePropertyChangedEvent(nameof(Performances));
            });
            worker.RunWorkerAsync(System.Reflection.Assembly.GetExecutingAssembly().Location);
        }