Esempio n. 1
0
        public Form GetDefaultGridForm(BAL.Business.View view)
        {
            var gridForm = (Form)FormService.GridFormType.GetConstructor(new Type[0]).Invoke(new object[0]);

            if (gridForm is IDataContexable)
            {
                ((IDataContexable)gridForm).DataContext = view;
            }
            gridForm.StartPosition = FormStartPosition.CenterParent;
            return(gridForm);
        }
Esempio n. 2
0
        public DialogResult OpenView(BAL.Business.View view, bool modal)
        {
            var gridForm = this.GetDefaultGridForm(view);

            if (modal)
            {
                return(gridForm.ShowDialog());
            }
            else
            {
                gridForm.Show();
            }
            return(DialogResult.None);
        }
Esempio n. 3
0
        public DialogResult ShowGridFormDialog(BAL.Business.View view)
        {
            var gridForm = this.GetDefaultGridForm(view);

            return(gridForm.ShowDialog());
        }
Esempio n. 4
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;
                }
            }
        }