diff --git a/DatabaseConnection.sln b/DatabaseConnection.sln new file mode 100644 index 0000000..ddbffb3 --- /dev/null +++ b/DatabaseConnection.sln @@ -0,0 +1,24 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35514.174 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseConnection", "DatabaseConnection\DatabaseConnection.csproj", "{5203607C-9729-4636-92B8-08E390F08BFF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5203607C-9729-4636-92B8-08E390F08BFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5203607C-9729-4636-92B8-08E390F08BFF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5203607C-9729-4636-92B8-08E390F08BFF}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {5203607C-9729-4636-92B8-08E390F08BFF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5203607C-9729-4636-92B8-08E390F08BFF}.Release|Any CPU.Build.0 = Release|Any CPU + {5203607C-9729-4636-92B8-08E390F08BFF}.Release|Any CPU.Deploy.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/DatabaseConnection/App.xaml b/DatabaseConnection/App.xaml new file mode 100644 index 0000000..6a73e71 --- /dev/null +++ b/DatabaseConnection/App.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/DatabaseConnection/App.xaml.cs b/DatabaseConnection/App.xaml.cs new file mode 100644 index 0000000..2c72e9a --- /dev/null +++ b/DatabaseConnection/App.xaml.cs @@ -0,0 +1,14 @@ +using DatabaseConnection.Services; + +namespace DatabaseConnection +{ + public partial class App : Application + { + public App(MainPage main) + { + InitializeComponent(); + + MainPage = main; + } + } +} diff --git a/DatabaseConnection/AppShell.xaml b/DatabaseConnection/AppShell.xaml new file mode 100644 index 0000000..d882f74 --- /dev/null +++ b/DatabaseConnection/AppShell.xaml @@ -0,0 +1,15 @@ + + + + + + diff --git a/DatabaseConnection/AppShell.xaml.cs b/DatabaseConnection/AppShell.xaml.cs new file mode 100644 index 0000000..cf37308 --- /dev/null +++ b/DatabaseConnection/AppShell.xaml.cs @@ -0,0 +1,10 @@ +namespace DatabaseConnection +{ + public partial class AppShell : Shell + { + public AppShell() + { + InitializeComponent(); + } + } +} diff --git a/DatabaseConnection/DatabaseConnection.csproj b/DatabaseConnection/DatabaseConnection.csproj new file mode 100644 index 0000000..e758bbd --- /dev/null +++ b/DatabaseConnection/DatabaseConnection.csproj @@ -0,0 +1,84 @@ + + + + net8.0-android;net8.0-ios;net8.0-maccatalyst + $(TargetFrameworks);net8.0-windows10.0.19041.0 + + + + + + + Exe + DatabaseConnection + true + true + enable + enable + + + DatabaseConnection + + + com.companyname.databaseconnection + + + 1.0 + 1 + + 11.0 + 13.1 + 21.0 + 10.0.17763.0 + 10.0.17763.0 + 6.5 + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + MSBuild:Compile + + + + diff --git a/DatabaseConnection/MainPage.xaml b/DatabaseConnection/MainPage.xaml new file mode 100644 index 0000000..20c3497 --- /dev/null +++ b/DatabaseConnection/MainPage.xaml @@ -0,0 +1,7 @@ + + + + diff --git a/DatabaseConnection/MainPage.xaml.cs b/DatabaseConnection/MainPage.xaml.cs new file mode 100644 index 0000000..c316d9d --- /dev/null +++ b/DatabaseConnection/MainPage.xaml.cs @@ -0,0 +1,18 @@ +using DatabaseConnection.View; + +namespace DatabaseConnection +{ + public partial class MainPage : TabbedPage + { + public MainPage(AuthorsPage ap, BooksPage bp, ReadersPage rp, WorkersPage wp) + { + InitializeComponent(); + + Children.Add(ap); + Children.Add(bp); + Children.Add(rp); + Children.Add(wp); + } + } + +} diff --git a/DatabaseConnection/MauiProgram.cs b/DatabaseConnection/MauiProgram.cs new file mode 100644 index 0000000..85cff0a --- /dev/null +++ b/DatabaseConnection/MauiProgram.cs @@ -0,0 +1,45 @@ +using DatabaseConnection.Services; +using DatabaseConnection.View; +using DatabaseConnection.ViewModel; +using Microsoft.Extensions.Logging; + +namespace DatabaseConnection +{ + public static class MauiProgram + { + public static MauiApp CreateMauiApp() + { + var builder = MauiApp.CreateBuilder(); + DatabaseService dbService = new(); + + builder.Services.AddSingleton(sp => new DatabaseService()); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + + builder + .UseMauiApp() + .ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); + fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); + }); + +#if DEBUG + builder.Logging.AddDebug(); +#endif + + return builder.Build(); + } + } +} diff --git a/DatabaseConnection/Model/Author.cs b/DatabaseConnection/Model/Author.cs new file mode 100644 index 0000000..6ed012d --- /dev/null +++ b/DatabaseConnection/Model/Author.cs @@ -0,0 +1,10 @@ +namespace DatabaseConnection.Model +{ + public class Author + { + public int Id { get; set; } + public string? Name { get; set; } + public string? Surname { get; set; } + public string? Birthdate { get; set; } + } +} diff --git a/DatabaseConnection/Model/Book.cs b/DatabaseConnection/Model/Book.cs new file mode 100644 index 0000000..855ae45 --- /dev/null +++ b/DatabaseConnection/Model/Book.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseConnection.Model +{ + public class Book + { + public int Id { get; set; } + public string? Title { get; set; } + public string? Author { get; set; } + public string? Category { get; set; } + public string? Publisher { get; set; } + public string? PublishDate { get; set; } + public double Price { get; set; } + public int Amount { get; set; } + } +} diff --git a/DatabaseConnection/Model/Reader.cs b/DatabaseConnection/Model/Reader.cs new file mode 100644 index 0000000..3ed3fd1 --- /dev/null +++ b/DatabaseConnection/Model/Reader.cs @@ -0,0 +1,19 @@ +namespace DatabaseConnection.Model +{ + public class Reader + { + public int Id { get; set; } + public string? Name { get; set; } + public string? Surname { get; set; } + public string? Address { get; set; } + public string? Birthdate { get; set; } + public long Number { get; set; } + public string? EmailAddress { get; set; } + public Book[] RentedBooks { get; set; } + + public Reader() + { + RentedBooks = []; + } + } +} diff --git a/DatabaseConnection/Model/Worker.cs b/DatabaseConnection/Model/Worker.cs new file mode 100644 index 0000000..e9d46fa --- /dev/null +++ b/DatabaseConnection/Model/Worker.cs @@ -0,0 +1,13 @@ +namespace DatabaseConnection.Model +{ + public class Worker + { + public int Id { get; set; } + public string? Name { get; set; } + public string? Surname { get; set; } + public string? StartOfWorking { get; set; } + public string? Position { get; set; } + public double HourlyRate { get; set; } + public string? EndOfWorking { get; set; } + } +} diff --git a/DatabaseConnection/Platforms/Android/AndroidManifest.xml b/DatabaseConnection/Platforms/Android/AndroidManifest.xml new file mode 100644 index 0000000..e9937ad --- /dev/null +++ b/DatabaseConnection/Platforms/Android/AndroidManifest.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DatabaseConnection/Platforms/Android/MainActivity.cs b/DatabaseConnection/Platforms/Android/MainActivity.cs new file mode 100644 index 0000000..c7f5111 --- /dev/null +++ b/DatabaseConnection/Platforms/Android/MainActivity.cs @@ -0,0 +1,11 @@ +using Android.App; +using Android.Content.PM; +using Android.OS; + +namespace DatabaseConnection +{ + [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] + public class MainActivity : MauiAppCompatActivity + { + } +} diff --git a/DatabaseConnection/Platforms/Android/MainApplication.cs b/DatabaseConnection/Platforms/Android/MainApplication.cs new file mode 100644 index 0000000..789f265 --- /dev/null +++ b/DatabaseConnection/Platforms/Android/MainApplication.cs @@ -0,0 +1,16 @@ +using Android.App; +using Android.Runtime; + +namespace DatabaseConnection +{ + [Application] + public class MainApplication : MauiApplication + { + public MainApplication(IntPtr handle, JniHandleOwnership ownership) + : base(handle, ownership) + { + } + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + } +} diff --git a/DatabaseConnection/Platforms/Android/Resources/values/colors.xml b/DatabaseConnection/Platforms/Android/Resources/values/colors.xml new file mode 100644 index 0000000..c04d749 --- /dev/null +++ b/DatabaseConnection/Platforms/Android/Resources/values/colors.xml @@ -0,0 +1,6 @@ + + + #512BD4 + #2B0B98 + #2B0B98 + \ No newline at end of file diff --git a/DatabaseConnection/Platforms/MacCatalyst/AppDelegate.cs b/DatabaseConnection/Platforms/MacCatalyst/AppDelegate.cs new file mode 100644 index 0000000..65f6b4a --- /dev/null +++ b/DatabaseConnection/Platforms/MacCatalyst/AppDelegate.cs @@ -0,0 +1,10 @@ +using Foundation; + +namespace DatabaseConnection +{ + [Register("AppDelegate")] + public class AppDelegate : MauiUIApplicationDelegate + { + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + } +} diff --git a/DatabaseConnection/Platforms/MacCatalyst/Entitlements.plist b/DatabaseConnection/Platforms/MacCatalyst/Entitlements.plist new file mode 100644 index 0000000..de4adc9 --- /dev/null +++ b/DatabaseConnection/Platforms/MacCatalyst/Entitlements.plist @@ -0,0 +1,14 @@ + + + + + + + com.apple.security.app-sandbox + + + com.apple.security.network.client + + + + diff --git a/DatabaseConnection/Platforms/MacCatalyst/Info.plist b/DatabaseConnection/Platforms/MacCatalyst/Info.plist new file mode 100644 index 0000000..7268977 --- /dev/null +++ b/DatabaseConnection/Platforms/MacCatalyst/Info.plist @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + UIDeviceFamily + + 2 + + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + XSAppIconAssets + Assets.xcassets/appicon.appiconset + + diff --git a/DatabaseConnection/Platforms/MacCatalyst/Program.cs b/DatabaseConnection/Platforms/MacCatalyst/Program.cs new file mode 100644 index 0000000..8e7c75b --- /dev/null +++ b/DatabaseConnection/Platforms/MacCatalyst/Program.cs @@ -0,0 +1,16 @@ +using ObjCRuntime; +using UIKit; + +namespace DatabaseConnection +{ + public class Program + { + // This is the main entry point of the application. + static void Main(string[] args) + { + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); + } + } +} diff --git a/DatabaseConnection/Platforms/Tizen/Main.cs b/DatabaseConnection/Platforms/Tizen/Main.cs new file mode 100644 index 0000000..84283e1 --- /dev/null +++ b/DatabaseConnection/Platforms/Tizen/Main.cs @@ -0,0 +1,17 @@ +using System; +using Microsoft.Maui; +using Microsoft.Maui.Hosting; + +namespace DatabaseConnection +{ + internal class Program : MauiApplication + { + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + + static void Main(string[] args) + { + var app = new Program(); + app.Run(args); + } + } +} diff --git a/DatabaseConnection/Platforms/Tizen/tizen-manifest.xml b/DatabaseConnection/Platforms/Tizen/tizen-manifest.xml new file mode 100644 index 0000000..c1f4619 --- /dev/null +++ b/DatabaseConnection/Platforms/Tizen/tizen-manifest.xml @@ -0,0 +1,15 @@ + + + + + + maui-appicon-placeholder + + + + + http://tizen.org/privilege/internet + + + + \ No newline at end of file diff --git a/DatabaseConnection/Platforms/Windows/App.xaml b/DatabaseConnection/Platforms/Windows/App.xaml new file mode 100644 index 0000000..df5aef5 --- /dev/null +++ b/DatabaseConnection/Platforms/Windows/App.xaml @@ -0,0 +1,8 @@ + + + diff --git a/DatabaseConnection/Platforms/Windows/App.xaml.cs b/DatabaseConnection/Platforms/Windows/App.xaml.cs new file mode 100644 index 0000000..3fb3538 --- /dev/null +++ b/DatabaseConnection/Platforms/Windows/App.xaml.cs @@ -0,0 +1,25 @@ +using Microsoft.UI.Xaml; + +// To learn more about WinUI, the WinUI project structure, +// and more about our project templates, see: http://aka.ms/winui-project-info. + +namespace DatabaseConnection.WinUI +{ + /// + /// Provides application-specific behavior to supplement the default Application class. + /// + public partial class App : MauiWinUIApplication + { + /// + /// Initializes the singleton application object. This is the first line of authored code + /// executed, and as such is the logical equivalent of main() or WinMain(). + /// + public App() + { + this.InitializeComponent(); + } + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + } + +} diff --git a/DatabaseConnection/Platforms/Windows/Package.appxmanifest b/DatabaseConnection/Platforms/Windows/Package.appxmanifest new file mode 100644 index 0000000..5db493d --- /dev/null +++ b/DatabaseConnection/Platforms/Windows/Package.appxmanifest @@ -0,0 +1,46 @@ + + + + + + + + + $placeholder$ + User Name + $placeholder$.png + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DatabaseConnection/Platforms/Windows/app.manifest b/DatabaseConnection/Platforms/Windows/app.manifest new file mode 100644 index 0000000..09ead84 --- /dev/null +++ b/DatabaseConnection/Platforms/Windows/app.manifest @@ -0,0 +1,15 @@ + + + + + + + + true/PM + PerMonitorV2, PerMonitor + + + diff --git a/DatabaseConnection/Platforms/iOS/AppDelegate.cs b/DatabaseConnection/Platforms/iOS/AppDelegate.cs new file mode 100644 index 0000000..65f6b4a --- /dev/null +++ b/DatabaseConnection/Platforms/iOS/AppDelegate.cs @@ -0,0 +1,10 @@ +using Foundation; + +namespace DatabaseConnection +{ + [Register("AppDelegate")] + public class AppDelegate : MauiUIApplicationDelegate + { + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + } +} diff --git a/DatabaseConnection/Platforms/iOS/Info.plist b/DatabaseConnection/Platforms/iOS/Info.plist new file mode 100644 index 0000000..0004a4f --- /dev/null +++ b/DatabaseConnection/Platforms/iOS/Info.plist @@ -0,0 +1,32 @@ + + + + + LSRequiresIPhoneOS + + UIDeviceFamily + + 1 + 2 + + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + XSAppIconAssets + Assets.xcassets/appicon.appiconset + + diff --git a/DatabaseConnection/Platforms/iOS/Program.cs b/DatabaseConnection/Platforms/iOS/Program.cs new file mode 100644 index 0000000..8e7c75b --- /dev/null +++ b/DatabaseConnection/Platforms/iOS/Program.cs @@ -0,0 +1,16 @@ +using ObjCRuntime; +using UIKit; + +namespace DatabaseConnection +{ + public class Program + { + // This is the main entry point of the application. + static void Main(string[] args) + { + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); + } + } +} diff --git a/DatabaseConnection/Platforms/iOS/Resources/PrivacyInfo.xcprivacy b/DatabaseConnection/Platforms/iOS/Resources/PrivacyInfo.xcprivacy new file mode 100644 index 0000000..24ab3b4 --- /dev/null +++ b/DatabaseConnection/Platforms/iOS/Resources/PrivacyInfo.xcprivacy @@ -0,0 +1,51 @@ + + + + + + NSPrivacyAccessedAPITypes + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryFileTimestamp + NSPrivacyAccessedAPITypeReasons + + C617.1 + + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategorySystemBootTime + NSPrivacyAccessedAPITypeReasons + + 35F9.1 + + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryDiskSpace + NSPrivacyAccessedAPITypeReasons + + E174.1 + + + + + + diff --git a/DatabaseConnection/Properties/launchSettings.json b/DatabaseConnection/Properties/launchSettings.json new file mode 100644 index 0000000..edf8aad --- /dev/null +++ b/DatabaseConnection/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Windows Machine": { + "commandName": "MsixPackage", + "nativeDebugging": false + } + } +} \ No newline at end of file diff --git a/DatabaseConnection/Resources/AppIcon/appicon.svg b/DatabaseConnection/Resources/AppIcon/appicon.svg new file mode 100644 index 0000000..9d63b65 --- /dev/null +++ b/DatabaseConnection/Resources/AppIcon/appicon.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/DatabaseConnection/Resources/AppIcon/appiconfg.svg b/DatabaseConnection/Resources/AppIcon/appiconfg.svg new file mode 100644 index 0000000..21dfb25 --- /dev/null +++ b/DatabaseConnection/Resources/AppIcon/appiconfg.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/DatabaseConnection/Resources/Fonts/OpenSans-Regular.ttf b/DatabaseConnection/Resources/Fonts/OpenSans-Regular.ttf new file mode 100644 index 0000000..36eb5ce Binary files /dev/null and b/DatabaseConnection/Resources/Fonts/OpenSans-Regular.ttf differ diff --git a/DatabaseConnection/Resources/Fonts/OpenSans-Semibold.ttf b/DatabaseConnection/Resources/Fonts/OpenSans-Semibold.ttf new file mode 100644 index 0000000..d1f015f Binary files /dev/null and b/DatabaseConnection/Resources/Fonts/OpenSans-Semibold.ttf differ diff --git a/DatabaseConnection/Resources/Images/dotnet_bot.png b/DatabaseConnection/Resources/Images/dotnet_bot.png new file mode 100644 index 0000000..f93ce02 Binary files /dev/null and b/DatabaseConnection/Resources/Images/dotnet_bot.png differ diff --git a/DatabaseConnection/Resources/Raw/AboutAssets.txt b/DatabaseConnection/Resources/Raw/AboutAssets.txt new file mode 100644 index 0000000..89dc758 --- /dev/null +++ b/DatabaseConnection/Resources/Raw/AboutAssets.txt @@ -0,0 +1,15 @@ +Any raw assets you want to be deployed with your application can be placed in +this directory (and child directories). Deployment of the asset to your application +is automatically handled by the following `MauiAsset` Build Action within your `.csproj`. + + + +These files will be deployed with your package and will be accessible using Essentials: + + async Task LoadMauiAsset() + { + using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); + using var reader = new StreamReader(stream); + + var contents = reader.ReadToEnd(); + } diff --git a/DatabaseConnection/Resources/Splash/splash.svg b/DatabaseConnection/Resources/Splash/splash.svg new file mode 100644 index 0000000..21dfb25 --- /dev/null +++ b/DatabaseConnection/Resources/Splash/splash.svg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/DatabaseConnection/Resources/Styles/Colors.xaml b/DatabaseConnection/Resources/Styles/Colors.xaml new file mode 100644 index 0000000..30307a5 --- /dev/null +++ b/DatabaseConnection/Resources/Styles/Colors.xaml @@ -0,0 +1,45 @@ + + + + + + + #512BD4 + #ac99ea + #242424 + #DFD8F7 + #9880e5 + #2B0B98 + + White + Black + #D600AA + #190649 + #1f1f1f + + #E1E1E1 + #C8C8C8 + #ACACAC + #919191 + #6E6E6E + #404040 + #212121 + #141414 + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DatabaseConnection/Resources/Styles/Styles.xaml b/DatabaseConnection/Resources/Styles/Styles.xaml new file mode 100644 index 0000000..6641e3a --- /dev/null +++ b/DatabaseConnection/Resources/Styles/Styles.xaml @@ -0,0 +1,427 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DatabaseConnection/Services/AuthorService.cs b/DatabaseConnection/Services/AuthorService.cs new file mode 100644 index 0000000..eee9fb8 --- /dev/null +++ b/DatabaseConnection/Services/AuthorService.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Data; +using System.Threading.Tasks; +using DatabaseConnection.Model; + +namespace DatabaseConnection.Services +{ + public partial class AuthorService + { + private readonly DatabaseService databaseService; + + public AuthorService(DatabaseService databaseService) => this.databaseService = databaseService; + + public async Task> GetAuthors() + { + List authors = []; + var table = await databaseService.ExecuteQuery("SELECT * FROM autorzy_ksiazek"); + foreach (DataRow row in table.Rows) + { + authors.Add(new Author + { + Id = Convert.ToInt32(row["id_autor"]), + Name = row["imie"].ToString(), + Surname = row["nazwisko"].ToString(), + Birthdate = row["data_urodzenia"].ToString() + }); + + } + return authors; + } + + public async Task AddAuthor(Author author) + { + return await databaseService.ExecuteNonQuery($"INSERT INTO autorzy_ksiazek(imie, nazwisko, data_urodzenia) VALUES('{author.Name}', '{author.Surname}', '{author.Birthdate}');"); + } + } +} diff --git a/DatabaseConnection/Services/BookService.cs b/DatabaseConnection/Services/BookService.cs new file mode 100644 index 0000000..1293f7b --- /dev/null +++ b/DatabaseConnection/Services/BookService.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Data; +using System.Threading.Tasks; +using DatabaseConnection.Model; + +namespace DatabaseConnection.Services +{ + public class BookService + { + private readonly DatabaseService databaseService; + + public BookService(DatabaseService databaseService) => this.databaseService = databaseService; + + public async Task> GetBooks() + { + List books = []; + + var table = await databaseService.ExecuteQuery("SELECT id_ksiazka, tytul, GROUP_CONCAT(imie, ' ', nazwisko) as autor, kategoria.nazwa, wydawca, data_publikacji, cena, ilosc FROM ksiazki, autorzy_ksiazek, kategoria WHERE ksiazki.id_kategoria = kategoria.id_kategoria AND ksiazki.id_autor = autorzy_ksiazek.id_autor GROUP BY tytul"); + foreach (DataRow row in table.Rows) + { + books.Add(new Book + { + Id = Convert.ToInt32(row["id_ksiazka"]), + Title = row["tytul"].ToString(), + Author = row["autor"].ToString(), + Category = row["nazwa"].ToString(), + Publisher = row["wydawca"].ToString(), + PublishDate = row["data_publikacji"].ToString(), + Price = Convert.ToDouble(row["cena"]), + Amount = Convert.ToInt32(row["ilosc"]) + }); + } + + return books; + } + } +} diff --git a/DatabaseConnection/Services/DatabaseService.cs b/DatabaseConnection/Services/DatabaseService.cs new file mode 100644 index 0000000..94c595d --- /dev/null +++ b/DatabaseConnection/Services/DatabaseService.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MySql.Data.MySqlClient; + +namespace DatabaseConnection.Services +{ + public class DatabaseService + { + private string _connectionString = "Server=localhost;Database=biblioteka;User=root;Password=;"; + + public MySqlConnection Connection() + { + return new MySqlConnection(_connectionString); + } + + public async Task ExecuteQuery(string query) + { + using MySqlConnection connection = Connection(); + await connection.OpenAsync(); + using MySqlCommand command = new(query, connection); + + using var reader = await command.ExecuteReaderAsync(); + var table = new DataTable(); + table.Load(reader); + return table; + } + + public async Task ExecuteNonQuery(string query) + { + using MySqlConnection connection = Connection(); + await connection.OpenAsync(); + using MySqlCommand command = new(query, connection); + + return await command.ExecuteNonQueryAsync(); + } + } +} diff --git a/DatabaseConnection/Services/ReaderService.cs b/DatabaseConnection/Services/ReaderService.cs new file mode 100644 index 0000000..c5955f5 --- /dev/null +++ b/DatabaseConnection/Services/ReaderService.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using System.Data; +using System.Threading.Tasks; +using DatabaseConnection.Model; + +namespace DatabaseConnection.Services +{ + public class ReaderService + { + private readonly DatabaseService databaseService; + + public ReaderService(DatabaseService databaseService) => this.databaseService = databaseService; + + public async Task> GetReaders() + { + List readers = []; + + var table = await databaseService.ExecuteQuery("SELECT * FROM czytelnicy"); + foreach (DataRow row in table.Rows) + { + readers.Add(new Reader + { + Id = Convert.ToInt32(row["id_autor"]), + Name = row["imie"].ToString(), + Surname = row["nazwisko"].ToString(), + Address = row["adres_zamieszkania"].ToString(), + Birthdate = row["data_urodzenia"].ToString(), + Number = (long)Convert.ToInt64(row["numer_telefonu"]), + EmailAddress = row["adres_email"].ToString() + }); + } + + return readers; + } + + public async Task AddReader(Reader reader) + { + return await databaseService.ExecuteNonQuery($"INSERT INTO czytelnicy(imie, nazwisko, data_urodzenia, adres_zamieszkania, numer_telefonu, adres_email) VALUES('{reader.Name}', '{reader.Surname}', '{reader.Birthdate}', '{reader.Address}', '{reader.Number}', '{reader.EmailAddress}');"); + } + } +} diff --git a/DatabaseConnection/Services/WorkerService.cs b/DatabaseConnection/Services/WorkerService.cs new file mode 100644 index 0000000..102a6e6 --- /dev/null +++ b/DatabaseConnection/Services/WorkerService.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using System.Data; +using System.Threading.Tasks; +using DatabaseConnection.Model; + +namespace DatabaseConnection.Services +{ + public class WorkerService + { + private readonly DatabaseService databaseService; + + public WorkerService(DatabaseService databaseService) => this.databaseService = databaseService; + + public async Task> GetWorkers() + { + List workers = []; + + var table = await databaseService.ExecuteQuery("SELECT * FROM pracownicy"); + foreach (DataRow row in table.Rows) + { + workers.Add(new Worker + { + Id = Convert.ToInt32(row["id_autor"]), + Name = row["imie"].ToString(), + Surname = row["nazwisko"].ToString(), + StartOfWorking = row["data_rozpoczecia_pracy"].ToString(), + Position = row["stanowisko"].ToString(), + HourlyRate = Convert.ToDouble(row["stawka_godzinowa"]), + EndOfWorking = row["data_zakonczenia_pracy"].ToString() + }); + } + + return workers; + } + } +} diff --git a/DatabaseConnection/View/AuthorsPage.xaml b/DatabaseConnection/View/AuthorsPage.xaml new file mode 100644 index 0000000..cf338ed --- /dev/null +++ b/DatabaseConnection/View/AuthorsPage.xaml @@ -0,0 +1,30 @@ + + + +