frmCaseFileCompare.cs 35 KB

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