public FrmBatchCodeMaker(string longservername) { InitializeComponent(); dbset = DbConfig.GetSetting(longservername); dbobj = DBOMaker.CreateDbObj(dbset.DbType); dbobj.DbConnectStr = dbset.ConnectStr; this.lblServer.Text = dbset.Server; }
private void CreatDbObj(string servername) { var dbset = DbConfig.GetSetting(servername); //todo:这儿要尽量做到通用。 dbObject = DBOMaker.CreateDbObj(dbset.DbType); dbObject.DbConnectStr = dbset.ConnectStr; }
public void GenerateDataGridView() { if (this.CurrentDbViewForm == null) { MessageBox.Show("无可用对象!"); } dgvDefine.AutoGenerateColumns = false; #region 手动生成列(已注释) /* * DataGridViewTextBoxColumn colAttribute = new System.Windows.Forms.DataGridViewTextBoxColumn(); * colAttribute.DataPropertyName = "ColumnName"; * colAttribute.HeaderText = "属性名称"; * colAttribute.Name = "colAttribute"; * * DataGridViewComboBoxColumn colType = new System.Windows.Forms.DataGridViewComboBoxColumn(); * colAttribute.DataPropertyName = "TypeName"; * colAttribute.HeaderText = "类型"; * colAttribute.Name = "colType"; * * DataGridViewTextBoxColumn colTitle = new System.Windows.Forms.DataGridViewTextBoxColumn(); * colAttribute.DataPropertyName = "ColDescription"; * colAttribute.HeaderText = "标题"; * colAttribute.Name = "colTitle"; * * DataGridViewTextBoxColumn colDTColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); * colAttribute.DataPropertyName = "ColumnName"; * colAttribute.HeaderText = "列名"; * colAttribute.Name = "colDTColumnName"; * * DataGridViewComboBoxColumn colDTDataType = new System.Windows.Forms.DataGridViewComboBoxColumn(); * colAttribute.DataPropertyName = ""; * colAttribute.HeaderText = "数据类型"; * colAttribute.Name = "colDTDataType"; * * DataGridViewTextBoxColumn colDTDataLength = new System.Windows.Forms.DataGridViewTextBoxColumn(); * colAttribute.DataPropertyName = "Length"; * colAttribute.HeaderText = "长度"; * colAttribute.Name = "colDTDataLength"; * * DataGridViewTextBoxColumn colDTDataPreci = new System.Windows.Forms.DataGridViewTextBoxColumn(); * colAttribute.DataPropertyName = "Preci"; * colAttribute.HeaderText = "小数"; * colAttribute.Name = "colDTDataPreci"; * * DataGridViewCheckBoxColumn colDTDataNull = new System.Windows.Forms.DataGridViewCheckBoxColumn(); * colAttribute.DataPropertyName = "IsNull"; * colAttribute.HeaderText = "非空"; * colDTDataNull.Width = 45; * colAttribute.Name = "colDTDataNull"; * * DataGridViewCheckBoxColumn colDTDataPrimaryKey = new System.Windows.Forms.DataGridViewCheckBoxColumn(); * colAttribute.DataPropertyName = "IsPK"; * colAttribute.HeaderText = "主键"; * colDTDataNull.Width = 45; * colAttribute.Name = "colDTDataPrimaryKey"; * * DataGridViewCheckBoxColumn colDTDataIdentity = new System.Windows.Forms.DataGridViewCheckBoxColumn(); * colAttribute.DataPropertyName = "IsIdentity"; * colAttribute.HeaderText = "自增"; * colDTDataNull.Width = 45; * colAttribute.Name = "colDTDataIdentity"; * * DataGridViewTextBoxColumn colDTDataDefaultValue = new System.Windows.Forms.DataGridViewTextBoxColumn(); * colAttribute.DataPropertyName = "DefaultVal"; * colAttribute.HeaderText = "默认值"; * colAttribute.Name = "colDTDataDefaultValue"; * * this.dgvDefine.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] * { * colAttribute, colType, colTitle, colDTColumnName, colDTDataType, colDTDataLength, * colDTDataPreci, colDTDataNull, colDTDataPrimaryKey, colDTDataIdentity, colDTDataDefaultValue * }); */ #endregion var selectedNode = this.CurrentDbViewForm.treeView1.SelectedNode; if (selectedNode == null) { return; } this.ServerName = selectedNode.Parent.Parent.Parent.Text; this.DBName = selectedNode.Parent.Parent.Text; this.TableName = selectedNode.Text; txtName.Text = this.TableName; txtTableName.Text = this.TableName; dbSet = DbConfig.GetSetting(this.ServerName); var listDataTypeRefer = GetDataTypeRefer(); colType.ValueMember = "To"; colType.DisplayMember = "To"; colType.DataPropertyName = "To"; colType.DataSource = listDataTypeRefer; colDTDataType.ValueMember = "From"; colDTDataType.DisplayMember = "From"; colDTDataType.DataPropertyName = "From"; colDTDataType.DataSource = listDataTypeRefer; //todo:这儿要尽量做到通用。 idbObj = DBOMaker.CreateDbObj(dbSet.DbType); idbObj.DbConnectStr = dbSet.ConnectStr; var colList = idbObj.GetColumnInfoList(this.DBName, this.TableName); dgvDefine.DataSource = colList; }