public void Genetate(List <Grids> result) { try { Strings.Write(config, "config.xml"); dynamic res = ExcelHelper.LoadXml(); if (string.IsNullOrEmpty(res.en)) { return; } CreateFile(res.en); ExcelHelper helper = new ExcelHelper(); //result = helper.OpenExcel((int)res.count); dynamic foo = assemblyPage(res.en, result, res.datas); List <string> excels = foo.vs; //url string url = ""; //生成assembly Strings.Write(Strings.LoadJson("assembly.txt").Replace("NMSL", res.en), dir + "\\" + res.en + "\\Properties\\AssemblyInfo.cs"); for (int i = 0; i < result.Count; i++) { List <DataGrids> datas = res.datas; url += Strings.CreateGetallUrl_new(res.en, result[i], 1); switch (result[i].Identity) { case "主页": { Strings.Write(excels[i], dir + "\\" + res.en + "\\Views\\" + result[i].PageCode + ".xaml"); Strings.Write(Strings.GetIndexXamlCs(res.en), dir + "\\" + res.en + "\\Views\\" + result[i].PageCode + ".xaml.cs"); //没实现LoadData() Strings.Write(Strings.GetIndexVM_new(res.en, MyControls.GetDataGridBinding(datas.Take((int)foo.ids[i]).ToList()) + MyControls.CreateWord_new(result[i]) + Strings.CreateCommand_new(result[i], res.en), ""), dir + "\\" + res.en + "\\ViewModels\\" + result[i].PageCode + "VM.cs"); } break; case "新增": { Strings.Write(excels[i], dir + "\\" + res.en + "\\Views\\" + result[i].PageCode + ".xaml"); Strings.Write(Strings.GetAddPageXamlCs(res.en), dir + "\\" + res.en + "\\Views\\" + result[i].PageCode + ".xaml.cs"); Strings.Write(Strings.GetAddVM(res.en, MyControls.GetDataGridBinding(datas.Take((int)foo.ids[i]).ToList()) + MyControls.CreateWord_new(result[i]), "", "", "new") + Strings.CreateCommand_new(result[i], res.en), dir + "\\" + res.en + "\\ViewModels\\" + result[i].PageCode + "VM.cs"); url += Strings.CreateAddUrl(res.en); } break; case "编辑": { Strings.Write(excels[i], dir + "\\" + res.en + "\\Views\\" + result[i].PageCode + ".xaml"); Strings.Write(Strings.GetEditPageXamlCs(res.en), dir + "\\" + res.en + "\\Views\\" + result[i].PageCode + ".xaml.cs"); Strings.Write(Strings.GetEditVM(res.en, MyControls.GetDataGridBinding(datas.Take((int)foo.ids[i]).ToList()) + MyControls.CreateWord_new(result[i]), "", "", "", "new") + Strings.CreateCommand_new(result[i], res.en), dir + "\\" + res.en + "\\ViewModels\\" + result[i].PageCode + "VM.cs"); url += Strings.CreateEditUrl(res.en); } break; case "导入": { Strings.Write(excels[i], dir + "\\" + res.en + "\\Views\\" + result[i].PageCode + ".xaml"); Strings.Write(Strings.GetImportXamlCs(res.en), dir + "\\" + res.en + "\\Views\\" + result[i].PageCode + ".xaml.cs"); Strings.Write(Strings.GetImprotVM_new(res.en, result[i].grids, MyControls.GetDataGridBinding(datas.Take((int)foo.ids[i]).ToList()) + MyControls.CreateWord_new(result[i]) + Strings.CreateCommand_new(result[i], res.en), Import.CreateXss_new(result[i]), Import.CreateNull_new(result[i]), Import.CreateRepeat_new(result[i]), Import.CreateRepeatFunction_new(result[i]), Import.CheckImportData_new(result[i])), dir + "\\" + res.en + "\\ViewModels\\" + result[i].PageCode + "VM.cs"); url += Import.CreateImportUrl_new(res.en, result[i]); } break; default: { Strings.Write(excels[i], dir + "\\" + res.en + "\\Views\\" + result[i].PageCode + ".xaml"); Strings.Write(Strings.GetBoxesXamlCs(res.en, result[i].PageCode), dir + "\\" + res.en + "\\Views\\" + result[i].PageCode + ".xaml.cs"); Strings.Write(Strings.GetBoxesVM_new(res.en, result[i].PageCode, MyControls.GetDataGridBinding(datas.Take((int)foo.ids[i]).ToList()) + MyControls.CreateWord_new(result[i]) + Strings.CreateCommand_new(result[i], res.en)), dir + "\\" + res.en + "\\ViewModels\\" + result[i].PageCode + "VM.cs"); } break; } } string Include = Strings.GetInclude_new(result); string Complie = Strings.GetComplie_new(result); Strings.Write(Strings.GetCsproj_new(res.en, Complie, Include), dir + "\\" + res.en + "\\" + res.en + ".csproj"); Strings.Write(Strings.GetServices(res.en, url), dir + "\\" + res.en + "\\Services.cs"); //两个model Strings.Write(CreateClass.LoadModel_new(result, res.en), dir + "\\" + res.en + "\\Models\\Model.cs"); Strings.Write(CreateClass.LoadModel(res.en), dir + "\\" + res.en + "\\Models\\ComboxModel.cs"); //Resource文件 Strings.Write(Strings.GetResource(res.en, Resources.CreateResorce_new(Resources.AllRes_new(result)), "new"), dir + "\\" + res.en + "\\Resources\\Strings.zh-CN.xaml");//资源文件 } catch (Exception ex) { Warning warning = new Warning(ex.Message); warning.ShowDialog(); } }
/// <summary> /// /// </summary> /// <param name="csproj">项目名称</param> /// <param name="Model">模型</param> /// <param name="Extend">扩展内容</param> /// <returns></returns> private bool CreateProj(string csproj, string Model, string Extend = "") { try { #region if (String.IsNullOrEmpty(ProjectName)) { return(false); } string dir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); Directory.CreateDirectory(dir + "\\" + csproj); Directory.CreateDirectory(dir + "\\" + csproj + "\\Models"); Directory.CreateDirectory(dir + "\\" + csproj + "\\Properties"); Directory.CreateDirectory(dir + "\\" + csproj + "\\Resources"); Directory.CreateDirectory(dir + "\\" + csproj + "\\ViewModels"); Directory.CreateDirectory(dir + "\\" + csproj + "\\Views"); Strings.Write(Strings.GetAssembly(ProjectName), dir + "\\" + csproj + "\\Properties\\AssemblyInfo.cs"); //Write(Strings.resx, dir + "\\" + csproj + "\\Properties\\Resources.resx"); Strings.Write(CreateClass.LoadModel(IndexBodies, ProjectName), dir + "\\" + csproj + "\\Models\\Model.cs"); Strings.Write(CreateClass.LoadModel(ProjectName), dir + "\\" + csproj + "\\Models\\ComboxModel.cs"); Strings.Write(Strings.GetIndexPage(csproj, Buttons.CreateButton(Buttones), MyControls.CreateContents(IndexContents), MyControls.CreateDataGrid(IndexBodies)), dir + "\\" + csproj + "\\Views\\IndexPage.xaml"); //indexpage.xaml Strings.Write(Strings.GetIndexXamlCs(csproj), dir + "\\" + csproj + "\\Views\\IndexPage.xaml.cs"); //xaml.cs Strings.Write(Strings.GetIndexVM(csproj, MyControls.CreateWord(IndexContents) + CreateCommand(IndexContents, Buttones, boxes), Strings.CreateLoadData(IndexContents)), dir + "\\" + csproj + "\\ViewModels\\IndexPageVM.cs"); //indexVM string res = Strings.CreateGetallUrl(csproj, IndexContents, 1) + Strings.CreateDeleteUrl(csproj) + Strings.CreateUpdateUrl(csproj); string Include = ""; string Complie = ""; //Add if (AddChecked) { Strings.Write(Strings.GetAddPageXaml(csproj, MyControls.CreateAddContents(AddContents), "auto"), dir + "\\" + csproj + "\\Views\\Add.xaml"); //Add.xaml Strings.Write(Strings.GetAddPageXamlCs(csproj), dir + "\\" + csproj + "\\Views\\Add.xaml.cs"); //xaml.cs Strings.Write(Strings.GetAddVM(csproj, MyControls.CreateWord(AddContents) + CreateCommand(AddContents, new List <MyModel>() { }), Strings.PostData(AddContents), Strings.IsLegal(AddContents)), dir + "\\" + csproj + "\\ViewModels\\AddVM.cs"); //AddVM res += Strings.CreateAddUrl(csproj); Include += GetAddInclude; Complie += GetAddComplie; } if (EditChecked) { Strings.Write(Strings.GetEditPageXaml(csproj, MyControls.CreateAddContents(AddContents), "auto"), dir + "\\" + csproj + "\\Views\\Edit.xaml"); //Edit.xaml Strings.Write(Strings.GetEditPageXamlCs(csproj), dir + "\\" + csproj + "\\Views\\Edit.xaml.cs"); //xaml.cs Strings.Write(Strings.GetEditVM(csproj, MyControls.CreateWord(AddContents) + CreateCommand(AddContents, new List <MyModel>() { }), Strings.PostData(AddContents), Strings.IsLegal(AddContents), Strings.CreateEditLoadData(AddContents)), dir + "\\" + csproj + "\\ViewModels\\EditVM.cs"); //AddVM res += Strings.CreateEditUrl(csproj); Include += GetEditInclude; Complie += GetEditComplie; } //Import if (ImportChecked) { Strings.Write(Strings.GetImportXaml(csproj, MyControls.CreateDataGrid(ImportBidies)), dir + "\\" + csproj + "\\Views\\ImportPage.xaml"); //Import.xaml Strings.Write(Strings.GetImportXamlCs(csproj), dir + "\\" + csproj + "\\Views\\ImportPage.xaml.cs"); //xaml.cs Strings.Write(Strings.GetImprotVM(csproj, ImportBidies, Import.CreateXss(ImportBidies), Import.CreateNull(ImportBidies), Import.CreateRepeat(ImportBidies), Import.CreateRepeatFunction(ImportBidies), Import.CheckImportData(ImportBidies)), dir + "\\" + csproj + "\\ViewModels\\ImportPageVM.cs"); //ImportVM res += Import.CreateImportUrl(csproj, ImportBidies); Include += GetImportInclude; Complie += GetImportComplie; } if (boxes.Count > 0) { foreach (var ds in boxes) { Strings.Write(Strings.GetBoxesXaml(csproj, ds.BOX_CODE, MyControls.CreateDataGrid(ds.Body), ds.SEARCH_CODE), dir + "\\" + csproj + "\\Views\\" + ds.BOX_CODE + ".xaml"); //Add.xaml Strings.Write(Strings.GetBoxesXamlCs(csproj, ds.BOX_CODE), dir + "\\" + csproj + "\\Views\\" + ds.BOX_CODE + ".xaml.cs"); //xaml.cs Strings.Write(Strings.GetBoxesVM(csproj, ds.BOX_CODE, MyControls.CreateWord(ds.Body), Strings.CreateBoxUrl(csproj, ds.BOX_CODE, ds.SEARCH_CODE)), dir + "\\" + csproj + "\\ViewModels\\" + ds.BOX_CODE + "VM.cs"); //AddVM } Include += GetInclude(boxes); Complie += GetComplie(boxes); } Strings.Write(Strings.GetResource(ChineseName, Resources.CreateResorce(Resources.AllRes(IndexContents, IndexBodies, boxes))), dir + "\\" + csproj + "\\Resources\\Strings.zh-CN.xaml");//资源文件 Strings.Write(Strings.GetCsproj(csproj, Complie, Include), dir + "\\" + csproj + "\\" + csproj + ".csproj"); Strings.Write(Strings.GetServices(csproj, res), dir + "\\" + csproj + "\\Services.cs"); Domain = Strings.CreateGetallUrl(csproj, IndexContents).Replace("\r\n\t\t", ""); #endregion #region 生成后台 Directory.CreateDirectory(dir + "\\" + ServerName); Directory.CreateDirectory(dir + "\\" + ServerName + "\\Models"); Directory.CreateDirectory(dir + "\\" + ServerName + "\\Properties"); Directory.CreateDirectory(dir + "\\" + ServerName + "\\Domains"); Directory.CreateDirectory(dir + "\\" + ServerName + "\\Services"); var ls = ServerName.Split('.'); Strings.Write(Domains.GetAssembly(ServerName, ChineseName), dir + "\\" + ServerName + "\\Properties\\AssemblyInfo.cs"); Strings.Write(Domains.GetCsproj(ServerName, LoadTables()), dir + "\\" + ServerName + "\\" + ServerName + ".csproj"); Strings.Write(Domains.GetDomain(ServerName, Domains.GetAllUrlBody(IndexContents, 1), Domains.GetHasWordUrl(ImportBidies, 1), Domains.GetHasWrodFunction(ImportBidies), Domains.GetAllFunction(Tables, IndexContents)), dir + "\\" + ServerName + "\\Domains\\" + ls.Last() + "Domain.cs"); Strings.Write(Domains.GetService(ServerName, Domains.GetAllUrlHeader(ServerName, IndexContents), Domains.GetAllUrlBody(IndexContents, 1), Domains.GetAllUrlBody(IndexContents, 0), ChineseName, Domains.GetHasWordUrl(ImportBidies, 0), Domains.GetHasWordUrl(ImportBidies, 1), Domains.GetHasWordUrl(ImportBidies, 2)), dir + "\\" + ServerName + "\\Services\\" + ls.Last() + "Service.cs"); if (ModelChecked) { CreateDbModel(); } #endregion return(true); } catch (Exception) { return(false); } }