frmCaseFileCompare.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. using ICSharpCode.SharpZipLib.Tar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.IO.Compression;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using wispro.sp.utility;
  14. using SharpCompress.Archives;
  15. using SharpCompress.Archives.Rar;
  16. using SharpCompress.Common;
  17. using System.Collections;
  18. using wispro.sp.entity.CompareCase;
  19. using wispro.sp.share.webViewObject;
  20. using System.Net.Http;
  21. using System.Net.Http.Json;
  22. using wispro.sp.share;
  23. using OpenQA.Selenium.Support.UI;
  24. using System.Dynamic;
  25. namespace wispro.sp.winClient
  26. {
  27. public partial class frmCaseFileCompare : Form
  28. {
  29. private CompareDocx draft_fristReturn;
  30. private CompareDocx fristReturn_Finally;
  31. public frmCaseFileCompare()
  32. {
  33. InitializeComponent();
  34. }
  35. private void label1_Click(object sender, EventArgs e)
  36. {
  37. }
  38. private HttpClient CreateHttp()
  39. {
  40. HttpClientHandler clientHandler = new HttpClientHandler();
  41. clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
  42. return new HttpClient(clientHandler);
  43. }
  44. string strAPIBaseUri = "http://localhost:39476";
  45. private async Task<bool> SaveCompareResult(CaseInfo caseinfo)
  46. {
  47. share.webViewObject.loginDto dto = new share.webViewObject.loginDto();
  48. dto.Name = "caiyangl";
  49. dto.Password = "Lqftiu807005";
  50. var response = await CreateHttp().PostAsJsonAsync<loginDto>($"{strAPIBaseUri}/api/account/Login", dto);
  51. if (response.IsSuccessStatusCode)
  52. {
  53. userToken? Token = await response.Content.ReadFromJsonAsync<userToken>();
  54. HttpClient http = CreateHttp();//
  55. http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Token?.Token);
  56. try
  57. {
  58. var data = await http.PostAsJsonAsync<CaseInfo>($"{strAPIBaseUri}/api/CaseFileCompare/Save", caseinfo);
  59. if (data.IsSuccessStatusCode)
  60. {
  61. var ret = await data.Content.ReadFromJsonAsync<ApiSaveResponse>();
  62. if(ret.Success)
  63. {
  64. return true;
  65. }
  66. else
  67. {
  68. throw new Exception(ret.ErrorMessage);
  69. }
  70. }
  71. else
  72. {
  73. return false;
  74. }
  75. }
  76. catch (Exception ex)
  77. {
  78. return false;
  79. }
  80. }
  81. return false;
  82. }
  83. private CaseInfo getCaseInfo_files(string caseNo,out string draftFile,out string returnFile,out string finalFile)
  84. {
  85. draftFile = null;
  86. returnFile = null;
  87. finalFile = null;
  88. var retFiles = wispro.sp.utility.IPEasyUtility.DownloadCaseFiles(caseNo);
  89. if (retFiles != null)
  90. {
  91. CaseInfo caseInfo = new CaseInfo();
  92. caseInfo.CaseNo = retFiles.CaseNo;
  93. IDictionary<String, Object> keyValuePairs = (IDictionary<String, Object>)retFiles;
  94. if (keyValuePairs.ContainsKey("CaseName"))
  95. {
  96. caseInfo.CaseName = retFiles.CaseName;
  97. }
  98. if (keyValuePairs.ContainsKey("Customer"))
  99. {
  100. caseInfo.Customer = new entity.Customer() { Name = retFiles.Customer };
  101. }
  102. if (keyValuePairs.ContainsKey("FirstDraftDate"))
  103. {
  104. caseInfo.DraftDate = string.IsNullOrEmpty(retFiles.FirstDraftDate) ? null : DateTime.Parse(retFiles.FirstDraftDate);
  105. }
  106. if (keyValuePairs.ContainsKey("ReturnDate"))
  107. {
  108. caseInfo.ReturnDate = string.IsNullOrEmpty(retFiles.ReturnDate) ? null : DateTime.Parse(retFiles.ReturnDate);
  109. }
  110. if (keyValuePairs.ContainsKey("FinalizationDate"))
  111. {
  112. caseInfo.FinalVersionDate = string.IsNullOrEmpty(retFiles.FinalizationDate) ? null : DateTime.Parse(retFiles.FinalizationDate);
  113. }
  114. if (keyValuePairs.ContainsKey("DoPersons"))
  115. {
  116. caseInfo.Handlers = retFiles.DoPersons;
  117. }
  118. if (keyValuePairs.ContainsKey("Reviewer"))
  119. {
  120. if (!string.IsNullOrEmpty(retFiles.Reviewer))
  121. {
  122. caseInfo.Reviewer = new entity.Staff() { Name = retFiles.Reviewer };
  123. }
  124. }
  125. if (keyValuePairs.ContainsKey("draftFile"))
  126. {
  127. draftFile = retFiles.draftFile;
  128. }
  129. if (keyValuePairs.ContainsKey("firstReturnFile"))
  130. {
  131. returnFile = retFiles.firstReturnFile;
  132. }
  133. if (keyValuePairs.ContainsKey("finallyFile"))
  134. {
  135. finalFile = retFiles.finallyFile;
  136. }
  137. return caseInfo;
  138. }
  139. else
  140. {
  141. return null;
  142. }
  143. }
  144. private void compareCaseFile()
  145. {
  146. DataTable table = wispro.sp.utility.IPEasyUtility.GetFinished3FilesCases(1);
  147. if (table != null)
  148. {
  149. foreach (DataRow row in table.Rows)
  150. {
  151. if (row["申请类型"].ToString().Trim() == "外观设计")
  152. {
  153. continue;
  154. }
  155. string draftFile = string.Empty;
  156. string returnFile =string.Empty;
  157. string finalFile =string.Empty;
  158. string CaseNo = row["我方文号"].ToString();
  159. CaseInfo caseInfo = getCaseInfo_files(CaseNo, out draftFile,out returnFile, out finalFile);
  160. int i = (string.IsNullOrEmpty(draftFile) ? 1 : 0) +
  161. (string.IsNullOrEmpty(returnFile) ? 1 : 0) +
  162. (string.IsNullOrEmpty(finalFile) ? 1 : 0);
  163. if (i > 1)
  164. {
  165. CompareFiles(draftFile, returnFile, finalFile, caseInfo);
  166. SaveCompareResult(caseInfo);
  167. }
  168. }
  169. }
  170. }
  171. private void CompareFiles(string draftFile, string returnFile, string finalFile, CaseInfo caseInfo)
  172. {
  173. string strExtractPath = @"c:\temp";
  174. string tmpdraftFile = ExtractFile(draftFile,0,strExtractPath);
  175. string tmpreturnFile = ExtractFile(returnFile, 1, strExtractPath);
  176. string tmpfinalFile = ExtractFile(finalFile, 2, strExtractPath);
  177. if (!string.IsNullOrEmpty(tmpdraftFile) && !string.IsNullOrEmpty(tmpreturnFile))
  178. {
  179. CompareDocx docx = new CompareDocx();
  180. docx.Compare(tmpdraftFile, tmpreturnFile);
  181. if(docx.FulltextResult.oldWordCount > 0)
  182. {
  183. caseInfo.DRRFulltext = docx.FulltextResult;
  184. }
  185. if (docx.AbstractResult.oldWordCount > 0)
  186. {
  187. caseInfo.DRRAbstract = docx.AbstractResult;
  188. }
  189. if (docx.ClaimResult.oldWordCount > 0)
  190. {
  191. caseInfo.DRRCalim = docx.ClaimResult;
  192. }
  193. if (docx.AbstractResult.oldWordCount > 0)
  194. {
  195. caseInfo.DRRAll = docx.AllStringResult;
  196. }
  197. }
  198. if (!string.IsNullOrEmpty(tmpfinalFile) && !string.IsNullOrEmpty(tmpreturnFile))
  199. {
  200. CompareDocx docx = new CompareDocx();
  201. docx.Compare(tmpreturnFile, tmpfinalFile);
  202. if (docx.FulltextResult.oldWordCount > 0)
  203. {
  204. caseInfo.RFRFulltext = docx.FulltextResult;
  205. }
  206. if (docx.AbstractResult.oldWordCount > 0)
  207. {
  208. caseInfo.RFRAbstract = docx.AbstractResult;
  209. }
  210. if (docx.ClaimResult.oldWordCount > 0)
  211. {
  212. caseInfo.RFRCalim = docx.ClaimResult;
  213. }
  214. if (docx.AllStringResult.oldWordCount > 0)
  215. {
  216. caseInfo.RFRAll = docx.AllStringResult;
  217. }
  218. }
  219. #region 清除下载和解压缩后的文件
  220. if (System.IO.File.Exists(returnFile))
  221. {
  222. System.IO.File.Delete(returnFile);
  223. }
  224. if (System.IO.File.Exists(draftFile))
  225. {
  226. System.IO.File.Delete(draftFile);
  227. }
  228. if (System.IO.File.Exists(finalFile))
  229. {
  230. System.IO.File.Delete(finalFile);
  231. }
  232. if (System.IO.Directory.Exists(Path.Combine(strExtractPath,returnFile.Substring(0,returnFile.Length -4))))
  233. {
  234. System.IO.Directory.Delete(Path.Combine(strExtractPath, returnFile.Substring(0, returnFile.Length - 4)), true);
  235. }
  236. if (System.IO.Directory.Exists(Path.Combine(strExtractPath, draftFile.Substring(0, draftFile.Length - 4))))
  237. {
  238. System.IO.Directory.Delete(Path.Combine(strExtractPath, draftFile.Substring(0, draftFile.Length - 4)),true);
  239. }
  240. if (System.IO.Directory.Exists(Path.Combine(strExtractPath, finalFile.Substring(0, finalFile.Length - 4))))
  241. {
  242. System.IO.Directory.Delete(Path.Combine(strExtractPath, finalFile.Substring(0, finalFile.Length - 4)),true);
  243. }
  244. #endregion
  245. }
  246. private string ExtractFile(string file,int type,string strExtractPath)
  247. {
  248. if (file.ToLower().EndsWith(".zip") || file.ToLower().EndsWith(".rar"))
  249. {
  250. string extractPath = Path.Combine(strExtractPath, file.Substring(0,file.Length-4));
  251. if (file.ToLower().EndsWith(".zip"))
  252. {
  253. ExtractZip(file, extractPath);
  254. }
  255. else
  256. {
  257. ExtractRarFile(file, extractPath);
  258. }
  259. foreach (string f in Directory.GetFiles(extractPath, "*.*", SearchOption.AllDirectories))
  260. {
  261. switch (type)
  262. {
  263. case 0:
  264. if (f.ToUpper().IndexOf("V1R", StringComparison.OrdinalIgnoreCase) > 0)
  265. {
  266. return f;
  267. }
  268. break;
  269. case 1:
  270. if (f.ToUpper().IndexOf("V1F", StringComparison.OrdinalIgnoreCase) > 0)
  271. {
  272. return f;
  273. }
  274. break;
  275. case 2:
  276. if (f.IndexOf("定稿", StringComparison.OrdinalIgnoreCase) > 0)
  277. {
  278. return f;
  279. }
  280. break;
  281. }
  282. }
  283. return null;
  284. }
  285. else
  286. {
  287. return file;
  288. }
  289. }
  290. CaseInfo caseInfo;
  291. private void button1_Click(object sender, EventArgs e)
  292. {
  293. //compareCaseFile();
  294. //return;
  295. if (string.IsNullOrEmpty(this.txtCaseNo.Text))
  296. {
  297. MessageBox.Show("请输入案号!", "提示框", MessageBoxButtons.OK);
  298. this.txtCaseNo.Focus();
  299. return;
  300. }
  301. string draftFile = string.Empty;
  302. string finalFile = string.Empty;
  303. string returnFile = string.Empty;
  304. caseInfo = getCaseInfo_files(txtCaseNo.Text.Trim(), out draftFile, out returnFile, out finalFile);
  305. int i = (string.IsNullOrEmpty(draftFile) ? 0 : 1) +
  306. (string.IsNullOrEmpty(returnFile) ? 0 : 1) +
  307. (string.IsNullOrEmpty(finalFile) ? 0 : 1);
  308. if (i > 1)
  309. {
  310. CompareFiles(draftFile, returnFile, finalFile, caseInfo);
  311. SaveCompareResult(caseInfo);
  312. }
  313. comboBox1.SelectedIndex = 0;
  314. }
  315. private void ExtractZip(string zipFilePath, string extractPath)
  316. {
  317. Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
  318. // 确保提取目录存在
  319. Directory.CreateDirectory(extractPath);
  320. // 使用 ZipArchive 解压缩 ZIP 文件
  321. using (FileStream zipToOpen = new FileStream(zipFilePath, FileMode.Open))
  322. {
  323. using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read, true, Encoding.GetEncoding("GB2312")))
  324. {
  325. foreach (ZipArchiveEntry entry in archive.Entries)
  326. {
  327. if (entry.FullName.EndsWith("/", StringComparison.Ordinal) || entry.FullName.EndsWith("\\", StringComparison.Ordinal))
  328. {
  329. Console.WriteLine($"目录: {entry.FullName}");
  330. }
  331. else
  332. {
  333. string entryPath = Path.Combine(extractPath, entry.FullName);
  334. Directory.CreateDirectory(new System.IO.FileInfo(entryPath).Directory.FullName);
  335. entry.ExtractToFile(entryPath, true);
  336. }
  337. }
  338. }
  339. }
  340. }
  341. public static void ExtractRarFile(string rarPath, string outputPath)
  342. {
  343. try
  344. {
  345. // 确保输出目录存在
  346. Directory.CreateDirectory(outputPath);
  347. // 打开RAR文件
  348. using (var archive = RarArchive.Open(rarPath))
  349. {
  350. // 遍历所有文件
  351. foreach (var entry in archive.Entries)
  352. {
  353. if (!entry.IsDirectory)
  354. {
  355. // 构建完整输出路径
  356. string outputFilePath = Path.Combine(outputPath, entry.Key);
  357. // 确保输出文件的目录存在
  358. Directory.CreateDirectory(Path.GetDirectoryName(outputFilePath));
  359. // 解压文件
  360. entry.WriteToFile(outputFilePath, new ExtractionOptions
  361. {
  362. ExtractFullPath = true,
  363. Overwrite = true
  364. });
  365. }
  366. }
  367. }
  368. }
  369. catch (Exception ex)
  370. {
  371. throw new Exception($"解压RAR文件时出错: {ex.Message}");
  372. }
  373. }
  374. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  375. {
  376. if (caseInfo != null )
  377. {
  378. richTextBox1.Clear();
  379. string strHtml = string.Empty;
  380. switch (comboBox1.SelectedIndex)
  381. {
  382. case 0:
  383. if (caseInfo.DRRAll != null)
  384. {
  385. strHtml = $"<b>所有文字比较:</b><br/><p>初稿与第一次返稿比较结果:</p><p>初稿文件字数:{caseInfo.DRRAll.oldWordCount}</p><p>删除文字数量:{caseInfo.DRRAll.DeleteCount}</p><p>插入文字数量:{caseInfo.DRRAll.InsertCount}</p><p>修改比率:{(caseInfo.DRRAll.diffRate * 100).ToString("0.0000")}%</p><p>文档语义相似度:{(caseInfo.DRRAll.TextSimilarity*100).ToString("0.0000")}%</p>";
  386. }
  387. if (caseInfo.RFRAll != null)
  388. {
  389. strHtml = strHtml + $"<p></p><p>第一次返稿与定稿比较结果:</p><p>第一次返稿文件字数:{ caseInfo.RFRAll.oldWordCount}</p><p>删除文字数量:{caseInfo.RFRAll.DeleteCount}</p><p>插入文字数量:{caseInfo.RFRAll.InsertCount}</p><p>修改比率:{(caseInfo.RFRAll.diffRate * 100).ToString("0.0000")}%</p><p>文档语义相似度:{(caseInfo.RFRAll.TextSimilarity * 100).ToString("0.0000")}%</p>";
  390. }
  391. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
  392. break;
  393. case 1:
  394. if (caseInfo.DRRAll != null)
  395. {
  396. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.DRRAll.CompareResultString);
  397. }
  398. break;
  399. case 2:
  400. if (caseInfo.RFRAll != null)
  401. {
  402. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.RFRAll.CompareResultString);
  403. }
  404. break;
  405. case 3:
  406. if (caseInfo.DRRAbstract != null)
  407. {
  408. strHtml = $"<b>摘要比较:</b><br/><p>初稿与第一次返稿比较结果:</p><p>初稿文件字数:{caseInfo.DRRAbstract.oldWordCount}</p><p>删除文字数量:{caseInfo.DRRAbstract.DeleteCount}</p><p>插入文字数量:{caseInfo.DRRAbstract.InsertCount}</p><p>修改比率:{(caseInfo.DRRAbstract.diffRate * 100).ToString("0.0000")}%</p><p>语义相似度:{(caseInfo.DRRAbstract.TextSimilarity * 100).ToString("0.0000")}%</p>";
  409. }
  410. if (caseInfo.RFRAbstract != null)
  411. {
  412. strHtml = strHtml + $"<p></p><p>第一次返稿与定稿比较结果:</p><p>第一次返稿文件字数:{caseInfo.RFRAbstract.oldWordCount}</p><p>删除文字数量:{caseInfo.RFRAbstract.DeleteCount}</p><p>插入文字数量:{caseInfo.RFRAbstract.InsertCount}</p><p>修改比率:{(caseInfo.RFRAbstract.diffRate * 100).ToString("0.0000")}%</p><p>语义相似度:{(caseInfo.RFRAbstract.TextSimilarity * 100).ToString("0.0000")}%</p>";
  413. }
  414. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
  415. break;
  416. case 4:
  417. if (caseInfo.DRRAbstract != null)
  418. {
  419. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.DRRAbstract.CompareResultString);
  420. }
  421. break;
  422. case 5:
  423. if (caseInfo.RFRAbstract != null)
  424. {
  425. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.RFRAbstract.CompareResultString);
  426. }
  427. break;
  428. case 6:
  429. if (caseInfo.DRRCalim != null)
  430. {
  431. strHtml = $"<b>权力要求比较:</b><br/><p>初稿与第一次返稿比较结果:</p><p>初稿文件字数:{caseInfo.DRRCalim.oldWordCount}</p><p>删除文字数量:{caseInfo.DRRCalim.DeleteCount}</p><p>插入文字数量:{caseInfo.DRRCalim.InsertCount}</p><p>修改比率:{(caseInfo.DRRCalim.diffRate * 100).ToString("0.0000")}%</p><p>语义相似度:{(caseInfo.DRRCalim.TextSimilarity * 100).ToString("0.0000")}%</p>";
  432. }
  433. if (caseInfo.RFRCalim != null)
  434. {
  435. strHtml = strHtml + $"<p></p><p>第一次返稿与定稿比较结果:</p><p>第一次返稿文件字数:{caseInfo.RFRCalim.oldWordCount}</p><p>删除文字数量:{caseInfo.RFRCalim.DeleteCount}</p><p>插入文字数量:{caseInfo.RFRCalim.InsertCount}</p><p>修改比率:{(caseInfo.RFRCalim.diffRate * 100).ToString("0.0000")}%</p><p>语义相似度:{(caseInfo.RFRCalim.TextSimilarity * 100).ToString("0.0000")}%</p>";
  436. }
  437. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
  438. break;
  439. case 7:
  440. if (caseInfo.DRRCalim != null)
  441. {
  442. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.DRRCalim.CompareResultString);
  443. }
  444. break;
  445. case 8:
  446. if (caseInfo.RFRCalim != null)
  447. {
  448. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.RFRCalim.CompareResultString);
  449. }
  450. break;
  451. case 9:
  452. if (caseInfo.DRRFulltext != null)
  453. {
  454. strHtml = $"<b>说明书比较:</b><br/><p>初稿与第一次返稿比较结果:</p><p>初稿文件字数:{caseInfo.DRRFulltext.oldWordCount}</p><p>删除文字数量:{caseInfo.DRRFulltext.DeleteCount}</p><p>插入文字数量:{caseInfo.DRRFulltext.InsertCount}</p><p>修改比率:{(caseInfo.DRRFulltext.diffRate * 100).ToString("0.0000")}%</p><p>语义相似度:{(caseInfo.DRRFulltext.TextSimilarity * 100).ToString("0.0000")}%</p>";
  455. }
  456. if (caseInfo.RFRFulltext != null)
  457. {
  458. strHtml = strHtml + $"<p></p><p>第一次返稿与定稿比较结果:</p><p>第一次返稿文件字数:{caseInfo.RFRFulltext.oldWordCount}</p><p>删除文字数量:{caseInfo.RFRFulltext.DeleteCount}</p><p>插入文字数量:{caseInfo.RFRFulltext.InsertCount}</p><p>修改比率:{(caseInfo.RFRFulltext.diffRate * 100).ToString("0.0000")}%</p><p>语义相似度:{(caseInfo.RFRFulltext.TextSimilarity * 100).ToString("0.0000")}%</p>";
  459. }
  460. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
  461. break;
  462. case 10:
  463. if (caseInfo.DRRFulltext != null)
  464. {
  465. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.DRRFulltext.CompareResultString);
  466. }
  467. break;
  468. case 11:
  469. if (caseInfo.RFRFulltext != null)
  470. {
  471. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.RFRFulltext.CompareResultString);
  472. }
  473. break;
  474. }
  475. }
  476. }
  477. private void button2_Click(object sender, EventArgs e)
  478. {
  479. new Form1().ShowDialog();
  480. return;
  481. var caseInfo = IPEasyUtility.DownloadReport("每月绩效统计--上个月递交完成案件",true);
  482. return;
  483. var retData = IPEasyUtility.GetFinished3FilesCases(1);
  484. return;
  485. OpenFileDialog openFileDialog = new OpenFileDialog();
  486. if(openFileDialog.ShowDialog() == DialogResult.OK)
  487. {
  488. string strPath = openFileDialog.FileName.ToLower().Replace(".rar", "").Replace(".zip","");
  489. if(openFileDialog.FileName.Contains(".rar"))
  490. {
  491. ExtractRarFile(openFileDialog.FileName, strPath);
  492. }
  493. else
  494. {
  495. ExtractZip(openFileDialog.FileName,strPath);
  496. }
  497. string[] files = Directory.EnumerateFiles(strPath, "*.*", SearchOption.AllDirectories).ToArray<string>();
  498. Array.Sort(files);
  499. Array.Reverse(files);
  500. draft_fristReturn = new CompareDocx();
  501. draft_fristReturn.Compare(files[0], files[1]);
  502. if (files.Length > 2)
  503. {
  504. fristReturn_Finally = new CompareDocx();
  505. fristReturn_Finally.Compare(files[1], files[2]);
  506. }
  507. SaveResult(strPath,draft_fristReturn);
  508. SaveResult(strPath, fristReturn_Finally);
  509. }
  510. }
  511. private void SaveResult(string strPath,CompareDocx draft_fristReturn)
  512. {
  513. string strHtml = @"<!DOCTYPE html>
  514. <html lang=""en"">
  515. <head>
  516. <meta charset=""utf-8"">
  517. <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"">
  518. <meta name=""description"" content=""email code"">
  519. <meta name=""viewport"" content=""width=device-width, initial-scale=1"">
  520. <title>对比结果</title>
  521. <script>
  522. function toggleDiv() {
  523. var radio = document.querySelector('input[name=""options""]:checked');
  524. if(!radio){
  525. return
  526. }
  527. var value = radio.value
  528. var div = document.getElementById('resultContent');
  529. var childrenDom = div.children
  530. if(!childrenDom || childrenDom.length==0){
  531. return
  532. }
  533. for(var i = 0;i<childrenDom.length;i++){
  534. var dom = childrenDom[i]
  535. if(dom.id == value){
  536. dom.className = 'checked'
  537. }else{
  538. dom.className = ''
  539. }
  540. }
  541. }
  542. </script>
  543. </head>
  544. <!--对比结果模板-->
  545. <body>
  546. <div class=""contrastResult"">
  547. <form action="""">
  548. <div>
  549. <label for=""originalFile"">原文件:</label>
  550. <span id=""originalFile"">{0}</span>
  551. </div>
  552. <div>
  553. <label for=""contrastFile"">对比文件:</label>
  554. <span id=""contrastFile"">{1}</span>
  555. </div>
  556. <div>
  557. <label for=""result"">对比结果:</label>
  558. <div id=""result"">
  559. <table>
  560. <thead>
  561. <tr>
  562. <td></td>
  563. <td>全部对比</td>
  564. <td>摘要</td>
  565. <td>权利要求</td>
  566. <td>说明书</td>
  567. </tr>
  568. </thead>
  569. <tbody>
  570. <tr>
  571. <td>原文字数</td>
  572. <td>{2}</td>
  573. <td>{3}</td>
  574. <td>{4}</td>
  575. <td>{5}</td>
  576. </tr>
  577. <tr>
  578. <td>删除字数</td>
  579. <td>{6}</td>
  580. <td>{7}</td>
  581. <td>{8}</td>
  582. <td>{9}</td>
  583. </tr>
  584. <tr>
  585. <td>插入字数</td>
  586. <td>{10}</td>
  587. <td>{11}</td>
  588. <td>{12}</td>
  589. <td>{13}</td>
  590. </tr>
  591. <tr>
  592. <td>修改比例</td>
  593. <td>{14}</td>
  594. <td>{15}</td>
  595. <td>{16}</td>
  596. <td>{17}</td>
  597. </tr>
  598. <tr>
  599. <td>语义相似度</td>
  600. <td>{18}</td>
  601. <td>{19}</td>
  602. <td>{20}</td>
  603. <td>{21}</td>
  604. </tr>
  605. </tbody>
  606. </table>
  607. </div>
  608. </div>
  609. <div class=""resultType"">
  610. <label for="""">结果:</label>
  611. <input type=""radio"" name=""options"" value=""allContrast"" id=""allContrast"" checked onchange=""toggleDiv()"">
  612. <label for=""allContrast"">全部对比</label>
  613. <input type=""radio"" name=""options"" value=""abstract"" id=""abstract"" onchange=""toggleDiv()"">
  614. <label for=""abstract"">摘要</label>
  615. <input type=""radio"" name=""options"" value=""claim"" id=""claim"" onchange=""toggleDiv()"">
  616. <label for=""claim"">权利要求</label>
  617. <input type=""radio"" name=""options"" value=""instructions"" id=""instructions"" onchange=""toggleDiv()"">
  618. <label for=""instructions"">说明书</label>
  619. </div>
  620. <div id=""resultContent"">
  621. <div id=""allContrast"">{22}</div>
  622. <div id=""abstract"">{23}</div>
  623. <div id=""claim"">{24}</div>
  624. <div id=""instructions"">{25}</div>
  625. </div>
  626. </form>
  627. </div>
  628. <script>
  629. toggleDiv();
  630. </script>
  631. </body>
  632. <style>
  633. .contrastResult{
  634. width: 1000px;
  635. margin: 0 auto;
  636. padding: 50px 0;
  637. }
  638. div{
  639. margin: 20px 0 ;
  640. }
  641. table{
  642. width: 100%;
  643. table-layout: fixed;
  644. border-collapse: collapse;
  645. }
  646. table td{
  647. border: 1px solid black;
  648. padding: 10px;
  649. }
  650. table thead td{
  651. text-align: center;
  652. }
  653. table tr>td:first-child{
  654. width: 120px;
  655. }
  656. #resultContent>div{
  657. display: none;
  658. overflow:auto;
  659. height:400px;
  660. }
  661. .checked{
  662. display: block !important;
  663. }
  664. </style>
  665. </html>";
  666. if (draft_fristReturn != null)
  667. {
  668. var temHtml = strHtml
  669. .Replace("{0}", new FileInfo(draft_fristReturn.oldDocument.FilePath).Name)
  670. .Replace("{1}", new FileInfo(draft_fristReturn.newDocument.FilePath).Name)
  671. .Replace("{2}", draft_fristReturn.AllStringResult.oldWordCount.ToString())
  672. .Replace("{3}", draft_fristReturn.AbstractResult.oldWordCount.ToString())
  673. .Replace("{4}", draft_fristReturn.ClaimResult.oldWordCount.ToString())
  674. .Replace("{5}", draft_fristReturn.FulltextResult.oldWordCount.ToString())
  675. .Replace("{6}", draft_fristReturn.AllStringResult.DeleteCount.ToString())
  676. .Replace("{7}", draft_fristReturn.AbstractResult.DeleteCount.ToString())
  677. .Replace("{8}", draft_fristReturn.ClaimResult.DeleteCount.ToString())
  678. .Replace("{9}", draft_fristReturn.FulltextResult.DeleteCount.ToString())
  679. .Replace("{10}", draft_fristReturn.AllStringResult.InsertCount.ToString())
  680. .Replace("{11}", draft_fristReturn.AbstractResult.InsertCount.ToString())
  681. .Replace("{12}", draft_fristReturn.ClaimResult.InsertCount.ToString())
  682. .Replace("{13}", draft_fristReturn.FulltextResult.InsertCount.ToString())
  683. .Replace("{14}", (draft_fristReturn.AllStringResult.diffRate * 100).ToString("0.0000") + "%")
  684. .Replace("{15}", (draft_fristReturn.AbstractResult.diffRate * 100).ToString("0.0000") + "%")
  685. .Replace("{16}", (draft_fristReturn.ClaimResult.diffRate * 100).ToString("0.0000") + "%")
  686. .Replace("{17}", (draft_fristReturn.FulltextResult.diffRate * 100).ToString("0.0000") + "%")
  687. .Replace("{18}", (draft_fristReturn.AllStringResult.TextSimilarity * 100).ToString("0.0000") + "%")
  688. .Replace("{19}", (draft_fristReturn.AbstractResult.TextSimilarity * 100).ToString("0.0000") + "%")
  689. .Replace("{20}", (draft_fristReturn.ClaimResult.TextSimilarity * 100).ToString("0.0000") + "%")
  690. .Replace("{21}", (draft_fristReturn.FulltextResult.TextSimilarity * 100).ToString("0.0000") + "%")
  691. .Replace("{22}", draft_fristReturn.AllStringResult.CompareResultString)
  692. .Replace("{23}", draft_fristReturn.AbstractResult.CompareResultString)
  693. .Replace("{24}", draft_fristReturn.ClaimResult.CompareResultString)
  694. .Replace("{25}", draft_fristReturn.FulltextResult.CompareResultString);
  695. string fileName = $"{new FileInfo(draft_fristReturn.oldDocument.FilePath).Name}_{new FileInfo(draft_fristReturn.newDocument.FilePath).Name}.html";
  696. using (var f = File.CreateText(Path.Combine(strPath, fileName)))
  697. {
  698. f.Write(temHtml);
  699. }
  700. }
  701. }
  702. }
  703. }