示例#1
0
        ShowDialog(Type ControlType, string ModuleName,
                   ParentEntity Entity)
        {
            using (new WaitCursor(true))
            {
                if (ControlType.IsSubclassOf(typeof(DocumentForm)))
                {
                    ParentEntity orig;

                    frmSingletonEntity frm = new frmSingletonEntity();

                    Control FormCtrl = (Control)BaseFactory
                                       .CreateInstance(ControlType);
                    BindingSource bnd = BaseWinFramework.FindMainBindingSource(
                        (Form)FormCtrl, typeof(ParentEntity));

                    orig = bnd.DataSource as ParentEntity;

                    if (orig == null)
                    {
                        if (Entity == null)
                        {
                            orig = (ParentEntity)
                                   BaseFactory.CreateInstance((Type)bnd.DataSource);
                            if (!orig.LoadEntity())
                            {
                                orig.SetDefaultValue();
                            }
                            frm.pe = (ParentEntity)MetaData.CloneAll(orig);
                            frm.pe.SetOriginal(orig);
                        }
                        else
                        {
                            frm.pe = Entity;
                            MetaData.CloneToOriginal(Entity);
                            orig = Entity.GetOriginal();
                        }
                    }

                    frm.DialogMode = true;

                    ((IRuleInitUI)frm.pe).InitUI();

                    DocumentForm frmc = (DocumentForm)FormCtrl;
                    frm.frmc = frmc;

                    bnd.DataSource = frm.pe;
                    IEntityControl df = FormCtrl as IEntityControl;
                    if (df != null)
                    {
                        df.InitNavigator(null);
                    }
                    ((IRuleInitUI)frm.pe).AfterInitNavigator(null);

                    BaseWinFramework.WinForm.AutoFormat
                    .AutoFormatForm(FormCtrl, false);
                    //BaseWinFramework.WinForm.AutoLockEntity.LockForm(frm.pe,
                    //    MetaData.GetTableDef(frm.pe.GetType()), FormCtrl);

                    frm.ep            = new DXErrorProvider(frm);
                    frm.ep.DataSource = bnd;

                    if (frmc != null)
                    {
                        frmc.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                        frmc.FormClosed     += new FormClosedEventHandler(frmc_FormClosed);
                        frmc.TopLevel        = false;
                        frmc.Parent          = frm;
                        frm.Width            = frmc.Width + frm.Width -
                                               frm.DisplayRectangle.Width;

                        if (frmc.ShowConfirmButton)
                        {
                            frm.Height = frmc.Height + 70;
                        }
                        else
                        {
                            frm.Height = frmc.Height + frm.Height -
                                         frm.DisplayRectangle.Height;
                            frm.simpleButton1.Visible = false;
                            frm.simpleButton2.Visible = false;
                        }
                        frmc.Show();
                    }
                    else
                    {
                        frm.Width  = FormCtrl.Width + frm.Width - frm.DisplayRectangle.Width;
                        frm.Height = FormCtrl.Height + 70;
                        frm.Controls.Add(FormCtrl);
                    }
                    if (frmc != null && frmc.Text.Length > 0)
                    {
                        frm.Text = frmc.Text;
                    }
                    else
                    {
                        frm.Text = BaseUtility.SplitName(ModuleName.Length == 0 ?
                                                         orig.GetType().Name : ModuleName);
                    }

                    ((Control)frmc).TabIndex = 0;
                    return(frm.ShowForm(BaseWinFramework.MdiParent));
                }
                else
                {
                    XtraForm frm = (XtraForm)BaseFactory.CreateInstance(ControlType);
                    return(frm.ShowDialog(BaseWinFramework.MdiParent));
                }
            }
        }