frmCaseFileCompare.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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. using System.Diagnostics;
  26. using NPOI.Util;
  27. using NPOI.SS.Formula.Functions;
  28. namespace wispro.sp.winClient
  29. {
  30. public partial class frmCaseFileCompare : Form
  31. {
  32. private CompareDocx draft_fristReturn;
  33. private CompareDocx fristReturn_Finally;
  34. public frmCaseFileCompare()
  35. {
  36. InitializeComponent();
  37. }
  38. private void label1_Click(object sender, EventArgs e)
  39. {
  40. }
  41. private CaseInfo getCaseInfo_files(string caseNo, out string draftFile, out string returnFile, out string finalFile)
  42. {
  43. draftFile = null;
  44. returnFile = null;
  45. finalFile = null;
  46. var retFiles = wispro.sp.utility.IPEasyUtility.DownloadCaseFiles(caseNo);
  47. if (retFiles != null)
  48. {
  49. CaseInfo caseInfo = new CaseInfo();
  50. caseInfo.CaseNo = retFiles.CaseNo;
  51. IDictionary<String, Object> keyValuePairs = (IDictionary<String, Object>)retFiles;
  52. if (keyValuePairs.ContainsKey("CaseName"))
  53. {
  54. caseInfo.CaseName = retFiles.CaseName;
  55. }
  56. if (keyValuePairs.ContainsKey("Customer"))
  57. {
  58. caseInfo.Customer = new entity.Customer() { Name = retFiles.Customer };
  59. }
  60. if (keyValuePairs.ContainsKey("FirstDraftDate"))
  61. {
  62. caseInfo.DraftDate = string.IsNullOrEmpty(retFiles.FirstDraftDate) ? null : DateTime.Parse(retFiles.FirstDraftDate);
  63. }
  64. if (keyValuePairs.ContainsKey("ReturnDate"))
  65. {
  66. caseInfo.ReturnDate = string.IsNullOrEmpty(retFiles.ReturnDate) ? null : DateTime.Parse(retFiles.ReturnDate);
  67. }
  68. if (keyValuePairs.ContainsKey("FinalizationDate"))
  69. {
  70. caseInfo.FinalVersionDate = string.IsNullOrEmpty(retFiles.FinalizationDate) ? null : DateTime.Parse(retFiles.FinalizationDate);
  71. }
  72. if (keyValuePairs.ContainsKey("DoPersons"))
  73. {
  74. caseInfo.Handlers = retFiles.DoPersons;
  75. caseInfo.Handlers = caseInfo.Handlers.Trim();
  76. if(caseInfo.Handlers.Substring(caseInfo.Handlers.Length - 1) == ";")
  77. {
  78. caseInfo.Handlers = caseInfo.Handlers.Substring(0, caseInfo.Handlers.Length - 1);
  79. }
  80. }
  81. if (keyValuePairs.ContainsKey("Reviewer"))
  82. {
  83. if (!string.IsNullOrEmpty(retFiles.Reviewer))
  84. {
  85. caseInfo.Reviewer = new entity.Staff() { Name = retFiles.Reviewer };
  86. }
  87. }
  88. if (keyValuePairs.ContainsKey("draftFile"))
  89. {
  90. draftFile = retFiles.draftFile;
  91. }
  92. if (keyValuePairs.ContainsKey("firstReturnFile"))
  93. {
  94. returnFile = retFiles.firstReturnFile;
  95. }
  96. if (keyValuePairs.ContainsKey("finallyFile"))
  97. {
  98. finalFile = retFiles.finallyFile;
  99. }
  100. return caseInfo;
  101. }
  102. else
  103. {
  104. return null;
  105. }
  106. }
  107. private async Task compareCaseFile(DateTime start,DateTime end)
  108. {
  109. DataTable table = wispro.sp.utility.IPEasyUtility.GetFinished3FilesCases(1,start,end);
  110. if (table != null)
  111. {
  112. int iIndex = 0;
  113. foreach (DataRow row in table.Rows)
  114. {
  115. iIndex++;
  116. string CaseNo = row["我方文号"].ToString();
  117. if (row["申请类型"].ToString().Trim() == "外观设计")
  118. {
  119. string str = $"{DateTime.Now}\t{iIndex}/{CaseNo}\t外观设计";
  120. DebugLog(str);
  121. continue;
  122. }
  123. string draftFile = string.Empty;
  124. string returnFile = string.Empty;
  125. string finalFile = string.Empty;
  126. if (!string.IsNullOrEmpty(CaseNo) && !CaseNo.StartsWith("PACN"))
  127. {
  128. DebugLog($"{DateTime.Now}\t{iIndex}/{table.Rows.Count}\t{CaseNo}\t非中国专利申请");
  129. continue ;
  130. }
  131. var isExistResp = await new APIService().CaseExist(CaseNo);
  132. if (isExistResp || !CaseNo.StartsWith("PACN"))
  133. {
  134. DebugLog($"{DateTime.Now}\t{iIndex}/{table.Rows.Count}\t{CaseNo}\t已存在!");
  135. continue;
  136. }
  137. int iTry = 0;
  138. tryAgain:
  139. try
  140. {
  141. CaseInfo caseInfo = getCaseInfo_files(CaseNo, out draftFile, out returnFile, out finalFile);
  142. int i = (string.IsNullOrEmpty(draftFile) ? 0 : 1) +
  143. (string.IsNullOrEmpty(returnFile) ? 0 : 1) +
  144. (string.IsNullOrEmpty(finalFile) ? 0 : 1);
  145. DebugLog($"{DateTime.Now}\t{iIndex}/{table.Rows.Count}\t{CaseNo},{(string.IsNullOrEmpty(draftFile) ? 0 : 1)},{(string.IsNullOrEmpty(returnFile) ? 0 : 1)},{(string.IsNullOrEmpty(finalFile) ? 0 : 1)}");
  146. if (i > 1 && returnFile != null)
  147. {
  148. CompareFiles(draftFile, returnFile, finalFile, caseInfo);
  149. await new APIService().SaveCompareResult(caseInfo);
  150. }
  151. try
  152. {
  153. if (File.Exists(draftFile))
  154. {
  155. File.Delete(draftFile);
  156. }
  157. if (File.Exists(returnFile))
  158. {
  159. File.Delete(returnFile);
  160. }
  161. if (File.Exists(finalFile))
  162. {
  163. File.Delete(finalFile);
  164. }
  165. }
  166. catch { }
  167. }
  168. catch(Exception ex)
  169. {
  170. if(iTry < 3)
  171. {
  172. iTry++;
  173. goto tryAgain;
  174. }
  175. DebugLog($"{DateTime.Now}\t{ iIndex}/{ table.Rows.Count}\t{CaseNo},{ ex.Message}");
  176. }
  177. }
  178. }
  179. static void DebugLog(string str)
  180. {
  181. using (StreamWriter writer = new StreamWriter(@"c:\temp\caseFileInfo.txt", true))
  182. {
  183. writer.WriteLine(str);
  184. }
  185. }
  186. }
  187. private void CompareFiles(string draftFile, string returnFile, string finalFile, CaseInfo caseInfo)
  188. {
  189. string strExtractPath = @"c:\temp";
  190. string tmpdraftFile = ExtractFile(draftFile, 0, strExtractPath);
  191. string tmpreturnFile = ExtractFile(returnFile, 1, strExtractPath);
  192. string tmpfinalFile = ExtractFile(finalFile, 2, strExtractPath);
  193. if (!string.IsNullOrEmpty(tmpdraftFile) && !string.IsNullOrEmpty(tmpreturnFile))
  194. {
  195. CompareDocx docx = new CompareDocx();
  196. docx.Compare(tmpdraftFile, tmpreturnFile);
  197. if (docx.FulltextResult.oldWordCount > 0)
  198. {
  199. caseInfo.DRRFulltext = docx.FulltextResult;
  200. }
  201. if (docx.AbstractResult.oldWordCount > 0)
  202. {
  203. caseInfo.DRRAbstract = docx.AbstractResult;
  204. }
  205. if (docx.ClaimResult.oldWordCount > 0)
  206. {
  207. caseInfo.DRRCalim = docx.ClaimResult;
  208. }
  209. if (docx.AllStringResult.oldWordCount > 0)
  210. {
  211. caseInfo.DRRAll = docx.AllStringResult;
  212. }
  213. }
  214. if (!string.IsNullOrEmpty(tmpfinalFile) && !string.IsNullOrEmpty(tmpreturnFile))
  215. {
  216. CompareDocx docx = new CompareDocx();
  217. docx.Compare(tmpreturnFile, tmpfinalFile);
  218. if (docx.FulltextResult.oldWordCount > 0)
  219. {
  220. caseInfo.RFRFulltext = docx.FulltextResult;
  221. }
  222. if (docx.AbstractResult.oldWordCount > 0)
  223. {
  224. caseInfo.RFRAbstract = docx.AbstractResult;
  225. }
  226. if (docx.ClaimResult.oldWordCount > 0)
  227. {
  228. caseInfo.RFRCalim = docx.ClaimResult;
  229. }
  230. if (docx.AllStringResult.oldWordCount > 0)
  231. {
  232. caseInfo.RFRAll = docx.AllStringResult;
  233. }
  234. }
  235. #region 清除下载和解压缩后的文件
  236. if (System.IO.File.Exists(returnFile))
  237. {
  238. System.IO.File.Delete(returnFile);
  239. }
  240. if (System.IO.File.Exists(draftFile))
  241. {
  242. System.IO.File.Delete(draftFile);
  243. }
  244. if (System.IO.File.Exists(finalFile))
  245. {
  246. System.IO.File.Delete(finalFile);
  247. }
  248. if (System.IO.File.Exists(tmpdraftFile))
  249. {
  250. System.IO.File.Delete(tmpdraftFile);
  251. }
  252. if (System.IO.File.Exists(tmpfinalFile))
  253. {
  254. System.IO.File.Delete(tmpfinalFile);
  255. }
  256. if (System.IO.File.Exists(tmpreturnFile))
  257. {
  258. System.IO.File.Delete(tmpreturnFile);
  259. }
  260. if (!string.IsNullOrEmpty(returnFile) && System.IO.Directory.Exists(Path.Combine(strExtractPath, returnFile.Substring(0, returnFile.Length - 4))))
  261. {
  262. System.IO.Directory.Delete(Path.Combine(strExtractPath, returnFile.Substring(0, returnFile.Length - 4)), true);
  263. }
  264. if (!string.IsNullOrEmpty(draftFile) && System.IO.Directory.Exists(Path.Combine(strExtractPath, draftFile.Substring(0, draftFile.Length - 4))))
  265. {
  266. System.IO.Directory.Delete(Path.Combine(strExtractPath, draftFile.Substring(0, draftFile.Length - 4)), true);
  267. }
  268. if (!string.IsNullOrEmpty(finalFile) && System.IO.Directory.Exists(Path.Combine(strExtractPath, finalFile.Substring(0, finalFile.Length - 4))))
  269. {
  270. System.IO.Directory.Delete(Path.Combine(strExtractPath, finalFile.Substring(0, finalFile.Length - 4)), true);
  271. }
  272. #endregion
  273. }
  274. CaseInfo caseInfo;
  275. private void button1_Click(object sender, EventArgs e)
  276. {
  277. if (string.IsNullOrEmpty(this.txtCaseNo.Text))
  278. {
  279. if (MessageBox.Show("获取前一天所有的完成案件,并比较文档?", "提示框", MessageBoxButtons.YesNo) == DialogResult.Yes)
  280. {
  281. compareCaseFile(DateTime.Parse("2024-12-01"),DateTime.Now);
  282. return;
  283. }
  284. else
  285. {
  286. MessageBox.Show("请输入案号!", "提示框", MessageBoxButtons.OK);
  287. this.txtCaseNo.Focus();
  288. return;
  289. }
  290. }
  291. else
  292. {
  293. #region 获取文本框中输入的案件,并比较三个文件
  294. string draftFile = string.Empty;
  295. string finalFile = string.Empty;
  296. string returnFile = string.Empty;
  297. caseInfo = getCaseInfo_files(txtCaseNo.Text.Trim(), out draftFile, out returnFile, out finalFile);
  298. int i = (string.IsNullOrEmpty(draftFile) ? 0 : 1) +
  299. (string.IsNullOrEmpty(returnFile) ? 0 : 1) +
  300. (string.IsNullOrEmpty(finalFile) ? 0 : 1);
  301. if (i > 1)
  302. {
  303. CompareFiles(draftFile, returnFile, finalFile, caseInfo);
  304. new APIService().SaveCompareResult(caseInfo);
  305. }
  306. comboBox1.SelectedIndex = 0;
  307. #endregion
  308. }
  309. }
  310. private static bool isValidFile(string strFile,int type)
  311. {
  312. if (string.IsNullOrEmpty(strFile)) { return false; }
  313. string strfileName = new FileInfo(strFile).Name;
  314. switch (type)
  315. {
  316. case 0:
  317. if (strfileName.ToUpper().IndexOf("检索报告", StringComparison.OrdinalIgnoreCase) < 0 &&
  318. strfileName.ToUpper().IndexOf("通知书", StringComparison.OrdinalIgnoreCase) < 0 &&
  319. strfileName.ToUpper().IndexOf("查新报告", StringComparison.OrdinalIgnoreCase) < 0 &&
  320. strfileName.ToUpper().IndexOf("对比文件", StringComparison.OrdinalIgnoreCase) < 0 &&
  321. strfileName.ToUpper().IndexOf("检索文档", StringComparison.OrdinalIgnoreCase) < 0 &&
  322. (strfileName.ToUpper().IndexOf("申请文档", StringComparison.OrdinalIgnoreCase) > 0 ||
  323. strfileName.ToUpper().IndexOf("申请文件", StringComparison.OrdinalIgnoreCase) > 0 ||
  324. strfileName.ToUpper().IndexOf("权利要求", StringComparison.OrdinalIgnoreCase) > 0 ||
  325. strfileName.ToUpper().IndexOf("V1R", StringComparison.OrdinalIgnoreCase) > 0))
  326. {
  327. return true;
  328. }
  329. break;
  330. case 1:
  331. if ((strfileName.ToUpper().IndexOf("申请文件", StringComparison.OrdinalIgnoreCase) > 0 ||
  332. strfileName.ToUpper().IndexOf("V1F", StringComparison.OrdinalIgnoreCase) > 0 ||
  333. strfileName.ToUpper().IndexOf("初稿", StringComparison.OrdinalIgnoreCase) > 0 ||
  334. strfileName.ToUpper().IndexOf("权利要求", StringComparison.OrdinalIgnoreCase) > 0 ||
  335. strfileName.ToUpper().IndexOf("申请文档", StringComparison.OrdinalIgnoreCase) > 0 ||
  336. strfileName.ToUpper().IndexOf("说明书", StringComparison.OrdinalIgnoreCase) > 0) &&
  337. strfileName.ToUpper().IndexOf("检索报告", StringComparison.OrdinalIgnoreCase) < 0 &&
  338. strfileName.ToUpper().IndexOf("查新报告", StringComparison.OrdinalIgnoreCase) < 0 &&
  339. strfileName.ToUpper().IndexOf("对比文件", StringComparison.OrdinalIgnoreCase) < 0 &&
  340. strfileName.ToUpper().IndexOf("通知书", StringComparison.OrdinalIgnoreCase) < 0 &&
  341. strfileName.ToUpper().IndexOf("检索文档", StringComparison.OrdinalIgnoreCase) < 0)
  342. {
  343. return true;
  344. }
  345. break;
  346. case 2:
  347. if (strfileName.ToUpper().IndexOf("检索报告", StringComparison.OrdinalIgnoreCase) < 0 &&
  348. strfileName.ToUpper().IndexOf("查新报告", StringComparison.OrdinalIgnoreCase) < 0 &&
  349. strfileName.ToUpper().IndexOf("对比文件", StringComparison.OrdinalIgnoreCase) < 0 &&
  350. strfileName.ToUpper().IndexOf("检索文档", StringComparison.OrdinalIgnoreCase) < 0)
  351. {
  352. return true;
  353. }
  354. break;
  355. }
  356. return false;
  357. }
  358. private static string ExtractFile(string file, int type, string strExtractPath)
  359. {
  360. if (string.IsNullOrEmpty(file))
  361. {
  362. return null;
  363. }
  364. if (file.ToLower().EndsWith(".zip") || file.ToLower().EndsWith(".rar"))
  365. {
  366. string temFileName = new FileInfo(file).Name;
  367. string extractPath = Path.Combine(strExtractPath, temFileName.Substring(0, temFileName.Length - 4));
  368. if (file.ToLower().EndsWith(".zip"))
  369. {
  370. ExtractFileUtil.ExtractZip(file, extractPath);
  371. }
  372. else
  373. {
  374. ExtractFileUtil.ExtractRarFile(file, extractPath);
  375. }
  376. foreach (string f in Directory.GetFiles(extractPath, "*.*", SearchOption.AllDirectories))
  377. {
  378. if (isValidFile(f, type))
  379. {
  380. return f;
  381. }
  382. }
  383. return null;
  384. }
  385. else
  386. {
  387. if (file.ToLower().EndsWith(".eml"))
  388. {
  389. emlFileReader emlFile = new emlFileReader(file);
  390. if (emlFile.AttachFiles != null)
  391. {
  392. string retFile = null;
  393. foreach (var temfile in emlFile.AttachFiles)
  394. {
  395. string temExtractFile = ExtractFile(temfile, type, strExtractPath);
  396. if (isValidFile(temExtractFile,type))
  397. {
  398. retFile = temExtractFile;
  399. break;
  400. }
  401. }
  402. if(retFile == null && emlFile.AttachFiles.Count ==1)
  403. {
  404. retFile = ExtractFile(emlFile.AttachFiles[0], type, strExtractPath);
  405. }
  406. foreach (var temfile in emlFile.AttachFiles)
  407. {
  408. if (temfile != retFile)
  409. {
  410. File.Delete(temfile);
  411. }
  412. }
  413. return retFile;
  414. }
  415. return null;
  416. }
  417. else
  418. {
  419. return file;
  420. }
  421. }
  422. }
  423. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  424. {
  425. if (caseInfo != null)
  426. {
  427. richTextBox1.Clear();
  428. string strHtml = string.Empty;
  429. switch (comboBox1.SelectedIndex)
  430. {
  431. case 0:
  432. if (caseInfo.DRRAll != null)
  433. {
  434. 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>";
  435. }
  436. if (caseInfo.RFRAll != null)
  437. {
  438. 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>";
  439. }
  440. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
  441. break;
  442. case 1:
  443. if (caseInfo.DRRAll != null)
  444. {
  445. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.DRRAll.CompareResultString);
  446. }
  447. break;
  448. case 2:
  449. if (caseInfo.RFRAll != null)
  450. {
  451. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.RFRAll.CompareResultString);
  452. }
  453. break;
  454. case 3:
  455. if (caseInfo.DRRAbstract != null)
  456. {
  457. 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>";
  458. }
  459. if (caseInfo.RFRAbstract != null)
  460. {
  461. 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>";
  462. }
  463. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
  464. break;
  465. case 4:
  466. if (caseInfo.DRRAbstract != null)
  467. {
  468. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.DRRAbstract.CompareResultString);
  469. }
  470. break;
  471. case 5:
  472. if (caseInfo.RFRAbstract != null)
  473. {
  474. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.RFRAbstract.CompareResultString);
  475. }
  476. break;
  477. case 6:
  478. if (caseInfo.DRRCalim != null)
  479. {
  480. 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>";
  481. }
  482. if (caseInfo.RFRCalim != null)
  483. {
  484. 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>";
  485. }
  486. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
  487. break;
  488. case 7:
  489. if (caseInfo.DRRCalim != null)
  490. {
  491. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.DRRCalim.CompareResultString);
  492. }
  493. break;
  494. case 8:
  495. if (caseInfo.RFRCalim != null)
  496. {
  497. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.RFRCalim.CompareResultString);
  498. }
  499. break;
  500. case 9:
  501. if (caseInfo.DRRFulltext != null)
  502. {
  503. 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>";
  504. }
  505. if (caseInfo.RFRFulltext != null)
  506. {
  507. 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>";
  508. }
  509. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
  510. break;
  511. case 10:
  512. if (caseInfo.DRRFulltext != null)
  513. {
  514. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.DRRFulltext.CompareResultString);
  515. }
  516. break;
  517. case 11:
  518. if (caseInfo.RFRFulltext != null)
  519. {
  520. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(caseInfo.RFRFulltext.CompareResultString);
  521. }
  522. break;
  523. }
  524. }
  525. }
  526. private void button2_Click(object sender, EventArgs e)
  527. {
  528. new Form1().ShowDialog();
  529. #region 选择文档比较
  530. //OpenFileDialog openFileDialog = new OpenFileDialog();
  531. //if(openFileDialog.ShowDialog() == DialogResult.OK)
  532. //{
  533. // string strPath = openFileDialog.FileName.ToLower().Replace(".rar", "").Replace(".zip","");
  534. // if(openFileDialog.FileName.Contains(".rar"))
  535. // {
  536. // ExtractFileUtil.ExtractRarFile(openFileDialog.FileName, strPath);
  537. // }
  538. // else
  539. // {
  540. // ExtractFileUtil.ExtractZip(openFileDialog.FileName,strPath);
  541. // }
  542. // string[] files = Directory.EnumerateFiles(strPath, "*.*", SearchOption.AllDirectories).ToArray<string>();
  543. // Array.Sort(files);
  544. // Array.Reverse(files);
  545. // draft_fristReturn = new CompareDocx();
  546. // draft_fristReturn.Compare(files[0], files[1]);
  547. // if (files.Length > 2)
  548. // {
  549. // fristReturn_Finally = new CompareDocx();
  550. // fristReturn_Finally.Compare(files[1], files[2]);
  551. // }
  552. // SaveResult(strPath,draft_fristReturn);
  553. // SaveResult(strPath, fristReturn_Finally);
  554. //}
  555. #endregion
  556. }
  557. private void SaveResult(string strPath, CompareDocx draft_fristReturn)
  558. {
  559. string strHtml = @"<!DOCTYPE html>
  560. <html lang=""en"">
  561. <head>
  562. <meta charset=""utf-8"">
  563. <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"">
  564. <meta name=""description"" content=""email code"">
  565. <meta name=""viewport"" content=""width=device-width, initial-scale=1"">
  566. <title>对比结果</title>
  567. <script>
  568. function toggleDiv() {
  569. var radio = document.querySelector('input[name=""options""]:checked');
  570. if(!radio){
  571. return
  572. }
  573. var value = radio.value
  574. var div = document.getElementById('resultContent');
  575. var childrenDom = div.children
  576. if(!childrenDom || childrenDom.length==0){
  577. return
  578. }
  579. for(var i = 0;i<childrenDom.length;i++){
  580. var dom = childrenDom[i]
  581. if(dom.id == value){
  582. dom.className = 'checked'
  583. }else{
  584. dom.className = ''
  585. }
  586. }
  587. }
  588. </script>
  589. </head>
  590. <!--对比结果模板-->
  591. <body>
  592. <div class=""contrastResult"">
  593. <form action="""">
  594. <div>
  595. <label for=""originalFile"">原文件:</label>
  596. <span id=""originalFile"">{0}</span>
  597. </div>
  598. <div>
  599. <label for=""contrastFile"">对比文件:</label>
  600. <span id=""contrastFile"">{1}</span>
  601. </div>
  602. <div>
  603. <label for=""result"">对比结果:</label>
  604. <div id=""result"">
  605. <table>
  606. <thead>
  607. <tr>
  608. <td></td>
  609. <td>全部对比</td>
  610. <td>摘要</td>
  611. <td>权利要求</td>
  612. <td>说明书</td>
  613. </tr>
  614. </thead>
  615. <tbody>
  616. <tr>
  617. <td>原文字数</td>
  618. <td>{2}</td>
  619. <td>{3}</td>
  620. <td>{4}</td>
  621. <td>{5}</td>
  622. </tr>
  623. <tr>
  624. <td>删除字数</td>
  625. <td>{6}</td>
  626. <td>{7}</td>
  627. <td>{8}</td>
  628. <td>{9}</td>
  629. </tr>
  630. <tr>
  631. <td>插入字数</td>
  632. <td>{10}</td>
  633. <td>{11}</td>
  634. <td>{12}</td>
  635. <td>{13}</td>
  636. </tr>
  637. <tr>
  638. <td>修改比例</td>
  639. <td>{14}</td>
  640. <td>{15}</td>
  641. <td>{16}</td>
  642. <td>{17}</td>
  643. </tr>
  644. <tr>
  645. <td>语义相似度</td>
  646. <td>{18}</td>
  647. <td>{19}</td>
  648. <td>{20}</td>
  649. <td>{21}</td>
  650. </tr>
  651. </tbody>
  652. </table>
  653. </div>
  654. </div>
  655. <div class=""resultType"">
  656. <label for="""">结果:</label>
  657. <input type=""radio"" name=""options"" value=""allContrast"" id=""allContrast"" checked onchange=""toggleDiv()"">
  658. <label for=""allContrast"">全部对比</label>
  659. <input type=""radio"" name=""options"" value=""abstract"" id=""abstract"" onchange=""toggleDiv()"">
  660. <label for=""abstract"">摘要</label>
  661. <input type=""radio"" name=""options"" value=""claim"" id=""claim"" onchange=""toggleDiv()"">
  662. <label for=""claim"">权利要求</label>
  663. <input type=""radio"" name=""options"" value=""instructions"" id=""instructions"" onchange=""toggleDiv()"">
  664. <label for=""instructions"">说明书</label>
  665. </div>
  666. <div id=""resultContent"">
  667. <div id=""allContrast"">{22}</div>
  668. <div id=""abstract"">{23}</div>
  669. <div id=""claim"">{24}</div>
  670. <div id=""instructions"">{25}</div>
  671. </div>
  672. </form>
  673. </div>
  674. <script>
  675. toggleDiv();
  676. </script>
  677. </body>
  678. <style>
  679. .contrastResult{
  680. width: 1000px;
  681. margin: 0 auto;
  682. padding: 50px 0;
  683. }
  684. div{
  685. margin: 20px 0 ;
  686. }
  687. table{
  688. width: 100%;
  689. table-layout: fixed;
  690. border-collapse: collapse;
  691. }
  692. table td{
  693. border: 1px solid black;
  694. padding: 10px;
  695. }
  696. table thead td{
  697. text-align: center;
  698. }
  699. table tr>td:first-child{
  700. width: 120px;
  701. }
  702. #resultContent>div{
  703. display: none;
  704. overflow:auto;
  705. height:400px;
  706. }
  707. .checked{
  708. display: block !important;
  709. }
  710. </style>
  711. </html>";
  712. if (draft_fristReturn != null)
  713. {
  714. var temHtml = strHtml
  715. .Replace("{0}", new FileInfo(draft_fristReturn.oldDocument.FilePath).Name)
  716. .Replace("{1}", new FileInfo(draft_fristReturn.newDocument.FilePath).Name)
  717. .Replace("{2}", draft_fristReturn.AllStringResult.oldWordCount.ToString())
  718. .Replace("{3}", draft_fristReturn.AbstractResult.oldWordCount.ToString())
  719. .Replace("{4}", draft_fristReturn.ClaimResult.oldWordCount.ToString())
  720. .Replace("{5}", draft_fristReturn.FulltextResult.oldWordCount.ToString())
  721. .Replace("{6}", draft_fristReturn.AllStringResult.DeleteCount.ToString())
  722. .Replace("{7}", draft_fristReturn.AbstractResult.DeleteCount.ToString())
  723. .Replace("{8}", draft_fristReturn.ClaimResult.DeleteCount.ToString())
  724. .Replace("{9}", draft_fristReturn.FulltextResult.DeleteCount.ToString())
  725. .Replace("{10}", draft_fristReturn.AllStringResult.InsertCount.ToString())
  726. .Replace("{11}", draft_fristReturn.AbstractResult.InsertCount.ToString())
  727. .Replace("{12}", draft_fristReturn.ClaimResult.InsertCount.ToString())
  728. .Replace("{13}", draft_fristReturn.FulltextResult.InsertCount.ToString())
  729. .Replace("{14}", (draft_fristReturn.AllStringResult.diffRate * 100).ToString("0.0000") + "%")
  730. .Replace("{15}", (draft_fristReturn.AbstractResult.diffRate * 100).ToString("0.0000") + "%")
  731. .Replace("{16}", (draft_fristReturn.ClaimResult.diffRate * 100).ToString("0.0000") + "%")
  732. .Replace("{17}", (draft_fristReturn.FulltextResult.diffRate * 100).ToString("0.0000") + "%")
  733. .Replace("{18}", (draft_fristReturn.AllStringResult.TextSimilarity * 100).ToString("0.0000") + "%")
  734. .Replace("{19}", (draft_fristReturn.AbstractResult.TextSimilarity * 100).ToString("0.0000") + "%")
  735. .Replace("{20}", (draft_fristReturn.ClaimResult.TextSimilarity * 100).ToString("0.0000") + "%")
  736. .Replace("{21}", (draft_fristReturn.FulltextResult.TextSimilarity * 100).ToString("0.0000") + "%")
  737. .Replace("{22}", draft_fristReturn.AllStringResult.CompareResultString)
  738. .Replace("{23}", draft_fristReturn.AbstractResult.CompareResultString)
  739. .Replace("{24}", draft_fristReturn.ClaimResult.CompareResultString)
  740. .Replace("{25}", draft_fristReturn.FulltextResult.CompareResultString);
  741. string fileName = $"{new FileInfo(draft_fristReturn.oldDocument.FilePath).Name}_{new FileInfo(draft_fristReturn.newDocument.FilePath).Name}.html";
  742. using (var f = File.CreateText(Path.Combine(strPath, fileName)))
  743. {
  744. f.Write(temHtml);
  745. }
  746. }
  747. }
  748. private void button3_Click(object sender, EventArgs e)
  749. {
  750. emlFileReader reader = new emlFileReader(@"D:\Users\luowen\Downloads\2f7e92c1-e009-4b19-ba8d-332e8f6f2ffc.eml");
  751. }
  752. private void txtCaseNo_TextChanged(object sender, EventArgs e)
  753. {
  754. }
  755. }
  756. }