using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.IO.Compression; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using wispro.sp.utility; namespace wispro.sp.winClient { public partial class frmCaseFileCompare : Form { private CompareDocx draft_fristReturn; private CompareDocx fristReturn_Finally; public frmCaseFileCompare() { InitializeComponent(); } private void label1_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtCaseNo.Text)) { MessageBox.Show("请输入案号!","提示框",MessageBoxButtons.OK); this.txtCaseNo.Focus(); return; } var retObj1 = IPEasyUtility.DownloadCaseFiles(this.txtCaseNo.Text); string draftFile = null; string firstReFile = null; string finallyFile = null; if (((IDictionary)retObj1).ContainsKey("finallyFile")) { if (!string.IsNullOrEmpty(retObj1.finallyFile)) { if (retObj1.finallyFile.EndsWith(".zip")) { ExtractZip(retObj1.finallyFile, $"c:\\temp\\{retObj1.CaseNo}\\finallyFile"); foreach (string f in Directory.GetFiles($"c:\\temp\\{retObj1.CaseNo}\\finallyFile", "*.*", SearchOption.AllDirectories)) { if (f.IndexOf("定稿", StringComparison.OrdinalIgnoreCase) > 0) { finallyFile = f; break; } } } else { finallyFile = retObj1.finallyFile; } } } if (((IDictionary)retObj1).ContainsKey("firstReturnFile")) { if (!string.IsNullOrEmpty(retObj1.firstReturnFile)) { if (retObj1.firstReturnFile.EndsWith(".zip")) { ExtractZip(retObj1.firstReturnFile, $"c:\\temp\\{retObj1.CaseNo}\\firstReturnFile"); foreach (string f in Directory.GetFiles($"c:\\temp\\{retObj1.CaseNo}\\firstReturnFile", "*.*", SearchOption.AllDirectories)) { if (f.IndexOf("v1F", StringComparison.OrdinalIgnoreCase) > 0) { firstReFile = f; break; } } } else { firstReFile = retObj1.firstReturnFile; } } } if (((IDictionary)retObj1).ContainsKey("draftFile")) { if (!string.IsNullOrEmpty(retObj1.draftFile)) { if (retObj1.draftFile.EndsWith(".zip")) { ExtractZip(retObj1.draftFile, $"c:\\temp\\{retObj1.CaseNo}\\draftFile"); foreach (string f in Directory.GetFiles($"c:\\temp\\{retObj1.CaseNo}\\draftFile", "*.*", SearchOption.AllDirectories)) { if (f.IndexOf("v1r0", StringComparison.OrdinalIgnoreCase) > 0) { draftFile = f; break; } } } else { draftFile = retObj1.draftFile; } } } if(!string.IsNullOrEmpty(firstReFile) && !string.IsNullOrEmpty(draftFile)) { draft_fristReturn = new CompareDocx(); draft_fristReturn.Compare(draftFile, firstReFile); } if (!string.IsNullOrEmpty(firstReFile) && !string.IsNullOrEmpty(finallyFile)) { fristReturn_Finally = new CompareDocx(); fristReturn_Finally.Compare(firstReFile, finallyFile); } try { if (!string.IsNullOrEmpty(retObj1.finallyFile)) File.Delete(retObj1.finallyFile); } catch { } try { if (!string.IsNullOrEmpty(retObj1.draftFile)) File.Delete(retObj1.draftFile); } catch { } try { if (!string.IsNullOrEmpty(retObj1.draftFile)) File.Delete(retObj1.firstReturnFile); } catch { } if (Directory.Exists($"c:\\temp\\{retObj1.CaseNo}")) { Directory.Delete($"c:\\temp\\{retObj1.CaseNo}", true); } lblMsg.Text = string.Empty; if (string.IsNullOrEmpty(draftFile)) { lblMsg.Text = "初稿文件没有找到"; } if (string.IsNullOrEmpty(firstReFile)) { lblMsg.Text = $"{lblMsg.Text},第一次返稿文件没有找到!"; } if (string.IsNullOrEmpty(finallyFile)) { lblMsg.Text = $"{lblMsg.Text},定稿文件没有找到!"; } comboBox1.SelectedIndex = 0; } private void ExtractZip(string zipFilePath, string extractPath) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // 确保提取目录存在 Directory.CreateDirectory(extractPath); // 使用 ZipArchive 解压缩 ZIP 文件 using (FileStream zipToOpen = new FileStream(zipFilePath, FileMode.Open)) { using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Read, true, Encoding.GetEncoding("GB2312"))) { foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.FullName.EndsWith("/", StringComparison.Ordinal) || entry.FullName.EndsWith("\\", StringComparison.Ordinal)) { Console.WriteLine($"目录: {entry.FullName}"); } else { string entryPath = Path.Combine(extractPath, entry.FullName); Directory.CreateDirectory(new System.IO.FileInfo(entryPath).Directory.FullName); entry.ExtractToFile(entryPath, true); } } } } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (draft_fristReturn != null || fristReturn_Finally != null) { richTextBox1.Clear(); switch (comboBox1.SelectedIndex) { case 0: string strHtml = string.Empty; if(draft_fristReturn != null) { strHtml = $"

初稿与第一次返稿比较结果:

初稿文件字数:{draft_fristReturn.oldDocumentCount}

删除文字数量:{draft_fristReturn.DeleteCount}

插入文字数量:{draft_fristReturn.InsertCount}

修改比率:{(draft_fristReturn.diffRate * 100).ToString("0.0000")}%

"; } if(fristReturn_Finally != null) { strHtml = strHtml + $"

第一次返稿与定稿比较结果:

第一次返稿文件字数:{fristReturn_Finally.oldDocumentCount}

删除文字数量:{fristReturn_Finally.DeleteCount}

插入文字数量:{fristReturn_Finally.InsertCount}

修改比率:{(fristReturn_Finally.diffRate * 100).ToString("0.0000")}%

"; } richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml); break; case 1: if (draft_fristReturn != null) { richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(draft_fristReturn.CompareResultString); } break; case 2: if(fristReturn_Finally!= null) { richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(fristReturn_Finally.CompareResultString); } break; } } } } }