Exemple #1
0
        private void openForm(Control form, bool modal = false)
        {
            if (!modal)
            {
                using (new WaitCursor())
                {
                    IControlContainer cc = mainForm as IControlContainer;
                    if (typeof(Form).IsAssignableFrom(form.GetType()))
                    {
                        ((Form)form).TopLevel        = false;
                        ((Form)form).FormBorderStyle = FormBorderStyle.None;
                        //((Form)form).WindowState = FormWindowState.Maximized;
                        var rec = cc.GetClientRectagle();
                        ((Form)form).Location = new System.Drawing.Point(0, 0);
                        ((Form)form).Size     = new System.Drawing.Size(rec.Width, rec.Height);
                        ((Form)form).Dock     = DockStyle.Fill;
                    }


                    if (cc != null)
                    {
                        var col = cc.GetControlCollection();
                        int idx = col.Add(form);
                        //((Control)form).Show();
                    }
                }
            }
            else
            {
                ((Form)form).StartPosition = FormStartPosition.CenterParent;
                lastDialogResult           = ((Form)form).ShowDialog();
            }
        }
Exemple #2
0
        private void onMenuItemClick(object sender, EventArgs e)
        {
            IMenuItem item = sender as IMenuItem;

            if (item != null && item.MenuAction != MenuActionsType.None)
            {
                if (!FormService.CheckMenuActionRights(item))
                {
                    return;
                }

                switch (item.MenuAction)
                {
                case MenuActionsType.OpenForm:
                    if (item.FormType != null)
                    {
                        using (new WaitCursor())
                        {
                            IControlContainer cc = mainForm as IControlContainer;
                            var form             = item.FormType.GetConstructor(new Type[0]).Invoke(new object[0]);
                            if (typeof(Form).IsAssignableFrom(form.GetType()))
                            {
                                ((Form)form).TopLevel        = false;
                                ((Form)form).FormBorderStyle = FormBorderStyle.None;
                                //((Form)form).WindowState = FormWindowState.Maximized;
                                var rec = cc.GetClientRectagle();
                                ((Form)form).Location = new System.Drawing.Point(0, 0);
                                ((Form)form).Size     = new System.Drawing.Size(rec.Width, rec.Height);
                                ((Form)form).Dock     = DockStyle.Fill;
                            }


                            if (cc != null)
                            {
                                var col = cc.GetControlCollection();
                                col.Add(form);
                                ((Control)form).Show();
                            }
                        }
                    }
                    break;

                case MenuActionsType.OpenFormModal:
                    if (item.FormType != null)
                    {
                        var form = item.FormType.GetConstructor(new Type[0]).Invoke(new object[0]);
                        if (typeof(Form).IsAssignableFrom(form.GetType()))
                        {
                            ((Form)form).FormBorderStyle = FormBorderStyle.FixedDialog;
                            ((Form)form).StartPosition   = FormStartPosition.CenterParent;
                            ((Form)form).ShowDialog();
                        }
                    }
                    break;

                case MenuActionsType.OpenViewModal:
                case MenuActionsType.OpenView:
                    Session session = null;
                    if ((item.ActionAttribute.Options & ActionOptions.WithoutSession) == ActionOptions.None)
                    {
                        session = AppController.Instance.CurrentLogin.CreateSession(false, false, "");
                    }
                    BAL.Business.View view = null;
                    if (item.ActionAttribute.ViewType != null)
                    {
                        if (item.ActionAttribute.Data != null)
                        {
                            try
                            {
                                if (session != null)
                                {
                                    view = (BAL.Business.View)item.ActionAttribute.ViewType.GetConstructor(new Type[] { typeof(Session), typeof(IMenuItem) }).Invoke(new object[] { session, item });
                                }
                                else
                                {
                                    view = (BAL.Business.View)item.ActionAttribute.ViewType.GetConstructor(new Type[] { typeof(IMenuItem) }).Invoke(new object[] { item });
                                }
                            }
                            catch { }
                        }
                        if (view == null)
                        {
                            if (session != null)
                            {
                                view = (BAL.Business.View)item.ActionAttribute.ViewType.GetConstructor(new Type[] { typeof(Session) }).Invoke(new object[] { session });
                            }
                            else
                            {
                                view = (BAL.Business.View)item.ActionAttribute.ViewType.GetConstructor(new Type[0]).Invoke(new object[0]);
                            }
                        }
                    }
                    else if (item.ActionAttribute.DataType != null && session != null)
                    {
                        var tableName = this.getTableName(item.ActionAttribute.DataType);
                        if (!string.IsNullOrEmpty(tableName))
                        {
                            var table = session.Tables[tableName];
                            view = table.CreateView();
                        }
                    }
                    if (view != null)
                    {
                        view.Load();
                        var gridForm = this.GetDefaultGridForm(view);
                        gridForm.FormClosed += (s, a) =>
                        {
                            view.Dispose();
                            if (session != null)
                            {
                                session.Dispose();
                            }
                        };
                        this.openForm((Control)gridForm, item.MenuAction == MenuActionsType.OpenViewModal);
                    }
                    break;
                }
            }
        }