frmCaseFileCompare.cs 37 KB

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