示例#1
0
文件: Main.cs 项目: yuanrui/Examples
        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
            }
        }
示例#2
0
文件: Main.cs 项目: yuanrui/Examples
        private void cboDatabase_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(cboDatabase.Text) || cboDatabase.SelectedValue == null)
            {
                MessageBox.Show(string.Format("数据库未选择{0}未连接数据库? 请尝试连接数据库! ", Environment.NewLine));
                return;
            }

            string connStr = GetConnStr(cboDatabase.SelectedValue.ToString());
            CodeEntityDataReader entDataReader = new CodeEntityDataReader(connStr);
            var tableList = entDataReader.GetTables();
            dgvColumns.DataSource = null;

            lstTable.DisplayMember = "Name";
            lstTable.ValueMember = "Name";

            lstTable.Items.Clear();
            if (tableList != null && tableList.Any())
            {
                lstTable.Items.AddRange(tableList.ToArray());
            }
            else
            {
                return;
            }
        }
示例#3
0
文件: Main.cs 项目: yuanrui/Examples
        private void lstTable_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboDatabase.SelectedValue == null || string.IsNullOrWhiteSpace(cboDatabase.SelectedValue.ToString()))
            {
                MessageBox.Show("未选择数据!");
                return;
            }

            var table = lstTable.SelectedItem as Table;
            if (table == null)
            {
                return;
            }

            string dbName = cboDatabase.SelectedValue.ToString();

            var columnList = new CodeEntityDataReader(GetConnStr(dbName)).GetColumns(table);
            dgvColumns.DataSource = columnList;

            string className = table.Name;
            if (rbtnAddPrefix.Checked)
            {
                if (! table.Name.StartsWith(txtPrefix.Text))
                {
                    className = string.Format("{0}{1}", txtPrefix.Text, table.Name);
                }
            }
            else
            {
                if (rbtnRemovePrefix.Checked)
                {
                    if (table.Name.StartsWith(txtPrefix.Text))
                    {
                        className = table.Name.Remove(0, txtPrefix.Text.Count());
                    }
                }
            }

            if (chkSuffix.Checked)
            {
                className = string.Format("{0}{1}", className, txtSuffix.Text);
            }

            lblTable.Text = string.Format("注释:{2} 表名:{0} 实体类名:{1}", table.Name, className, table.Comment);
        }
示例#4
0
文件: Main.cs 项目: yuanrui/Examples
        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("生成成功!");
        }