private void CreateColumInfoToWord(DbLoginFor _DbLoginFor, bool _isTable = true) { IFrameWorkDb _IFrameWorkDb = null; _IFrameWorkDb = FrameWorkDbFactory.CreateNewFrameWorkDb(_DbLoginFor.ConnString, _DbLoginFor.Db_Type); if (_IFrameWorkDb == null) { MsgBox.Warning("您选中的表或者视图节点数据类型存在问题,请前去确认......."); return; } List <DbTableInfo> _tableList = _IFrameWorkDb.GetTables();//获取所的表 Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); bool _isSqlite = _DbLoginFor.Db_Type == 1 ? true : false; if (_isTable)//生成表的数据字典 { CreateCellStyle(builder); for (int i = 0; i < _tableList.Count; i++) { CreateTitleCell(builder, _tableList[i].Name); List <ColumnInfo> _columList = _IFrameWorkDb.GetColumsFromTable(_tableList[i].Name); CreateCell(builder, _columList, _isSqlite); } } else//生成视图的数据字典 { //下面加载视图 List <DbTableInfo> _viewList = _IFrameWorkDb.GetViews();//获取所有的视图 CreateCellStyle(builder); for (int i = 0; i < _viewList.Count; i++) { CreateTitleCell(builder, _tableList[i].Name, 2); //获取视图的每列信息 List <ColumnInfo> _columList = _IFrameWorkDb.GetColumsFromView(_viewList[i].Name); CreateCell(builder, _columList, _isSqlite); } } string _name = DialogUnitity.DialogSaveWordFile(ConstKeyUnitity.CAPTIONTEXT); if (string.IsNullOrEmpty(_name)) { MsgBox.Warning("保存文件名不可以为空..."); return; } doc.Save(_name); MsgBox.Infor("数据字典导出完成...."); }
private void CreateCSFileOneByOne(DbLoginFor _DbLoginFor, CodeTemplet __CodeTemplet, string _FolderPath, int _tableType = 1) { //加载所有的表 IFrameWorkDb _IFrameWorkDb = null; List <DbTableInfo> _tableList = null; _IFrameWorkDb = FrameWorkDbFactory.CreateNewFrameWorkDb(_DbLoginFor.ConnString, _DbLoginFor.Db_Type); if (_IFrameWorkDb == null) { MsgBox.Warning("您配置的数据库节点存在问题....."); return; } if (_tableType == 1)//表 { //System.Diagnostics.Stopwatch _stp= System.Diagnostics.Stopwatch.StartNew(); //_stp.Start(); _tableList = _IFrameWorkDb.GetTables();//获取所的表 List <Task> _TaskList = new List <Task>(); for (int i = 0; i < _tableList.Count; i++) { _TaskList.Add(Task.Factory.StartNew(new Func <object, int>(it => { int val1 = (int)it; IFrameWorkDb _IFrameWorkDbTheard = null; _IFrameWorkDbTheard = FrameWorkDbFactory.CreateNewFrameWorkDb(_DbLoginFor.ConnString, _DbLoginFor.Db_Type); List <ColumnInfo> _columnList = _IFrameWorkDbTheard.GetColumsFromTable(_tableList[val1].Name); foreach (var item in _columnList) { if (CSDBDic.ContainsKey(item.TypeName.Trim().ToUpper())) { item.TypeName = CSDBDic[item.TypeName.ToUpper()]; } } string CodeString = CreareRazorString(__CodeTemplet.CTemplet_Context, _tableList[val1].Name, __CodeTemplet.CTemplet_NameSP, __CodeTemplet.CTemplet_DbType, _columnList); string _fileName = _FolderPath + @"\" + __CodeTemplet.CTemplet_CPrefix.Trim() + _tableList[val1].Name + ".cs"; FileUnitity.StringToNewFile(_fileName, CodeString, System.Text.Encoding.UTF8); return(1); }), i)); if (i % 5 == 0) { Task.WaitAll(_TaskList.ToArray()); } } //_stp.Stop(); MsgBox.Infor(_stp.ElapsedMilliseconds.ToString()); } else //视图 { _tableList = _IFrameWorkDb.GetViews();//获取所的视图 List <Task> _TaskList = new List <Task>(); for (int i = 0; i < _tableList.Count; i++) { _TaskList.Add(Task.Factory.StartNew(new Func <object, int>(it => { int val1 = (int)it; List <ColumnInfo> _columnList = _IFrameWorkDb.GetColumsFromView(_tableList[val1].Name); foreach (var item in _columnList) { if (CSDBDic.ContainsKey(item.TypeName.Trim().ToUpper())) { item.TypeName = CSDBDic[item.TypeName.ToUpper()]; } } string CodeString = CreareRazorString(__CodeTemplet.CTemplet_Context, _tableList[val1].Name, __CodeTemplet.CTemplet_NameSP, __CodeTemplet.CTemplet_DbType, _columnList); string _fileName = _FolderPath + @"\" + __CodeTemplet.CTemplet_CPrefix.Trim() + _tableList[val1].Name + ".cs"; FileUnitity.StringToNewFile(_fileName, CodeString, System.Text.Encoding.UTF8); return(1); }), i)); if (i % 5 == 0) { Task.WaitAll(_TaskList.ToArray()); } } } }
private void simpleButton1_Click(object sender, EventArgs e) { _CodeClassPref = string.Empty; _CodeClassName = string.Empty; DevExpress.XtraTreeList.Nodes.TreeListNode __TempNode = _CurrentSelectNode; if (this.comboBox1.SelectedIndex == 0) { MsgBox.Warning("请您先选中生成代码的模板......"); return; } //生成代码 if (string.IsNullOrEmpty(this.textBox2.Text.Trim())) { MsgBox.Warning("请您先选中表或者视图......"); return; } //1.0 获取选中的模板文件的内容 CodeTemplet __CodeTemplet = this.comboBox1.SelectedItem as CodeTemplet; if (null == __CodeTemplet) { MsgBox.Warning("您选中的模板有问题,请前去确认......."); return; } string compText = __CodeTemplet.CTemplet_Context; //数据库节点 DevExpress.XtraTreeList.Nodes.TreeListNode _rootNode = __TempNode.ParentNode.ParentNode; if (_rootNode == null) { MsgBox.Warning("您选中的表或者视图节点数据存在问题,请前去确认......."); return; } DbLoginFor __DbLoginFor = _rootNode.Tag as DbLoginFor; IFrameWorkDb _IFrameWorkDb = null; _IFrameWorkDb = FrameWorkDbFactory.CreateNewFrameWorkDb(__DbLoginFor.ConnString, __DbLoginFor.Db_Type); if (_IFrameWorkDb == null) { MsgBox.Warning("您选中的表或者视图节点数据类型存在问题,请前去确认......."); return; } string _ClassName = this.textBox2.Text.Trim(); string _TableName = this.textBox2.Text.Trim(); string _NameSpace = this.textBox1.Text.Trim(); string _SqlName = __CodeTemplet.CTemplet_DbType; _CodeClassPref = this.textBox3.Text.Trim(); _CodeClassName = this.textBox2.Text.Trim(); Task.Factory.StartNew(new Action(() => { string _tvstring = __TempNode.ParentNode.Tag as string; List <ColumnInfo> _ColumnInfoList = null; if (_tvstring.Trim() == "表") { _ColumnInfoList = _IFrameWorkDb.GetColumsFromTable(_TableName); } else if (_tvstring.Trim() == "视图") { _ColumnInfoList = _IFrameWorkDb.GetColumsFromView(_TableName); } foreach (var item in _ColumnInfoList) { if (CSDBDic.ContainsKey(item.TypeName.Trim().ToUpper())) { item.TypeName = CSDBDic[item.TypeName.ToUpper()]; } } //templateKey string _GenerdString = Engine.Razor.RunCompile(__CodeTemplet.CTemplet_Context, StringUnitity.GetNewGUID(), null, new { ClassName = _ClassName, //类名 TableName = _TableName, //表名 Columns = _ColumnInfoList, //表的列信息 NameSpace = _NameSpace, //命名空间 SqlName = _SqlName //数据库类型 }); this.Invoke(new MethodInvoker(() => { this.fastColoredTextBox1.Text = _GenerdString; })); })); }