/// <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> public ChildForm OpenChildForm(Type formType, List <KeyValuePair <string, object> > parameters, Guid id = default(Guid)) { ChildForm form = null; if (typeof(ChildForm).IsAssignableFrom(formType)) { var forms = GetListChildForm(formType); //search int indexById = GetFormIndex(formType.Name, id); if (indexById >= 0 && forms.Count > 0) // is open { form = forms[indexById]; } if (form != null) { form.Activate(); } else //create new { int index = FindOpenForm(formType.Name, true); if (formType == typeof(ReleaseNoteNewEditXtraForm) && index >= 0)// this type form is open in edit mode { if (id == default(Guid)) { string text = Program.LanguageManager.GetString(StringResources.MainWindow_CloseEditingReleaseNote); notify.ShowWarning(text, ""); form = forms[index]; form.Activate(); } else { string text = Program.LanguageManager.GetString(StringResources.MainWindow_OpenReleaseNoteReadOnly); if (notify.ShowYesNo(text, "")) { form = ShowChildForm(formType, parameters, false); } } } else { form = ShowChildForm(formType, parameters, true); } } } else { var e = new ApplicationException(String.Format("Could not create child form {0} because not of child type.", formType.Name)); log.Error(e.Message); throw e; } return(form); }
/// <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); }