Esempio n. 1
0
        /// <summary>
        /// 生成代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            List<ModelTable> listTables = getCheckedTableName();

            if (listTables.Count == 0)
            {
                MessageBox.Show("还未勾选任何表名");
                return;
            }

            Enumeration.DataBaseType Type = (Enumeration.DataBaseType)cbxDataBase.SelectedIndex;
            Generate gen = new Generate(Type);
            string dbName = "";
            if (Type == Enumeration.DataBaseType.Oracle)
            {
                dbName = new OracleConnection(OracleHelper.connectStr).Database;
            }
            if (Type == Enumeration.DataBaseType.MySQL)
            {
                dbName = new MySqlConnection(MySqlHelper.connectStr).Database;
            }
            if (Type == Enumeration.DataBaseType.MSSQL)
            {
                dbName = new SqlConnection(SqlHelper.connectStr).Database;
            }
            else
            {
            }

            gen.GenerateContext(listTables, dbName);
            //gen.GenerateModelEntities(listTables);
            foreach (ModelTable item in listTables)
            {
                gen.GenerateModel((Enumeration.DataBaseType)cbxDataBase.SelectedIndex, item.Table_Name, item.TabCamelName);
                gen.GenerateMapping((Enumeration.DataBaseType)cbxDataBase.SelectedIndex, item.Table_Name);
            }

            //MessageBox.Show("生成文件成功!");
            System.Diagnostics.Process.Start("explorer.exe ", gen.gGeneFile);
        }
Esempio n. 2
0
        /// <summary>
        /// 创建存放原名称和骆驼法名称对应关系的XML文件
        /// </summary>
        private void createCorrespondingXmlWhenNotExist()
        {
            Enumeration.DataBaseType type = (Enumeration.DataBaseType)cbxDataBase.SelectedIndex;
            Generate gen = new Generate(type);

            if (!File.Exists(gen.correspondingXmlPath))
            {
                DataTable dtTableName = new DataTable();
                dtTableName.Columns.Add("OriName");
                dtTableName.Columns.Add("Camel_Name");
                dtTableName.TableName = "dt";
                dtTableName.Rows.Add(new string[] { "1", "1" });
                dtTableName.WriteXml(gen.correspondingXmlPath);
            }
        }