예제 #1
0
        internal virtual bool IsSuch(FormParams otherFormParams)
        {
            if (otherFormParams == null)
            {
                throw new ArgumentNullException("OtherFormParams");
            }

            // Есть смысл сравнивать только с окнами, открывающимся не в диалоговом режиме
            if (Params != null && otherFormParams.ShowType != FormShowTypeEnum.Dialog && otherFormParams.ReasonType != FormReasonTypeEnum.New)
            {
                if (Params.ReasonType == otherFormParams.ReasonType && Params.Objects.Length == otherFormParams.Objects.Length)
                {
                    bool objectsEquals = true;
                    for (int i = 0; i < Params.Objects.Length; i++)
                    {
                        if (!object.Equals(Params.Objects[i], otherFormParams.Objects[i]))
                        {
                            objectsEquals = false;
                            break;
                        }
                    }
                    if (objectsEquals)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
예제 #2
0
        private static object OpenForm <T>(FormParams Params) where T : MyForm, new()
        {
            try
            {
                CreateFormResult <T> createResult;
                if (MainForm != null)
                {
                    MainForm.Cursor = Cursors.WaitCursor;
                }
                object resFromForm = null;

                if ((createResult = CreateForm <T>(Params, false)) != null)
                {
                    if (createResult.IsNewForm)
                    {
                        resFromForm = createResult.Form.ShowWithParams();
                    }
                }
                if (MainForm != null)
                {
                    MainForm.Cursor = Cursors.Default;
                }
                return(resFromForm);
            }
            catch (Exception e)
            {
                if (MainForm != null)
                {
                    MainForm.Cursor = Cursors.Default;
                }

                return(null);
            }
        }
예제 #3
0
        private static CreateFormResult <T> CreateForm <T>(FormParams formParams, bool showErrors) where T : MyForm, new()
        {
            try
            {
                T findedForm = null;
                for (int i = 0; i < Application.OpenForms.Count; i++)
                {
                    if (Application.OpenForms[i].GetType() == typeof(T))
                    {
                        if (((T)Application.OpenForms[i]).IsSuch(formParams))
                        {
                            findedForm = (T)Application.OpenForms[i];
                            break;
                        }
                    }
                }
                if (findedForm != null)
                {
                    if (findedForm.WindowState == FormWindowState.Minimized)
                    {
                        findedForm.WindowState = FormWindowState.Normal;
                    }
                    findedForm.Activate();
                    return(new CreateFormResult <T>(findedForm, false));
                }

                T form = null;

                try
                {
                    {
                        form        = new T();
                        form.Params = formParams;
                        form.LoadData();
                    }
                }
                catch
                {
                    if (form != null)
                    {
                        form.Dispose();
                    }
                    throw;
                }
                finally
                {
                }

                return(new CreateFormResult <T>(form, true));
            }
            catch (Exception err)
            {
                CatchError?.Invoke(null, new FormErrorEventArgs(err));
                return(null);
            }
        }
예제 #4
0
 internal override bool IsSuch(FormParams otherFormParams)
 {
     return(true);
 }