Exemplo n.º 1
8
 protected virtual BaseEdit CreateEditorEx(BaseEdit e)
 {
     BaseEdit edit;
     if (this.column.RealColumnEdit is RepositoryItemProgressBar)
     {
         edit = new SpinEdit();
     }
     else if (this.column.RealColumnEdit is RepositoryItemMemoEdit)
     {
         edit = new MemoExEdit();
         ((MemoExEdit) edit).Properties.ShowIcon = false;
     }
     else if (this.IsLookUpEditors() && this.IsDisplayTextFilter())
     {
         RepositoryItem item = GridCriteriaHelper.CreateDisplayTextEditor(this.CurrentColumn);
         edit = item.CreateEditor();
         edit.Properties.Assign(item);
     }
     else
     {
         edit = this.column.RealColumnEdit.CreateEditor();
         edit.Properties.ResetEvents();
         edit.Properties.Assign(this.column.RealColumnEdit);
     }
     if (edit is ComboBoxEdit)
     {
         ((ComboBoxEdit) edit).Properties.UseCtrlScroll = false;
     }
     if (edit is ImageComboBoxEdit)
     {
         ((ImageComboBoxEdit) edit).Properties.UseCtrlScroll = false;
     }
     TextEdit edit2 = edit as TextEdit;
     if (edit2 != null)
     {
         edit2.Properties.AllowNullInput = DefaultBoolean.True;
     }
     return edit;
 }
Exemplo n.º 2
0
        protected override Control CreateControl()
        {
            MemoExEdit editor = new MemoExEdit();

            editor.AutoSize = false;

            return(editor);
        }
        private async void OnExecuteScriptButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Kind != DevExpress.XtraEditors.Controls.ButtonPredefines.Search)
            {
                return;
            }
            MemoExEdit edit   = (MemoExEdit)sender;
            bool       result = await ExecuteScript <bool>(3000, edit.Text, false);

            if (!result)
            {
                XtraMessageBox.Show("script execution timeout");
            }
        }
Exemplo n.º 4
0
        private void createEditors(int rowIndex, bool applyToAllButton)
        {
            var layoutControl = new LayoutControl();

            Controls.Add(layoutControl);
            layoutControl.Dock = DockStyle.Fill;
            layoutControl.AllowCustomization = false;

            foreach (MetaDataColumn col in _data.Columns)
            {
                LayoutControlItem colItem = layoutControl.Root.AddItem();
                colItem.Name        = col.DisplayName.FormatForLabel();
                colItem.ControlName = col.DisplayName;
                BaseEdit editor;

                if (col.DataType == typeof(string))
                {
                    if (col.ListOfValues != null && col.ListOfValues.Count > 0)
                    {
                        if (col.IsListOfValuesFixed)
                        {
                            editor = new ImageComboBoxEdit();
                            var cb             = editor as ImageComboBoxEdit;
                            var imageListSmall = getImageList(col.ListOfImages, IconSizes.Size16x16);
                            var imageListLarge = getImageList(col.ListOfImages, IconSizes.Size32x32);
                            cb.Properties.SmallImages = imageListSmall;
                            cb.Properties.LargeImages = imageListLarge;
                            foreach (var s in col.ListOfValues)
                            {
                                cb.Properties.Items.Add(new ImageComboBoxItem(s.Value, s.Key, getImageIndex(imageListLarge, s.Key)));
                            }
                            cb.Properties.AutoComplete   = true;
                            cb.Properties.AllowNullInput = col.Required ? DefaultBoolean.False : DefaultBoolean.True;
                            setEditorProperties(cb.Properties, col);
                            cb.Properties.CloseUpKey = new KeyShortcut(Keys.Enter);
                            cb.SelectedValueChanged += onSelectedValueChanged;
                        }
                        else
                        {
                            editor = new MRUEdit();
                            var cb = editor as MRUEdit;
                            foreach (var s in col.ListOfValues)
                            {
                                cb.Properties.Items.Add(s.Value);
                            }
                            cb.Properties.AutoComplete   = true;
                            cb.Properties.AllowNullInput = col.Required ? DefaultBoolean.False : DefaultBoolean.True;
                            setEditorProperties(cb.Properties, col);
                            cb.Properties.CloseUpKey          = new KeyShortcut(Keys.Enter);
                            cb.SelectedValueChanged          += onSelectedValueChanged;
                            cb.Properties.AllowRemoveMRUItems = false;
                        }
                    }
                    else
                    {
                        if (col.MaxLength > TEXT_LENGTH_FOR_MEMO_EDITOR)
                        {
                            editor = new MemoExEdit();
                            var me = editor as MemoExEdit;
                            me.Properties.AllowNullInput = col.Required ? DefaultBoolean.False : DefaultBoolean.True;
                            me.Properties.MaxLength      = maxLengthFor(col);
                            setEditorProperties(me.Properties, col);
                            me.Properties.CloseUpKey = new KeyShortcut(Keys.Enter);
                        }
                        else
                        {
                            editor = new TextEdit();
                            var te = editor as TextEdit;
                            te.Properties.AllowNullInput = col.Required ? DefaultBoolean.False : DefaultBoolean.True;
                            te.Properties.MaxLength      = maxLengthFor(col);
                            setEditorProperties(te.Properties, col);
                        }
                    }
                }
                else if (col.DataType == typeof(DateTime))
                {
                    editor = new DateEdit();
                    var de = editor as DateEdit;
                    de.Properties.ShowClear = !col.Required;
                    setEditorProperties(de.Properties, col);
                    de.Properties.CloseUpKey = new KeyShortcut(Keys.Enter);
                }

                else if (col.DataType == typeof(bool))
                {
                    editor = new CheckEdit();
                    var ce = editor as CheckEdit;
                    ce.Properties.Caption        = col.DisplayName;
                    ce.Properties.GlyphAlignment = HorzAlignment.Far;
                    ce.Properties.NullStyle      = StyleIndeterminate.Inactive;
                    ce.Properties.AllowGrayed    = !col.Required;
                    setEditorProperties(ce.Properties, col);
                }
                else if (col.DataType == typeof(double))
                {
                    editor = new TextEdit();
                    var te = editor as TextEdit;
                    te.Properties.AllowNullInput = col.Required ? DefaultBoolean.False : DefaultBoolean.True;
                    // te.Properties.MaxLength = col.MaxLength;
                    setEditorProperties(te.Properties, col);
                    te.Properties.Mask.MaskType = MaskType.RegEx;
                    te.Properties.Mask.EditMask = RegularExpression.Numeric;
                }
                else if (col.DataType == typeof(int))
                {
                    editor = new SpinEdit();
                    var se = editor as SpinEdit;
                    if (col.MinValue != null)
                    {
                        if (col.MinValueAllowed)
                        {
                            se.Properties.MinValue = (decimal)col.MinValue;
                        }
                        else
                        {
                            se.Properties.MinValue = (decimal)col.MinValue + 1;
                        }
                    }
                    if (col.MaxValue != null)
                    {
                        if (col.MaxValueAllowed)
                        {
                            se.Properties.MaxValue = (decimal)col.MaxValue;
                        }
                        else
                        {
                            se.Properties.MaxValue = (decimal)col.MaxValue - 1;
                        }
                    }
                    se.Properties.AllowNullInput = col.Required ? DefaultBoolean.False : DefaultBoolean.True;
                    setEditorProperties(se.Properties, col);
                }
                else
                {
                    editor = new TextEdit();
                    var te = editor as TextEdit;
                    te.Properties.AllowNullInput = col.Required ? DefaultBoolean.False : DefaultBoolean.True;
                    te.Properties.MaxLength      = col.MaxLength;
                    setEditorProperties(te.Properties, col);
                }

                if (col.Required)
                {
                    editor.BackColor = Color.LightYellow;
                }
                editor.Validating       += onEditorValidating;
                editor.TextChanged      += OnEditorTextChanged;
                editor.EditValueChanged += OnEditorTextChanged;
                editor.Validated        += onEditorValidated;

                editor.ToolTipController = new ToolTipController();
                editor.SuperTip          = new SuperToolTip();
                editor.SuperTip.Items.AddTitle(col.DisplayName);
                editor.SuperTip.Items.Add(col.Description);

                //add information about ranges to the tool tip
                if (col.MinValue != null || col.MaxValue != null)
                {
                    var lowerBound = col.MinValue == null ? INFINITY_SIGN : (col.MinValueAllowed) ? "[" : "]";
                    var lowerValue = col.MinValue == null ? String.Empty : col.MinValue.ToString();
                    var upperValue = col.MaxValue == null ? String.Empty : col.MaxValue.ToString();
                    var upperBound = col.MaxValue == null ? INFINITY_SIGN : (col.MaxValueAllowed) ? "]" : "[";
                    var text       = $"Valid values must be within range {lowerBound}{lowerValue};{upperValue}{upperBound}.";
                    editor.SuperTip.Items.Add(text);
                }

                editor.Name = col.ColumnName;
                editor.DataBindings.Add(new Binding("EditValue", _data, col.ColumnName));
                editor.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
                if (shouldSetDefaultValue(col))
                {
                    editor.EditValue = col.DefaultValue;
                }

                colItem.Control = editor;

                var btnColItem = layoutControl.Root.AddItem();
                btnColItem.Move(colItem, InsertType.Right);
                var button = createThisMetaDataValueApplyToAllButton(editor);

                button.Enabled = !col.IsColumnUsedForGrouping;

                btnColItem.Control = button;

                btnColItem.TextVisible = false;
            }

            // bind to given row index
            if (_data.Rows.Count > 0 && rowIndex >= 0 && rowIndex < _data.Rows.Count)
            {
                BindingContext[_data].Position = rowIndex;
            }

            if (!applyToAllButton)
            {
                return;
            }
            _copyButton = new UxSimpleButton();
            var copyItem = layoutControl.Root.AddItem();

            copyItem.Control     = _copyButton;
            _copyButton.Name     = "btnApplyToAll";
            _copyButton.Text     = Captions.Importer.ApplyToAll;
            _copyButton.ToolTip  = Captions.Importer.ApplyToAll;
            _copyButton.Image    = ApplicationIcons.ApplyAll;
            _copyButton.Enabled  = IsDataValid;
            _copyButton.Click   += onCopyButtonClick;
            copyItem.TextVisible = false;
        }
Exemplo n.º 5
0
        /// <summary>
        /// 创建自定义控件
        /// </summary>
        public void CreateDynamicControl()
        {
            if (DynamicMasterTableData.Select("bSystemColumn=0").Length > 0)
            {
                pnlDynamic.Visible = true;

                //每行控件数
                int iControlColumn = Convert.ToInt32(DynamicMasterTableData.Rows[0]["iControlColumn"]);
                //控件间距
                int iControlSpace = Convert.ToInt32(DynamicMasterTableData.Rows[0]["iControlSpace"]);
                //先计算需要生成控件的数据,去除如果在自定义字段权限设置中设置为不可见的数据
                List<DataRow> drs = DynamicMasterTableData.Select("bSystemColumn=0 AND bShowInPanel=1").ToList();

                if (!SecurityCenter.IsAdmin && FormFieldSetting.Rows.Count > 0)
                {
                    for (int i = 0; i < drs.Count; i++)
                    {
                        //取只有是主表/单表的数据
                        foreach (DataRow drField in FormFieldSetting.Select("sTableName='" + MasterTableName + "'"))
                        {
                            if (drs[i]["sFieldName"].ToString() == drField["sFieldName"].ToString() &&
                                !Convert.ToBoolean(drField["bVisiable"]))
                            {
                                drs.Remove(drs[i]);
                            }
                        }
                    }
                }

                //计算控件总共行数
                int iRows = 0;
                if (drs.Count > 0)
                {
                    if (drs.Count % iControlColumn != 0)
                    {
                        iRows = (int)Math.Floor(Convert.ToDecimal(drs.Count / iControlColumn)) + 1;
                    }
                    else
                    {
                        iRows = Convert.ToInt32(drs.Count / iControlColumn);
                    }
                    //设置控件数计数
                    int iControl = 0;
                    for (int j = 0; j < iRows; j++)
                    {
                        for (int i = 0; i < iControlColumn; i++)
                        {
                            //控件类型
                            string sControlType = drs[iControl]["sControlType"].ToString();
                            //创建控件
                            //Lable大小控制为80X21,其他输入控件大小为120X21
                            Label lblControl = new Label();
                            lblControl.AutoSize = false;
                            lblControl.Size = new Size(80, 21);
                            lblControl.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i, ControlY + (21 + 10) * j);
                            //控件命名规则:lbl+字段名
                            lblControl.Name = "lbl" + drs[iControl]["sFieldName"].ToString();
                            lblControl.TextAlign = ContentAlignment.BottomLeft;
                            //当控件类型为复选框\单选\Label标签时不创建Lable控件
                            if (sControlType != "chk" && sControlType != "rad" && sControlType != "lbl")
                            {
                                lblControl.Text = LangCenter.Instance.IsDefaultLanguage ? drs[iControl]["sCaption"].ToString() : drs[iControl]["sCaption"].ToString();
                            }
                            else
                                lblControl.Visible = false;
                            pnlDynamic.Controls.Add(lblControl);
                            switch (sControlType)
                            {
                                case "txt":
                                    {
                                        TextEdit txt = new TextEdit();
                                        txt.Size = new Size(120, 21);
                                        txt.Name = "txt" + drs[iControl]["sFieldName"].ToString();
                                        txt.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j);
                                        pnlDynamic.Controls.Add(txt);
                                        break;
                                    }
                                case "mtxt":
                                    {
                                        MemoEdit mtxt = new MemoEdit();
                                        mtxt.Size = new Size(120, 21);
                                        mtxt.Name = "mtxt" + drs[iControl]["sFieldName"].ToString();
                                        mtxt.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j);
                                        pnlDynamic.Controls.Add(mtxt);
                                        break;
                                    }
                                case "btxt":
                                    {
                                        MemoExEdit btxt = new MemoExEdit();
                                        btxt.Size = new Size(120, 21);
                                        btxt.Name = "btxt" + drs[iControl]["sFieldName"].ToString();
                                        btxt.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j);
                                        pnlDynamic.Controls.Add(btxt);
                                        break;
                                    }
                                case "cbx":
                                    {
                                        ImageComboBoxEdit cbx = new ImageComboBoxEdit();
                                        cbx.Size = new Size(120, 21);
                                        cbx.Name = "cbx" + drs[iControl]["sFieldName"].ToString();
                                        cbx.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j);
                                        pnlDynamic.Controls.Add(cbx);
                                        break;
                                    }
                                case "chk":
                                    {
                                        CheckEdit chk = new CheckEdit();
                                        chk.Size = new Size(120, 21);
                                        chk.Name = "chk" + drs[iControl]["sFieldName"].ToString();
                                        chk.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j);
                                        chk.CheckState = CheckState.Unchecked;
                                        chk.Text = LangCenter.Instance.IsDefaultLanguage ? drs[iControl]["sCaption"].ToString() : drs[iControl]["sEngCaption"].ToString();
                                        pnlDynamic.Controls.Add(chk);
                                        break;
                                    }
                                case "det":
                                    {
                                        DateEdit det = new DateEdit();
                                        det.Size = new Size(120, 21);
                                        det.Name = "det" + drs[iControl]["sFieldName"].ToString();
                                        det.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j);
                                        det.EditValue = null;
                                        pnlDynamic.Controls.Add(det);
                                        break;
                                    }
                                case "dett":
                                    {
                                        DateEdit dett = new DateEdit();
                                        dett.Size = new Size(120, 21);
                                        dett.Name = "dett" + drs[iControl]["sFieldName"].ToString();
                                        dett.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j);
                                        dett.EditValue = null;
                                        dett.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                                        dett.Properties.DisplayFormat.FormatString = "g";
                                        dett.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                                        dett.Properties.EditFormat.FormatString = "g";
                                        dett.Properties.EditMask = "g";
                                        pnlDynamic.Controls.Add(dett);
                                        break;
                                    }
                                case "img":
                                    {
                                        ImageEdit img = new ImageEdit();
                                        img.Size = new Size(120, 21);
                                        img.Name = "img" + drs[iControl]["sFieldName"].ToString();
                                        img.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j);
                                        pnlDynamic.Controls.Add(img);
                                        break;
                                    }
                                case "lbl":
                                    {
                                        LabelControl lbl = new LabelControl();
                                        lbl.Size = new Size(120, 21);
                                        lbl.Name = "lbl" + drs[iControl]["sFieldName"].ToString() + iControl.ToString();
                                        lbl.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j);
                                        lbl.Text = LangCenter.Instance.IsDefaultLanguage ? drs[iControl]["sCaption"].ToString() : drs[iControl]["sEngCaption"].ToString();
                                        pnlDynamic.Controls.Add(lbl);
                                        break;
                                    }
                                case "lkp":
                                    {
                                        SunriseLookUp lkp = new SunriseLookUp();
                                        lkp.Size = new Size(120, 21);
                                        lkp.Name = "lkp" + drs[iControl]["sFieldName"].ToString();
                                        lkp.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j);
                                        pnlDynamic.Controls.Add(lkp);
                                        break;
                                    }
                                case "mlkp":
                                    {
                                        SunriseMLookUp mlkp = new SunriseMLookUp();
                                        mlkp.Size = new Size(120, 21);
                                        mlkp.Name = "mlkp" + drs[iControl]["sFieldName"].ToString();
                                        mlkp.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j);
                                        pnlDynamic.Controls.Add(mlkp);
                                        break;
                                    }
                                case "rad":
                                    {
                                        RadioGroup rad = new RadioGroup();
                                        rad.Size = new Size(120, 21);
                                        rad.Name = "rad" + drs[iControl]["sFieldName"].ToString();
                                        rad.Location = new Point(ControlX + (80 + 120 + iControlSpace) * i + 80, ControlY + 4 + (21 + 10) * j);
                                        pnlDynamic.Controls.Add(rad);
                                        break;
                                    }
                            }
                            iControl++;
                            //当计数大于等于要创建的控件数量时则退出循环
                            if (iControl >= drs.Count)
                                break;
                        }
                    }
                }
                pnlDynamic.Height = ControlY + iRows * 31;
            }
            //初始化数据绑定
            InitDataBindings();
        }