frmCaseFileCompare.cs 41 KB

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