frmCaseFileCompare.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. try
  115. {
  116. if (!string.IsNullOrEmpty(retObj1.finallyFile))
  117. File.Delete(retObj1.finallyFile);
  118. }
  119. catch { }
  120. try
  121. {
  122. if (!string.IsNullOrEmpty(retObj1.draftFile))
  123. File.Delete(retObj1.draftFile);
  124. }
  125. catch { }
  126. try
  127. {
  128. if (!string.IsNullOrEmpty(retObj1.draftFile))
  129. File.Delete(retObj1.firstReturnFile);
  130. }
  131. catch { }
  132. if (Directory.Exists($"c:\\temp\\{retObj1.CaseNo}"))
  133. {
  134. Directory.Delete($"c:\\temp\\{retObj1.CaseNo}", true);
  135. }
  136. lblMsg.Text = string.Empty;
  137. if (string.IsNullOrEmpty(draftFile))
  138. {
  139. lblMsg.Text = "初稿文件没有找到";
  140. }
  141. if (string.IsNullOrEmpty(firstReFile))
  142. {
  143. lblMsg.Text = $"{lblMsg.Text},第一次返稿文件没有找到!";
  144. }
  145. if (string.IsNullOrEmpty(finallyFile))
  146. {
  147. lblMsg.Text = $"{lblMsg.Text},定稿文件没有找到!";
  148. }
  149. comboBox1.SelectedIndex = 0;
  150. }
  151. private void ExtractZip(string zipFilePath, string extractPath)
  152. {
  153. Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
  154. // 确保提取目录存在
  155. Directory.CreateDirectory(extractPath);
  156. // 使用 ZipArchive 解压缩 ZIP 文件
  157. using (FileStream zipToOpen = new FileStream(zipFilePath, FileMode.Open))
  158. {
  159. using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read, true, Encoding.GetEncoding("GB2312")))
  160. {
  161. foreach (ZipArchiveEntry entry in archive.Entries)
  162. {
  163. if (entry.FullName.EndsWith("/", StringComparison.Ordinal) || entry.FullName.EndsWith("\\", StringComparison.Ordinal))
  164. {
  165. Console.WriteLine($"目录: {entry.FullName}");
  166. }
  167. else
  168. {
  169. string entryPath = Path.Combine(extractPath, entry.FullName);
  170. Directory.CreateDirectory(new System.IO.FileInfo(entryPath).Directory.FullName);
  171. entry.ExtractToFile(entryPath, true);
  172. }
  173. }
  174. }
  175. }
  176. }
  177. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  178. {
  179. if (draft_fristReturn != null || fristReturn_Finally != null)
  180. {
  181. richTextBox1.Clear();
  182. switch (comboBox1.SelectedIndex)
  183. {
  184. case 0:
  185. string strHtml = string.Empty;
  186. if(draft_fristReturn != null)
  187. {
  188. 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>";
  189. }
  190. if(fristReturn_Finally != null)
  191. {
  192. 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>";
  193. }
  194. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
  195. break;
  196. case 1:
  197. if (draft_fristReturn != null)
  198. {
  199. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(draft_fristReturn.CompareResultString);
  200. }
  201. break;
  202. case 2:
  203. if(fristReturn_Finally!= null)
  204. {
  205. richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(fristReturn_Finally.CompareResultString);
  206. }
  207. break;
  208. }
  209. }
  210. }
  211. }
  212. }