Ejemplo n.º 1
0
        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--;
            }
        }
Ejemplo n.º 2
0
        private static Form Show
            (IApplicationForm appForm, IObject bo, bool isModal, bool readOnly, Dictionary <string, object> parameters = null, int width = 0,
            int height = 0)
        {
            if (appForm == null)
            {
                return(null);
            }

            if (appForm is IBasePanel && bo == null)
            {
                bo = ((IBasePanel)appForm).BusinessObject;
            }
            var id = (bo != null && bo.Key != null) ? bo.Key : appForm.Key;

            if (!Register(appForm, id))
            {
                var frm = ((Control)m_CurrentForm).FindForm();
                if (frm != null)
                {
                    return(frm);
                }
            }
            try
            {
                Form baseFormContainer;
                using (new WaitDialog())
                {
                    if (appForm is IBasePanel && ((IBasePanel)appForm).BusinessObject != bo)
                    {
                        var basePanel = (IBasePanel)appForm;
                        basePanel.BusinessObject = bo;
                    }

                    if (readOnly || ReadOnly)
                    {
                        SetReadOnly(appForm, true);
                    }
                    baseFormContainer = PrepareFormShowing(appForm, false, parameters, width, height);

                    appForm.Activate();
                    InitDesignManager(appForm);
                }
                if (isModal)
                {
                    ModalFormCount++;
                    baseFormContainer.ShowDialog();
                    FormDisposer.Add(appForm as Control);
                }
                else
                {
                    baseFormContainer.Show();
                }
                baseFormContainer.BringToFront();
                //активируем форму и готовим её к отображению
                return(baseFormContainer);
            }
            catch (Exception ex)
            {
                UnRegister(appForm);
                Dbg.Debug("error during form showing", ex.ToString());
                return(null);
            }
            finally
            {
                if (isModal)
                {
                    ModalFormCount--;
                }
            }
        }