Exemplo n.º 1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            var dialog = new SaveFileDialog()
            {
                AddExtension     = true,
                RestoreDirectory = true,
                FileName         = DateTime.Now.ToString("yyyy-MM-dd-HH-mm")
            };

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string path = "";

            var aux = dialog.FileName.Split('\\');

            //create folder selected on the dialog
            DirectoryInfo di = new DirectoryInfo(dialog.FileName);

            if (di.Exists == false)
            {
                di.Create();
            }

            for (int i = 0; i < aux.Length; i++)
            {
                path += aux[i] + "\\";
            }

            foreach (Model m in Program.project.Models)
            {
                if (chkTable.Checked)
                {
                    TableGenerator.Generate(m, path);
                }
                if (chkModel.Checked)
                {
                    ModelGenerator.Generate(m, path);
                }
                if (chkAPI.Checked)
                {
                    APIControllerGenerator.Generate(m, path);
                }
                if (chkDAL.Checked)
                {
                    RepositoryGenerator.Generate(m, path);
                }
                if (chkService.Checked)
                {
                    ServiceGenerator.Generate(m, path);
                }
                if (chkTsModel.Checked)
                {
                    ModelTsGenerator.Generate(m, path);
                }
            }

            foreach (var c in Program.project.Controllers)
            {
                if (chkTsService.Checked)
                {
                    ServiceTsGenerator.Generate(c);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 点击“批量生成按钮” =》 批量生成 Model、DAL、数据库结构表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void generate_button_Click(object sender, EventArgs e)
        {
            //1. 判断是否选择了表
            if (Right_listBox.Items.Count <= 0)
            {
                MessageBox.Show("请选择要生成的表!");
                return;
            }

            //2. 判断要生成的路径是否为空
            string outputPath = path_textBox.Text.Trim();

            if (outputPath.ToString() == "")
            {
                //如果是空值,则给一个默认路径
                outputPath        = "\\\\Mac\\Home\\Desktop";
                path_textBox.Text = outputPath;
            }

            //3. 判断要生成的路径是否存在
            if (!Directory.Exists(outputPath))
            {
                try
                {
                    //如果路径不存在,则自动生成路径
                    Directory.CreateDirectory(outputPath);
                }
                catch (Exception)
                {
                    //出错
                    MessageBox.Show("路径不存在!请选择正确的生成目录!");
                    return;
                }
            }

            //4. 判断命名空间是否为空
            if (namespace_textBox.Text.Trim().ToString() == "")
            {
                MessageBox.Show("请输入命名空间!");
                return;
            }

            //5. 获取基本信息
            string connStr     = getConnstr();
            string tablePrefix = table_prefix_textBox.Text.Trim();
            string author      = author_textBox.Text.Trim();
            string ns          = namespace_textBox.Text.Trim();
            string dbName      = DB_name_textBox.Text.Trim();

            //6. 生成 Model
            ModelGenerator.GenerateModel(ns, author, outputPath, tablePrefix, connStr, Right_listBox.Items);
            //7. 生成 DAL
            DalGenerator.GenerateDAL(ns, author, outputPath, tablePrefix, connStr, Right_listBox.Items);
            //8. 生成数据库操作助手类
            MSSQLHelperGenerator.GenerateMSSQLHelper(ns, outputPath, connStr);
            //9. 生成 数据库文档
            SqlFileGenerator.GenerateSqlFile(outputPath, connStr, listRight, dbName);


            //10. 告知生成成功
            string successMsg = "恭喜你!生成成功!";

            MessageBox.Show(successMsg);

            //11. 打开生成后的目录
            System.Diagnostics.Process.Start(outputPath);
        }