private void BindlistViewCol(string Dbname, string TableName) { List <ColumnInfo> collist = dbobj.GetColumnInfoList(Dbname, TableName); if ((collist != null) && (collist.Count > 0)) { listView1.Items.Clear(); list_KeyField.Items.Clear(); foreach (ColumnInfo col in collist) { string order = col.ColumnOrder; string columnName = col.ColumnName; string columnType = col.TypeName; string Length = col.Length; string Preci = col.Precision; string Scale = col.Scale; string defaultVal = col.DefaultVal; string description = col.Description; string IsIdentity = (col.IsIdentity) ? "√" : ""; string ispk = (col.IsPrimaryKey) ? "√" : ""; string isnull = (col.Nullable) ? "√" : ""; ListViewItem item1 = new ListViewItem(order, 0); item1.ImageIndex = 4; item1.SubItems.Add(columnName); item1.SubItems.Add(columnType); item1.SubItems.Add(Length); item1.SubItems.Add(Scale); item1.SubItems.Add(IsIdentity); if ((ispk == "√") && (isnull.Trim() == ""))//是主键,非空 { this.list_KeyField.Items.Add(columnName + "(" + columnType + ")"); } else { ispk = ""; } item1.SubItems.Add(ispk); item1.SubItems.Add(isnull); item1.SubItems.Add(defaultVal); listView1.Items.AddRange(new ListViewItem[] { item1 }); } } btn_SelAll_Click(null, null); //txtTabname.Text = TableName; //txtClassName.Text = TableName; }
private void BindlistViewCol(string Dbname, string TableName) { this.chk_CS_GetMaxID.Checked = true; List <ColumnInfo> collist = dbobj.GetColumnInfoList(Dbname, TableName); if ((collist != null) && (collist.Count > 0)) { listView1.Items.Clear(); list_KeyField.Items.Clear(); this.chk_CS_GetMaxID.Enabled = true; foreach (ColumnInfo col in collist) { string order = col.ColumnOrder; string columnName = col.ColumnName; string columnType = col.TypeName; string Length = col.Length; if (columnType == null) { Length = CodeCommon.GetDataTypeLenVal(columnType, Length); } if (dtCollection == null) { dtCollection = new Dictionary <string, int>(6) { { "char", 0 }, { "nchar", 1 }, { "binary", 2 }, { "varchar", 3 }, { "nvarchar", 4 }, { "varbinary", 5 } }; } int num; if (!dtCollection.TryGetValue(columnType, out num)) { Length = CodeCommon.GetDataTypeLenVal(columnType, Length); break; } switch (num) { case 0: case 1: case 2: Length = CodeCommon.GetDataTypeLenVal(columnType, Length); break; case 3: case 4: case 5: Length = CodeCommon.GetDataTypeLenVal(columnType.Trim().ToLower(), Length); break; default: Length = CodeCommon.GetDataTypeLenVal(columnType, Length); break; } string Preci = col.Precision; string Scale = col.Scale; string defaultVal = col.DefaultVal; string description = col.Description; string IsIdentity = (col.IsIdentity) ? "√" : ""; string ispk = (col.IsPrimaryKey) ? "√" : ""; string isnull = (col.Nullable) ? "√" : ""; ListViewItem item1 = new ListViewItem(order, 0); item1.ImageIndex = 4; item1.SubItems.Add(columnName); item1.SubItems.Add(columnType); item1.SubItems.Add(Length); item1.SubItems.Add(Scale); item1.SubItems.Add(IsIdentity); if ((ispk == "√") && (isnull.Trim() == ""))//是主键,非空 { this.list_KeyField.Items.Add(columnName); if (IsIdentity == "√") { this.chk_CS_GetMaxID.Checked = false; this.chk_CS_GetMaxID.Enabled = false; this.chk_DB_GetMaxID.Checked = false; this.chk_DB_GetMaxID.Enabled = false; //KeyIsIdentity = true; } } else { ispk = ""; if (IsIdentity == "√") { this.list_KeyField.Items.Add(columnName); this.chk_CS_GetMaxID.Checked = false; this.chk_CS_GetMaxID.Enabled = false; this.chk_DB_GetMaxID.Checked = false; this.chk_DB_GetMaxID.Enabled = false; //KeyIsIdentity = true; } } item1.SubItems.Add(ispk); item1.SubItems.Add(isnull); item1.SubItems.Add(defaultVal); listView1.Items.AddRange(new ListViewItem[] { item1 }); } } btn_SelAll_Click(null, null); txtTabname.Text = TableName; txtClassName.Text = TableName; lblkeycount.Text = list_KeyField.Items.Count.ToString() + "个主键"; }
private void BindlistViewCol(string Dbname, string TableName) { SetListViewMenu("colum"); //创建列表 this.listView1.Columns.Clear(); this.listView1.Items.Clear(); this.listView1.LargeImageList = imglistView; this.listView1.SmallImageList = imglistView; this.listView1.View = View.Details; this.listView1.GridLines = true; this.listView1.FullRowSelect = true; listView1.Columns.Add("序号", 60, HorizontalAlignment.Left); listView1.Columns.Add("列名", 110, HorizontalAlignment.Left); listView1.Columns.Add("数据类型", 80, HorizontalAlignment.Left); listView1.Columns.Add("长度", 40, HorizontalAlignment.Left); listView1.Columns.Add("小数", 40, HorizontalAlignment.Left); listView1.Columns.Add("标识", 40, HorizontalAlignment.Center); listView1.Columns.Add("主键", 40, HorizontalAlignment.Center); listView1.Columns.Add("允许空", 60, HorizontalAlignment.Center); listView1.Columns.Add("默认值", 100, HorizontalAlignment.Left); //listView1.Columns.Add("字段说明", 100, HorizontalAlignment.Left); List <ColumnInfo> collist = dbobj.GetColumnInfoList(Dbname, TableName); if ((collist != null) && (collist.Count > 0)) { foreach (ColumnInfo col in collist) { string order = col.ColumnOrder; string columnName = col.ColumnName; string columnType = col.TypeName; string Length = col.Length; switch (columnType) { case "varchar": case "nvarchar": case "char": case "nchar": case "varbinary": { Length = CodeCommon.GetDataTypeLenVal(columnType, Length); } break; default: break; } string Preci = col.Precision; string Scale = col.Scale; string defaultVal = col.DefaultVal; string description = col.Description; string IsIdentity = (col.IsIdentity) ? "√" : ""; string ispk = (col.IsPrimaryKey) ? "√" : ""; string isnull = (col.Nullable) ? "√" : ""; ListViewItem item1 = new ListViewItem(order, 0); item1.ImageIndex = 4; item1.SubItems.Add(columnName); item1.SubItems.Add(columnType); item1.SubItems.Add(Length); item1.SubItems.Add(Scale); item1.SubItems.Add(IsIdentity); if ((ispk == "√") && (isnull.Trim() == "")) { } else { ispk = ""; } item1.SubItems.Add(ispk); item1.SubItems.Add(isnull); item1.SubItems.Add(defaultVal); listView1.Items.AddRange(new ListViewItem[] { item1 }); } } }