// Copyright (c) 2017- schick Informatik // Description: Dialogbox zum Vergleichen zweier Excel via Named cells // using bsmd.database; using System; using System.Diagnostics; using System.IO; using System.Windows; namespace ENI2.EditControls { /// /// Interaction logic for CompareExcelDialog.xaml /// public partial class CompareExcelDialog : Controls.StatusWindowBase { #region Fields private string _sourcePath = null; private string _targetPath = null; #endregion public CompareExcelDialog() { InitializeComponent(); } #region Drag&Drop event handler private void imageSource_Drop(object sender, DragEventArgs e) { string[] files = (string[]) e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) Console.WriteLine(file); if(files.Length > 0) { if(File.Exists(files[0])) { if(files[0].EndsWith("xls") || files[0].EndsWith("xlsx")) { _sourcePath = files[0]; textBoxSource.Text = _sourcePath; } else { textBoxSource.Text = null; _sourcePath = null; } } else { textBoxSource.Text = null; _sourcePath = null; } EnableCompareButton(); } } private void imageTarget_Drop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) Console.WriteLine(file); if (files.Length > 0) { if (File.Exists(files[0])) { if (files[0].EndsWith("xls") || files[0].EndsWith("xlsx")) { _targetPath = files[0]; textBoxTarget.Text = _targetPath; } else { _targetPath = null; textBoxTarget.Text = null; } } else { _targetPath = null; textBoxTarget.Text = null; } EnableCompareButton(); } } private void imageSource_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effects = DragDropEffects.Copy; } } private void textBoxSource_PreviewDragOver(object sender, DragEventArgs e) { e.Handled = true; } #endregion #region private methods private void EnableCompareButton() { this.buttonCompare.IsEnabled = (_targetPath != null) && (_sourcePath != null); } #endregion #region Comparison button handler logic private void buttonCompare_Click(object sender, RoutedEventArgs e) { Util.UIHelper.SetBusyState(); string resultPath = Excel.ExcelComparer.Compare(_sourcePath, _targetPath, out string errorMessage); if(!errorMessage.IsNullOrEmpty()) { MessageBox.Show(errorMessage, "Comparison error", MessageBoxButton.OK, MessageBoxImage.Warning); } if(File.Exists(resultPath)) { if(new FileInfo(resultPath).Length > 0) { Process.Start(resultPath); } } // reset input values this.textBoxSource.Text = null; this.textBoxTarget.Text = null; this._sourcePath = null; this._targetPath = null; EnableCompareButton(); this.Close(); } #endregion } }