### List Databases (F4) - enova365 Source: https://github.com/soneta/soneta.fundamentals/blob/master/ReadME.md Loads a list of enova365 databases from 'Lista baz danych.xml' and displays them in the console. This example reads from an XML file. ```C# using Soneta.Business; using Soneta.Business.App; using Soneta.Business.UI; using System.Xml.Linq; public class Example { public static void ListDatabases(Session session) { XDocument doc = XDocument.Load("Lista baz danych.xml"); foreach (XElement element in doc.Root.Elements()) { Console.WriteLine(element.Attribute("Name").Value); } } } ``` -------------------------------- ### Print Report (F6) - enova365 Source: https://github.com/soneta/soneta.fundamentals/blob/master/ReadME.md Prints a sample REPX or ASPX report to PDF and saves it to a file. This example demonstrates report generation and file saving. ```C# using Soneta.Business; using Soneta.Business.App; using Soneta.Business.UI; using Soneta.Handel; using Soneta.Reports; using System.IO; public class Example { public static void PrintReport(Session session) { ReportsModule rm = ReportsModule.GetInstance(session); HandelModule hm = HandelModule.GetInstance(session); // Example: Print a REPX report using (Report report = rm.LoadReport("MyReport.repx")) { report.SetParameterValue("Param1", "Value1"); using (Stream stream = File.Create("MyReport.pdf")) { rm.Print(report, stream, ReportFormat.Pdf); } } // Example: Print an ASPX report (if applicable) // using (Report report = rm.LoadReport("MyAspxReport.aspx")) // { // report.SetParameterValue("Param1", "Value1"); // using (Stream stream = File.Create("MyAspxReport.pdf")) // { // rm.Print(report, stream, ReportFormat.Pdf); // } // } } } ``` -------------------------------- ### Initialize and Log In to enova365 Database Source: https://context7.com/soneta/soneta.fundamentals/llms.txt The `Enova` class handles loading enova365 SDKs, establishing a database connection, and logging in a user. `InitializeAndLogIn()` combines these steps. Ensure `WithUI = true` for printouts. The `Database` instance is retrieved from `BusApplication`, and login is performed via `Db.Login()`. This singleton instance is then used for all subsequent operations. ```csharp internal class Enova { private static Enova _instance; internal static Enova Instance => _instance ?? (_instance = new Enova()); private Database db; internal Database Db => db; private Login _login; internal Login Login => _login; internal void InitializeAndLogIn() { string dbname = "szkolenia"; // nazwa bazy danych enova365 string user = "Administrator"; string pwd = ""; // 1. Załaduj assemblies enova365 (WithUI = true wymagane dla wydruków) var loader = new Loader { WithUI = true, WithNet = false }; loader.Load(); // 2. Pobierz instancję bazy danych db = BusApplication.Instance[dbname]; // 3. Zaloguj użytkownika SessionStateDisposable = SessionState.Create().Attach(); _login = Db.Login(false, user, pwd); // => konsola: "Poprawnie zalogowano do bazy" } // Tworzenie sesji: readOnly=true dla odczytu, false dla zapisu; config=false w typowych przypadkach internal Session CreateSession(bool readOnly, bool config) => Login.CreateSession(readOnly, config); internal void Unload() { _login?.Database.Dispose(); _login?.Dispose(); SessionStateDisposable?.Dispose(); } } // Użycie w Program.cs Enova.Instance.InitializeAndLogIn(); // ... operacje biznesowe ... Enova.Instance.Unload(); ``` -------------------------------- ### Register Menu Options using MEF Source: https://context7.com/soneta/soneta.fundamentals/llms.txt Each application feature is a class decorated with MEF attributes (`[Export(typeof(IOption))]`, `[ExportMetadata]`) defining its console menu key, description, and priority. The `CompositionContainer` discovers these classes. The `IOption` interface requires an implementation of the `Run()` method, which returns `false` to exit the application. The main loop discovers and displays these options, sorted by priority. ```csharp interface IOption { bool Run(); // false = zamknij aplikację } public interface IOptionData { int Priority { get; } ConsoleKey Key { get; } string Description { get; } } // Przykładowa opcja wyjścia (Q) [Export(typeof(IOption))] [ExportMetadata("Key", ConsoleKey.Q)] [ExportMetadata("Description", "Zakończ")] [ExportMetadata("Priority", 1000)] class Exit : IOption { bool IOption.Run() { Enova.Instance.Unload(); return false; // sygnalizuje zakończenie pętli menu } } // Pętla główna – odkrycie i wyświetlenie opcji using var catalog = new AssemblyCatalog(typeof(Program).Assembly); using var mef = new CompositionContainer(catalog); // Wyświetl opcje posortowane wg priorytetu mef.GetExports() .Select(o => o.Metadata) .OrderBy(o => o.Key) .ToList() .ForEach(o => Console.WriteLine("({0}) - {1}", o.Key, o.Description)); // Wyjście: // (F1) - Wczytanie kontrahentów // (F2) - Wczytanie towarów // ... // (Q) - Zakończ ``` -------------------------------- ### List Enova365 Databases Source: https://context7.com/soneta/soneta.fundamentals/llms.txt Displays all Enova365 databases registered in the 'Lista baz danych.xml' file. This is achieved by calling `Enova.Instance.ListDatabases()`, which iterates through `BusApplication.Instance` and prints database names to the console. ```csharp [Export(typeof(IOption))] [ExportMetadata("Key", ConsoleKey.F4)] [ExportMetadata("Description", "Lista baz")] [ExportMetadata("Priority", 40)] class ListaBaz : IOption { public bool Run() { // Wypisuje wszystkie bazy z BusApplication na konsolę Enova.Instance.ListDatabases(); return true; } } // Implementacja w Enova.cs public void ListDatabases() { BusApplication.Instance .Cast() .ToList() .ForEach(db => Console.WriteLine(db.Name)); // Przykładowe wyjście: // szkolenia // produkcja // test } // Dostęp programowy do listy nazw baz (właściwość IEnumerable) IEnumerable nazwyBaz = Enova.Instance.Databases; // => ["szkolenia", "produkcja", "test"] ``` -------------------------------- ### Create Object (F5) - enova365 Source: https://github.com/soneta/soneta.fundamentals/blob/master/ReadME.md Creates a new good and sets some of its properties. Requires enova365 context. ```C# using Soneta.Business; using Soneta.Business.App; using Soneta.Business.UI; using Soneta.Handel; public class Example { public static void CreateObject(Session session) { HandelModule hm = HandelModule.GetInstance(session); Towar t = hm.Towary.New(); t.Symbol = "A1"; t.Nazwa = "Nowy towar"; t.Opis = "Opis nowego towaru"; session.Save(); } } ``` -------------------------------- ### Run Options Asynchronously with Progress Bar Source: https://context7.com/soneta/soneta.fundamentals/llms.txt Initiates an option in a background thread and displays an animated progress bar in the console. Results and exceptions are safely passed back to the main thread. This is an internal mechanism for menu loops and does not require modification by developers extending the project. ```csharp // Uruchomienie opcji asynchronicznie z paskiem postępu static internal bool RunAsync(IOption option) { int delay = 80; // ms między odświeżeniami paska var startedAt = DateTime.Now; var runner = new OptionRunner(); using (var bw = new BackgroundWorker()) { bw.DoWork += runner.Run_Work; bw.RunWorkerCompleted += runner.Run_Completed; bw.RunWorkerAsync(option); while (bw.IsBusy) { Thread.Sleep(delay); DrawProgress((DateTime.Now - startedAt).TotalMilliseconds / delay); // Animacja w konsoli: [=-----] [-=----] ... } } return runner._result ?? true; } ``` ```csharp // Pasek postępu w konsoli static void DrawProgress(double progress) { int len = 6; char[] dots = { '-', '=' }; int val = Convert.ToInt32(progress % len); Console.Write("[{0}]\r", string.Empty .PadLeft(1, dots[1]) .PadLeft(val, dots[0]) .PadRight(len, dots[0])); } ``` ```csharp // Obsługa błędów w wątku tła void Run_Work(object sender, DoWorkEventArgs e) { try { Console.ForegroundColor = ConsoleColor.DarkGreen; var opt = (IOption)e.Argument; e.Result = opt.Run(); } finally { Console.ResetColor(); } } ``` -------------------------------- ### Generate PDF Report in Soneta Source: https://context7.com/soneta/soneta.fundamentals/llms.txt Demonstrates generating a report (ASPX or REPX) to a PDF file using the IReportService. The report configuration specifies the output format, template source, and session context. The generated PDF is saved to a local file path. ```csharp using System.ComponentModel.Composition; using System.Console; using System.IO; using System.Diagnostics; using Soneta.Business; using Soneta.Business.App; using Soneta.Business.UI; using Soneta.Tools; using Soneta.Report; [Export(typeof(IOption))] [ExportMetadata("Key", ConsoleKey.F6)] [ExportMetadata("Description", "Wydruk")] [ExportMetadata("Priority", 50)] class Wydruk : IOption { public bool Run() { Login login = Enova.Instance.Login; using (Session session = login.CreateSession(readOnly: false, config: false)) { var appDir = Path.GetDirectoryName( Process.GetCurrentProcess().MainModule.FileName); // Konfiguracja raportu var rr = new ReportResult { Format = ReportResultFormat.PDF, TemplateFileSource = AspxSource.Local, // plik lokalny // Wydruk ASPX: TemplateFileName = Path.Combine(appDir, "Reports\\dummy.aspx"), // Wydruk REPX (alternatywnie): // TemplateFileName = Path.Combine(appDir, "Reports\\dummy.repx"), Context = Context.Empty.Clone(session), SilentProgress = true, }; // Pobranie serwisu raportów przez DI var service = session.GetRequiredService(); // Generowanie raportu – zwraca Stream z PDF using (var stream = service.GenerateReport(rr)) { var outputPath = Path.Combine(appDir, "Wydruk testowy.pdf"); if (File.Exists(outputPath)) File.Delete(outputPath); using var file = File.Create(outputPath); stream.CopyTo(file); file.Flush(); Console.WriteLine($"Wygenerowano PDF: ({stream.Length}B) {outputPath}"); // => Wygenerowano PDF: (12345B) C:\app\Wydruk testowy.pdf } } return true; } } ``` -------------------------------- ### Load Customers (F1) - enova365 Source: https://github.com/soneta/soneta.fundamentals/blob/master/ReadME.md Loads a list of customers and displays them in the console. Requires enova365 context. ```C# using Soneta.Business; using Soneta.Business.App; using Soneta.Business.UI; using Soneta.Handel; using System.Linq; public class Example { public static void LoadCustomers(Session session) { HandelModule hm = HandelModule.GetInstance(session); foreach (Kontrahent k in hm.Kontrahenci.Where(x => x.Symbol.StartsWith("A")).OrderBy(x => x.Symbol)) { Console.WriteLine(k.Symbol + " " + k.Nazwa); } } } ``` -------------------------------- ### Load Goods (F2) - enova365 Source: https://github.com/soneta/soneta.fundamentals/blob/master/ReadME.md Loads a list of goods and displays them in the console. Requires enova365 context. ```C# using Soneta.Business; using Soneta.Business.App; using Soneta.Business.UI; using Soneta.Handel; using System.Linq; public class Example { public static void LoadGoods(Session session) { HandelModule hm = HandelModule.GetInstance(session); foreach (Towar t in hm.Towary.Where(x => x.Symbol.StartsWith("A")).OrderBy(x => x.Symbol)) { Console.WriteLine(t.Symbol + " " + t.Nazwa); } } } ``` -------------------------------- ### Create New Object in Soneta Source: https://context7.com/soneta/soneta.fundamentals/llms.txt Demonstrates creating a new 'Towar' object. The object is initially in a detached state and becomes attached after being added to the table. Properties can only be set after attachment. Ensure to commit the transaction and save the session. ```csharp using System.ComponentModel.Composition; using System.Console; using Soneta.Business; using Soneta.Business.App; using Soneta.Business.UI; using Soneta.Towary; [Export(typeof(IOption))] [ExportMetadata("Key", ConsoleKey.F5)] [ExportMetadata("Description", "Utworzenie obiektu")] [ExportMetadata("Priority", 50)] class NowyObiekt : IOption { public bool Run() { Login login = Enova.Instance.Login; using (Session session = login.CreateSession(readOnly: false, config: false)) { TowaryModule tm = TowaryModule.GetInstance(session); // Transakcja biznesowa w bloku using (automatyczny Dispose) using (ITransaction tr = session.Logout(true)) { // 1. Utwórz obiekt – stan: detached (ID < 0, brak sesji) Towar towar = new Towar(); // 2. Dodaj do tabeli – stan: attached (ID > 0, sesja przyłączona) tm.Towary.AddRow(towar); // 3. Ustaw właściwości (dopiero po AddRow!) towar.Kod = "?"; towar.Nazwa = "Nowy Towar"; // 4. Zatwierdź transakcję tr.Commit(); } // 5. Zapisz do bazy (fizyczny INSERT SQL) session.Save(); } return true; } } ``` -------------------------------- ### Read Products from Inventory Module Source: https://context7.com/soneta/soneta.fundamentals/llms.txt Reads a list of products from the Enova365 Inventory module. Products are displayed sorted by EAN code. The session is created in read-only mode. ```csharp [Export(typeof(IOption))] [ExportMetadata("Key", ConsoleKey.F2)] [ExportMetadata("Description", "Wczytanie towarów")] [ExportMetadata("Priority", 20)] class WczytanieTowarow : IOption { public bool Run() { Login login = Enova.Instance.Login; using (Session session = login.CreateSession(readOnly: true, config: false)) { TowaryModule tm = TowaryModule.GetInstance(session); // Iteracja po towarach posortowanych wg kodu EAN foreach (Towar t in tm.Towary.WgEAN) { Console.WriteLine(t); // wywołuje Towar.ToString() } // Przykładowe wyjście: // 5901234123457 - BIKINI // 5901234123464 - KOSZULKA } return true; } } ``` -------------------------------- ### Read Customers from CRM Module Source: https://context7.com/soneta/soneta.fundamentals/llms.txt Reads a list of customers from the Enova365 CRM module. The session is created in read-only mode. Customers are iterated in alphabetical order by name. ```csharp [Export(typeof(IOption))] [ExportMetadata("Key", ConsoleKey.F1)] [ExportMetadata("Description", "Wczytanie kontrahentów")] [ExportMetadata("Priority", 10)] class WczytanieKontrahentow : IOption { public bool Run() { Login login = Enova.Instance.Login; using (Session session = login.CreateSession(readOnly: true, config: false)) { // Pobranie instancji modułu CRM dla bieżącej sesji CRMModule crm = CRMModule.GetInstance(session); // Iteracja po kontrahentach posortowanych alfabetycznie wg nazwy foreach (Kontrahent k in crm.Kontrahenci.WgNazwy) { Console.WriteLine(k.Nazwa); } // Przykładowe wyjście: // ABC Sp. z o.o. // XYZ S.A. // ... } return true; // kontynuuj pętlę menu } } ``` -------------------------------- ### Modify Object (F3) - enova365 Source: https://github.com/soneta/soneta.fundamentals/blob/master/ReadME.md Loads a specific good and modifies its description. Requires enova365 context. ```C# using Soneta.Business; using Soneta.Business.App; using Soneta.Business.UI; using Soneta.Handel; using System.Linq; public class Example { public static void ModifyObject(Session session) { HandelModule hm = HandelModule.GetInstance(session); Towar t = hm.Towary.GetBySymbol("A1"); if (t != null) { t.Opis = "Nowy opis"; session.Save(); } } } ``` -------------------------------- ### Modify Product Record Source: https://context7.com/soneta/soneta.fundamentals/llms.txt Modifies an existing product record in the Enova365 Inventory module. The session is opened in write mode. Business transactions are managed using `session.Logout(true)` and committed with `tr.Commit()`. Changes are saved to the database with `session.Save()`. ```csharp [Export(typeof(IOption))] [ExportMetadata("Key", ConsoleKey.F3)] [ExportMetadata("Description", "Modyfikacja obiektu")] [ExportMetadata("Priority", 30)] class ModyfikacjaObiektu : IOption { public bool Run() { Login login = Enova.Instance.Login; using (Session session = login.CreateSession(readOnly: false, config: false)) { TowaryModule tm = TowaryModule.GetInstance(session); // Wczytanie towaru po unikalnym kluczu – zwraca pojedynczy obiekt // (indeks po kluczu nieunikalnym zwraca SubTable<>) Towar bikini = tm.Towary.WgKodu["BIKINI"]; // Otwarcie transakcji biznesowej (można zagnieżdżać) ITransaction tr = session.Logout(true); // Modyfikacja właściwości obiektu bikini.Opis = "Zmodyfikowane przez Soneta.Fundamentals " + DateTime.Now; // Zatwierdzenie transakcji tr.Commit(); tr.Dispose(); // Zapis do bazy danych (fizyczny zapis SQL) session.Save(); } return true; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.