commit 591f726ba07be1dde2e6bd2fa30b388fb363557d Author: Artemij Date: Sun May 3 12:50:03 2026 +1000 viktorpiktor1605@gmail.com diff --git a/Policlinica.sln b/Policlinica.sln new file mode 100644 index 0000000..30fa257 --- /dev/null +++ b/Policlinica.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Policlinica", "Policlinica\Policlinica.csproj", "{EAE71C88-6E94-4B85-BC83-CFA81A4A09E6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EAE71C88-6E94-4B85-BC83-CFA81A4A09E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EAE71C88-6E94-4B85-BC83-CFA81A4A09E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EAE71C88-6E94-4B85-BC83-CFA81A4A09E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EAE71C88-6E94-4B85-BC83-CFA81A4A09E6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Policlinica.sln.DotSettings.user b/Policlinica.sln.DotSettings.user new file mode 100644 index 0000000..5cd1961 --- /dev/null +++ b/Policlinica.sln.DotSettings.user @@ -0,0 +1,2 @@ + + ForceIncluded \ No newline at end of file diff --git a/Policlinica/App.axaml b/Policlinica/App.axaml new file mode 100644 index 0000000..a9112a7 --- /dev/null +++ b/Policlinica/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Policlinica/App.axaml.cs b/Policlinica/App.axaml.cs new file mode 100644 index 0000000..a21fc3a --- /dev/null +++ b/Policlinica/App.axaml.cs @@ -0,0 +1,56 @@ +using System; +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Data.Core.Plugins; +using System.Linq; +using Avalonia.Markup.Xaml; +using Microsoft.Extensions.DependencyInjection; +using Policlinica.ViewModels; +using Policlinica.Views; + +namespace Policlinica; + +public partial class App : Application +{ + private readonly IServiceProvider _serviceProvider; + + public App(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + + DisableAvaloniaDataAnnotationValidation(); + + var vm = _serviceProvider.GetRequiredService(); + var win = _serviceProvider.GetRequiredService(); + win.DataContext = vm; + desktop.MainWindow = win; + } + + base.OnFrameworkInitializationCompleted(); + } + + private void DisableAvaloniaDataAnnotationValidation() + { + + var dataValidationPluginsToRemove = + BindingPlugins.DataValidators.OfType().ToArray(); + + + foreach (var plugin in dataValidationPluginsToRemove) + { + BindingPlugins.DataValidators.Remove(plugin); + } + } +} \ No newline at end of file diff --git a/Policlinica/Assets/avalonia-logo.ico b/Policlinica/Assets/avalonia-logo.ico new file mode 100644 index 0000000..f7da8bb Binary files /dev/null and b/Policlinica/Assets/avalonia-logo.ico differ diff --git a/Policlinica/DB/DatabaseConnection.cs b/Policlinica/DB/DatabaseConnection.cs new file mode 100644 index 0000000..3e7a6d8 --- /dev/null +++ b/Policlinica/DB/DatabaseConnection.cs @@ -0,0 +1,6 @@ +namespace Policlinica.DB; + +public class DatabaseConnection +{ + public string ConnectionString { get; set; } +} \ No newline at end of file diff --git a/Policlinica/DB/DoctorRepository.cs b/Policlinica/DB/DoctorRepository.cs new file mode 100644 index 0000000..2d07ae1 --- /dev/null +++ b/Policlinica/DB/DoctorRepository.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using Microsoft.Extensions.Options; +using MySqlConnector; + +namespace Policlinica.DB; + +public class DoctorRepository +{ + MySqlConnection connection; + + public DoctorRepository(IOptions connect) + { + connection = new MySqlConnection(connect.Value.ConnectionString); + } + public List GetDoctorsByTest() + { + List result = new List(); + string sql = "select * from doctors"; + try + { + connection.Open(); + using (var mc = new MySqlCommand(sql, connection)) + using (var dr = mc.ExecuteReader()) + { + while (dr.Read()) + { + result.Add(new Doctors + { + Id = dr.GetInt32("id"), + Title = dr.GetString("title"), + Description = dr.GetString("description"), + + }); + } + } + + connection.Close(); + } + catch (MySqlException ex) + { + Console.WriteLine(ex); + } + catch (Exception e) + { + Console.WriteLine(e); + } + + return result; + } +} + + diff --git a/Policlinica/DB/UserRepository.cs b/Policlinica/DB/UserRepository.cs new file mode 100644 index 0000000..658f426 --- /dev/null +++ b/Policlinica/DB/UserRepository.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using Microsoft.Extensions.Options; +using MySqlConnector; + +namespace Policlinica.DB; + +public class UserRepository +{ + MySqlConnection connection; + + public UserRepository(IOptions connect) + { + connection = new MySqlConnection(connect.Value.ConnectionString); + } + + + public void InsertUser(Users users) + { + var sql1 = "INSERT INTO Polyclinica.users (id, name, password) VALUES (0, @name, @password); "; + var sql2 = "SELECT max(id) as id FROM Polyclinica.users;"; + + } + + + public List GetUsersByTest() + { + List result = new List(); + string sql = "select * from users"; + try + { + connection.Open(); + using (var mc = new MySqlCommand(sql, connection)) + using (var dr = mc.ExecuteReader()) + { + while (dr.Read()) + { + result.Add(new Users + { + Id = dr.GetInt32("id"), + Name = dr.GetString("name"), + Password = dr.GetString("password"), + + }); + } + } + + connection.Close(); + } + catch (MySqlException ex) + { + Console.WriteLine(ex); + } + catch (Exception e) + { + Console.WriteLine(e); + } + + return result; + } +} \ No newline at end of file diff --git a/Policlinica/Models/Doctors.cs b/Policlinica/Models/Doctors.cs new file mode 100644 index 0000000..c204253 --- /dev/null +++ b/Policlinica/Models/Doctors.cs @@ -0,0 +1,10 @@ +namespace Policlinica.DB; + +public class Doctors +{ + public int Id { get; set; } + + public string Title { get; set; } + + public string Description { get; set; } +} \ No newline at end of file diff --git a/Policlinica/Models/RecordItems.cs b/Policlinica/Models/RecordItems.cs new file mode 100644 index 0000000..3308154 --- /dev/null +++ b/Policlinica/Models/RecordItems.cs @@ -0,0 +1,12 @@ +namespace Policlinica.DB; + +public class RecordItems +{ + public int Id { get; set; } + + public int ServiceId { get; set; } + + public int RecordId { get; set; } + + public decimal ServicePrice { get; set; } +} \ No newline at end of file diff --git a/Policlinica/Models/Records.cs b/Policlinica/Models/Records.cs new file mode 100644 index 0000000..3483b38 --- /dev/null +++ b/Policlinica/Models/Records.cs @@ -0,0 +1,20 @@ +using System; + +namespace Policlinica.DB; + +public class Records +{ + public int Id { get; set; } + + public string ClientName { get; set; } + + public string ClientSurname { get; set; } + + public int DoctorId { get; set; } + + public int UserId { get; set; } + + public decimal TotalAmount { get; set; } + + public DateTime RecordDate { get; set; } +} \ No newline at end of file diff --git a/Policlinica/Models/Services.cs b/Policlinica/Models/Services.cs new file mode 100644 index 0000000..9e7e720 --- /dev/null +++ b/Policlinica/Models/Services.cs @@ -0,0 +1,12 @@ +namespace Policlinica.DB; + +public class Services +{ + public int Id { get; set; } + + public string ServiceName { get; set; } + + public decimal Price { get; set; } + + public int DoctorId { get; set; } +} \ No newline at end of file diff --git a/Policlinica/Models/Users.cs b/Policlinica/Models/Users.cs new file mode 100644 index 0000000..3978653 --- /dev/null +++ b/Policlinica/Models/Users.cs @@ -0,0 +1,10 @@ +namespace Policlinica.DB; + +public class Users +{ + public int Id { get; set; } + + public string Name { get; set; } + + public string Password {get; set;} +} \ No newline at end of file diff --git a/Policlinica/Policlinica.csproj b/Policlinica/Policlinica.csproj new file mode 100644 index 0000000..d6b5820 --- /dev/null +++ b/Policlinica/Policlinica.csproj @@ -0,0 +1,35 @@ + + + WinExe + net10.0 + enable + app.manifest + true + + + + + + + + + + + + + + None + All + + + + + + + + + + PreserveNewest + + + diff --git a/Policlinica/Program.cs b/Policlinica/Program.cs new file mode 100644 index 0000000..27a3146 --- /dev/null +++ b/Policlinica/Program.cs @@ -0,0 +1,51 @@ +using Avalonia; +using System; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Policlinica.DB; +using Policlinica.ViewModels; +using Policlinica.Views; + + + +namespace Policlinica; + +sealed class Program +{ + [STAThread] + public static void Main(string[] args) + { + var host = Host.CreateDefaultBuilder(). + ConfigureAppConfiguration((context, config) => + { + config.SetBasePath(AppContext.BaseDirectory) + .AddJsonFile("appsetting.json") + .AddEnvironmentVariables(); + }). + ConfigureServices((c,s) => + { + s.Configure(c.Configuration. + GetSection("DatabaseConnection")); + //окна + s.AddTransient(); + s.AddTransient(); + s.AddTransient(); + s.AddTransient(); + + //Репозитории + s.AddTransient(); + s.AddTransient(); + }). + Build(); + BuildAvaloniaApp(host.Services) + .StartWithClassicDesktopLifetime(args); + } + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp(IServiceProvider serviceProvider) + => AppBuilder.Configure(()=> new App(serviceProvider)) + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); +} \ No newline at end of file diff --git a/Policlinica/ViewLocator.cs b/Policlinica/ViewLocator.cs new file mode 100644 index 0000000..4150eb1 --- /dev/null +++ b/Policlinica/ViewLocator.cs @@ -0,0 +1,37 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using Policlinica.ViewModels; + +namespace Policlinica; + +/// +/// Given a view model, returns the corresponding view if possible. +/// +[RequiresUnreferencedCode( + "Default implementation of ViewLocator involves reflection which may be trimmed away.", + Url = "https://docs.avaloniaui.net/docs/concepts/view-locator")] +public class ViewLocator : IDataTemplate +{ + public Control? Build(object? param) + { + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + var type = Type.GetType(name); + + if (type != null) + { + return (Control)Activator.CreateInstance(type)!; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object? data) + { + return data is ViewModelBase; + } +} \ No newline at end of file diff --git a/Policlinica/ViewModels/AdminWindowViewModel.cs b/Policlinica/ViewModels/AdminWindowViewModel.cs new file mode 100644 index 0000000..94a737a --- /dev/null +++ b/Policlinica/ViewModels/AdminWindowViewModel.cs @@ -0,0 +1,6 @@ +namespace Policlinica.ViewModels; + +public class AdminWindowViewModel +{ + +} \ No newline at end of file diff --git a/Policlinica/ViewModels/PasswordWindowViewModel.cs b/Policlinica/ViewModels/PasswordWindowViewModel.cs new file mode 100644 index 0000000..88c3d76 --- /dev/null +++ b/Policlinica/ViewModels/PasswordWindowViewModel.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Microsoft.Extensions.DependencyInjection; +using Policlinica.DB; +using Policlinica.Views; + +namespace Policlinica.ViewModels; + +public partial class PasswordWindowViewModel : ViewModelBase +{ + private readonly IServiceProvider _serviceProvider; + private readonly IServiceProvider _provider; + [ObservableProperty] string username; + [ObservableProperty] string password; + [ObservableProperty] List _usersList; + [ObservableProperty] private Users selectedUsers; + [ObservableProperty] UserRepository _repository; + + public PasswordWindowViewModel(IServiceProvider provider, UserRepository repository ) + { + _provider = provider; + _usersList = repository.GetUsersByTest(); + // _repository = repository; + } + + [RelayCommand] + public void StartTest() + { + if (SelectedUsers == null) + return; + var vm = ActivatorUtilities.CreateInstance( + _provider, + SelectedUsers, + Username); + var win = _provider.GetRequiredService(); + //vm.SetClose(win.Close); + win.DataContext = vm; + win.Show(); + // close(); + + } + [RelayCommand] + public void SaveDB() + { + Users user = new Users + { + Name = Username, + Password = Password, + Id = SelectedUsers.Id, + + }; + _repository.InsertUser(user); + if (SelectedUsers == null) + return; + var vm = _serviceProvider.GetRequiredService(); + var win = _serviceProvider.GetRequiredService(); + + //vm.SetClose(win.Close); + win.DataContext = vm; + win.Show(); + //close(); + } +} \ No newline at end of file diff --git a/Policlinica/ViewModels/ViewModelBase.cs b/Policlinica/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..be0ddca --- /dev/null +++ b/Policlinica/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace Policlinica.ViewModels; + +public abstract class ViewModelBase : ObservableObject +{ +} \ No newline at end of file diff --git a/Policlinica/Views/AdminWindow.axaml b/Policlinica/Views/AdminWindow.axaml new file mode 100644 index 0000000..c836953 --- /dev/null +++ b/Policlinica/Views/AdminWindow.axaml @@ -0,0 +1,9 @@ + + Welcome to Avalonia! + diff --git a/Policlinica/Views/AdminWindow.axaml.cs b/Policlinica/Views/AdminWindow.axaml.cs new file mode 100644 index 0000000..ff3acae --- /dev/null +++ b/Policlinica/Views/AdminWindow.axaml.cs @@ -0,0 +1,13 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; + +namespace Policlinica.Views; + +public partial class AdminWindow : Window +{ + public AdminWindow() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/Policlinica/Views/PasswordWindow.axaml b/Policlinica/Views/PasswordWindow.axaml new file mode 100644 index 0000000..1ae100c --- /dev/null +++ b/Policlinica/Views/PasswordWindow.axaml @@ -0,0 +1,29 @@ + + + + + + + + + + +