private ISqlGen GetSQLProvider(string database) { var setting = ConfigurationManager.ConnectionStrings[database]; if (setting == null) { throw new Exception("数据库连接未在web.config中配置!"); } var SQLProvider = GenTables.GetGenProvider(setting.ProviderName); return(SQLProvider); }
public void Generate(string tableName) { this.CurrentTable = GenTables.GetTables(tableName, this.DbType, this.ConnectionString); var sModel = GenModel(); var sIDAL = GenIDAL(); var sDAL = GenDAL(); var sIBLL = GenIBLL(); var sBLL = GenBLL(); string sPathModel = OutputPath + "\\Model"; string sPathIDAL = OutputPath + "\\IDAL"; string sPathDAL = OutputPath + "\\DAL"; string sPathIBLL = OutputPath + "\\IBLL"; string sPathBLL = OutputPath + "\\BLL"; if (!Directory.Exists(sPathModel)) { Directory.CreateDirectory(sPathModel); } if (!Directory.Exists(sPathIDAL)) { Directory.CreateDirectory(sPathIDAL); } if (!Directory.Exists(sPathDAL)) { Directory.CreateDirectory(sPathDAL); } if (!Directory.Exists(sPathIBLL)) { Directory.CreateDirectory(sPathIBLL); } if (!Directory.Exists(sPathBLL)) { Directory.CreateDirectory(sPathBLL); } //输出到文件中 model CreateFile(String.Format("{0}\\{1}.cs", sPathModel, this.CurrentTable.TableName), sModel); //输出到文件中 idal CreateFile(String.Format("{0}\\IDAL_{1}.cs", sPathIDAL, this.CurrentTable.TableName), sIDAL); //输出到文件中 dal CreateFile(String.Format("{0}\\DAL_{1}.cs", sPathDAL, this.CurrentTable.TableName), sDAL); //输出到文件中 ibll CreateFile(String.Format("{0}\\IBLL_{1}.cs", sPathIBLL, this.CurrentTable.TableName), sIBLL); //输出到文件中 bll CreateFile(String.Format("{0}\\BLL_{1}.cs", sPathBLL, this.CurrentTable.TableName), sBLL); }
private void btnJoin_Click(object sender, RoutedEventArgs e) { var provider = this.cbDbType.SelectionBoxItem; if (provider == null || string.IsNullOrEmpty(provider.ToString())) { return; } lastProvider = provider.ToString(); lastConnection = this.txtConnString.Text.Trim(); this.btnJoin.IsEnabled = false; Task.Run(() => { try { _tables = GenTables.GetTables(this.lastProvider, this.lastConnection); } catch (Exception ex) { this.lableStatus.Dispatcher.Invoke(() => { this.lableStatus.Content = ex.Message; }); } finally { this.btnJoin.Dispatcher.Invoke(() => { this.btnJoin.IsEnabled = true; }); if (_tables != null) { this.tableTreeView.Dispatcher.Invoke(() => { this.tableTreeView.ItemsSource = _tables; }); } } }); }
/// <summary> /// 链接数据库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnConnect_Click(object sender, EventArgs e) { lastProvider = dbType.Text.Trim(); lastConnection = ConString.Text.Trim(); if (providers.IndexOf(lastProvider) < 0) { providers.Add(lastProvider); } if (connections.IndexOf(lastConnection) < 0) { connections.Add(lastConnection); } //var Tables = GenTables.GetTables(dbType.Text, ConString.Text); var Tables = GenTables.GetTables(dbType.Text); var ParentNode = new TreeNode { Text = RootNodeText, Tag = RootNodeTag }; foreach (var T in Tables) { var TN = new TreeNode { Text = T.TableName, Tag = T, ForeColor = Color.Blue }; foreach (var TS in T.TableSchemas) { var TN2 = new TreeNode { Text = string.Format("{0}[{1}]", TS.ColumnName, TS.SqlTypeName), Tag = TS }; TN.Nodes.Add(TN2); } ParentNode.Nodes.Add(TN); } this.TableTreeView.Nodes.Clear(); this.TableTreeView.Nodes.Add(ParentNode); this.TableTreeView.Nodes[0].Expand(); }