123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607 |
- using ICSharpCode.SharpZipLib.Tar;
- 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;
- using SharpCompress.Archives;
- using SharpCompress.Archives.Rar;
- using SharpCompress.Common;
- using System.Collections;
- 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);
- }
- return;
- 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);
- }
- }
- }
- }
- }
- public static void ExtractRarFile(string rarPath, string outputPath)
- {
- try
- {
- // 确保输出目录存在
- Directory.CreateDirectory(outputPath);
- // 打开RAR文件
- using (var archive = RarArchive.Open(rarPath))
- {
- // 遍历所有文件
- foreach (var entry in archive.Entries)
- {
- if (!entry.IsDirectory)
- {
- // 构建完整输出路径
- string outputFilePath = Path.Combine(outputPath, entry.Key);
- // 确保输出文件的目录存在
- Directory.CreateDirectory(Path.GetDirectoryName(outputFilePath));
- // 解压文件
- entry.WriteToFile(outputFilePath, new ExtractionOptions
- {
- ExtractFullPath = true,
- Overwrite = true
- });
- }
- }
- }
- }
- catch (Exception ex)
- {
- throw new Exception($"解压RAR文件时出错: {ex.Message}");
- }
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (draft_fristReturn != null || fristReturn_Finally != null)
- {
- richTextBox1.Clear();
- string strHtml = string.Empty;
- switch (comboBox1.SelectedIndex)
- {
- case 0:
- if (draft_fristReturn != null)
- {
- strHtml = $"<b>所有文字比较:</b><br/><p>初稿与第一次返稿比较结果:</p><p>初稿文件字数:{draft_fristReturn.AllStringResult.oldWordCount}</p><p>删除文字数量:{draft_fristReturn.AllStringResult.DeleteCount}</p><p>插入文字数量:{draft_fristReturn.AllStringResult.InsertCount}</p><p>修改比率:{(draft_fristReturn.AllStringResult.diffRate * 100).ToString("0.0000")}%</p><p>文档语义相似度:{(draft_fristReturn.AllStringResult.TextSimilarity*100).ToString("0.0000")}%</p>";
- }
- if (fristReturn_Finally != null)
- {
- strHtml = strHtml + $"<p></p><p>第一次返稿与定稿比较结果:</p><p>第一次返稿文件字数:{fristReturn_Finally.AllStringResult.oldWordCount}</p><p>删除文字数量:{fristReturn_Finally.AllStringResult.DeleteCount}</p><p>插入文字数量:{fristReturn_Finally.AllStringResult.InsertCount}</p><p>修改比率:{(fristReturn_Finally.AllStringResult.diffRate * 100).ToString("0.0000")}%</p><p>文档语义相似度:{(fristReturn_Finally.AllStringResult.TextSimilarity * 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.AllStringResult.CompareResultString);
- }
- break;
- case 2:
- if (fristReturn_Finally != null)
- {
- richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(fristReturn_Finally.AllStringResult.CompareResultString);
- }
- break;
- case 3:
- if (draft_fristReturn != null)
- {
- strHtml = $"<b>摘要比较:</b><br/><p>初稿与第一次返稿比较结果:</p><p>初稿文件字数:{draft_fristReturn.AbstractResult.oldWordCount}</p><p>删除文字数量:{draft_fristReturn.AbstractResult.DeleteCount}</p><p>插入文字数量:{draft_fristReturn.AbstractResult.InsertCount}</p><p>修改比率:{(draft_fristReturn.AbstractResult.diffRate * 100).ToString("0.0000")}%</p><p>语义相似度:{(draft_fristReturn.AbstractResult.TextSimilarity * 100).ToString("0.0000")}%</p>";
- }
- if (fristReturn_Finally != null)
- {
- strHtml = strHtml + $"<p></p><p>第一次返稿与定稿比较结果:</p><p>第一次返稿文件字数:{fristReturn_Finally.AbstractResult.oldWordCount}</p><p>删除文字数量:{fristReturn_Finally.AbstractResult.DeleteCount}</p><p>插入文字数量:{fristReturn_Finally.AbstractResult.InsertCount}</p><p>修改比率:{(fristReturn_Finally.AbstractResult.diffRate * 100).ToString("0.0000")}%</p><p>语义相似度:{(fristReturn_Finally.AbstractResult.TextSimilarity * 100).ToString("0.0000")}%</p>";
- }
- richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
- break;
- case 4:
- if (draft_fristReturn != null)
- {
- richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(draft_fristReturn.AbstractResult.CompareResultString);
- }
- break;
- case 5:
- if (fristReturn_Finally != null)
- {
- richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(fristReturn_Finally.AbstractResult.CompareResultString);
- }
- break;
- case 6:
- if (draft_fristReturn != null)
- {
- strHtml = $"<b>权力要求比较:</b><br/><p>初稿与第一次返稿比较结果:</p><p>初稿文件字数:{draft_fristReturn.ClaimResult.oldWordCount}</p><p>删除文字数量:{draft_fristReturn.ClaimResult.DeleteCount}</p><p>插入文字数量:{draft_fristReturn.ClaimResult.InsertCount}</p><p>修改比率:{(draft_fristReturn.ClaimResult.diffRate * 100).ToString("0.0000")}%</p><p>语义相似度:{(draft_fristReturn.ClaimResult.TextSimilarity * 100).ToString("0.0000")}%</p>";
- }
- if (fristReturn_Finally != null)
- {
- strHtml = strHtml + $"<p></p><p>第一次返稿与定稿比较结果:</p><p>第一次返稿文件字数:{fristReturn_Finally.ClaimResult.oldWordCount}</p><p>删除文字数量:{fristReturn_Finally.ClaimResult.DeleteCount}</p><p>插入文字数量:{fristReturn_Finally.ClaimResult.InsertCount}</p><p>修改比率:{(fristReturn_Finally.ClaimResult.diffRate * 100).ToString("0.0000")}%</p><p>语义相似度:{(fristReturn_Finally.ClaimResult.TextSimilarity * 100).ToString("0.0000")}%</p>";
- }
- richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
- break;
- case 7:
- if (draft_fristReturn != null)
- {
- richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(draft_fristReturn.ClaimResult.CompareResultString);
- }
- break;
- case 8:
- if (fristReturn_Finally != null)
- {
- richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(fristReturn_Finally.ClaimResult.CompareResultString);
- }
- break;
- case 9:
- if (draft_fristReturn != null)
- {
- strHtml = $"<b>说明书比较:</b><br/><p>初稿与第一次返稿比较结果:</p><p>初稿文件字数:{draft_fristReturn.FulltextResult.oldWordCount}</p><p>删除文字数量:{draft_fristReturn.FulltextResult.DeleteCount}</p><p>插入文字数量:{draft_fristReturn.FulltextResult.InsertCount}</p><p>修改比率:{(draft_fristReturn.FulltextResult.diffRate * 100).ToString("0.0000")}%</p><p>语义相似度:{(draft_fristReturn.FulltextResult.TextSimilarity * 100).ToString("0.0000")}%</p>";
- }
- if (fristReturn_Finally != null)
- {
- strHtml = strHtml + $"<p></p><p>第一次返稿与定稿比较结果:</p><p>第一次返稿文件字数:{fristReturn_Finally.FulltextResult.oldWordCount}</p><p>删除文字数量:{fristReturn_Finally.FulltextResult.DeleteCount}</p><p>插入文字数量:{fristReturn_Finally.FulltextResult.InsertCount}</p><p>修改比率:{(fristReturn_Finally.FulltextResult.diffRate * 100).ToString("0.0000")}%</p><p>语义相似度:{(fristReturn_Finally.FulltextResult.TextSimilarity * 100).ToString("0.0000")}%</p>";
- }
- richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(strHtml);
- break;
- case 10:
- if (draft_fristReturn != null)
- {
- richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(draft_fristReturn.FulltextResult.CompareResultString);
- }
- break;
- case 11:
- if (fristReturn_Finally != null)
- {
- richTextBox1.Rtf = new HtmlToRtfConverter().ConvertHtmlToRtf(fristReturn_Finally.FulltextResult.CompareResultString);
- }
- break;
- }
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- if(openFileDialog.ShowDialog() == DialogResult.OK)
- {
- string strPath = openFileDialog.FileName.ToLower().Replace(".rar", "").Replace(".zip","");
- if(openFileDialog.FileName.Contains(".rar"))
- {
- ExtractRarFile(openFileDialog.FileName, strPath);
- }
- else
- {
- ExtractZip(openFileDialog.FileName,strPath);
- }
-
- string[] files = Directory.EnumerateFiles(strPath, "*.*", SearchOption.AllDirectories).ToArray<string>();
- Array.Sort(files);
- Array.Reverse(files);
- draft_fristReturn = new CompareDocx();
- draft_fristReturn.Compare(files[0], files[1]);
- if (files.Length > 2)
- {
- fristReturn_Finally = new CompareDocx();
- fristReturn_Finally.Compare(files[1], files[2]);
- }
- SaveResult(strPath,draft_fristReturn);
- SaveResult(strPath, fristReturn_Finally);
- }
- }
- private void SaveResult(string strPath,CompareDocx draft_fristReturn)
- {
- string strHtml = @"<!DOCTYPE html>
- <html lang=""en"">
- <head>
- <meta charset=""utf-8"">
- <meta http-equiv=""X-UA-Compatible"" content=""IE=edge"">
- <meta name=""description"" content=""email code"">
- <meta name=""viewport"" content=""width=device-width, initial-scale=1"">
- <title>对比结果</title>
- <script>
- function toggleDiv() {
-
- var radio = document.querySelector('input[name=""options""]:checked');
- if(!radio){
- return
- }
- var value = radio.value
- var div = document.getElementById('resultContent');
- var childrenDom = div.children
- if(!childrenDom || childrenDom.length==0){
- return
- }
- for(var i = 0;i<childrenDom.length;i++){
- var dom = childrenDom[i]
- if(dom.id == value){
- dom.className = 'checked'
- }else{
- dom.className = ''
- }
- }
- }
- </script>
- </head>
- <!--对比结果模板-->
- <body>
- <div class=""contrastResult"">
- <form action="""">
- <div>
- <label for=""originalFile"">原文件:</label>
- <span id=""originalFile"">{0}</span>
- </div>
- <div>
- <label for=""contrastFile"">对比文件:</label>
- <span id=""contrastFile"">{1}</span>
- </div>
- <div>
- <label for=""result"">对比结果:</label>
- <div id=""result"">
- <table>
- <thead>
- <tr>
- <td></td>
- <td>全部对比</td>
- <td>摘要</td>
- <td>权利要求</td>
- <td>说明书</td>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>原文字数</td>
- <td>{2}</td>
- <td>{3}</td>
- <td>{4}</td>
- <td>{5}</td>
- </tr>
- <tr>
- <td>删除字数</td>
- <td>{6}</td>
- <td>{7}</td>
- <td>{8}</td>
- <td>{9}</td>
- </tr>
- <tr>
- <td>插入字数</td>
- <td>{10}</td>
- <td>{11}</td>
- <td>{12}</td>
- <td>{13}</td>
- </tr>
- <tr>
- <td>修改比例</td>
- <td>{14}</td>
- <td>{15}</td>
- <td>{16}</td>
- <td>{17}</td>
- </tr>
- <tr>
- <td>语义相似度</td>
- <td>{18}</td>
- <td>{19}</td>
- <td>{20}</td>
- <td>{21}</td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- <div class=""resultType"">
- <label for="""">结果:</label>
- <input type=""radio"" name=""options"" value=""allContrast"" id=""allContrast"" checked onchange=""toggleDiv()"">
- <label for=""allContrast"">全部对比</label>
- <input type=""radio"" name=""options"" value=""abstract"" id=""abstract"" onchange=""toggleDiv()"">
- <label for=""abstract"">摘要</label>
- <input type=""radio"" name=""options"" value=""claim"" id=""claim"" onchange=""toggleDiv()"">
- <label for=""claim"">权利要求</label>
- <input type=""radio"" name=""options"" value=""instructions"" id=""instructions"" onchange=""toggleDiv()"">
- <label for=""instructions"">说明书</label>
- </div>
- <div id=""resultContent"">
- <div id=""allContrast"">{22}</div>
- <div id=""abstract"">{23}</div>
- <div id=""claim"">{24}</div>
- <div id=""instructions"">{25}</div>
- </div>
- </form>
-
- </div>
- <script>
- toggleDiv();
- </script>
- </body>
- <style>
- .contrastResult{
- width: 1000px;
- margin: 0 auto;
- padding: 50px 0;
- }
- div{
- margin: 20px 0 ;
- }
- table{
- width: 100%;
- table-layout: fixed;
- border-collapse: collapse;
- }
- table td{
- border: 1px solid black;
- padding: 10px;
- }
- table thead td{
- text-align: center;
- }
- table tr>td:first-child{
- width: 120px;
- }
- #resultContent>div{
- display: none;
- overflow:auto;
- height:400px;
- }
- .checked{
- display: block !important;
- }
- </style>
- </html>";
- if (draft_fristReturn != null)
- {
- var temHtml = strHtml
- .Replace("{0}", new FileInfo(draft_fristReturn.oldDocument.FilePath).Name)
- .Replace("{1}", new FileInfo(draft_fristReturn.newDocument.FilePath).Name)
- .Replace("{2}", draft_fristReturn.AllStringResult.oldWordCount.ToString())
- .Replace("{3}", draft_fristReturn.AbstractResult.oldWordCount.ToString())
- .Replace("{4}", draft_fristReturn.ClaimResult.oldWordCount.ToString())
- .Replace("{5}", draft_fristReturn.FulltextResult.oldWordCount.ToString())
- .Replace("{6}", draft_fristReturn.AllStringResult.DeleteCount.ToString())
- .Replace("{7}", draft_fristReturn.AbstractResult.DeleteCount.ToString())
- .Replace("{8}", draft_fristReturn.ClaimResult.DeleteCount.ToString())
- .Replace("{9}", draft_fristReturn.FulltextResult.DeleteCount.ToString())
- .Replace("{10}", draft_fristReturn.AllStringResult.InsertCount.ToString())
- .Replace("{11}", draft_fristReturn.AbstractResult.InsertCount.ToString())
- .Replace("{12}", draft_fristReturn.ClaimResult.InsertCount.ToString())
- .Replace("{13}", draft_fristReturn.FulltextResult.InsertCount.ToString())
- .Replace("{14}", (draft_fristReturn.AllStringResult.diffRate * 100).ToString("0.0000") + "%")
- .Replace("{15}", (draft_fristReturn.AbstractResult.diffRate * 100).ToString("0.0000") + "%")
- .Replace("{16}", (draft_fristReturn.ClaimResult.diffRate * 100).ToString("0.0000") + "%")
- .Replace("{17}", (draft_fristReturn.FulltextResult.diffRate * 100).ToString("0.0000") + "%")
- .Replace("{18}", (draft_fristReturn.AllStringResult.TextSimilarity * 100).ToString("0.0000") + "%")
- .Replace("{19}", (draft_fristReturn.AbstractResult.TextSimilarity * 100).ToString("0.0000") + "%")
- .Replace("{20}", (draft_fristReturn.ClaimResult.TextSimilarity * 100).ToString("0.0000") + "%")
- .Replace("{21}", (draft_fristReturn.FulltextResult.TextSimilarity * 100).ToString("0.0000") + "%")
- .Replace("{22}", draft_fristReturn.AllStringResult.CompareResultString)
- .Replace("{23}", draft_fristReturn.AbstractResult.CompareResultString)
- .Replace("{24}", draft_fristReturn.ClaimResult.CompareResultString)
- .Replace("{25}", draft_fristReturn.FulltextResult.CompareResultString);
- string fileName = $"{new FileInfo(draft_fristReturn.oldDocument.FilePath).Name}_{new FileInfo(draft_fristReturn.newDocument.FilePath).Name}.html";
- using (var f = File.CreateText(Path.Combine(strPath, fileName)))
- {
- f.Write(temHtml);
- }
- }
- }
- }
- }
|