/// <summary> /// 初始化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BatchForm_Load(object sender, EventArgs e) { sysconfigModel = UtilsHelper.GetSysconfigModel(); txtNamaspace.Text = sysconfigModel.Namespace; var index = connectionModel.Name.IndexOf("["); if (index < 0) { index = connectionModel.Name.IndexOf("("); } llServer.Text = connectionModel.Name.Substring(0, index); llDatabaseName.Text = DatabaseName; txtPath.Text = sysconfigModel.BatchDirectoryPath; DataTable tablesDT = null; if (ConnectionModel.DbType.Equals(DatabaseType.MsAccess.ToString())) { dbObject = new WEF.DbDAL.OleDb.DbObject(ConnectionModel.ConnectionString); } else if (ConnectionModel.DbType.Equals(DatabaseType.SqlServer.ToString())) { dbObject = new WEF.DbDAL.SQL2000.DbObject(ConnectionModel.ConnectionString); } else if (ConnectionModel.DbType.Equals(DatabaseType.SqlServer9.ToString())) { dbObject = new WEF.DbDAL.SQL2005.DbObject(ConnectionModel.ConnectionString); } else if (ConnectionModel.DbType.Equals(DatabaseType.Oracle.ToString())) { dbObject = new WEF.DbDAL.Oracle.DbObject(ConnectionModel.ConnectionString); } else if (ConnectionModel.DbType.Equals(DatabaseType.Sqlite3.ToString())) { dbObject = new WEF.DbDAL.SQLite.DbObject(ConnectionModel.ConnectionString); } else if (ConnectionModel.DbType.Equals(DatabaseType.MySql.ToString())) { dbObject = new WEF.DbDAL.MySql.DbObject(ConnectionModel.ConnectionString); } tablesDT = dbObject.GetTables(DatabaseName); DataRow[] drs = tablesDT.Select("", "name asc"); if (null != drs && drs.Length > 0) { foreach (DataRow dr in drs) { lbleft.Items.Add(dr[0]); tableview.Add(dr[0].ToString(), false); } } }
private void cmbDB_SelectedIndexChanged(object sender, System.EventArgs e) { DbName = cmbDB.Text; List <string> tabNames = dbobj.GetTables(DbName); this.listTable1.Items.Clear(); this.listTable2.Items.Clear(); if (tabNames.Count > 0) { foreach (string tabname in tabNames) { listTable1.Items.Add(tabname); } } IsHasItem(); }
/// <summary> /// 初始化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BatchForm_Load(object sender, EventArgs e) { try { sysconfigModel = UtilsHelper.GetSysconfigModel(); txtNamaspace.Text = sysconfigModel.Namespace; var index = connectionModel.Name.IndexOf("["); if (index < 0) { index = connectionModel.Name.IndexOf("("); } llServer.Text = connectionModel.Name.Substring(0, index); llDatabaseName.Text = DatabaseName; txtPath.Text = sysconfigModel.BatchDirectoryPath; DataTable tablesDT = null; dbObject = DBObjectHelper.GetDBObject(ConnectionModel); tablesDT = dbObject.GetTables(DatabaseName); DataRow[] drs = tablesDT.Select("", "name asc"); if (null != drs && drs.Length > 0) { foreach (DataRow dr in drs) { lbleft.Items.Add(dr[0]); tableview.Add(dr[0].ToString(), false); } } } catch (Exception ex) { MessageBox.Show($""); this.Close(); } }
public FrmDbToScript(string longServerName) { InitializeComponent(); dsb = ObjHelper.CreatDsb(longServerName); dbobj = ObjHelper.CreatDbObj(longServerName); int s = longServerName.IndexOf("("); string server = longServerName.Substring(0, s); this.lblServer.Text = server; List <string> dblist = dbobj.GetTables(""); if (dblist != null) { if (dblist.Count > 0) { foreach (string dbName in dblist) { this.cmbDB.Items.Add(dbName); } } } //DataTable dt = dbobj.GetDBList(); //if (dt != null) //{ // foreach (DataRow row in dt.Rows) // { // string dbName = row["name"].ToString(); // this.cmbDB.Items.Add(dbName); // } //} this.btn_Creat.Enabled = false; if (cmbDB.Items.Count > 0) { this.cmbDB.SelectedIndex = 0; } }
private void FrmBatchCodeMaker_Shown(object sender, EventArgs e) { string mastedb = "master"; switch (dbobj.DbType) { case "SQL2000": case "SQL2005": case "SQL2008": mastedb = "master"; break; case "Oracle": case "OleDb": mastedb = dbset.DbName; break; case "MySQL": mastedb = "mysql"; break; } if ((dbset.DbName == "") || (dbset.DbName == mastedb)) { List <string> dblist = dbobj.GetDBList(); if (dblist != null) { if (dblist.Count > 0) { foreach (string dbname in dblist) { this.cboDBList.Items.Add(dbname); } } } } else { this.cboDBList.Items.Add(dbset.DbName); } if (this.cboDBList.Items.Count > 0) { this.cboDBList.SelectedIndex = 0; } else { List <string> tabNames = dbobj.GetTables(""); this.listTable1.Items.Clear(); this.listTable2.Items.Clear(); if (tabNames.Count > 0) { foreach (string tabname in tabNames) { listTable1.Items.Add(tabname); } } } this.btnExport.Enabled = false; SettingHelper setting = new SettingHelper(); setting.GetSetting(); txtTargetFolder.Text = setting.Output; txtNamespace.Text = setting.Project; txtCompanyName.Text = setting.Company; txtDeveloper.Text = setting.Author; txtCreateYear.Text = DateTime.Now.Year.ToString(); txtCreateDate.Text = DateTime.Now.ToString("yyyy-MM-dd"); }
public DataSourse GetData(string constr) { DataSourse dataSourse = new DataSourse(); string dbName = constr.Substring(0, constr.IndexOf(";")).Substring(constr.IndexOf("=") + 1); IDbObject dbObject = (IDbObject) new DataAccess(); dbObject.DbConnectStr = constr; List <string> tables = dbObject.GetTables(dbName); List <TableData> list1 = new List <TableData>(); List <Reference> list2 = new List <Reference>(); if (tables != null && tables.Count > 0) { foreach (string tableName in tables) { TableData tableData = new TableData(); tableData.Code = tableName; tableData.Name = tableName; tableData.Id = tableName; List <string> list3 = new List <string>(); DataTable columnInfoList = dbObject.GetColumnInfoList(dbName, tableName); List <Column> list4 = new List <Column>(); foreach (DataRow row in (InternalDataCollectionBase)columnInfoList.Rows) { Column column1 = new Column(); column1.Code = DataRowExtensions.Field <string>(row, 1).Trim(); column1.Comment = DataRowExtensions.Field <string>(row, 15).Trim(); column1.DataType = DataRowExtensions.Field <string>(row, 2).Trim(); column1.Displayed = "true"; Column column2 = column1; string str1 = tableName; int num = DataRowExtensions.Field <int>(row, 0); string str2 = num.ToString(); string str3 = str1 + str2; column2.Id = str3; Column column3 = column1; num = DataRowExtensions.Field <int>(row, 3); string str4 = num.ToString(); column3.Length = str4; column1.Mandatory = DataRowExtensions.Field <string>(row, 13).Trim() == "√" ? "" : "1"; column1.Name = DataRowExtensions.Field <string>(row, 1).Trim(); column1.TableCode = tableName; column1.TableId = tableData.Id; if (DataRowExtensions.Field <string>(row, 7).Trim() != "d") { list3.Add(column1.Id); } list4.Add(column1); } tableData.Columns = list4; if (list3.Count > 0) { tableData.PrimaryKey = new Key() { KeyId = Guid.NewGuid().ToString(), ColumnRef = list3.ToArray() } } ; list1.Add(tableData); } } if (list1 != null && list1.Count > 0) { foreach (TableData tableData in list1) { TableData tab = tableData; foreach (DataRow dataRow in (InternalDataCollectionBase)dbObject.GetTableRefrence(dbName, tab.Code).Rows) { DataRow item = dataRow; Reference r = new Reference(); r.ParentTable = Enumerable.SingleOrDefault <string>(Enumerable.Select <TableData, string>(Enumerable.Where <TableData>((IEnumerable <TableData>)list1, (Func <TableData, bool>)(t => t.Code == DataRowExtensions.Field <string>(item, 1).Trim())), (Func <TableData, string>)(t => t.Id))); r.ParentTableColumnRef = Enumerable.SingleOrDefault <string>(Enumerable.Select(Enumerable.Where(Enumerable.Where(Enumerable.SelectMany((IEnumerable <TableData>)list1, (Func <TableData, IEnumerable <Column> >)(t => (IEnumerable <Column>)t.Columns), (t, f) => { var fAnonymousType2 = new { t = t, f = f }; return(fAnonymousType2); }), param0 => param0.t.Id == r.ParentTable), param0 => param0.f.Code == DataRowExtensions.Field <string>(item, 2).Trim()), param0 => param0.f.Id)); r.Id = Guid.NewGuid().ToString(); r.ChildTable = tab.Id; r.ChildTableColumnRef = Enumerable.SingleOrDefault <string>(Enumerable.Select(Enumerable.Where(Enumerable.Where(Enumerable.SelectMany((IEnumerable <TableData>)list1, (Func <TableData, IEnumerable <Column> >)(t => (IEnumerable <Column>)t.Columns), (t, f) => { var fAnonymousType2 = new { t = t, f = f }; return(fAnonymousType2); }), param0 => param0.t.Id == tab.Id), param0 => param0.f.Code == DataRowExtensions.Field <string>(item, 0).Trim()), param0 => param0.f.Id)); list2.Add(r); } } } dataSourse.ListTable = list1; dataSourse.ListReference = list2; DataTable vieWs = dbObject.GetVIEWs(dbName); List <ViewData> list5 = new List <ViewData>(); if (vieWs != null && vieWs.Rows != null && vieWs.Rows.Count > 0) { foreach (DataRow row in (InternalDataCollectionBase)vieWs.Rows) { string str = DataRowExtensions.Field <string>(row, 0); if (!string.IsNullOrWhiteSpace(str)) { string objectViewInfo = dbObject.GetObjectViewInfo(dbName, str); DataTable dataTable = dbObject.QueryViewInfo(dbName, str); ViewData viewData = new ViewData(); viewData.Code = str; viewData.Name = str; viewData.Id = str; viewData.SQLQuery = objectViewInfo; List <Column> list3 = new List <Column>(); foreach (DataColumn dataColumn in (InternalDataCollectionBase)dataTable.Columns) { list3.Add(new Column() { Name = dataColumn.ColumnName, Code = dataColumn.ColumnName, Id = Guid.NewGuid().ToString() }); } viewData.Columns = list3; list5.Add(viewData); } } } dataSourse.ListView = list5; return(dataSourse); } }