From 583a09838e866f25ce87f0eda7a2c6e493d4544f Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Thu, 27 Nov 2025 15:19:48 +0100 Subject: [PATCH] Priprava projektu pro manipulaci ve VBA --- .drone.yml | 37 ++++ App.xaml | 4 +- App.xaml.cs | 2 +- AssemblyInfo.cs | 33 +++ ILRepack.targets | 22 ++ icopdf.ico => Logo.ico | Bin MainWindow.xaml | 2 +- MainWindow.xaml.cs | 56 ++--- PdfRozdelovac.cs | 4 - PomocneMetody.cs | 23 +- Product.wxs | 203 ++++++++++++++++++ Setup.wixproj | 46 ++++ Slucovac.cs | 62 ++++++ SlucovaniRozpisek.csproj | 23 +- ...ování rozpisek.sln => SlucovaniRozpisek.sln | 0 key.snk | Bin 0 -> 1172 bytes 16 files changed, 457 insertions(+), 60 deletions(-) create mode 100644 .drone.yml create mode 100644 ILRepack.targets rename icopdf.ico => Logo.ico (100%) create mode 100644 Product.wxs create mode 100644 Setup.wixproj create mode 100644 Slucovac.cs rename Slučování rozpisek.sln => SlucovaniRozpisek.sln (100%) create mode 100644 key.snk diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..38742d3 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,37 @@ +kind: pipeline +name: default + +steps: + - name: build + image: mcr.microsoft.com/dotnet/sdk:9.0 + commands: + - dotnet build --configuration Release SlucovaniRozpisek.csproj + + - name: installer + image: git.ivasoft.cz/sw/docker-wine-dotnet + commands: + - wine tlbexp.exe bin/Release/net472/SlucovaniRozpisek.dll /out:bin/Release/net472/SlucovaniRozpisek.tlb + - wine Eazfuscator.NET.exe bin/Release/net9.0-windows/SlucovaniRozpisek.dll -k key.snk -n --newline-flush + # HACK Second build is success as first invocation fails + # dotnet exec msi validate build.sh + # HACK Until dotnet 9 get released and have the bug https://github.com/dotnet/runtime/issues/98441 fixed + - apt update && apt install socat + - chmod +x build.sh + - socat -u EXEC:"./build.sh",pty,stderr,sigint,setsid,sane - + when: + event: tag + + - name: gitea_release + image: plugins/gitea-release + settings: + api_key: + from_secret: drone_release + base_url: https://git.exprojekt.cz + files: 'bin/Release/**/*.msi' + when: + event: tag \ No newline at end of file diff --git a/App.xaml b/App.xaml index 35759a2..91456e0 100644 --- a/App.xaml +++ b/App.xaml @@ -1,7 +1,7 @@ - diff --git a/App.xaml.cs b/App.xaml.cs index 95ca443..e3ef626 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -2,7 +2,7 @@ using System.Data; using System.Windows; -namespace Slučování_rozpisek +namespace SlucovaniRozpisek { /// /// Interaction logic for App.xaml diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs index b0ec827..259ccd5 100644 --- a/AssemblyInfo.cs +++ b/AssemblyInfo.cs @@ -1,5 +1,8 @@ +using System.Reflection; +using System.Runtime.InteropServices; using System.Windows; +#if false // !NETFRAMEWORK [assembly: ThemeInfo( ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located //(used if a resource is not found in the page, @@ -8,3 +11,33 @@ using System.Windows; //(used if a resource is not found in the page, // app, or any theme specific resource dictionaries) )] +#endif + +[assembly: AssemblyTitle("Slucovani Rozpisek")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("EXprojekt s.r.o.")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Copyright © 2025 EXProjekt s.r.o.")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("E8C102DB-4C3E-457F-A4FC-7A9BF6FBD105")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/ILRepack.targets b/ILRepack.targets new file mode 100644 index 0000000..12dcec5 --- /dev/null +++ b/ILRepack.targets @@ -0,0 +1,22 @@ + + + \ No newline at end of file diff --git a/icopdf.ico b/Logo.ico similarity index 100% rename from icopdf.ico rename to Logo.ico diff --git a/MainWindow.xaml b/MainWindow.xaml index 6ffa485..e18ca61 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SlucovaniRozpisek" mc:Ignorable="d" - Title="Slučování rozpisek" SizeToContent="WidthAndHeight" Background="WhiteSmoke" Icon=".\icopdf.ico" + Title="Slučování rozpisek" SizeToContent="WidthAndHeight" Background="WhiteSmoke" Icon=".\Logo.ico" WindowStartupLocation="Manual" Left="200" Top="200" > diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 4bd76a6..fed0beb 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -1,4 +1,6 @@ -using Microsoft.Win32; +#if !NETFRAMEWORK + +using Microsoft.Win32; using System.ComponentModel; using System.Diagnostics; using System.IO; @@ -22,9 +24,9 @@ namespace SlucovaniRozpisek // 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"; + 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 } @@ -82,48 +84,32 @@ namespace SlucovaniRozpisek return; } - if (!PomocneMetody. ObsahujePdf(ViewModel.CestaPrilohy)) + 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?", + 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; } - 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); - } + 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) @@ -149,7 +135,7 @@ namespace SlucovaniRozpisek } } - + public class MainViewModel : INotifyPropertyChanged { @@ -201,4 +187,6 @@ namespace SlucovaniRozpisek PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/PdfRozdelovac.cs b/PdfRozdelovac.cs index 40ddd06..ef1b510 100644 --- a/PdfRozdelovac.cs +++ b/PdfRozdelovac.cs @@ -5,14 +5,12 @@ public List ParovePrilohy { get; private set; } public List NeparovePrilohy { get; private set; } public List NeparoveRozpisky { get; private set; } - public string Zprava { get; private set; } public PdfRozdelovac(List lstPrilohy, List lstRozpisky) { ParovePrilohy = new List(); NeparovePrilohy = new List(); NeparoveRozpisky = new List(lstRozpisky); - Zprava = string.Empty; RozdelPdfSoubor(lstPrilohy, lstRozpisky); } @@ -33,8 +31,6 @@ } NeparoveRozpisky = NeparoveRozpisky.Where(r => !r.EndsWith("_rozpiska")).ToList(); - - Zprava = $"Počet párových příloh: {ParovePrilohy.Count}\nPočet nepárových příloh: {NeparovePrilohy.Count}\nPočet nepárových rozpisek: {NeparoveRozpisky.Count}"; } } } diff --git a/PomocneMetody.cs b/PomocneMetody.cs index ccf612d..cb3949e 100644 --- a/PomocneMetody.cs +++ b/PomocneMetody.cs @@ -3,8 +3,10 @@ using System.Windows; using PdfSharp.Pdf; using PdfSharp.Pdf.IO; using PdfSharp.Drawing; +using System.Runtime.InteropServices; -public static class PomocneMetody +[ComVisible(false)] +static class PomocneMetody { public static bool ObsahujePdf(string cestaSlozky) { @@ -42,16 +44,6 @@ public static class PomocneMetody .ToList(); } - public static string NormalizujCestu(string cesta) - { - if (string.IsNullOrWhiteSpace(cesta)) - { - throw new ArgumentException("Neplatná cesta ke složce.", nameof(cesta)); - } - - return cesta.EndsWith(Path.DirectorySeparatorChar) ? cesta : cesta + Path.DirectorySeparatorChar; - } - public static void KopirujSoubor(string zdrojovySoubor, string cilovySoubor, bool prepsatExistujici) { if (string.IsNullOrWhiteSpace(zdrojovySoubor) || string.IsNullOrWhiteSpace(cilovySoubor)) @@ -80,7 +72,8 @@ public static class PomocneMetody } catch (IOException ex) { - MessageBox.Show($"Chyba při kopírování souboru {zdrojovySoubor}: {ex.Message}", "Chyba", MessageBoxButton.OK, MessageBoxImage.Error); + //MessageBox.Show($"Chyba při kopírování souboru {zdrojovySoubor}: {ex.Message}", "Chyba", MessageBoxButton.OK, MessageBoxImage.Error); + throw new Exception($"Chyba při kopírování souboru {zdrojovySoubor}: {ex.Message}"); } } @@ -125,14 +118,16 @@ public static class PomocneMetody } else { - MessageBox.Show("Druhý PDF dokument neobsahuje žádné stránky.", "Chyba", MessageBoxButton.OK, MessageBoxImage.Warning); + //MessageBox.Show("Druhý PDF dokument neobsahuje žádné stránky.", "Chyba", MessageBoxButton.OK, MessageBoxImage.Warning); + throw new Exception("Druhý PDF dokument neobsahuje žádné stránky."); } } } } catch (IOException ex) { - MessageBox.Show($"Chyba při práci s PDF soubory: {ex.Message}", "Chyba", MessageBoxButton.OK, MessageBoxImage.Error); + //MessageBox.Show($"Chyba při práci s PDF soubory: {ex.Message}", "Chyba", MessageBoxButton.OK, MessageBoxImage.Error); + throw new Exception($"Chyba při práci s PDF soubory: {ex.Message}"); } } } \ No newline at end of file diff --git a/Product.wxs b/Product.wxs new file mode 100644 index 0000000..e44e624 --- /dev/null +++ b/Product.wxs @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Setup.wixproj b/Setup.wixproj new file mode 100644 index 0000000..908534f --- /dev/null +++ b/Setup.wixproj @@ -0,0 +1,46 @@ + + + net9.0-windows + true + false + false + false + disable + latest + + Debug + x64 + 3.0 + {8019CECD-859A-4755-8759-08F1BE8592C1} + 2.0 + SlucovaniRozpisek + Package + true + + + bin\Debug\net9.0-windows + obj\$(Configuration)\ + Debug; + + + bin\Release\net9.0-windows + obj\$(Configuration)\ + + + + + + Designer + + + + + + + + + + + + + diff --git a/Slucovac.cs b/Slucovac.cs new file mode 100644 index 0000000..ed8d3f0 --- /dev/null +++ b/Slucovac.cs @@ -0,0 +1,62 @@ +using System.IO; +using System.Runtime.InteropServices; + +namespace SlucovaniRozpisek +{ + /// + /// Creates the on demand. + /// + [Guid("6C356D2C-614C-4371-A11C-D93E40E096FB")] + [InterfaceType(ComInterfaceType.InterfaceIsDual)] + [ComVisible(true)] + public interface ISlucovacRozpisek + { + [DispId(1)] + void PripravaRozpisky(string cestaPrilohy, string cestaRozpisky, out int parovePrilohy, out int neparovePrilohy, out int neparoveRozpisky); + [DispId(2)] + void SlucRozpisky(string cestaPrilohy, string cestaRozpisky, string cestaVystup); + } + + /// + /// Implementation of the . + /// + [ComVisible(true)] + [Guid("ABD284DF-509C-4E0F-9D19-96A3416738D4")] + [ClassInterface(ClassInterfaceType.None)] + public sealed class SlucovacRozpisek : StandardOleMarshalObject, ISlucovacRozpisek + { + public void PripravaRozpisky(string cestaPrilohy, string cestaRozpisky, out int parovePrilohy, out int neparovePrilohy, out int neparoveRozpisky) + { + List lstPrilohy = PomocneMetody.NactiPdfNazvyBezKoncovky(cestaPrilohy); + List lstRozpisky = PomocneMetody.NactiPdfNazvyBezKoncovky(cestaRozpisky); + PdfRozdelovac pdfka = new PdfRozdelovac(lstPrilohy, lstRozpisky); + parovePrilohy = pdfka.ParovePrilohy.Count; + neparovePrilohy = pdfka.NeparovePrilohy.Count; + neparoveRozpisky = pdfka.NeparoveRozpisky.Count; + } + + public void SlucRozpisky(string cestaPrilohy, string cestaRozpisky, string cestaVystup) + { + List lstPrilohy = PomocneMetody.NactiPdfNazvyBezKoncovky(cestaPrilohy); + + List lstRozpisky = PomocneMetody.NactiPdfNazvyBezKoncovky(cestaRozpisky); + + PdfRozdelovac pdfka = new PdfRozdelovac(lstPrilohy, lstRozpisky); + + foreach (string pdf in pdfka.NeparovePrilohy) + { + PomocneMetody.KopirujSoubor(Path.Combine(cestaPrilohy, pdf + ".pdf"), Path.Combine(cestaVystup, pdf + ".pdf"), true); + } + + foreach (string pdf in pdfka.NeparoveRozpisky) + { + PomocneMetody.KopirujSoubor(Path.Combine(cestaRozpisky, pdf + ".pdf"), Path.Combine(cestaVystup, pdf + ".pdf"), true); + } + + foreach (string pdf in pdfka.ParovePrilohy) + { + PomocneMetody.SloucitPdf(Path.Combine(cestaPrilohy, pdf + ".pdf"), Path.Combine(cestaRozpisky, pdf + "_rozpiska.pdf"), Path.Combine(cestaVystup, pdf + ".pdf"), true); + } + } + } +} diff --git a/SlucovaniRozpisek.csproj b/SlucovaniRozpisek.csproj index ad7de77..d718f63 100644 --- a/SlucovaniRozpisek.csproj +++ b/SlucovaniRozpisek.csproj @@ -2,26 +2,41 @@ WinExe - net8.0-windows + Library + net9.0-windows;net472 + false SlucovaniRozpisek enable enable true + false False - icopdf.ico + Logo.ico + false + 10.0 + true + key.snk - + - + Always + + + + + + + + diff --git a/Slučování rozpisek.sln b/SlucovaniRozpisek.sln similarity index 100% rename from Slučování rozpisek.sln rename to SlucovaniRozpisek.sln diff --git a/key.snk b/key.snk new file mode 100644 index 0000000000000000000000000000000000000000..66afa3e1e66ab19151a73d3cbf8aacb6798d722a GIT binary patch literal 1172 zcmV;F1Z(>T0ssI2Bme+XQ$aES2mk;90097HO2hpPnH4}TIK2i9PI@79Vbcqy0QDRS zZ!*7y(Ow(JR?VKL$yUFKaoSRZ7C-O4=LsKFy||2X?INxr@MV7Ll+mn@oo*HdHtFjl$<>}@e{*kD(94FoL;O;kH)}8zoeGD;Ne5tQG?V|?_AHFl8 zTV5_e=zIm32|4`^*e=xw%_)>JES%^cc1c^;=4A=~$l49?WRrx`F4f!gFF3`v$v$*( z)hg?BbUvsxvgY(cImZ|2JYk{ddz-e31_g=C2$lO&xB<7Pv3-%(Kv~-I0CEZ)ec zXwdIkOTjii19d5uDgc!jD+61X7pPgfU{yz^^D@Q^pkGCqf&9j4#l@vkUXL}aUT`03 zztP~w#9?hs(mVh1wf}}KxsFbmRPTV89AWzVh}&||np+oW1NfJD1$qeIOfo1PCiczYrfwX&|UX}^bg9rm9Hsod(O=L_Y72H4a0-E zdTQXER+2&g-IO82*npgG(kgb)i?87sL4ZdXx1V?XSaFqcCpfrco~bVZiOFNIS+g?z zFot)GJa!C^gZ~2^;Ou~6Rm(cY-qVqRYHxU9p|(-e*oyYq1g~u<=cHV3sq-2RgSyj7$>fj(gZMSOvnn>kTH$qN_nv>&6#4 zXrh)YYdZPRK^REPD{Co;Zp2Sz8h~ZMUgGG?7~n1XWf=(7bg{#=PE!EYb_Ic?wp~sG zhW~ftsv-sg(*}bI z4iy1$ZR$zbH^Y3O4G7{xK5tMIbUE-w6QPsXx1QO=lzuFM-`KX6CJ2q|Fign-RzRigN6 zVJd(*c8u17&&Up*khX1|+|O=KsxBqG9>w#jPeQH~oBWc74>U2*7yA`cHGkd&v6h__ mMEr0_<75^XLAYIRg$KAeK^&|7VFSfkIxLG02?2BNaI!f&`7-