Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
        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("生成成功!");
        }