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.Colorder; string columnName = col.ColumnName; string columnType = col.TypeName; string Length = col.Length; string Preci = col.Preci; string Scale = col.Scale; string defaultVal = col.DefaultVal; string description = col.DeText; string IsIdentity = (col.IsIdentity) ? "√" : ""; string ispk = (col.IsPK) ? "√" : ""; string isnull = (col.cisNull) ? "√" : ""; 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 BindlistViewCol1(string Dbname, string TableName) { List <ColumnInfo> collist = dbobj.GetColumnInfoList(Dbname, TableName); if ((collist != null) && (collist.Count > 0)) { this.listView1.Items.Clear(); cmbox_PField.Items.Clear(); foreach (ColumnInfo col in collist) { string order = col.Colorder; string columnName = col.ColumnName; string typename = col.TypeName; this.cmbox_PField.Items.Add(columnName); ListViewItem item1 = new ListViewItem(order, 0); item1.Checked = true; item1.ImageIndex = -1; item1.SubItems.Add(columnName); item1.SubItems.Add(typename); listView1.Items.AddRange(new ListViewItem[] { item1 }); } if (cmbox_PField.Items.Count > 0) { cmbox_PField.SelectedIndex = 0; } } 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.Colorder; string columnName = col.ColumnName; string columnType = col.TypeName; string Length = col.Length; if (columnType == "nvarchar") { Length = (int.Parse(Length) / 2).ToString(); } string Preci = col.Preci; string Scale = col.Scale; string defaultVal = col.DefaultVal; string description = col.DeText; string IsIdentity = (col.IsIdentity) ? "√" : ""; string ispk = (col.IsPK) ? "√" : ""; string isnull = (col.cisNull) ? "√" : ""; 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.Colorder; 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.Preci; string Scale = col.Scale; string defaultVal = col.DefaultVal; string description = col.DeText; string IsIdentity = (col.IsIdentity) ? "√" : ""; string ispk = (col.IsPK) ? "√" : ""; string isnull = (col.cisNull) ? "√" : ""; 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 }); } } }