frmCaseFileCompare.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.IO.Compression;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using wispro.sp.utility;
  13. namespace wispro.sp.winClient
  14. {
  15. public partial class frmCaseFileCompare : Form
  16. {
  17. private CompareDocx draft_fristReturn;
  18. private CompareDocx fristReturn_Finally;
  19. public frmCaseFileCompare()
  20. {
  21. InitializeComponent();
  22. }
  23. private void label1_Click(object sender, EventArgs e)
  24. {
  25. }
  26. private void button1_Click(object sender, EventArgs e)
  27. {
  28. if (string.IsNullOrEmpty(this.txtCaseNo.Text))
  29. {
  30. MessageBox.Show("请输入案号!","提示框",MessageBoxButtons.OK);
  31. this.txtCaseNo.Focus();
  32. return;
  33. }
  34. var retObj1 = IPEasyUtility.DownloadCaseFiles(this.txtCaseNo.Text);
  35. string draftFile = null;
  36. string firstReFile = null;
  37. string finallyFile = null;
  38. if (((IDictionary<string, object>)retObj1).ContainsKey("finallyFile"))
  39. {
  40. if (!string.IsNullOrEmpty(retObj1.finallyFile))
  41. {
  42. if (retObj1.finallyFile.EndsWith(".zip"))
  43. {
  44. ExtractZip(retObj1.finallyFile, $"c:\\temp\\{retObj1.CaseNo}\\finallyFile");
  45. foreach (string f in Directory.GetFiles($"c:\\temp\\{retObj1.CaseNo}\\finallyFile", "*.*", SearchOption.AllDirectories))
  46. {
  47. if (f.IndexOf("定稿", StringComparison.OrdinalIgnoreCase) > 0)
  48. {
  49. finallyFile = f;
  50. break;
  51. }
  52. }
  53. }
  54. else
  55. {
  56. finallyFile = retObj1.finallyFile;
  57. }
  58. }
  59. }
  60. if (((IDictionary<string, object>)retObj1).ContainsKey("firstReturnFile"))
  61. {
  62. if (!string.IsNullOrEmpty(retObj1.firstReturnFile))
  63. {
  64. if (retObj1.firstReturnFile.EndsWith(".zip"))
  65. {
  66. ExtractZip(retObj1.firstReturnFile, $"c:\\temp\\{retObj1.CaseNo}\\firstReturnFile");
  67. foreach (string f in Directory.GetFiles($"c:\\temp\\{retObj1.CaseNo}\\firstReturnFile", "*.*", SearchOption.AllDirectories))
  68. {
  69. if (f.IndexOf("v1F", StringComparison.OrdinalIgnoreCase) > 0)
  70. {
  71. firstReFile = f;
  72. break;
  73. }
  74. }
  75. }
  76. else
  77. {
  78. firstReFile = retObj1.firstReturnFile;
  79. }
  80. }
  81. }
  82. if (((IDictionary<string, object>)retObj1).ContainsKey("draftFile"))
  83. {
  84. if (!string.IsNullOrEmpty(retObj1.draftFile))
  85. {
  86. if (retObj1.draftFile.EndsWith(".zip"))
  87. {
  88. ExtractZip(retObj1.draftFile, $"c:\\temp\\{retObj1.CaseNo}\\draftFile");
  89. foreach (string f in Directory.GetFiles($"c:\\temp\\{retObj1.CaseNo}\\draftFile", "*.*", SearchOption.AllDirectories))
  90. {
  91. if (f.IndexOf("v1r0", StringComparison.OrdinalIgnoreCase) > 0)
  92. {
  93. draftFile = f;
  94. break;
  95. }
  96. }
  97. }
  98. else
  99. {
  100. draftFile = retObj1.draftFile;
  101. }
  102. }
  103. }
  104. if(!string.IsNullOrEmpty(firstReFile) && !string.IsNullOrEmpty(draftFile))
  105. {
  106. draft_fristReturn = new CompareDocx();
  107. draft_fristReturn.Compare(draftFile, firstReFile);
  108. }
  109. if (!string.IsNullOrEmpty(firstReFile) && !string.IsNullOrEmpty(finallyFile))
  110. {
  111. fristReturn_Finally = new CompareDocx();
  112. fristReturn_Finally.Compare(firstReFile, finallyFile);
  113. }
  114. if (!string.IsNullOrEmpty(retObj1.finallyFile))
  115. File.Delete(retObj1.finallyFile);
  116. if (!string.IsNullOrEmpty(retObj1.draftFile))
  117. File.Delete(retObj1.draftFile);
  118. if (!string.IsNullOrEmpty(retObj1.draftFile))
  119. File.Delete(retObj1.firstReturnFile);
  120. if (Directory.Exists($"c:\\temp\\{retObj1.CaseNo}"))
  121. {
  122. Directory.Delete($"c:\\temp\\{retObj1.CaseNo}", true);
  123. }
  124. comboBox1.SelectedIndex = 0;
  125. }
  126. private void ExtractZip(string zipFilePath, string extractPath)
  127. {
  128. Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
  129. // 确保提取目录存在
  130. Directory.CreateDirectory(extractPath);
  131. // 使用 ZipArchive 解压缩 ZIP 文件
  132. using (FileStream zipToOpen = new FileStream(zipFilePath, FileMode.Open))
  133. {
  134. using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read, true, Encoding.GetEncoding("GB2312")))
  135. {
  136. foreach (ZipArchiveEntry entry in archive.Entries)
  137. {
  138. if (entry.FullName.EndsWith("/", StringComparison.Ordinal) || entry.FullName.EndsWith("\\", StringComparison.Ordinal))
  139. {
  140. Console.WriteLine($"目录: {entry.FullName}");
  141. }
  142. else
  143. {
  144. string entryPath = Path.Combine(extractPath, entry.FullName);
  145. Directory.CreateDirectory(new System.IO.FileInfo(entryPath).Directory.FullName);
  146. entry.ExtractToFile(entryPath, true);
  147. }
  148. }
  149. }
  150. }
  151. }
  152. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  153. {
  154. if (draft_fristReturn != null || fristReturn_Finally != null)
  155. {
  156. richTextBox1.Clear();
  157. switch (comboBox1.SelectedIndex)
  158. {
  159. case 0:
  160. string strHtml = string.Empty;
  161. if(draft_fristReturn != null)
  162. {
  163. strHtml = $"<p>初稿与第一次返稿比较结果:</p><p>初稿文件字数:{draft_fristReturn.oldDocumentCount}</p><p>删除文字数量:{draft_fristReturn.DeleteCount}</p><p>插入文字数量:{draft_fristReturn.InsertCount}</p><p>修改比率:{(draft_fristReturn.diffRate * 100).ToString("0.0000")}%</p>";
  164. }
  165. if(fristReturn_Finally != null)
  166. {
  167. strHtml = strHtml + $"<p></p><p>第一次返稿与定稿比较结果:</p><p>第一次返稿文件字数:{fristReturn_Finally.oldDocumentCount}</p><p>删除文字数量:{fristReturn_Finally.DeleteCount}</p><p>插入文字数量:{fristReturn_Finally.InsertCount}</p><p>修改比率:{(fristReturn_Finally.diffRate * 100).ToString("0.0000")}%</p>";
  168. }
  169. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
  170. break;
  171. case 1:
  172. if (draft_fristReturn != null)
  173. {
  174. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(draft_fristReturn.CompareResultString);
  175. }
  176. break;
  177. case 2:
  178. if(fristReturn_Finally!= null)
  179. {
  180. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(fristReturn_Finally.CompareResultString);
  181. }
  182. break;
  183. }
  184. }
  185. }
  186. }
  187. }