예제 #1
0
        public async Task DeleteRack(object obj)
        {
            if (NotNetOrConnection)
            {
                return;
            }

            RackViewModel rvm = (RackViewModel)obj;

            string variant1 = String.Format(AppResources.RacksPlanViewModel_DeleteRack, rvm.No);
            string variant2 = String.Format(AppResources.RacksPlanViewModel_DeleteRack2, rvm.No);
            string variant3 = String.Format(AppResources.RacksPlanViewModel_DeleteRackAndBins, rvm.No);

            var action = await App.Current.MainPage.DisplayActionSheet(
                AppResources.RacksPlanViewModel_DeleteQuestion,
                AppResources.RacksPlanViewModel_DeleteCancel,
                null,
                variant1,
                variant2,
                variant3);

            if ((action != null) && (action != AppResources.RacksPlanViewModel_DeleteCancel))
            {
                if (action == variant1)
                {
                    try
                    {
                        await rvm.SaveToRackSchemeVisible(false);
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.Message);
                        ErrorText = e.Message;
                        State     = ModelState.Error;
                    }
                }

                if (action == variant2)
                {
                    try
                    {
                        await NAV.DeleteRack(rvm.ID, ACD.Default).ConfigureAwait(true);
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.Message);
                        ErrorText = e.Message;
                        State     = ModelState.Error;
                    }
                }

                if (action == variant3)
                {
                    try
                    {
                        State         = ModelState.Loading;
                        LoadAnimation = true;

                        await NAV.DeleteRack(rvm.ID, ACD.Default).ConfigureAwait(true);

                        NAVFilter navfilter = new NAVFilter
                        {
                            LocationCodeFilter = rvm.LocationCode,
                            ZoneCodeFilter     = rvm.ZoneCode,
                            RackIDFilter       = rvm.ID.ToString()
                        };

                        string     bindeleteerrors = "";
                        List <Bin> binsinrack      = await NAV.GetBinList(navfilter, ACD.Default).ConfigureAwait(true);

                        if (NotDisposed)
                        {
                            foreach (Bin bin in binsinrack)
                            {
                                try
                                {
                                    LoadingText = bin.Code;
                                    await NAV.DeleteBin(bin.LocationCode, bin.Code, ACD.Default).ConfigureAwait(true);
                                }
                                catch (Exception exp)
                                {
                                    bindeleteerrors += bin.Code + " : " + exp.InnerException.Message + Environment.NewLine + Environment.NewLine;
                                }
                            }
                        }

                        if (string.IsNullOrEmpty(bindeleteerrors))
                        {
                            State = ModelState.Normal;
                        }
                        else
                        {
                            ErrorText = AppResources.RacksPlanViewModel_DeleteBinErrors + "  " + Environment.NewLine + bindeleteerrors;
                            State     = ModelState.Error;
                        }
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.Message);
                        ErrorText = e.Message;
                        State     = ModelState.Error;
                    }
                }
                await Load();
            }
        }