123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- 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<string, object>)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<string, object>)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<string, object>)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);
- }
-
- if (!string.IsNullOrEmpty(retObj1.finallyFile))
- File.Delete(retObj1.finallyFile);
- if (!string.IsNullOrEmpty(retObj1.draftFile))
- File.Delete(retObj1.draftFile);
- if (!string.IsNullOrEmpty(retObj1.draftFile))
- File.Delete(retObj1.firstReturnFile);
- if (Directory.Exists($"c:\\temp\\{retObj1.CaseNo}"))
- {
- Directory.Delete($"c:\\temp\\{retObj1.CaseNo}", true);
- }
- 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 = $"<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>";
- }
-
- if(fristReturn_Finally != null)
- {
- 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>";
- }
- 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;
- }
- }
- }
- }
- }
|