private bool AddCaption(ViewStructure cl) { string lbname = "label" + UnitIndex; Label lb = new Label(); lb.AutoSize = true; lb.Text = cl.Caption; Graphics gh = lb.CreateGraphics(); gh.PageUnit = GraphicsUnit.Pixel; gh.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; int lbwidth = (int)(gh.MeasureString(lb.Text, lb.Font).Width); if (Location.X >= PanelSize.Width - (GapRow + cl.ControlWidth + lbwidth) || (ColumnIndex >= ColumnCount) && ColumnCount != 0) { Location.Y += GapRow + 20; //行间距+控件宽度 RowIndex++; ColumnIndex = 0; Location.X = 20; //if (Location.Y >= PanelSize.Height - 20) return false; } Designcode.Declare += "DevExpress.XtraEditors.LabelControl " + lbname + ";\n"; Designcode.Instantiation += "this." + lbname + " = new DevExpress.XtraEditors.LabelControl();\n"; Designcode.ControlAdd += "this.panelControl1.Controls.Add(this." + lbname + ");\n"; Designcode.ControlInit += "//\n// " + lbname + "\n//\n"; Designcode.ControlInit += "this." + lbname + ".AutoSize = true;\n"; Designcode.ControlInit += "this." + lbname + ".Location = new System.Drawing.Point(" + Location.X + "," + Location.Y + ");\n"; Designcode.ControlInit += "this." + lbname + ".TabIndex = " + UnitIndex + ";\n"; Designcode.ControlInit += "this." + lbname + ".Text = \"" + cl.Caption + "\";\n"; Location.X += (GapDescription + lbwidth); return(true); }
private List <ViewStructure> DataInvert(DataTable aTable) { if (aTable == null) { return(null); } List <ViewStructure> columns = new List <ViewStructure>(); foreach (DataRow dr in aTable.Rows) { ViewStructure structure = new ViewStructure(dr["FieldName"].ToString(), dr["Caption"].ToString(), dr["ControlType"].ToString(), acontrolwidth: Convert.ToInt16(dr["ControlWidth"].ToString() == "" ? "0" : dr["ControlWidth"].ToString()), anullable: dr["Nullable"].ToString() != "N"); columns.Add(structure); } return(columns); }
private bool AddControl(ViewStructure cl) { //遍历命名空间下所有类 Type[] classes = Assembly.Load("HollySource").GetTypes(); Control ctl = null; foreach (var item in classes) { if (item.Name == cl.ControlType) { ctl = (Control)Activator.CreateInstance(item); ctl.Width = cl.ControlWidth; ctl.Height = 20; } } if (ctl == null) { return(false); } string clname = string.Empty; switch (ctl.GetType().Name) { case "TextEditEx": clname = "txt" + cl.FieldName; Designcode.Declare += "private HollySource.TextEditEx " + clname + ";\n"; Designcode.Instantiation += "this." + clname + " = new HollySource.TextEditEx();\n"; Designcode.ControlInit += "//\n// " + clname + "\n//\n"; Designcode.ControlInit += "this." + clname + ".Location = new System.Drawing.Point(" + Location.X + "," + Location.Y + ");\n"; Designcode.ControlInit += "this." + clname + ".Size = new System.Drawing.Size(" + cl.ControlWidth + ", 20);\n"; Designcode.ControlInit += "this." + clname + ".TabIndex = " + UnitIndex + ";\n"; #region 空值判断和刷新 if (NeedNullJudge && !cl.Nullable) { Designcode.NullableJudge += "if (string.IsNullOrEmpty(this." + clname + ".Text))\n{\n"; Designcode.NullableJudge += "this.DialogInformation(\"" + cl.Caption + "不能为空!\");\n"; Designcode.NullableJudge += "this." + clname + ".Focus();\n}\n"; } if (NeedRefresh) { Designcode.Refresh += "this." + clname + ".Text = string.Empty;\n"; } #endregion break; case "SearchLookUpEditEx": break; case "LookUpEditEx": clname = "cmb" + cl.FieldName; Designcode.Declare += "private HollySource.LookUpEditEx " + clname + ";\n"; Designcode.Instantiation += "this." + clname + " = new HollySource.LookUpEditEx();\n"; Designcode.ControlInit += "//\n// " + clname + "\n//\n"; Designcode.ControlInit += "this." + clname + ".AutoClear = true;\n"; Designcode.ControlInit += "this." + clname + ".Location = new System.Drawing.Point(" + Location.X + "," + Location.Y + ");\n"; Designcode.ControlInit += "this." + clname + ".Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {\n"; Designcode.ControlInit += "new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});\n"; Designcode.ControlInit += "this." + clname + ".Properties.Columns.AddRange(new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {\n"; Designcode.ControlInit += "new DevExpress.XtraEditors.Controls.LookUpColumnInfo(\"ID\", \"编号\", 20, DevExpress.Utils.FormatType.None, \"\", false, DevExpress.Utils.HorzAlignment.Default),\n"; Designcode.ControlInit += "new DevExpress.XtraEditors.Controls.LookUpColumnInfo(\"NAME\", \"名称\")});\n"; Designcode.ControlInit += "this." + clname + ".Properties.DisplayMember = \"NAME\";\n"; Designcode.ControlInit += "this." + clname + ".Properties.NullText = \"\";\n"; Designcode.ControlInit += "this." + clname + ".Properties.SearchMode = DevExpress.XtraEditors.Controls.SearchMode.OnlyInPopup;\n"; Designcode.ControlInit += "this." + clname + ".Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;\n"; Designcode.ControlInit += "this." + clname + ".Properties.ValueMember = \"ID\";\n"; Designcode.ControlInit += "this." + clname + ".Size = new System.Drawing.Size(" + cl.ControlWidth + ", 20);\n"; Designcode.ControlInit += "this." + clname + ".TabIndex = " + UnitIndex + ";\n"; #region 空值判断和刷新 if (NeedNullJudge && !cl.Nullable) { Designcode.NullableJudge += "if (string.IsNullOrEmpty(this." + clname + ".Key))\n{\n"; Designcode.NullableJudge += "this.DialogInformation(\"" + cl.Caption + "不能为空!\");\n"; Designcode.NullableJudge += "this." + clname + ".Focus();\n}\n"; } if (NeedRefresh) { Designcode.Refresh += "this." + clname + ".Key = string.Empty;\n"; } #endregion break; case "ListBoxControlEx": break; case "DateEditEx": clname = "de" + cl.FieldName; Designcode.Declare += "private HollySource.DateEditEx " + clname + ";\n"; Designcode.Instantiation += "this." + clname + " = new HollySource.DateEditEx();\n"; Designcode.ControlInit += "//\n// " + clname + "\n//\n"; Designcode.ControlInit += "this." + clname + ".Location = new System.Drawing.Point(" + Location.X + "," + Location.Y + ");\n"; Designcode.ControlInit += "this." + clname + ".DateFormat = null;\n"; Designcode.ControlInit += "this." + clname + ".DateType = null;\n"; Designcode.ControlInit += "this." + clname + ".EditValue = null;\n"; Designcode.ControlInit += "this." + clname + ".Name = \"" + clname + "\";\n"; Designcode.ControlInit += "this." + clname + ".Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {\n"; Designcode.ControlInit += "new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});\n"; Designcode.ControlInit += "this." + clname + ".Properties.CalendarTimeProperties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {\n"; Designcode.ControlInit += "new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});\n"; Designcode.ControlInit += "this." + clname + ".Properties.DisplayFormat.FormatString = \"yyyy-MM-dd\";\n"; Designcode.ControlInit += "this." + clname + ".Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;\n"; Designcode.ControlInit += "this." + clname + ".Properties.EditFormat.FormatString = \"yyyy-MM-dd\";\n"; Designcode.ControlInit += "this." + clname + ".Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.Custom;\n"; Designcode.ControlInit += "this." + clname + ".Properties.Mask.EditMask = \"yyyy-MM-dd\";\n"; Designcode.ControlInit += "this." + clname + ".Properties.Mask.UseMaskAsDisplayFormat = true;\n"; Designcode.ControlInit += "this." + clname + ".QueryParamName = \"\";\n"; Designcode.ControlInit += "this." + clname + ".Size = new System.Drawing.Size(" + cl.ControlWidth + ", 20);\n"; Designcode.ControlInit += "this." + clname + ".TabIndex = " + UnitIndex + ";\n"; Designcode.ControlInit += "this." + clname + ".Value = \"\";\n"; #region 空值判断和刷新 if (NeedNullJudge && !cl.Nullable) { Designcode.NullableJudge += "if (string.IsNullOrEmpty(this." + clname + ".Value))\n{\n"; Designcode.NullableJudge += "this.DialogInformation(\"" + cl.Caption + "不能为空!\");\n"; Designcode.NullableJudge += "this." + clname + ".Focus();\n}\n"; } if (NeedRefresh) { Designcode.Refresh += "this." + clname + ".Value = string.Empty;\n"; } #endregion break; case "ComboBoxEx": clname = "cmb" + cl.FieldName; Designcode.Declare += "private HollySource.ComboBoxEx " + clname + ";\n"; Designcode.Instantiation += "this." + clname + " = new HollySource.ComboBoxEx();\n"; Designcode.ControlInit += "//\n// " + clname + "\n//\n"; Designcode.ControlInit += "this." + clname + ".Location = new System.Drawing.Point(" + Location.X + "," + Location.Y + ");\n"; Designcode.ControlInit += "this." + clname + ".DisplayMember = \"name\";\n"; Designcode.ControlInit += "this." + clname + ".FormattingEnabled = true;\n"; Designcode.ControlInit += "this." + clname + ".Key = \"\";\n"; Designcode.ControlInit += "this." + clname + ".Name = \"" + clname + "\";\n"; Designcode.ControlInit += "this." + clname + ".Size = new System.Drawing.Size(" + cl.ControlWidth + ", 20);\n"; Designcode.ControlInit += "this." + clname + ".TabIndex = " + UnitIndex + ";\n"; Designcode.ControlInit += "this." + clname + ".Value = \"\";\n"; Designcode.ControlInit += "this." + clname + ".ValueMember = \"id\";\n"; #region 空值判断和刷新 if (NeedNullJudge && !cl.Nullable) { Designcode.NullableJudge += "if (string.IsNullOrEmpty(this." + clname + ".Key))\n{\n"; Designcode.NullableJudge += "this.DialogInformation(\"" + cl.Caption + "不能为空!\");\n"; Designcode.NullableJudge += "this." + clname + ".Focus();\n}\n"; } if (NeedRefresh) { Designcode.Refresh += "this." + clname + ".Key = string.Empty;\n"; } #endregion break; default: return(false); } Designcode.BeginInit += "((System.ComponentModel.ISupportInitialize)(this." + clname + ".Properties)).BeginInit();\n"; Designcode.EndInit += "((System.ComponentModel.ISupportInitialize)(this." + clname + ".Properties)).EndInit();\n"; Designcode.ControlAdd += "this.panelControl1.Controls.Add(this." + clname + ");\n"; Location.X += GapColumn + cl.ControlWidth; ColumnIndex++; UnitIndex++; return(true); }