Beispiel #1
0
        /// <summary>
        /// Creation of child form. Can be used from outside to pass some Guid of entity and number to newly created forms.
        /// </summary>
        /// <param name="formType">exact type of form</param>
        /// <param name="id">Guid of entity</param>
        /// <param name="parameters">input parameters passed to the newly created form</param>
        private ChildForm OpenReturnChildForm(DocumentTypes documentType, List <KeyValuePair <string, object> > parameters, Guid id = default(Guid))
        {
            ChildForm formToActivate = null;

            try
            {
                notify.ShowProcessing();

                FormFlags flags = FormFlags.Nothing;
                flags |= GetSecurityRestrictionReasons(documentType);

                // is possible for this option to open for this user, at all
                if (flags.HasFlag(FormFlags.CanReadAtThisWorkstation) && !flags.HasFlag(FormFlags.ReadAccessDenied) ||
                    flags.HasFlag(FormFlags.CanEditAtThisWorkstation) && !flags.HasFlag(FormFlags.EditAccessDenied))
                {
                    if (id != Guid.Empty)
                    {
                        formToActivate = childForms.GetById(id);
                    }
                    if (formToActivate == null)
                    {
                        IReadOnlyList <ChildForm> existingDocuments = childForms[documentType];

                        if (IsSingleDocumentPerProgram(documentType) && existingDocuments.Count > 0)
                        {
                            formToActivate = existingDocuments.First();
                        }
                        if (formToActivate == null)
                        {
                            flags |= (IsSingleEditModeDocument(documentType) && existingDocuments.Any((form) => { return(form.IsEditMode); }))
                                ? FormFlags.SingleEditAlreadyOpened : FormFlags.Nothing;

                            Main.Forms.Settings.SettingsXtraForm settingsForm = GetSettingsForm();

                            if ((settingsForm != null && settingsForm.IsEditMode && IsEditConflictWithSettings(documentType) ||
                                 documentType == DocumentTypes.Settings && SettingsConflictedDocumentsOpened().Any((form) => { return(form.IsEditMode); })
                                 )
                                )
                            {
                                flags |= FormFlags.EditConflict;
                            }

                            bool editMode;
                            if (CanOpen(documentType, id == Guid.Empty, flags, out editMode))
                            {
                                formToActivate = CreateChildForm(documentType, parameters);
                                if (formToActivate != null)
                                {
                                    formToActivate.IsEditMode = editMode;
                                    ShowChildForm(formToActivate);
                                }
                            }
                        }
                    }
                    if (formToActivate != null)
                    {
                        formToActivate.Activate();
                    }
                }
                else
                {
                    notify.ShowError(
                        Program.LanguageManager.GetString(StringResources.FormManager_AccessForbidden),
                        Program.LanguageManager.GetString(StringResources.FormManager_AccessHeader));
                    log.Warn("Attempt to open form with restricted access to it");
                }
            }
            finally
            {
                notify.HideProcessing();
            }
            return(formToActivate);
        }
Beispiel #2
0
        /// <summary>
        /// helper method to determine the possibility to open/create document.
        /// Can show questions to user.
        /// </summary>
        /// <param name="type">type of document</param>
        /// <param name="isNew">is entity supposed to be new</param>
        /// <param name="flags">flags pack</param>
        /// <param name="editMode">can/should this document to be opened in edit mode.</param>
        /// <returns></returns>
        private bool CanOpen(DocumentTypes type, bool isNew, FormFlags flags, out bool editMode)
        {
            editMode = !flags.HasFlag(FormFlags.EditAccessDenied) && flags.HasFlag(FormFlags.CanEditAtThisWorkstation);
            bool canOpen = true;

            if (flags.HasFlag(FormFlags.EditConflict))
            {
                if (type == DocumentTypes.Settings)
                {
                    canOpen &= notify.ShowYesNo(Program.LanguageManager.GetString(StringResources.Message_OpenSettingsForViewing),
                                                Program.LanguageManager.GetString(StringResources.Message_OpenSettingsForViewingHeader));
                }
                else
                {
                    canOpen &= notify.ShowYesNo(Program.LanguageManager.GetString(StringResources.Message_OpenFormForViewing),
                                                Program.LanguageManager.GetString(StringResources.Message_OpenFormForViewingHeader));
                }
                editMode = false;
            }
            if (flags.HasFlag(FormFlags.SingleEditAlreadyOpened))
            {
                string text = string.Empty;

                if (isNew)
                {
                    switch (type)
                    {
                    case DocumentTypes.MillReleaseNote:
                        text = Program.LanguageManager.GetString(StringResources.MainWindow_CloseEditingReleaseNote);
                        break;

                    case DocumentTypes.ConstructionJoint:
                        text = Program.LanguageManager.GetString(StringResources.MainWindow_ConstructionJoint);
                        break;

                    default:
                        break;
                    }
                    notify.ShowWarning(text, "");
                    canOpen = false;
                }
                else
                {
                    switch (type)
                    {
                    case DocumentTypes.MillReleaseNote:
                        text = Program.LanguageManager.GetString(StringResources.MainWindow_OpenReleaseNoteReadOnly);
                        break;

                    case DocumentTypes.ConstructionJoint:
                        text = Program.LanguageManager.GetString(StringResources.MainWindow_OpenConstructionJointReadOnly);
                        break;

                    default:
                        break;
                    }
                    canOpen &= notify.ShowYesNo(text, "");
                    editMode = false;
                }
            }
            return(canOpen);
        }