Beispiel #1
0
        private void Generate_Click(object sender, EventArgs e)
        {
            if (Tables.SelectedRows.Count > 0)
            {
                Generate.Enabled = false;
                IDictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add("database", ConfigurationManager.ConnectionStrings["connectionString"].ProviderName);
                parameters.Add("namespace", this.Namespace.Text);
                parameters.Add("nullableType", this.NullableType.Checked ? "?" : "");
                IList <Table> tables = new List <Table>();
                foreach (DataGridViewRow row in this.Tables.SelectedRows)
                {
                    tables.Add((Table)row.DataBoundItem);
                }
                IGeneratorService generatorService = new GeneratorService();
                generatorService.ConnectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
                generatorService.TemplatePath     = Path.Combine(Application.StartupPath, string.Format(@"Templates\{0}", this.Version.SelectedItem));
                generatorService.OutputPath       = Path.Combine(Application.StartupPath, "Outputs");
                //生成之前清空outputs文件夹
                DeleteFolder(generatorService.OutputPath);

                generatorService.Generate(tables, parameters);
                MessageBox.Show("生成成功");
                Generate.Enabled = true;
            }
            else
            {
                MessageBox.Show("请选择数据表");
            }
        }
        public IActionResult Generate(Class @class)
        {
            if (!ModelState.IsValid)
            {
                return(Content("Недостаточно данных!"));
            }

            return(Content(_service.Generate(@class)));
        }