public void SetHtmlSql(IUseCase aUseCase) { // 获取解决方案所在路径 // ServiceProvider sp = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte); DTE dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE; DTE2 dte2 = (DTE2)dte; if (dte == null) { return; } string solutionName = dte.Solution.FileName; Solution sln = dte.Solution; string solutionPath = Path.GetDirectoryName(solutionName); string solutionName2 = Path.GetFileNameWithoutExtension(solutionName); string projectName = Path.GetFileNameWithoutExtension(solutionName); string sqlpath = solutionPath + "\\" + projectName + "\\App_Data\\SqlCode\\"; string htmlpath = solutionPath + "\\" + projectName + "\\Job\\"; string tablename = string.Empty; string nodeSqlpath = string.Empty; string nodeHtmlpath = string.Empty; string titleName = aUseCase.Name; bool bJson = false; bool bCloseBtn = false; bool bDetailList = false; // 弹出对话框,设置html页面以及 对应sql文件 IEnumerable <IReference> refer = aUseCase.GetReferences("tablename"); if (refer.Count() > 0) { string value = refer.First().Value; tablename = value; } else { SetValue(aUseCase, sqlpath, htmlpath, ref tablename, ref nodeSqlpath, ref nodeHtmlpath, ref bJson, ref bCloseBtn, ref bDetailList); } IEnumerable <IReference> refer1 = aUseCase.GetReferences("sql.path"); if (refer1.Count() > 0) { string value = refer1.First().Value; nodeSqlpath = value; } else { SetValue(aUseCase, sqlpath, htmlpath, ref tablename, ref nodeSqlpath, ref nodeHtmlpath, ref bJson, ref bCloseBtn, ref bDetailList); } refer1 = aUseCase.GetReferences("html.path"); if (refer1.Count() > 0) { string value = refer1.First().Value; nodeHtmlpath = value; } else { SetValue(aUseCase, sqlpath, htmlpath, ref tablename, ref nodeSqlpath, ref nodeHtmlpath, ref bJson, ref bCloseBtn, ref bDetailList); } string originalSqlpath = nodeSqlpath; string originalHtmlpath = nodeHtmlpath; //if (AppSetting.GetAppConfig("bShowDlg") != "1") // AppSetting.UpdateAppConfig("bShowDlg", "1"); //else // AppSetting.UpdateAppConfig("bShowDlg", "0"); if (AppSetting.GetAppConfig("bShowDlg") == "1") { SetValue(aUseCase, sqlpath, htmlpath, ref tablename, ref nodeSqlpath, ref nodeHtmlpath, ref bJson, ref bCloseBtn, ref bDetailList); } if (originalSqlpath != nodeSqlpath) { bool bok = EnvDTEHelper.MoveFile(dte, projectName, originalSqlpath, nodeSqlpath); bok = EnvDTEHelper.MoveFile(dte, projectName, originalHtmlpath, nodeHtmlpath); } // 定位到文件 没有的话创建 string sqlFileName = Path.GetFileName(nodeSqlpath); if (!string.IsNullOrEmpty(nodeSqlpath)) { // string sqlFileName = Path.GetFileName(nodeSqlpath); if (!File.Exists(nodeSqlpath)) { // 手动创建文件并加入到项目中 string sql = "select * from " + tablename + "\r\n"; File.WriteAllText(nodeSqlpath, sql); EnvDTEHelper.AddFilesToProject(dte, solutionName2, nodeSqlpath); } dte.ItemOperations.OpenFile(nodeSqlpath); } if (!string.IsNullOrEmpty(nodeHtmlpath)) { string htmlFileName = Path.GetFileName(nodeHtmlpath); string procName = Path.GetFileNameWithoutExtension(nodeSqlpath); if (!File.Exists(nodeHtmlpath)) { string codeStr = string.Empty; bool bSuccess = FormatHtml.FormatCode(titleName, procName, tablename, ref codeStr, bJson, bCloseBtn, bDetailList); if (bSuccess) { // 手动创建文件并加入到项目中 File.WriteAllText(nodeHtmlpath, codeStr); EnvDTEHelper.AddFilesToProject(dte, solutionName2, nodeHtmlpath); } else { Debug.WriteLine("使用tt模板创建文件失败!Reason=" + codeStr); EnvDTEHelper.AddFile2Project(dte, solutionName2, "Job", nodeHtmlpath, ".html"); } if (bSuccess) { string theHtmlpath = nodeHtmlpath; theHtmlpath = theHtmlpath.Replace(solutionPath + "\\" + projectName, ""); WebStageInterface.Instance().AddItem2Menu(titleName, theHtmlpath); } } dte.ItemOperations.OpenFile(nodeHtmlpath); } /* * ProjectItem item = _dte.SelectedItems.Item(1).ProjectItem; * item.Properties.Item("CustomTool").Value = nameof(MinifyCodeGenerator); */ }