public void GetLists()
        {
            var save = SelectedList;    // unclear. Setting Lists will set SelectedList to null

            lists        = vm.SPOClient.GetLists();
            Lists        = vm.SPOSettings.ListFilter.Filter(Lists);
            SelectedList = save;

            if (Lists.Count() == 0)
            {
                return;
            }

            if (SelectedList == null)
            {
                SelectedList = SelectedList = Lists[0];
                return;
            }
            List <SPOList> ll = Lists.Where(n => n.Id == SelectedList.Id).ToList();

            SelectedList = ll.Count() > 0 ? ll.First() : SelectedList = Lists[0];
        }
Пример #2
0
        private void HandleTimer()
        {
            System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                lastFarmID     = "-1";
                lastProducerID = "-1";
                lastFieldID    = "-1";

                var selProducerID = (SelectedProducer != null) ? SelectedProducer.ID : "";
                var selFarmID     = (SelectedFarm != null) ? SelectedFarm.ID : "";
                var selFieldID    = (SelectedField != null) ? SelectedField.ID : "";
                var selItemID     = "";

                if (SelectedItem != null)
                {
                    selItemID = SelectedItem.ListID;
                }

                refresh();

                //restore selections
                int producerIndex = 0;
                for (producerIndex = 0; producerIndex < Producers.Count(); producerIndex++)
                {
                    if (Producers[producerIndex].ID == selProducerID)
                    {
                        break;
                    }
                }
                if (producerIndex >= Producers.Count())
                {
                    producerIndex = 0;
                }

                if (Producers.Count() > 0)
                {
                    SelectedProducer = Producers[producerIndex];
                }

                int farmIndex = 0;
                for (farmIndex = 0; farmIndex < Farms.Count(); farmIndex++)
                {
                    if (Farms[farmIndex].ID == selFarmID)
                    {
                        break;
                    }
                }
                if (farmIndex >= Farms.Count())
                {
                    farmIndex = 0;
                }

                if (Farms.Count() > 0)
                {
                    SelectedFarm = Farms[farmIndex];
                }

                int fieldIndex = 0;
                for (fieldIndex = 0; fieldIndex < Fields.Count(); fieldIndex++)
                {
                    if (Fields[fieldIndex].ID == selFieldID)
                    {
                        break;
                    }
                }
                if (fieldIndex >= Fields.Count())
                {
                    fieldIndex = 0;
                }

                if (Fields.Count() > 0)
                {
                    SelectedField = Fields[fieldIndex];
                }

                var item = Lists.SingleOrDefault(l => l.ListID == selItemID);
                if (item != null)
                {
                    SelectedItem = item;
                }
                else if (Lists.Count() > 0)
                {
                    SelectedItem = Lists[0];
                }
                else
                {
                    SelectedItem = null;
                }
            }));
        }
Пример #3
0
        private void ExecuteDeleteCheckedCommand()
        {
            Task.Run(() =>
            {
                try
                {
                    using (var _unitOfWork = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                    {
                        bool deleteConfirmed = false;

                        if (CottonDBMS.DataModels.Helpers.NetworkHelper.HasNetwork())
                        {
                            var selectedCount = Lists.Count(x => x.Checked);

                            if (selectedCount == 0)
                            {
                                System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                                {
                                    System.Windows.MessageBox.Show("No lists checked for delete.  Please check off at least one list to delete.");
                                }));
                                return;
                            }

                            var snsOnTruck = AggregateDataProvider.SerialNumbersOnTruck;


                            var moduleEntitiesOnTruck = _unitOfWork.ModuleRepository.FindMatching(x => snsOnTruck.Contains(x.Name));
                            var listIDsOnTruck        = moduleEntitiesOnTruck.Select(x => x.PickupListId).ToList();

                            var listsOnTruckCount = Lists.Count(x => listIDsOnTruck.Contains(x.ListID) && x.Checked);

                            System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                if (listsOnTruckCount > 0)
                                {
                                    deleteConfirmed = false;
                                    System.Windows.MessageBox.Show("Cannot perform delete. There are currently modules on the truck that belong to a list you are trying to delete.", "Confirmation");
                                    return;
                                }

                                if (System.Windows.MessageBox.Show("Are you sure you want to delete the " + selectedCount.ToString() + " checked list(s).", "Confirmation", System.Windows.MessageBoxButton.YesNo) == System.Windows.MessageBoxResult.Yes)
                                {
                                    deleteConfirmed = true;
                                }
                            }));

                            if (deleteConfirmed)
                            {
                                Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage {
                                    IsBusy = true, Message = "Processing..."
                                });
                                if (CottonDBMS.DataModels.Helpers.NetworkHelper.SyncProcessRunning())
                                {
                                    Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage {
                                        IsBusy = true, Message = "Waiting for background sync to complete."
                                    });
                                    CottonDBMS.DataModels.Helpers.NetworkHelper.WaitForSyncToStop();
                                }
                                else
                                {
                                    //run the sync to send data collected this also ensure after it completes
                                    //it will not start again during the release
                                    Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage {
                                        IsBusy = true, Message = "Sending collected data."
                                    });
                                    CottonDBMS.DataModels.Helpers.NetworkHelper.RunSync(System.Reflection.Assembly.GetExecutingAssembly().Location, false);
                                    CottonDBMS.DataModels.Helpers.NetworkHelper.WaitForSyncToStop();
                                }

                                var selectedListIds = Lists.Where(x => x.Checked && !listIDsOnTruck.Contains(x.ListID)).Select(x => x.ListID);
                                var listsToDelete   = _unitOfWork.PickupListRepository.FindMatching(x => selectedListIds.Contains(x.Id)).ToList();
                                _unitOfWork.PickupListRepository.BulkDeleteListAndModules(listsToDelete);

                                //run the sync again to ensure released lists go immediately back to cloud
                                Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage {
                                    IsBusy = true, Message = "Releasing lists."
                                });

                                Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage {
                                    IsBusy = true, Message = "Syncing..."
                                });
                                CottonDBMS.DataModels.Helpers.NetworkHelper.RunSync(System.Reflection.Assembly.GetExecutingAssembly().Location, false);
                                CottonDBMS.DataModels.Helpers.NetworkHelper.WaitForSyncToStop();
                                Messenger.Default.Send <BusyMessage>(new Messages.BusyMessage {
                                    IsBusy = false, Message = ""
                                });

                                Messenger.Default.Send <DataRefreshedMessage>(new DataRefreshedMessage());
                            }
                        }
                        else
                        {
                            //no network
                            System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                System.Windows.MessageBox.Show("No network.  A network connection is needed to delete lists.");
                            }));
                        }
                    }
                }
                catch (Exception exc)
                {
                    Logging.Logger.Log(exc);
                }
            });
        }