예제 #1
0
        /// <summary>
        /// Alerts the index of the view did dismiss with button.
        /// </summary>
        /// <param name="alertView">The alert view.</param>
        /// <param name="buttonIndex">Index of the button.</param>
        public void AlertViewDidDismissWithButtonIndex(/*UIAlertView*/ object alertView, int buttonIndex)
        {
            if (this.isErrorSaveDialog)
            {
                if (buttonIndex == 1)
                {
                    this.waitForSerialEntrySave = false;
                    this.isSaving = false;
                    if (!this.waitForSave)
                    {
                        if (this.serialEntryPageModelController.SerialEntry.ChangedRecordsForEndingSerialEntry().Count > 0)
                        {
                            this.closeOnErrors = true;
                            this.isSaving      = true;
                            this.serialEntryPageModelController.SaveWithDiscardedChanges();
                            return;
                        }

                        if (this.CloseOrganizerDelegate != null)
                        {
                            UPMCloseOrganizerDelegate del = this.CloseOrganizerDelegate;
                            this.CloseOrganizerDelegate = null;
                            del.UpOrganizerModelControllerAllowedClosingOrganizer(this);
                        }
                        else
                        {
                            this.HandleChangeManager();
                            this.HandleSaved();
                        }
                    }
                }
                else if (this.CloseOrganizerDelegate != null)
                {
                    this.Organizer.Status       = null;
                    this.CloseOrganizerDelegate = null;
                    this._modelControllerToRedraw.Page.Status  = null;
                    this._modelControllerToRedraw.Page.Invalid = true;
                    this.RedisplayPage(null, true);
                    this._modelControllerToRedraw = null;
                }
            }
        }
        /// <summary>
        /// Adds the page model controllers.
        /// </summary>
        public override void AddPageModelControllers()
        {
            this.RecordIdentification = this.ViewReference.ContextValueForKey("RecordId");
            this.RecordIdentification = UPCRMDataStore.DefaultStore.ReplaceRecordIdentification(this.RecordIdentification);
            ViewReference viewReference = this.ViewReference;

            if (this.OfflineRequest != null)
            {
                if (this.RecordIdentification.Contains("new"))
                {
                    UPCRMRecord rootRecord = ((UPOfflineRecordRequest)this.OfflineRequest).FirstRecordWithInfoAreaId(this.RecordIdentification.InfoAreaId());
                    if (rootRecord != null)
                    {
                        viewReference             = new ViewReference(this.ViewReference, this.RecordIdentification, rootRecord.RecordIdentification, null);
                        this.RecordIdentification = rootRecord.RecordIdentification;
                    }
                }
            }

            UPMOrganizer editOrganizer = new UPMOrganizer(StringIdentifier.IdentifierWithStringId("Edit"));

            this.TopLevelElement = editOrganizer;
            SerialEntryPageModelController tmpSerialEntryPageModelController = new SerialEntryPageModelController(viewReference, (UPOfflineSerialEntryRequest)this.OfflineRequest);

            //tmpSerialEntryPageModelController.AddObserverForKeyPathOptionsContext(this, "hasRunningChangeRequests", NSKeyValueObservingOptionNew, null);
            tmpSerialEntryPageModelController.Delegate = this;
            Page   overviewPage = tmpSerialEntryPageModelController.Page;
            string organizerHeaderText;
            string organizerDetailText = null;

            if (this.ExpandConfig != null)
            {
                UPConfigHeader header = ConfigurationUnitStore.DefaultStore.HeaderByNameFromGroup("Edit", this.ExpandConfig.HeaderGroupName);
                if (header != null)
                {
                    organizerDetailText = header.Label;
                    tmpSerialEntryPageModelController.Page.LabelText = organizerDetailText;
                }
            }

            if (string.IsNullOrEmpty(organizerDetailText))
            {
                if (!string.IsNullOrEmpty(this.InfoAreaId))
                {
                    organizerDetailText = UPCRMDataStore.DefaultStore.TableInfoForInfoArea(this.InfoAreaId).Label;
                }
                else
                {
                    organizerDetailText = UPCRMDataStore.DefaultStore.TableInfoForInfoArea(this.RecordIdentification.InfoAreaId()).Label;
                }
            }

            IConfigurationUnitStore configStore = ConfigurationUnitStore.DefaultStore;
            string rootRecordIdentification     = this.RecordIdentification;

            if (string.IsNullOrEmpty(rootRecordIdentification))
            {
                rootRecordIdentification = this.LinkRecordIdentification;
            }

            UPConfigTableCaption tableCaption = configStore.TableCaptionByName(rootRecordIdentification.InfoAreaId());
            string recordTableCaption         = null;

            if (tableCaption != null)
            {
                recordTableCaption = tableCaption.TableCaptionForRecordIdentification(rootRecordIdentification);
            }

            if (string.IsNullOrEmpty(recordTableCaption))
            {
                if (!string.IsNullOrEmpty(organizerDetailText))
                {
                    organizerHeaderText = organizerDetailText;
                    organizerDetailText = null;
                }
                else
                {
                    organizerHeaderText = rootRecordIdentification;
                }
            }
            else
            {
                organizerHeaderText = recordTableCaption;
            }

            this.Organizer.TitleText    = organizerHeaderText;
            this.Organizer.SubtitleText = organizerDetailText;
            this.AddPageModelController(tmpSerialEntryPageModelController);
            this.Organizer.AddPage(overviewPage);
            this.AddRemainingPageModelController();
            this.AddOrganizerActions();
            editOrganizer.ExpandFound = true;
        }
예제 #3
0
        private UPSerialEntryFinalSaveResult ExecuteFinalSave()
        {
            this.ModelControllerDelegate?.StopAllEditing();
            if (this.finalSaveCalled)
            {
                return(UPSerialEntryFinalSaveResult.Finished);
            }

            bool hasViolations = false;

            foreach (UPPageModelController modelController in this.PageModelControllers)
            {
                EditPageModelController editModelController = modelController as EditPageModelController;
                if (editModelController == null)
                {
                    continue;
                }

                if (editModelController.UpdatePageWithViolations())
                {
                    hasViolations = true;
                }
            }

            if (hasViolations)
            {
                return(UPSerialEntryFinalSaveResult.Abort);
            }

            this.finalSaveCalled = true;
            this.DisableAllActionItems(true);
            if (this.currentModelController is SerialEntryPageModelController)
            {
                UPMProgressStatus stillLoadingError = new UPMProgressStatus(StringIdentifier.IdentifierWithStringId("savingIdentifier"));
                UPMStringField    statusField       = new UPMStringField(StringIdentifier.IdentifierWithStringId("statusFieldIdentifier"));
                statusField.FieldValue = LocalizedString.TextWaitForChanges;
                stillLoadingError.StatusMessageField = statusField;
                this.Organizer.Status = stillLoadingError;
                this.InformAboutDidChangeTopLevelElement(this.TopLevelElement, this.TopLevelElement, null, null);
            }

            bool noChanges = true;

            if (!this.IsNew || !this.created)
            {
                List <UPCRMRecord> changedRecords = this.ChangedRecords(false);
                if (changedRecords?.Count > 0)
                {
                    this.EditRecordRequest.TitleLine   = this.Organizer.TitleText;
                    this.EditRecordRequest.DetailsLine = this.Organizer.SubtitleText;
                    this.waitForSave = true;
                    noChanges        = false;
                    this.EditRecordRequest.StartRequest(UPOfflineRequestMode.OnlineConfirm, changedRecords, this);
                }
            }

            foreach (UPPageModelController modelController in this.PageModelControllers)
            {
                if (modelController is SerialEntryPageModelController)
                {
                    SerialEntryPageModelController serialEntryModelController = (SerialEntryPageModelController)modelController;
                    this.waitForSerialEntrySave = true;
                    this.isSaving = true;
                    if (!serialEntryModelController.SaveAll())
                    {
                        this.waitForSerialEntrySave = false;
                        this.isSaving = false;
                    }
                    else
                    {
                        noChanges = false;
                    }
                }
            }

            if (noChanges)
            {
                this.HandleChangeManager();
                this.HandleSaved();
                return(UPSerialEntryFinalSaveResult.Finished);
            }

            return(UPSerialEntryFinalSaveResult.Pending);
        }
예제 #4
0
        /// <summary>
        /// Observes the value for key path of object change context.
        /// </summary>
        /// <param name="keyPath">The key path.</param>
        /// <param name="theObject">The object.</param>
        /// <param name="change">The change.</param>
        /// <param name="context">The context.</param>
        public void ObserveValueForKeyPathOfObjectChangeContext(string keyPath, object theObject, Dictionary <string, object> change, object context)
        {
            if (keyPath == "hasRunningChangeRequests")
            {
                SerialEntryPageModelController modelController = (SerialEntryPageModelController)theObject;
                this.PageModelControllerSetContextValueForKey(modelController, modelController.ChangeRequestError, "organizerError");
                if (modelController.ChangeRequestError != null && !this.closeOnErrors)
                {
                    this.isSaving = false;
                    if (this.organizerDealsWithSaveErrors)
                    {
                        this.Organizer.Status        = null;
                        modelController.Page.Status  = null;
                        modelController.Page.Invalid = true;
                        this.RedisplayPage(null, true);
                    }
                    else if (this.CloseOrganizerDelegate != null)
                    {
                        this._modelControllerToRedraw = modelController;
                    }

                    if (this.organizerDealsWithSaveErrors || this.CloseOrganizerDelegate != null)
                    {
                        this.organizerDealsWithSaveErrors = false;
                        if (modelController.SerialEntry.ConflictHandling)
                        {
                            this.currentModelController = modelController;
                            this.RedisplayPage(null, true);
                            return;
                        }
                        else
                        {
                            this.serialEntryPageModelController = modelController;
                            //UIAlertView alertview = new UIAlertView(LocalizationKeys.upTextYouMadeChanges, LocalizationKeys.upTextProcessSerialEntrySaveErrors, this, LocalizationKeys.upTextOK, LocalizationKeys.upTextBasicDiscardChanges, null);
                            //this.isErrorSaveDialog = true;
                            //alertview.Show();
                        }

                        return;
                    }
                }

                foreach (UPPageModelController pageModelController in this.PageModelControllers)
                {
                    var controller = pageModelController as SerialEntryWebContentModelController;
                    if (controller != null)
                    {
                        controller.Page.Invalid = true;
                        controller.ShouldWaitForPendingChanges = modelController.HasRunningChangeRequests;
                    }
                }

                if (this.isSaving && !modelController.HasRunningChangeRequests)
                {
                    this.organizerDealsWithSaveErrors = false;
                    this.waitForSerialEntrySave       = false;
                    this.isSaving = false;
                    if (!this.waitForSave)
                    {
                        if (this.CloseOrganizerDelegate != null)
                        {
                            UPMCloseOrganizerDelegate del = this.CloseOrganizerDelegate;
                            this.CloseOrganizerDelegate = null;
                            del.UpOrganizerModelControllerAllowedClosingOrganizer(this);
                        }
                        else
                        {
                            this.HandleChangeManager();
                            this.HandleSaved();
                        }
                    }
                }
            }
        }