Exemple #1
0
        private bool SetControlValueToEntity(IEntityControl ctrl)
        {
            PropertyMetaData schemaProperty = this.Properties[ctrl.PropertyName].SchemaProperty;
            PropertyInfo entityPi = schemaProperty.Property;
            if (entityPi.SetMethod != null)
            {
                SchemaInfo entitySchema = schemaProperty.Schema;

                using (FunctionScope fsEntity = new FunctionScope(this.RemoveEntityPropertyChanged, this.AddEntityPropertyChanged))
                {
                    using (FunctionScope fsControl = new FunctionScope(this.RemoveControlValueChanged, ctrl, this.AddControlValueChanged, ctrl))
                    {
                        ctrl.RemoveErrorMessage();

                        object value = ctrl.Value;

                        bool notNull = ctrl.Required || !entitySchema.IsNullable;

                        ConvertResult convertResult = this.Converter.Convert(value, entityPi.PropertyType, !notNull);
                        switch (convertResult.Result)
                        {
                            case ValidationResult.Valid:
                                entityPi.SetValue(this.entity, convertResult.ConvertedValue);
                                return true;
                            case ValidationResult.ValidNull:
                                entityPi.SetValue(this.entity, null);
                                return true;
                            case ValidationResult.Invalid:
                                ctrl.ShowErrorMessage(StringResources.InvalidDataMessage);
                                return false;
                            case ValidationResult.InvalidNull:
                                ctrl.ShowErrorMessage(StringResources.InvalidNullDataMessage);
                                return false;
                        }
                    }
                }
            }
            return true;
        }
Exemple #2
0
        ShowDialog(Type ControlType, string ModuleName)
        {
            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)
                    {
                        orig = (ParentEntity)
                               BaseFactory.CreateInstance((Type)bnd.DataSource);
                    }

                    if (!orig.LoadEntity())
                    {
                        orig.SetDefaultValue();
                    }

                    frm.pe = (ParentEntity)MetaData.CloneAll(orig);
                    frm.pe.SetOriginal(orig);

                    ((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.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                        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));
                }
            }
        }