private void gridView2_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { int i = this.gridView1.FocusedRowHandle; if (i >= 0) { //如果e.Valid等于false就会触发InvalidRowException事件 CustClassInfo citem = CustClassManager.Instance.AllClasses[i]; CustPropertyInfo item = (CustPropertyInfo)e.Row; if (!item.PropertyName.StartsWith("property_")) { item.PropertyName = "property_" + item.PropertyName; //属性名前面加个前缀 } //item.PropertyName = item.PropertyName.ToUpper(); //校验属性名是否为字母开头 if (!CustClassManager.regex字母开头.IsMatch(item.PropertyName)) { e.Valid = false; return; } if (citem.PropertyInfos.ToList().Where(p => p.PropertyName.Equals(item.PropertyName)).Count() > 1) { e.Valid = false; } } }
private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { //如果e.Valid等于false就会触发InvalidRowException事件 CustClassInfo item = (CustClassInfo)e.Row; if (!item.ClassName.StartsWith("class_")) { item.ClassName = "class_" + item.ClassName; //类名前面加个前缀 } //item.ClassName = item.ClassName.ToUpper(); //校验类名是否为字母开头 if (!CustClassManager.regex字母开头.IsMatch(item.ClassName)) { e.Valid = false; return; } if (CustClassManager.Instance.AllClasses.ToList().Where(p => p.ClassName.Equals(item.ClassName)).Count() > 1) { e.Valid = false; } }
public Control CreateSettingControl(CustClassInfo item) { XtraUserControl xtraUserControl = new XtraUserControl(); xtraUserControl.AutoScroll = true; xtraUserControl.Dock = DockStyle.Fill; xtraUserControl.Text = item.ClassName; SimpleButton button = new SimpleButton() { Text = "导出报表" }; button.Appearance.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); button.Appearance.Options.UseFont = true; button.Dock = System.Windows.Forms.DockStyle.Bottom; button.Location = new System.Drawing.Point(0, 0); button.Size = new System.Drawing.Size(240, 50); xtraUserControl.Controls.Add(button); ProgressBarControl progressBar = new ProgressBarControl(); progressBar.Dock = DockStyle.Bottom; progressBar.Properties.Appearance.BackColor = System.Drawing.Color.Gainsboro; progressBar.Properties.EndColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))); progressBar.Properties.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat; progressBar.Properties.LookAndFeel.UseDefaultLookAndFeel = false; progressBar.Properties.StartColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); progressBar.Size = new System.Drawing.Size(240, 30); xtraUserControl.Controls.Add(progressBar); //XtraForm form = new XtraForm(); if (item.ListOrSingle) { GridView gv = new GridView(); gv.OptionsView.ShowGroupPanel = false; gv.OptionsView.NewItemRowPosition = NewItemRowPosition.Top; gv.OptionsView.ShowFooter = true; GridControl gc = new GridControl(); gc.Dock = DockStyle.Fill; gc.MainView = gv; gc.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] { gv }); gv.GridControl = gc; if (item.ClassType == null) //如果还嵌套List { GridView gvSub = new GridView(); //最多嵌套两层 gvSub.OptionsView.ShowGroupPanel = false; gvSub.OptionsView.NewItemRowPosition = NewItemRowPosition.Top; gvSub.OptionsView.ShowFooter = true; gvSub.GridControl = gc; } object genericList = ClassDynamicCreater.CreateGeneric(typeof(BindingList <>), item.ClassType); if (item.DataSourceTag == null || item.DataSourceTag.GetType() != genericList.GetType()) { item.DataSourceTag = genericList; } //IBindingList ibl = item.DataSourceTag as IBindingList; gc.DataSource = item.DataSourceTag; //form.Controls.Add(gc); xtraUserControl.Controls.Add(gc); button.Click += (o, e) => { if (!Directory.Exists(ExportDirectory)) { Directory.CreateDirectory(ExportDirectory); } progressBar.Position = 0; gv.ExportToXlsx($@"{ExportDirectory}{item.ClassName}.xlsx"); progressBar.Position = 100; Task.Run(() => { Process.Start("explorer.exe", ExportDirectory); }); }; } else { PropertyGridControl pc = new PropertyGridControl(); pc.Dock = DockStyle.Fill; pc.SelectedObject = item.Instance; //form.Controls.Add(pc); xtraUserControl.Controls.Add(pc); button.Click += (o, e) => { if (!Directory.Exists(ExportDirectory)) { Directory.CreateDirectory(ExportDirectory); } progressBar.Position = 0; pc.ExportToXlsx($@"{ExportDirectory}{item.ClassName}.xlsx"); progressBar.Position = 100; Task.Run(() => { Process.Start("explorer.exe", ExportDirectory); }); }; } return(xtraUserControl); }
private void 查看_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { int i = this.gridView1.FocusedRowHandle; if (i >= 0) { CustClassInfo item = CustClassManager.Instance.AllClasses[i]; XtraForm form = new XtraForm(); if (item.ListOrSingle) { GridView gv = new GridView(); gv.OptionsView.ShowGroupPanel = false; gv.OptionsView.NewItemRowPosition = NewItemRowPosition.Top; gv.OptionsView.ShowFooter = true; GridControl gc = new GridControl(); gc.Dock = DockStyle.Fill; gc.MainView = gv; gc.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] { gv }); gv.GridControl = gc; foreach (var itemP in item.ClassType.GetProperties()) { Type typeP = itemP.PropertyType; if (typeP.IsGenericType) //判断是否有属性为List<> //注意这里最多嵌套两层,三层或以上的情况懒得再递归了,一般最多两层 { Type listSubType = typeP.GetGenericArguments()[0]; //如List<string>获取到string type GridView gvSub = new GridView(); gvSub.OptionsView.ShowGroupPanel = false; gvSub.OptionsView.NewItemRowPosition = NewItemRowPosition.Top; gvSub.OptionsView.ShowFooter = true; gvSub.GridControl = gc; GridLevelNode gridLevelNode = new GridLevelNode(); gridLevelNode.LevelTemplate = gvSub; gridLevelNode.RelationName = $@"{itemP.Name}"; gc.LevelTree.Nodes.AddRange(new GridLevelNode[] { gridLevelNode }); } } object genericList = ClassDynamicCreater.CreateGeneric(typeof(BindingList <>), item.ClassType); if (item.DataSourceTag == null || item.DataSourceTag.GetType() != genericList.GetType()) { item.DataSourceTag = genericList; } //IBindingList ibl = item.DataSourceTag as IBindingList; gc.DataSource = item.DataSourceTag; form.Controls.Add(gc); } else { PropertyGridControl pc = new PropertyGridControl(); pc.Dock = DockStyle.Fill; pc.SelectedObject = item.Instance; form.Controls.Add(pc); } form.ShowDialog(); } }