//private static string m_DefaultLayout; //public static string DefaultLayout //{ // get // { // return m_DefaultLayout; // } // set // { // m_DefaultLayout = value; // } //} public static void ResetLanguage() { LayoutCorrector.Init(); var openedFoms = new IApplicationForm[m_FormList.Count]; m_FormList.CopyTo(openedFoms); try { foreach (IApplicationForm frm in openedFoms) { //if (!(frm is IBaseListPanel || frm is IListFormsContainer)) if (((Control)frm).FindForm() != MainForm) { Close(frm); } else { ResetLanguage(frm); } } } catch (Exception ex) { Dbg.Trace(); Dbg.Debug(ex.ToString()); } }
private static bool LoadData(IApplicationForm appForm, ref object id) { using (new WaitDialog()) { try { bool ret = true; if (appForm is IBasePanel) { (appForm as IBasePanel).LoadData(ref id); } else if (appForm is IListFormsContainer) { //we doesn't check the ListPanel existence - it must exist (appForm as IListFormsContainer).ListPanels[0].LoadData(ref id); } else if (ReflectionHelper.HasMethod(appForm, "LoadData")) { var @params = new[] { id }; ret = (bool)ReflectionHelper.InvokeMethod(appForm, "LoadData", @params); id = @params[0]; } return(ret); } catch (Exception) { return(false); } } }
private static IApplicationForm GetPreviousForm(IApplicationForm form) { IApplicationForm nextForm = null; int i = m_FormList.IndexOf(form); if (i > 0) { nextForm = m_FormList[i - 1]; } else if (i == 0 && m_FormList.Count > 1) { nextForm = m_FormList[1]; } while (nextForm != null) { if (!((Control)nextForm).IsDisposed) { return(nextForm); } m_FormList.Remove(nextForm); nextForm = m_FormList.Count > 0 ? m_FormList[m_FormList.Count - 1] : null; } return(null); }
public static void OnFormActivate(object sender, EventArgs e) { IApplicationForm form = FindChildIApplicationForm(sender); if (form != null) { //if (form.LifeTimeState == LifeTimeState.DataLoading) //{ // return; //} //if (form.BusinessObject.ObjectType == BusinessObjectType.List) //{ // try // { // form.LoadData(null); // } // catch (Exception) // { // Close(form); // return; // } //} m_CurrentForm = form; } }
public static bool CloseNonListForms(bool needSave) { var openedFoms = new IApplicationForm[m_FormList.Count]; m_FormList.CopyTo(openedFoms); try { foreach (IApplicationForm frm in openedFoms) { //if (!(frm is IBaseListPanel || frm is IListFormsContainer)) if (((Control)frm).FindForm() != MainForm) { if (!Close(frm, DialogResult.Cancel, needSave ? FormClosingMode.SaveWithConfirmation : FormClosingMode.NoSave)) { return(false); } } } } catch (Exception ex) { Dbg.Trace(); Dbg.Debug(ex.ToString()); } m_CurrentForm = null; return(true); }
//This method is used for searching detail form with not empty ID //to check is it possible to delete it public static IApplicationForm FindFormByID(IApplicationForm sourceForm, object id) { if (id == null) { return(null); } return(m_FormList.Where(form => form.Key != null && form != sourceForm).FirstOrDefault(form => id.Equals(form.Key))); }
void setupForm(IApplicationForm instance) { //if (!Forms.Contains(instance)) //{ Forms.Add(instance); instance.Disposed += formDisposed; //} }
public static void ShowClient(Type typeForm, Control parentControl, IObject bo, Dictionary <string, object> @params = null) { if (typeForm == null) { return; } IApplicationForm appForm = null; try { using (new WaitDialog()) { var o = ClassLoader.LoadClass(typeForm); appForm = o as IApplicationForm; if (appForm == null) { return; } if (!Register(appForm, bo.Key)) { return; } if (bo.Key == null || (bo.Key is long && ((long)bo.Key) <= 0)) { object id = null; if (!LoadData(appForm, ref id)) { UnRegister(appForm); return; } } var basePanel = appForm as IBasePanel; if (basePanel != null) { basePanel.BusinessObject = bo; if (ReadOnly) { basePanel.ReadOnly = true; } } DisplayClientForm(appForm, parentControl); //if (!CanViewObject(frm)) //{ // return; //} } } catch (Exception ex) { UnRegister(appForm); Dbg.Debug("error during form showing", ex.ToString()); throw; } }
private static bool ShowModal (IApplicationForm appForm, Control owner, ref object id, Dictionary <string, object> @params, bool readOnly, int width, int height) { if (appForm == null) { return(false); } //if (!CanViewObject(form)) //{ // return false; //} if (@params != null) { appForm.StartUpParameters = @params; } if (readOnly || ReadOnly) { SetReadOnly(appForm, true); } if (!LoadData(appForm, ref id)) { //it is important to call Load data before placing BasePanel to Layout, in other case default search filters are ignored for list forms return(false); } try { Form baseFormContainer; using (new WaitDialog()) { baseFormContainer = PrepareFormShowing(appForm, true, @params, width, height); ModalFormCount++; InitDesignManager(appForm); } var ret = baseFormContainer.ShowDialog(owner); FormDisposer.Add(appForm as Control); if (ret == DialogResult.OK) { id = appForm.Key; return(true); } return(false); } catch (Exception ex) { ErrorForm.ShowError(StandardError.UnprocessedError, ex); return(false); } finally { ModalFormCount--; } }
public static bool ShowModal_ReadOnly (IApplicationForm form, Control owner, ref object id, object parentID, Dictionary <string, object> @params, int width = 0, int height = 0) { if (form == null) { return(false); } return(ShowModal(form, owner, ref id, @params, true, width, height)); }
public bool DestroyForm(IApplicationForm instance) { if (Forms.Contains(instance)) { instance.Disposed -= formDisposed; Forms.Remove(instance); return(true); } return(false); }
private static void SetReadOnly(IApplicationForm form, bool readOnly) { if (form is IBasePanel) { ((IBasePanel)form).ReadOnly = readOnly; } else if (ReflectionHelper.HasProperty(form, "ReadOnly")) { ReflectionHelper.SetProperty(form, "ReadOnly", readOnly); } }
public static bool CloseAll(bool needSave) { while (m_FormList.Count > 0) { if (!Close(m_FormList[0], DialogResult.Cancel, needSave ? FormClosingMode.SaveWithConfirmation : FormClosingMode.NoSave)) { return(false); } } m_CurrentForm = null; return(true); }
private static Control GetContainer(IApplicationForm appForm) { ILayout layout = null; var bp = appForm as IBasePanel; if (bp != null) { layout = bp.GetLayout(); } //Контейнер, содержащий всю смысловую часть формы, который требуется разместить либо в теле главной формы, либо на подложке созданной формы return((Control)layout ?? (Control)appForm); }
public static Form ShowNormal_ReadOnly (IApplicationForm appForm, IObject bo, Dictionary <string, object> parameters = null, int width = 0, int height = 0) { if (width < 0) { width = ((Control)appForm).Width; } if (height < 0) { height = ((Control)appForm).Height; } return(Show(appForm, bo, false, true, parameters, width, height)); }
public static Form ShowNormal_ReadOnly (IApplicationForm appForm, ref object id, Dictionary <string, object> parameters = null, int width = 0, int height = 0) { if (appForm == null) { return(null); } appForm.StartUpParameters = parameters; if (LoadData(appForm, ref id)) { return(ShowNormal(appForm, null, parameters, width, height, true)); } return(null); }
//It is possible the situation when form is closed after pressing one of the //child form buttons (SampleLogBook for example containes 2 other IApplicationForms and closed after closing //one of these forms) //In this case we should close the parent form, not the current one because parent form is registered in the forms list. //This method returns top level IApplicationForm and used in Close method. private static IApplicationForm GetRootAppForm(IApplicationForm form) { var parent = ((Control)form).Parent; while (parent != null) { if (parent is IApplicationForm && !(parent is BvForm)) { form = (IApplicationForm)parent; } parent = parent.Parent; } return(form); }
/// <summary> /// Показывает форму с панелью и layout в модальном режиме (используется для тестов) /// </summary> /// <param name="appForm"></param> public static void ShowSimpleFormModal(IApplicationForm appForm) { //var container = GetContainer(appForm); //var frm = new Form //{ // Size = new Size(800, 600), // StartPosition = FormStartPosition.CenterScreen, //}; //frm.Controls.Add(container); //container.Dock = DockStyle.Fill; var frm = PrepareFormShowing(appForm, true, null, 800, 600); frm.ShowDialog(); }
//private static bool CanViewObject(IApplicationForm frm) //{ // if (frm.BusinessObject == null) // { // return true; // } // if (!frm.BusinessObject.AccessPermissions.CanSelect) // { // MessageBox.Show(BvMessages.Get("msgNoSelectPermission", "You have no rights to view this form",null)); // return false; // } // return true; //} private static void DisplayCaption(IApplicationForm frm) { //Form f = ((Control)frm).FindForm(); //if (f == null) //{ // return; //} //if (((Control)frm).Visible && frm.Caption != "") //{ // f.Text = string.Format("[{2}]{0} - [{1}]", ApplicationContext.ApplicationCaption, frm.Caption, frm.FormID); //} //else //{ // f.Text = string.Format("[{1}]{0}", ApplicationContext.ApplicationCaption, frm.FormID); //} }
public static Control GetFormLayout(IApplicationForm child) { Debug.Assert(child != null, "base form can\'t be null"); var bp = child as IBasePanel; ILayout layout = null; if (bp != null) { layout = bp.GetLayout(); layout.ParentBasePanel = bp; } if (layout != null) { return((Control)layout); } return((Control)child); }
private static int CompareFormByID(IApplicationForm form, object id) { object key = form.Key; if (form.IsSingleTone) //list forms are considered as equals if their types are equals { return(0); } // key = (form as IBasePanel).BusinessObject.Key; if (Utils.IsEmpty(id)) { return(-1); } if ((key != null && key.Equals(id))) { return(0); } return(-1); }
public static void OnFormClosing(object sender, CancelEventArgs e) { IApplicationForm form = FindChildIApplicationForm(sender); if (form != null) { if (!FormClosing) { e.Cancel = true; //Close(form, DialogResult.Cancel, FormClosingMode.SaveWithConfirmation); //e.Cancel = false; (sender as Control).BeginInvoke( new MethodInvoker(() => Close(form, DialogResult.Cancel, FormClosingMode.SaveWithConfirmation))); } //if(form is IBasePanel) // (form as IBasePanel).LifeTimeState = LifeTimeState.Closing; //form.Release(); //UnRegister(form); } }
public static IApplicationForm FindForm(IApplicationForm formToFind, Comparison <IApplicationForm> compare) { foreach (IApplicationForm form in m_FormList) { if (form.GetType() != formToFind.GetType()) { continue; } if (compare != null) { if (compare(form, formToFind) == 0) { return(form); } continue; } return(form); } return(null); }
public static void ShowClient(IApplicationForm frm, Control parentControl, ref object id, Dictionary <string, object> @params = null) { if (frm == null) { return; } //if (!CanViewObject(frm)) //{ // return; //} if (!Register(frm, id)) { return; } try { if (!LoadData(frm, ref id)) { return; } //if (frm is IBasePanel) //{ // (frm as IBasePanel).StartUpParameters = @params; // (frm as IBasePanel).LoadData(ref id); //} using (new WaitDialog()) { DisplayClientForm(frm, parentControl); frm.Activate(); } } catch (Exception ex) { UnRegister(frm); Dbg.Debug("error during form showing", ex.ToString()); throw; } }
/// <summary> /// </summary> /// <param name="frm"></param> /// <param name="id"></param> /// <returns></returns> public static bool Register(IApplicationForm frm, object id) { if (m_CurrentForm != null) { var listPanel = m_CurrentForm as IBaseListPanel; if (listPanel != null) { listPanel.HideCustomization(); } } var ctl = FindFormByID(frm.GetType(), id); if (ctl == null) { m_FormList.Add(frm); m_CurrentForm = frm; return(true); } ctl.Activate(); m_CurrentForm = ctl; return(false); }
private static void Activate(IApplicationForm form) { if (form == null) { if (MainForm != null) { MainForm.Activate(); MainForm.BringToFront(); } return; } if (ModalFormCount > 0) { return; } if (m_FormList.IndexOf(form) >= 0) { form.Activate(); ((Control)form).BringToFront(); m_CurrentForm = form; } }
public static void ResetLanguage(IApplicationForm panel) { IObject bo = null; var frm = ((Control)panel).FindForm(); Control parent = ((Control)panel).Parent; var basePanel = panel as IBasePanel; if (basePanel != null) { bo = (basePanel).BusinessObject; parent = (((Control)(basePanel).GetLayout())).Parent; } Close(panel); if (bo != null) { if (frm == MainForm) { ShowClient(panel.GetType(), parent, bo); } else { ShowNormal(panel.GetType(), bo, null, ((Control)panel).Width, ((Control)panel).Height); } } else { object key = panel.Key; panel = (IApplicationForm)ClassLoader.LoadClass(panel.GetType()); if (frm == MainForm) { ShowClient(panel, parent, ref key); } else { ShowNormal(panel, ref key, null, ((Control)panel).Width, ((Control)panel).Height); } } }
public static void UnRegister(IApplicationForm frm) { if (frm == null) { return; } var parentForm = ((Control)frm).FindForm(); if (parentForm != null) { parentForm.KeyDown -= frm.BaseForm_KeyDown; } if (frm is ITranslationView && ((ITranslationView)frm).DCManager != null) { ((ITranslationView)frm).DCManager.Release(); } m_FormList.Remove(frm); if (ReferenceEquals(frm, m_CurrentForm)) { m_CurrentForm = null; } }
//private static int counter = 1; private static void DisplayClientForm(IApplicationForm frm, Control parentControl) { var formCtl = (Control)frm; var form = parentControl.FindForm(); var layout = GetFormLayout(frm); if (form != null) { form.SuspendLayout(); } formCtl.Visible = false; if (parentControl != form) { parentControl.SuspendLayout(); } layout.Dock = DockStyle.Fill; layout.Parent = parentControl; layout.BringToFront(); layout.Visible = true; formCtl.Visible = true; DisplayCaption(frm); if (parentControl != form) { parentControl.ResumeLayout(); } if (form != null) { form.ResumeLayout(); //This is the workaround for bring up layout when RTL mode is used if (Localizer.IsRtl) { form.ActiveControl = layout; WindowsAPI.SendMessage(form.Handle, 0x7 /*WM_SETFOCUS*/, (IntPtr)null, (IntPtr)null); } } InitDesignManager(frm); }
public static Form ShowModal (IApplicationForm appForm, IObject bo, Dictionary <string, object> parameters = null, int width = 0, int height = 0) { return(Show(appForm, bo, true, bo.ReadOnly, parameters, width, height)); }