frmCaseFileCompare.cs 40 KB

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