SlucovaniRozpisek/MainWindow.xaml.cs

192 lines
6.7 KiB
C#

#if !NETFRAMEWORK
using Microsoft.Win32;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Windows;
namespace SlucovaniRozpisek
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainViewModel ViewModel { get; set; }
public MainWindow()
{
InitializeComponent();
ViewModel = new MainViewModel();
this.DataContext = ViewModel;
// jen pro testování
#if (DEBUG)
ViewModel.CestaPrilohy = "C:\\Users\\klein\\Code\\_sluc test\\Přílohy";
ViewModel.CestaRozpisky = "C:\\Users\\klein\\Code\\_sluc test\\Rozpisky";
ViewModel.CestaVystup = "C:\\Users\\klein\\Code\\_sluc test\\+Přílohy s rozpiskami";
#endif
}
private void btnCestaPrilohyClick(object sender, RoutedEventArgs e)
{
OpenFolderDialog folderDialog = new OpenFolderDialog();
folderDialog.Title = "Vyberte složku s přílohami";
if (folderDialog.ShowDialog() == true)
{
ViewModel.CestaPrilohy = folderDialog.FolderName;
}
}
private void btnCestaRozpiskyClick(object sender, RoutedEventArgs e)
{
OpenFolderDialog folderDialog = new OpenFolderDialog();
folderDialog.Title = "Vyberte složku s rozpiskami";
if (folderDialog.ShowDialog() == true)
{
ViewModel.CestaRozpisky = folderDialog.FolderName;
}
}
private void btnCestaVystupClick(object sender, RoutedEventArgs e)
{
OpenFolderDialog folderDialog = new OpenFolderDialog();
folderDialog.Title = "Vyberte výstupní složku";
if (folderDialog.ShowDialog() == true)
{
ViewModel.CestaVystup = folderDialog.FolderName;
}
}
private void btnSlucRozpiskyClick(object sender, RoutedEventArgs e)
{
if (!Directory.Exists(ViewModel.CestaPrilohy))
{
MessageBox.Show("Složka s přílohami neexistuje,\nzadejte existující cestu.", "Kontrola složky",
MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (!Directory.Exists(ViewModel.CestaRozpisky))
{
MessageBox.Show("Složka s rozpiskami neexistuje,\nzadejte existující cestu.", "Kontrola složky",
MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (!Directory.Exists(ViewModel.CestaVystup))
{
MessageBox.Show("Výstupní složka neexistuje,\nzadejte existující cestu.", "Kontrola složky",
MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
if (!PomocneMetody.ObsahujePdf(ViewModel.CestaPrilohy))
{
MessageBox.Show("Složka s přílohami neobsahuje žádná PDF,\nkterá by se mohla dát sloučit.", "Kontrola existence PDF",
MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
try {
SlucovacRozpisek slucRoz = new SlucovacRozpisek();
slucRoz.PripravaRozpisky(ViewModel.CestaPrilohy, ViewModel.CestaRozpisky, out int parovePrilohy, out int neparovePrilohy, out int neparoveRozpisky);
string zprava = $"Počet párových příloh: {parovePrilohy}\nPočet nepárových příloh: {neparovePrilohy}\nPočet nepárových rozpisek: {neparoveRozpisky}";
if (MessageBox.Show(zprava, "Přejete si pokračovat?",
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
{
return;
}
slucRoz.SlucRozpisky(ViewModel.CestaPrilohy, ViewModel.CestaRozpisky, ViewModel.CestaVystup);
MessageBox.Show("Rozpisky byly úspěšně sloučeny.", "Hotovo",
MessageBoxButton.OK, MessageBoxImage.Information);
} catch (Exception ex)
{
MessageBox.Show($"Při slučování nastala chyba: {ex.Message}","Chyba", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void btnNapoveda(object sender, RoutedEventArgs e)
{
try
{
string helpFileName = "help.pdf"; // Název souboru s nápovědou
string helpFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, helpFileName);
if (File.Exists(helpFilePath))
{
Process.Start(new ProcessStartInfo(helpFilePath) { UseShellExecute = true });
}
else
{
MessageBox.Show("Soubor s nápovědou nebyl nalezen!", "Chyba", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
catch (Exception ex)
{
MessageBox.Show($"Chyba při otevírání nápovědy: {ex.Message}", "Chyba", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
public class MainViewModel : INotifyPropertyChanged
{
private string _cestaPrilohy = string.Empty; // inicializace
public string CestaPrilohy
{
get { return _cestaPrilohy; }
set
{
if (_cestaPrilohy != value)
{
_cestaPrilohy = value;
OnPropertyChanged(nameof(CestaPrilohy));
}
}
}
private string _cestaRozpisky = string.Empty; // inicializace
public string CestaRozpisky
{
get { return _cestaRozpisky; }
set
{
if (_cestaRozpisky != value)
{
_cestaRozpisky = value;
OnPropertyChanged(nameof(CestaRozpisky));
}
}
}
private string _cestaVystup = string.Empty; // inicializace
public string CestaVystup
{
get { return _cestaVystup; }
set
{
if (_cestaVystup != value)
{
_cestaVystup = value;
OnPropertyChanged(nameof(CestaVystup));
}
}
}
public event PropertyChangedEventHandler? PropertyChanged; // nullable event
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
#endif