private void FillDataGrid(LibDataTableStruct dtstruct, bool isclear) { //DataRow row = null; DataTable dt = this.dataGridView1.DataSource as DataTable; //DataColumn langcol = null; if (isclear) { dt.Rows.Clear(); } //if (System.Globalization.CultureInfo.InstalledUICulture.Name.ToUpper() == "ZH-CN") //{ // langcol = dt.Columns[Language.CHS.ToString()]; //} //DataRow[] drs = null; foreach (LibField f in dtstruct.Fields) { if (f.Items != null) { foreach (LibKeyValue item in f.Items) { if (string.IsNullOrEmpty(item.FromkeyValueID)) { AddDataGridRow(dtstruct.Name, string.Format("{0}_{1}", f.Name, item.Key), item.Value.ToString()); //row = dt.NewRow(); //row["TableNm"] = dtstruct.Name; //row["FieldNm"] = string.Format("{0}_{1}", f.Name, item.Key); //row[langcol] = item.Value; //FilllanguageValue(languagedt, dtstruct.Name, row["FieldNm"].ToString (), row); //dt.Rows.Add(row); } } } AddDataGridRow(dtstruct.Name, f.Name, f.DisplayName); //row = dt.NewRow(); //row["TableNm"] = dtstruct.Name; //row["FieldNm"] = f.Name; //row[langcol] = f.DisplayName; //FilllanguageValue(languagedt, dtstruct.Name, f.Name, row); //dt.Rows.Add(row); } }
/// <summary> /// 选入 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, System.EventArgs e) { LibRelateField relateField = null; string text = string.Empty; string tablenm = string.Empty; string fldnm = string.Empty; string[] array; foreach (var item in this.listBox1.SelectedItems) { this.listBox2.Items.Add(item); array = item.ToString().Split(SysConstManage.Point); tablenm = array[0]; LibDataTableStruct tableStruct = _tableStructs.FirstOrDefault(i => i.Name == tablenm); LibField field = tableStruct.Fields.FindFirst("Name", array[1]); relateField = new LibRelateField(); relateField.ID = Guid.NewGuid().ToString(); relateField.FieldNm = field.Name; relateField.DisplayNm = field.DisplayName; relateField.AliasName = field.AliasName; relateField.FieldType = field.FieldType; relateField.FromTableIndex = tableStruct.TableIndex; if (_relateFields.FirstOrDefault(i => i.FromTableIndex == tableStruct.TableIndex && i.FieldNm == field.Name) == null) { _relateFields.Add(relateField); } RelateFieldProperty property = (RelateFieldProperty)this.splitContainer1.Panel2.Controls[relateField.ID]; if (property == null) { property = new RelateFieldProperty(relateField.ID); property.Dock = DockStyle.Fill; property.SetPropertyValue(relateField, null); _rfieldPropertylist.Add(property); this.splitContainer1.Panel2.Controls.Add(property); } } for (int i = 0; i < this.listBox2.Items.Count; i++) { this.listBox1.Items.Remove(this.listBox2.Items[i]); } }
/// <summary>字段节点上的右键菜单</summary> /// <param name="sender"></param> /// <param name="e"></param> private void contextMenuStrip4_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { LibTreeNode curentNode = (LibTreeNode)this.treeView1.SelectedNode; LibDefineTable defineTB = _ds.DefTables.FindFirst("ID", ((LibTreeNode)curentNode.Parent.Parent).NodeId); LibDataTableStruct currentTBStruct = defineTB.TableStruct.FindFirst("ID", ((LibTreeNode)curentNode.Parent).NodeId); switch (e.ClickedItem.Name) { case "deleteField": //删除字段节点 //LibField f= currentTBStruct.Fields.FindFirst("ID", curentNode.NodeId); //currentTBStruct.Fields.Remove(f); currentTBStruct.Fields.Remove("ID", curentNode.NodeId); DefFieldProperty fp = this._fieldPropertylst.FirstOrDefault(i => i.Name == curentNode.NodeId); if (fp != null) { this._fieldPropertylst.Remove(fp); } this.treeView1.Nodes.Remove(curentNode); UpdateTabPageText(); break; } }
/// <summary>自定义表节点上的右键菜单</summary> /// <param name="sender"></param> /// <param name="e"></param> private void contextMenuStrip2_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { LibTreeNode curentNode = (LibTreeNode)this.treeView1.SelectedNode; LibDefineTable currentDefTB = _ds.DefTables.FindFirst("ID", curentNode.NodeId); if (currentDefTB.TableStruct == null) { currentDefTB.TableStruct = new LibCollection <LibDataTableStruct>(); } switch (e.ClickedItem.Name) { case "CreateTableStruct": //新建表结构 #region LibTreeNode tablestruc = new LibTreeNode(); tablestruc.NodeId = Guid.NewGuid().ToString(); tablestruc.Name = string.Format("{0}_TableStruct{1}", currentDefTB.TableName, currentDefTB.TableStruct.Count + 1); tablestruc.Text = tablestruc.Name; tablestruc.NodeType = NodeType.TableStruct; curentNode.Nodes.Add(tablestruc); TBStructProperty tbstructP = new TBStructProperty(tablestruc.NodeId); tbstructP.Dock = DockStyle.Fill; this._tbStructPropertylst.Add(tbstructP); this.splitContainer1.Panel2.Controls.Add(tbstructP); LibDataTableStruct tbstruct = new LibDataTableStruct(); tbstruct.ID = tablestruc.NodeId; tbstruct.Name = tablestruc.Name; tbstruct.DisplayName = tablestruc.Text; tbstruct.Ignore = true; currentDefTB.TableStruct.Add(tbstruct); tbstructP.SetPropertyValue(tbstruct, tablestruc); #endregion break; } }
/// <summary> /// /// </summary> /// <param name="tb"></param> /// <param name="fromfield">是否取来源字段关联出来的字段(只取属于关联表的字段)</param> /// <param name="relatefield">是否取来源字段关联出来的字段</param> /// <returns></returns> public DataTable DoCreateTableShema(LibDataTableStruct tb, bool fromfield = true, bool relatefield = false) { DataTable dt = null; DataColumn col = null; List <DataColumn> primarykey = null; dt = new DataTable(tb.Name); //dftb.Tables[index] = dt; primarykey = new List <DataColumn>(); foreach (LibField f in tb.Fields) { col = new DataColumn(f.Name); col.Caption = f.DisplayName; switch (f.FieldType) { case LibFieldType.Byte: col.DataType = typeof(bool); if (!f.AutoIncrement) { col.DefaultValue = 0; } break; case LibFieldType.Date: col.DataType = typeof(Date); //if (!f.AutoIncrement) // col.DefaultValue = new Date { value = DateTime.Now.ToString() }; break; case LibFieldType.DateTime: col.DataType = typeof(DateTime); if (!f.AutoIncrement) { col.DefaultValue = DateTime.Now; } break; case LibFieldType.Decimal: col.DataType = typeof(decimal); if (!f.AutoIncrement) { col.DefaultValue = 0; } break; case LibFieldType.Interger: col.DataType = typeof(Int32); if (!f.AutoIncrement) { col.DefaultValue = 0; } break; case LibFieldType.Long: col.DataType = typeof(long); if (!f.AutoIncrement) { col.DefaultValue = 0; } break; case LibFieldType.String: case LibFieldType.Text: col.DataType = typeof(string); if (!f.AutoIncrement) { col.DefaultValue = string.Empty; } break; case LibFieldType.Img: col.DataType = typeof(byte[]); break; } if (tb.PrimaryKey.Contains(f.Name))//属于主键 { primarykey.Add(col); } if (f.AutoIncrement) { col.AutoIncrement = true; col.AutoIncrementSeed = f.AutoIncrementSeed; col.AutoIncrementStep = f.AutoIncrementStep; } col.ExtendedProperties.Add(SysConstManage.ExtProp, new ColExtendedProperties { IsActive = f.IsActive, IsRelate = false, MapPrimarykey = f.RelatePrimarykey, DataTypeLen = f.FieldLength, Decimalpoint = f.Decimalpoint, AliasName = f.AliasName, FieldNm = f.Name, ObjectNm = f.ObjFieldName, ValidateExpression = f.ValidateExpression }); dt.Columns.Add(col); if (fromfield && f.SourceField != null && f.SourceField.Count > 0) { foreach (LibFromSourceField item in f.SourceField) { foreach (var relatef in item.RelateFieldNm) { if (!relatefield && relatef.FromTableIndex != item.FromTableIndex) { continue; } col = new DataColumn(string.IsNullOrEmpty(relatef.AliasName) ? relatef.FieldNm : relatef.AliasName); col.Caption = relatef.DisplayNm; switch (relatef.FieldType) { case LibFieldType.Byte: col.DataType = typeof(byte); col.DefaultValue = 0; break; case LibFieldType.Date: col.DataType = typeof(Date); break; case LibFieldType.DateTime: col.DataType = typeof(DateTime); col.DefaultValue = DateTime.Now; break; case LibFieldType.Decimal: col.DataType = typeof(decimal); col.DefaultValue = 0; break; case LibFieldType.Interger: col.DataType = typeof(Int32); col.DefaultValue = 0; break; case LibFieldType.Long: col.DataType = typeof(long); col.DefaultValue = 0; break; case LibFieldType.String: case LibFieldType.Text: col.DataType = typeof(string); col.DefaultValue = string.Empty; break; } col.ExtendedProperties.Add(SysConstManage.ExtProp, new ColExtendedProperties { IsActive = false, IsRelate = true, MapPrimarykey = string.Empty, DataTypeLen = 0, Decimalpoint = 0, ObjectNm = relatef.ObjFieldName, FromDSID = item.FromDataSource, FromTableIndex = relatef.FromTableIndex, SourceFieldNm = f.Name, FieldNm = relatef.FieldNm, AliasName = relatef.AliasName }); dt.Columns.Add(col); } } } } #region 系统默认新增的一列行号 用于系统对行项 唯一标识,自增长。 col = new DataColumn(SysConstManage.sdp_rowid); col.DataType = typeof(int); col.AutoIncrement = true; col.AutoIncrementSeed = 1; col.ExtendedProperties.Add(SysConstManage.ExtProp, new ColExtendedProperties { IsActive = false, IsRelate = false }); dt.Columns.Add(col); #endregion #region 系统默认新增的一列 是否选中。 col = new DataColumn(SysConstManage.IsSelect); col.DataType = typeof(bool); col.DefaultValue = false; col.ExtendedProperties.Add(SysConstManage.ExtProp, new ColExtendedProperties { IsActive = false, IsRelate = false }); dt.Columns.Add(col); #endregion #region 系统日志列 col = new DataColumn(SysConstManage.Sdp_LogId); col.DataType = typeof(string); col.DefaultValue = string.Empty; col.ExtendedProperties.Add(SysConstManage.ExtProp, new ColExtendedProperties { IsActive = true, IsRelate = false, DataTypeLen = 50 }); dt.Columns.Add(col); #endregion dt.PrimaryKey = primarykey.ToArray(); dt.ExtendedProperties.Add(SysConstManage.ExtProp, new TableExtendedProperties { TableIndex = tb.TableIndex, RelateTableIndex = tb.JoinTableIndex, Ignore = tb.Ignore }); return(dt); }
private void DataSourceControl_Load(object sender, EventArgs e) { _ds = ModelDesignProject.GetDataSourceById(_funNode.Name); //数据集节点 LibTreeNode dsNode = new LibTreeNode(); dsNode.Name = _funNode.Name; dsNode.Text = ReSourceManage.GetResource(NodeType.DefDataSet); dsNode.NodeType = NodeType.DefDataSet; if (_ds.DefTables == null) { _ds.DefTables = new LibCollection <LibDefineTable>(); //自定义表节点 #region LibTreeNode defTBNode = new LibTreeNode(); defTBNode.NodeId = Guid.NewGuid().ToString(); defTBNode.Name = string.Format("{0}", _funNode.Name); defTBNode.Text = string.Format("{0}({1})", _funNode.Text, defTBNode.Name); defTBNode.NodeType = NodeType.DefindTable; dsNode.Nodes.Add(defTBNode); //this._defTBPropertylst = new List<DefTBProperty>(); DefTBProperty deftbp = new DefTBProperty(defTBNode.NodeId); deftbp.Dock = DockStyle.Fill; this._defTBPropertylst.Add(deftbp); this.splitContainer1.Panel2.Controls.Add(deftbp); LibDefineTable definetb = new LibDefineTable(); definetb.ID = defTBNode.NodeId; definetb.TableName = defTBNode.Name; definetb.DisplayName = defTBNode.Text; _ds.DefTables.Add(definetb); deftbp.SetPropertyValue(definetb, defTBNode); #endregion //数据结构表 #region LibTreeNode tablestruc = new LibTreeNode(); tablestruc.NodeId = Guid.NewGuid().ToString(); tablestruc.Name = string.Format("{0}", _funNode.Name); tablestruc.Text = string.Format("{0}-{1}", "数据表", _funNode.Name); tablestruc.NodeType = NodeType.TableStruct; defTBNode.Nodes.Add(tablestruc); //this._tbStructPropertylst = new List<TBStructProperty>(); TBStructProperty tbstructP = new TBStructProperty(tablestruc.NodeId); tbstructP.Dock = DockStyle.Fill; this._tbStructPropertylst.Add(tbstructP); this.splitContainer1.Panel2.Controls.Add(tbstructP); LibDataTableStruct tbstruct = new LibDataTableStruct(); tbstruct.ID = tablestruc.NodeId; tbstruct.Name = tablestruc.Name; tbstruct.DisplayName = tablestruc.Text; definetb.TableStruct = new LibCollection <LibDataTableStruct>(); definetb.TableStruct.Add(tbstruct); tbstructP.SetPropertyValue(tbstruct, tablestruc); #endregion } else { LibTreeNode node = null; LibTreeNode dtstructNode = null; LibTreeNode fieldNode = null; foreach (LibDefineTable item in _ds.DefTables) { node = new LibTreeNode(); node.NodeId = item.ID; node.Name = item.TableName; node.Text = string.Format("{0}({1})", item.DisplayName, item.TableName); node.NodeType = NodeType.DefindTable; dsNode.Nodes.Add(node); if (item.TableStruct != null) { foreach (LibDataTableStruct dtstruct in item.TableStruct) { #region 添加表结构节点 dtstructNode = new LibTreeNode(); dtstructNode.NodeId = dtstruct.ID; dtstructNode.Name = dtstruct.Name; dtstructNode.Text = string.Format("{0}-{1}", "数据表", dtstruct.Name); dtstructNode.NodeType = NodeType.TableStruct; node.Nodes.Add(dtstructNode); #endregion if (dtstruct.Fields != null) { foreach (LibField field in dtstruct.Fields) { #region 添加字段节点 fieldNode = new LibTreeNode(); fieldNode.NodeId = field.ID; fieldNode.Name = field.Name; fieldNode.Text = string.Format("{0}({1})", field.Name, field.DisplayName); fieldNode.NodeType = NodeType.Field; dtstructNode.Nodes.Add(fieldNode); #endregion } } } } } } this.treeView1.Nodes.Add(dsNode); this.treeView1.SelectedNode = dsNode; }
private void DoCreateField(string fieldnm, string displaynm, LibSysField sysfd, LibTreeNode currentNode, LibDataTableStruct currentTBStruct) { LibTreeNode fieldNode = new LibTreeNode(); fieldNode.NodeId = Guid.NewGuid().ToString(); fieldNode.Name = sysfd != null ? sysfd.Name : fieldnm; fieldNode.Text = sysfd != null ? sysfd.DisplayName : displaynm; fieldNode.NodeType = NodeType.Field; currentNode.Nodes.Add(fieldNode); DefFieldProperty fieldP = new DefFieldProperty(fieldNode.NodeId); fieldP.Dock = DockStyle.Fill; this._fieldPropertylst.Add(fieldP); this.splitContainer1.Panel2.Controls.Add(fieldP); LibField field = new LibField(); field.ID = fieldNode.NodeId; field.Name = fieldNode.Name; field.DisplayName = fieldNode.Text; if (sysfd != null) { field.FieldType = sysfd.FieldType; field.FieldLength = sysfd.FieldLength; } else { field.FieldType = LibFieldType.String; field.FieldLength = 50; } field.IsActive = true; field.AllowNull = true; field.SysField = sysfd != null; currentTBStruct.Fields.Add(field); fieldP.SetPropertyValue(field, fieldNode); }
/// <summary> 表结构节点上的右键菜单</summary> /// <param name="sender"></param> /// <param name="e"></param> private void contextMenuStrip3_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { LibTreeNode curentNode = (LibTreeNode)this.treeView1.SelectedNode; LibDefineTable defineTB = _ds.DefTables.FindFirst("ID", ((LibTreeNode)curentNode.Parent).NodeId); LibDataTableStruct currentTBStruct = defineTB.TableStruct.FindFirst("ID", curentNode.NodeId); if (currentTBStruct.Fields == null) { currentTBStruct.Fields = new LibCollection <LibField>(); } switch (e.ClickedItem.Name) { case "CreateField": //新建字段 #region //LibTreeNode fieldNode = new LibTreeNode(); //fieldNode.NodeId = Guid.NewGuid().ToString(); //fieldNode.Name = string.Format("{0}_Field{1}", currentTBStruct.Name, currentTBStruct.Fields.Count + 1); //fieldNode.Text = fieldNode.Name; //fieldNode.NodeType = NodeType.Field; //curentNode.Nodes.Add(fieldNode); //DefFieldProperty fieldP = new DefFieldProperty(fieldNode.NodeId); //fieldP.Dock = DockStyle.Fill; //this._fieldPropertylst.Add(fieldP); //this.splitContainer1.Panel2.Controls.Add(fieldP); //LibField field = new LibField(); //field.ID = fieldNode.NodeId; //field.Name = fieldNode.Name; //field.DisplayName = fieldNode.Text; //currentTBStruct.Fields.Add(field); //fieldP.SetPropertyValue(field, fieldNode); string fieldnm = string.Format("Field{0}", currentTBStruct.Fields.Count + 1); DoCreateField(fieldnm, fieldnm, null, curentNode, currentTBStruct); UpdateTabPageText(); break; #endregion case "CreatesysFields": //添加系统字段 Panel p = new Panel(); p.Dock = DockStyle.Fill; p.Name = "pfieldcollection"; p.AutoScroll = true; ListBox listBox = new ListBox(); listBox.Dock = DockStyle.Fill; listBox.SelectionMode = SelectionMode.MultiExtended; p.Controls.Add(listBox); foreach (LibSysField sysfld in ModelManager.Sysfields) { listBox.Items.Add(sysfld); } FieldCollectionForm fielsform = new FieldCollectionForm(p); DialogResult dialog = fielsform.ShowDialog(this); if (dialog == DialogResult.OK) { foreach (LibSysField item in listBox.SelectedItems) { DoCreateField(string.Empty, string.Empty, item, curentNode, currentTBStruct); } UpdateTabPageText(); } break; } }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { LibTreeNode libnode = (LibTreeNode)e.Node; if (libnode == null) { return; } bool exists = false; switch (libnode.NodeType) { case NodeType.DefDataSet: if (this._dsProperty == null) { _dsProperty = new DataSourceProperty(); this.splitContainer1.Panel2.Controls.Add(_dsProperty); } SetPanel2ControlsVisible(_dsProperty); _ds.DataSourceName = string.IsNullOrEmpty(_ds.DataSourceName) ? _funNode.Text : _ds.DataSourceName; _ds.Package = string.IsNullOrEmpty(_ds.Package) ? _funNode.Package : _ds.Package; _dsProperty.SetPropertyValue(_ds, libnode); break; case NodeType.DefindTable: if (this._defTBPropertylst != null) { foreach (DefTBProperty item in _defTBPropertylst) { if (string.Compare(item.Name, libnode.NodeId) == 0) { SetPanel2ControlsVisible(item); exists = true; break; } } if (!exists) //还未创建对应的控件 { DefTBProperty deftbp = new DefTBProperty(libnode.NodeId); deftbp.Dock = DockStyle.Fill; this._defTBPropertylst.Add(deftbp); this.splitContainer1.Panel2.Controls.Add(deftbp); deftbp.SetPropertyValue(_ds.DefTables.FindFirst("ID", libnode.NodeId), libnode); SetPanel2ControlsVisible(deftbp); } } break; case NodeType.TableStruct: if (this._tbStructPropertylst != null) { foreach (TBStructProperty item in _tbStructPropertylst) { if (string.Compare(item.Name, libnode.NodeId) == 0) { SetPanel2ControlsVisible(item); exists = true; break; } } if (!exists) //还未创建对应的控件 { TBStructProperty tbstrucp = new TBStructProperty(libnode.NodeId); tbstrucp.Dock = DockStyle.Fill; this._tbStructPropertylst.Add(tbstrucp); this.splitContainer1.Panel2.Controls.Add(tbstrucp); LibDefineTable deftb = _ds.DefTables.FindFirst("ID", ((LibTreeNode)libnode.Parent).NodeId); tbstrucp.SetPropertyValue(deftb.TableStruct.FindFirst("ID", libnode.NodeId), libnode); SetPanel2ControlsVisible(tbstrucp); } } break; case NodeType.Field: if (this._fieldPropertylst != null) { foreach (DefFieldProperty item in _fieldPropertylst) { if (string.Compare(item.Name, libnode.NodeId) == 0) { SetPanel2ControlsVisible(item); exists = true; break; } } if (!exists) //还未创建对应的控件 { DefFieldProperty fieldp = new DefFieldProperty(libnode.NodeId); fieldp.Dock = DockStyle.Fill; this._fieldPropertylst.Add(fieldp); this.splitContainer1.Panel2.Controls.Add(fieldp); LibDefineTable deftb = _ds.DefTables.FindFirst("ID", ((LibTreeNode)libnode.Parent.Parent).NodeId); LibDataTableStruct dtstruct = deftb.TableStruct.FindFirst("ID", ((LibTreeNode)libnode.Parent).NodeId); fieldp.SetPropertyValue(dtstruct.Fields.FindFirst("ID", libnode.NodeId), libnode); SetPanel2ControlsVisible(fieldp); } } break; } }
public override void TextAndBotton_Click(object sender, EventArgs e) { Control ctl = sender as Control; string ctrNm = ctl.Name.Replace(SysConstManage.BtnCtrlNmPrefix, ""); Panel p = new Panel(); p.Dock = DockStyle.Fill; p.Name = "pfieldcollection"; p.AutoScroll = true; ListBox listBox = new ListBox(); listBox.Dock = DockStyle.Fill; p.Controls.Add(listBox); if (string.Compare(ctrNm, "fsfield_FromDataSource") == 0)//来源数据源 { string[] dsarray = ModelManager.GetAllDataSourceNm(string.Empty); if (dsarray != null && dsarray.Length > 0) { foreach (string item in dsarray) { listBox.Items.Add(item); } } FieldCollectionForm fielsform = new FieldCollectionForm(p); DialogResult dialog = fielsform.ShowDialog(this); if (dialog == DialogResult.OK) { if (this.Controls[ctrNm].Text.Trim() != listBox.SelectedItem.ToString()) { foreach (Control c in this.Controls) { if (c.GetType().Equals(typeof(TextBox))) { c.Text = string.Empty; } } this.Controls[ctrNm].Text = listBox.SelectedItem.ToString(); this.entity.FromDataSource = listBox.SelectedItem.ToString(); //this.Controls["fsfield_FromDefindTableNm"].Text = string.Empty; //this.Controls["fsfield_FromStructTableNm"].Text = string.Empty; //this.Controls["fsfield_FromFieldNm"].Text = string.Empty; } } } else if (string.Compare(ctrNm, "fsfield_FromDefindTableNm") == 0)//来源自定义表名 { if (!string.IsNullOrEmpty(this.Controls["fsfield_FromDataSource"].Text)) { this._ds = ModelManager.GetDataSource(this.Controls["fsfield_FromDataSource"].Text); if (this._ds != null && this._ds.DefTables != null) { foreach (LibDefineTable deftb in this._ds.DefTables) { listBox.Items.Add(deftb.TableName); } } } FieldCollectionForm fielsform = new FieldCollectionForm(p); DialogResult dialog = fielsform.ShowDialog(this); if (dialog == DialogResult.OK) { this.Controls[ctrNm].Text = listBox.SelectedItem.ToString(); this.entity.FromDefindTableNm = listBox.SelectedItem.ToString(); } } else if (string.Compare(ctrNm, "fsfield_FromStructTableNm") == 0)//来源数据表名 { if (!string.IsNullOrEmpty(this.Controls["fsfield_FromDefindTableNm"].Text)) { if (_ds == null) { _ds = ModelManager.GetDataSource(this.Controls["fsfield_FromDataSource"].Text); } LibDefineTable deftb = this._ds.DefTables.FindFirst("TableName", this.Controls["fsfield_FromDefindTableNm"].Text.Trim()); if (deftb != null) { foreach (LibDataTableStruct dt in deftb.TableStruct) { listBox.Items.Add(dt.Name); } } } FieldCollectionForm fielsform = new FieldCollectionForm(p); DialogResult dialog = fielsform.ShowDialog(this); if (dialog == DialogResult.OK) { this.Controls[ctrNm].Text = listBox.SelectedItem.ToString(); this.entity.FromStructTableNm = listBox.SelectedItem.ToString(); //foreach (LibDataTableStruct item in ) } } else if (string.Compare(ctrNm, "fsfield_FromFieldNm") == 0 || string.Compare(ctrNm, "fsfield_FromFieldDesc") == 0)//来源字段 { if (!string.IsNullOrEmpty(this.Controls["fsfield_FromStructTableNm"].Text)) { if (_ds == null) { _ds = ModelManager.GetDataSource(this.Controls["fsfield_FromDataSource"].Text); } LibDefineTable deftb = this._ds.DefTables.FindFirst("TableName", this.Controls["fsfield_FromDefindTableNm"].Text.Trim()); LibDataTableStruct dtstruct = deftb.TableStruct.FindFirst("Name", this.Controls["fsfield_FromStructTableNm"].Text.Trim()); if (dtstruct != null) { foreach (LibField f in dtstruct.Fields) { listBox.Items.Add(f.Name); } } } FieldCollectionForm fielsform = new FieldCollectionForm(p); DialogResult dialog = fielsform.ShowDialog(this); if (dialog == DialogResult.OK) { this.Controls[ctrNm].Text = listBox.SelectedItem.ToString(); if (string.Compare(ctrNm, "fsfield_FromFieldNm") == 0) { this.entity.FromFieldNm = listBox.SelectedItem.ToString(); } else { this.entity.FromFieldDesc = listBox.SelectedItem.ToString(); } } } else if (string.Compare(ctrNm, "fsfield_RelateFieldNm") == 0)//关联字段 { Panel p2 = new Panel(); p2.AutoScroll = true; LibDataTableStruct dtstruct = null; List <LibDataTableStruct> list = new List <LibDataTableStruct>(); //List<LibField> fields = new List<LibField>(); if (!string.IsNullOrEmpty(this.Controls["fsfield_FromStructTableNm"].Text)) { if (_ds == null) { _ds = ModelManager.GetDataSource(this.Controls["fsfield_FromDataSource"].Text); } List <int> indexs = null; foreach (LibDefineTable def in _ds.DefTables) { if (def.TableStruct == null) { continue; } list.AddRange(def.TableStruct.ToArray()); } LibDefineTable deftb = this._ds.DefTables.FindFirst("TableName", this.Controls["fsfield_FromDefindTableNm"].Text.Trim()); dtstruct = deftb.TableStruct.FindFirst("Name", this.Controls["fsfield_FromStructTableNm"].Text.Trim()); if (dtstruct != null) { listBox.SelectionMode = SelectionMode.MultiExtended; foreach (LibField f in dtstruct.Fields) { if (this.entity.RelateFieldNm == null || (this.entity.RelateFieldNm != null && this.entity.RelateFieldNm.FirstOrDefault(i => i.FromTableIndex == dtstruct.TableIndex && i.FieldNm == f.Name) == null)) { listBox.Items.Add(string.Format("{0}{2}{1}", dtstruct.Name, f.Name, SysConstManage.Point)); } } var relatetbs = list.Where(i => i.JoinTableIndex == dtstruct.TableIndex && i.TableIndex != dtstruct.TableIndex && i.Ignore).ToList(); while (relatetbs != null && relatetbs.Count > 0) { indexs = new List <int>(); foreach (LibDataTableStruct tb in relatetbs) { indexs.Add(tb.TableIndex); foreach (LibField f in tb.Fields) { if (this.entity.RelateFieldNm == null || (this.entity.RelateFieldNm != null && this.entity.RelateFieldNm.FirstOrDefault(i => i.FromTableIndex == tb.TableIndex && i.FieldNm == f.Name) == null)) { listBox.Items.Add(string.Format("{0}{2}{1}", tb.Name, f.Name, SysConstManage.Point)); } } } relatetbs = list.Where(i => indexs.Contains(i.JoinTableIndex) && i.TableIndex != i.JoinTableIndex && i.Ignore).ToList(); } } } if (this.entity.RelateFieldNm == null) { this.entity.RelateFieldNm = new List <LibRelateField>(); } RelateFieldControl relateFieldControl = new RelateFieldControl(listBox, list, this.entity.RelateFieldNm); relateFieldControl.Dock = DockStyle.Fill; p2.Controls.Add(relateFieldControl); DialogForm dialogForm = new DialogForm(p2); DialogResult dialog = dialogForm.ShowDialog(this); //FieldCollectionForm fielsform = new FieldCollectionForm(p); //DialogResult dialog = fielsform.ShowDialog(this); if (dialog == DialogResult.OK) { string text = string.Empty; SplitContainer ctr = relateFieldControl.Controls["splitContainer1"] as SplitContainer; foreach (Control c in ctr.Panel2.Controls) { RelateFieldProperty prop = c as RelateFieldProperty; prop.GetControlsValue(); } foreach (LibRelateField field in this.entity.RelateFieldNm) { if (text.Length > 0) { text += SysConstManage.Comma; } text += field.FieldNm; } //if (this.entity.RelateFieldNm == null) this.entity.RelateFieldNm = new List<LibRelateField>(); //this.entity.RelateFieldNm.Clear(); //LibRelateField relateField = null; //string text = string.Empty; //string tablenm = string.Empty; //string fldnm = string.Empty; //string[] array; //foreach (var item in listBox.SelectedItems) //{ // array = item.ToString().Split(SysConstManage.Point); // tablenm = array[0]; // LibDataTableStruct tableStruct = list.FirstOrDefault(i => i.Name == tablenm); // LibField field = tableStruct.Fields.FindFirst("Name", array[1]); // relateField = new LibRelateField(); // relateField.ID = Guid.NewGuid().ToString(); // relateField.FieldNm = field.Name; // relateField.DisplayNm = field.DisplayName; // relateField.AliasName = field.AliasName; // relateField.FieldType = field.FieldType; // relateField.FromTableIndex = tableStruct.TableIndex; // this.entity.RelateFieldNm.Add(relateField); // if (text.Length > 0) { text += SysConstManage.Comma; } // text += field.Name; //} this.Controls[ctrNm].Text = text; } } }