using Microsoft.Win32; using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Windows; namespace SlucovaniRozpisek { /// /// Interaction logic for MainWindow.xaml /// 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 = "d:\\Přesunuté\\.NET\\Csharp_výuka\\SlucovaniPDF\\Přílohy"; ViewModel.CestaRozpisky = "d:\\Přesunuté\\.NET\\Csharp_výuka\\SlucovaniPDF\\Rozpisky"; ViewModel.CestaVystup = "d:\\Přesunuté\\.NET\\Csharp_výuka\\SlucovaniPDF\\Výstup"; #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; } List lstPrilohy = PomocneMetody.NactiPdfNazvyBezKoncovky(ViewModel.CestaPrilohy); List lstRozpisky = PomocneMetody.NactiPdfNazvyBezKoncovky(ViewModel.CestaRozpisky); PdfRozdelovac pdfka = new PdfRozdelovac(lstPrilohy, lstRozpisky); if (MessageBox.Show(pdfka.Zprava, "Přejete si pokračovat?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } string cestaPrilohysLomitkem = PomocneMetody.NormalizujCestu(ViewModel.CestaPrilohy); string cestaRozpiskysLomitkem = PomocneMetody.NormalizujCestu(ViewModel.CestaRozpisky); string cestaVystupsLomitkem = PomocneMetody.NormalizujCestu(ViewModel.CestaVystup); foreach (string pdf in pdfka.NeparovePrilohy) { PomocneMetody.KopirujSoubor(cestaPrilohysLomitkem + pdf + ".pdf", cestaVystupsLomitkem + pdf + ".pdf", true); } foreach (string pdf in pdfka.NeparoveRozpisky) { PomocneMetody.KopirujSoubor(cestaRozpiskysLomitkem + pdf + ".pdf", cestaVystupsLomitkem + pdf + ".pdf", true); } foreach (string pdf in pdfka.ParovePrilohy) { PomocneMetody.SloucitPdf(cestaPrilohysLomitkem + pdf + ".pdf", cestaRozpiskysLomitkem + pdf + "_rozpiska.pdf", cestaVystupsLomitkem + pdf + ".pdf", true); } MessageBox.Show("Rozpisky byly úspěšně sloučeny.", "Hotovo", MessageBoxButton.OK, MessageBoxImage.Information); } 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)); } } }