private void btnGenerateCode_Click(object sender, EventArgs e) { Table table = new Table(); if (cboDatabase.SelectedValue == null) { MessageBox.Show("数据库未选择,未连接数据库?"); return; } string dbName = cboDatabase.SelectedValue.ToString(); CodeEntityDataReader entDataReader = new CodeEntityDataReader(GetConnStr(dbName)); table = lstTable.SelectedItem as Table; if (table == null) { MessageBox.Show("未选择要生成的数据表"); return; } string tableName = table.Name; List <Table> tableList = entDataReader.GetTables().ToList(); table = tableList.FirstOrDefault(m => m.Name == tableName); entDataReader.GetColumns(table); CodeEntityParameter entParam = GetEntityParameter(); CodeGenerator.Core.CodeGenerator code = new CodeGenerator.Core.CodeGenerator(); code.CreateCodeFile(table, entParam); MessageBox.Show("生成成功!"); }
void worker_DoWork(object sender, DoWorkEventArgs e) { if (worker != null && worker.CancellationPending != true) { CodeEntityParameter entParam = e.Argument as CodeEntityParameter; CodeGenerator.Core.CodeGenerator code = new CodeGenerator.Core.CodeGenerator(); CodeEntityDataReader entDataReader = new CodeEntityDataReader(GetConnStr(entParam.DataBaseName)); List<Table> list = new List<Table>(); foreach (var table in lstTable.Items) { list.Add(table as Table); } StartProgressDelegate startProgress = new StartProgressDelegate(StartProgress); //progressBar.Invoke(startProgress, new object[] { list.Count, 0, 1, 0 }); action3 = StartProgress; progressBar.Invoke(action3, new object[] { list.Count, 0, 1, 0 }); #region 用PLinq方式执行生成操作 //var pList = list.AsParallel<Table>(); //pList.ForAll((t) => { // entDataReader.ColumnList(t as Table); // code.CreateCodeFile(t as Table, entParam); // ShowProgressDelegate showProgress = new ShowProgressDelegate(ShowProgress); // progressBar.Invoke(showProgress); // ShowLabelDelegate showLable = new ShowLabelDelegate(ShowLabel); // lblMsg.Invoke(showLable, string.Format("正在处理数据表:{0}", t.Name)); //}); #endregion #region 传统方式foreach执行生成操作 //foreach (var table in list) //{ // entDataReader.ColumnList(table as Table); // code.CreateCodeFile(table as Table, entParam); // ShowProgressDelegate showProgress = new ShowProgressDelegate(ShowProgress); // progressBar.Invoke(showProgress); //} #endregion #region Parallel并行执行生成操作 Parallel.ForEach(list, (t) => { entDataReader.GetColumns(t as Table); code.CreateCodeFile(t as Table, entParam); #region 委托方式使用1 //ShowProgressDelegate showProgress = new ShowProgressDelegate(ShowProgress); //progressBar.Invoke(showProgress); //ShowLabelDelegate showLable = new ShowLabelDelegate(ShowLabel); //lblMsg.Invoke(showLable, string.Format("正在处理数据表:{0}", t.Name)); #endregion #region 委托方式使用2 action1 = ShowProgress; progressBar.Invoke(action1); action2 = ShowLabel; lblMsg.Invoke(action2, string.Format("正在处理数据表:{0}", t.Name)); #endregion }); #endregion } }
private void btnGenerateCode_Click(object sender, EventArgs e) { Table table = new Table(); if (cboDatabase.SelectedValue == null) { MessageBox.Show("数据库未选择,未连接数据库?"); return; } string dbName = cboDatabase.SelectedValue.ToString(); CodeEntityDataReader entDataReader = new CodeEntityDataReader(GetConnStr(dbName)); table = lstTable.SelectedItem as Table; if (table == null) { MessageBox.Show("未选择要生成的数据表"); return; } string tableName = table.Name; List<Table> tableList = entDataReader.GetTables().ToList(); table = tableList.FirstOrDefault(m => m.Name == tableName); entDataReader.GetColumns(table); CodeEntityParameter entParam = GetEntityParameter(); CodeGenerator.Core.CodeGenerator code = new CodeGenerator.Core.CodeGenerator(); code.CreateCodeFile(table, entParam); MessageBox.Show("生成成功!"); }
void worker_DoWork(object sender, DoWorkEventArgs e) { if (worker != null && worker.CancellationPending != true) { CodeEntityParameter entParam = e.Argument as CodeEntityParameter; CodeGenerator.Core.CodeGenerator code = new CodeGenerator.Core.CodeGenerator(); CodeEntityDataReader entDataReader = new CodeEntityDataReader(GetConnStr(entParam.DataBaseName)); List <Table> list = new List <Table>(); foreach (var table in lstTable.Items) { list.Add(table as Table); } StartProgressDelegate startProgress = new StartProgressDelegate(StartProgress); //progressBar.Invoke(startProgress, new object[] { list.Count, 0, 1, 0 }); action3 = StartProgress; progressBar.Invoke(action3, new object[] { list.Count, 0, 1, 0 }); #region 用PLinq方式执行生成操作 //var pList = list.AsParallel<Table>(); //pList.ForAll((t) => { // entDataReader.ColumnList(t as Table); // code.CreateCodeFile(t as Table, entParam); // ShowProgressDelegate showProgress = new ShowProgressDelegate(ShowProgress); // progressBar.Invoke(showProgress); // ShowLabelDelegate showLable = new ShowLabelDelegate(ShowLabel); // lblMsg.Invoke(showLable, string.Format("正在处理数据表:{0}", t.Name)); //}); #endregion #region 统方式foreach执行生成操作 //foreach (var table in list) //{ // entDataReader.ColumnList(table as Table); // code.CreateCodeFile(table as Table, entParam); // ShowProgressDelegate showProgress = new ShowProgressDelegate(ShowProgress); // progressBar.Invoke(showProgress); //} #endregion #region Parallel并行执行生成操作 Parallel.ForEach(list, (t) => { entDataReader.GetColumns(t as Table); code.CreateCodeFile(t as Table, entParam); #region 委托方式使用1 //ShowProgressDelegate showProgress = new ShowProgressDelegate(ShowProgress); //progressBar.Invoke(showProgress); //ShowLabelDelegate showLable = new ShowLabelDelegate(ShowLabel); //lblMsg.Invoke(showLable, string.Format("正在处理数据表:{0}", t.Name)); #endregion #region 委托方式使用2 action1 = ShowProgress; progressBar.Invoke(action1); action2 = ShowLabel; lblMsg.Invoke(action2, string.Format("正在处理数据表:{0}", t.Name)); #endregion }); #endregion } }