Excel Vergleich jetzt mit Speicherdialog

This commit is contained in:
Daniel Schick 2022-09-21 17:48:43 +02:00
parent eb001c78bc
commit 6ca0a5dda9
5 changed files with 30 additions and 17 deletions

View File

@ -72,7 +72,7 @@ namespace ENI2.DetailViewControls
this.textBoxENI.IsReadOnly = !iAmAdmin; this.textBoxENI.IsReadOnly = !iAmAdmin;
this.textBoxIMO.IsReadOnly = !iAmAdmin; this.textBoxIMO.IsReadOnly = !iAmAdmin;
this.locodePoC.IsEnabled = iAmAdmin; this.locodePoC.IsEnabled = iAmAdmin;
this.textBoxDisplayId.IsReadOnly = !iAmAdmin; this.textBoxDisplayId.IsReadOnly = !iAmAdmin;
this.textBoxENI.DataContext = this.Core; this.textBoxENI.DataContext = this.Core;
this.textBoxIMO.DataContext = this.Core; this.textBoxIMO.DataContext = this.Core;

View File

@ -3,6 +3,7 @@
// //
using bsmd.database; using bsmd.database;
using Microsoft.Win32;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@ -174,15 +175,26 @@ namespace ENI2.EditControls
private void buttonCompare_Click(object sender, RoutedEventArgs e) private void buttonCompare_Click(object sender, RoutedEventArgs e)
{ {
Util.UIHelper.SetBusyState(); Util.UIHelper.SetBusyState();
string resultPath = Excel.ExcelComparer.Compare(_sourcePath, _targetPath, out string errorMessage);
if(!errorMessage.IsNullOrEmpty()) { string defaultName = string.Format("{0}.xlsx", Guid.NewGuid().ToString());
MessageBox.Show(errorMessage, "Comparison error", MessageBoxButton.OK, MessageBoxImage.Warning); SaveFileDialog sfd = new SaveFileDialog
}
if(File.Exists(resultPath))
{ {
if(new FileInfo(resultPath).Length > 0) Filter = "Excel Files|*.xls;*.xlsx",
FileName = defaultName
};
if (sfd.ShowDialog() ?? false)
{
string resultPath = Excel.ExcelComparer.Compare(_sourcePath, _targetPath, sfd.FileName, out string errorMessage);
if (!errorMessage.IsNullOrEmpty()) {
MessageBox.Show(errorMessage, "Comparison error", MessageBoxButton.OK, MessageBoxImage.Warning);
}
if (File.Exists(resultPath))
{ {
Process.Start(resultPath); if (new FileInfo(resultPath).Length > 0)
{
Process.Start(resultPath);
}
} }
} }

View File

@ -23,7 +23,7 @@ namespace ENI2.EditControls
{ {
InitializeComponent(); InitializeComponent();
Loaded += CopyDeclarationDialog_Loaded; Loaded += CopyDeclarationDialog_Loaded;
} }
#region Properties #region Properties

View File

@ -38,7 +38,7 @@ namespace ENI2.EditControls
this.EnableOK(false); this.EnableOK(false);
this.locodePoC.PropertyChanged += LocodePoC_PropertyChanged; this.locodePoC.PropertyChanged += LocodePoC_PropertyChanged;
} }
private void VisitIdDialog_OKClicked() private void VisitIdDialog_OKClicked()
{ {

View File

@ -61,17 +61,16 @@ namespace ENI2.Excel
return columnName; return columnName;
} }
public static string Compare(string sourcePath, string targetPath, out string errorMessage) public static string Compare(string sourcePath, string targetPath, string comparisonFileName, out string errorMessage)
{ {
string fileName = Path.GetTempPath() + Guid.NewGuid().ToString() + ".xlsx";
errorMessage = ""; errorMessage = "";
int counter = 0; int counter = 0;
try try
{ {
File.Copy(targetPath, fileName); File.Copy(targetPath, comparisonFileName);
ExcelReader source = new ExcelReader(sourcePath, true, false); ExcelReader source = new ExcelReader(sourcePath, true, false);
ExcelReader comparison = new ExcelReader(fileName, false, false); ExcelReader comparison = new ExcelReader(comparisonFileName, false, false);
/* erste Variante Vergleich über Namen der Zellen /* erste Variante Vergleich über Namen der Zellen
@ -182,7 +181,9 @@ namespace ENI2.Excel
} }
} }
comparison.Save(fileName); comparison.Save(comparisonFileName);
source.Dispose();
comparison.Dispose();
errorMessage = string.Format("{0} differences found", counter); errorMessage = string.Format("{0} differences found", counter);
} }
catch (Exception ex) catch (Exception ex)
@ -190,7 +191,7 @@ namespace ENI2.Excel
errorMessage = ex.Message; errorMessage = ex.Message;
} }
return fileName; return comparisonFileName;
} }
} }