diff --git a/Appsettings.json b/Appsettings.json index e616c3a..c89e8b1 100644 --- a/Appsettings.json +++ b/Appsettings.json @@ -1,5 +1,5 @@ { - "DatabseConnection": { - "ConnectionString" : "server=localhost;userid=root;password=root;database=bathhousemanagment" + "DatabaseConnection": { + "ConnectionString" : "server=localhost;user=root;password=root;database=bathhouse" } } \ No newline at end of file diff --git a/Database/OrderRepository.cs b/Database/OrderRepository.cs index 4fe6c48..367f784 100644 --- a/Database/OrderRepository.cs +++ b/Database/OrderRepository.cs @@ -18,7 +18,7 @@ public class OrderRepository public List GetOrders() { List result = new(); - string sql = "select * from orders"; + string sql = "select o.id as oid, o.client_id as ocid, o.employee_id as eid, o.discount_id as did, o.service_id as sid, o.zone_id as zid, c.name as cname, c.surname as csurname, o.order_time as otime, e.name as ename, e.surname as esurname, d.name as dname, s.name as sname, z.name as zname from `order` o join client c on o.client_id = c.id join employee e on o.employee_id = e.id join discount d on o.discount_id = d.id join service s on o.service_id = s.id join zone z on o.zone_id = z.id \n"; try { connection.Open(); @@ -29,14 +29,51 @@ public class OrderRepository { result.Add(new Order { + /* Id = reader.GetInt32("id"), ClientId = reader.GetInt32("client_id"), ZoneId = reader.GetInt32("zone_id"), OrderDate = reader.GetDateTime("order_date"), - WorkPrice = reader.GetInt32("work_price"), + ServiceId = reader.GetInt32("service_id"), EmployeeId = reader.GetInt32("employee_id"), DiscountId = reader.GetInt32("discount_id"), FinalPrice = reader.GetInt32("final_price"), + */ + Client = new Client() + { + Id = reader.GetInt32("ocid"), + Name = reader.GetString("cname"), + Surname = reader.GetString("csurname"), + }, + + Employee = new Employee() + { + Id = reader.GetInt32("eid"), + Name = reader.GetString("ename"), + Surname = reader.GetString("esurname"), + }, + + Discount = new Discount() + { + Id = reader.GetInt32("did"), + Name = reader.GetString("dname"), + }, + + Zone = new Zone() + { + Id = reader.GetInt32("zid"), + Name = reader.GetString("zname"), + }, + + Service = new Service() + { + Id = reader.GetInt32("sid"), + Name = reader.GetString("sname"), + }, + FinalPrice = reader.GetInt32("final_price"), + OrderDate = reader.GetDateTime("order_date"), + Id = reader.GetInt32("oid"), + }); } } @@ -52,7 +89,7 @@ public class OrderRepository public bool InsertOrder(Order order) { string sql = - "insert into `order` (`id`, `client_id`, `zone_id`, `order_date`, `work_price`, `employee_id`, `discount_id`, `final_price`) values (0, @client_id, @client_id, @zone_id, @order_date, @work_price, @employee_id, @discount_id, @final_price)"; + "insert into `order` (`id`, `client_id`, `zone_id`, `order_date`, `service_id`, `employee_id`, `discount_id`, `final_price`) values (0, @client_id, @client_id, @zone_id, @order_date, @service_id, @employee_id, @discount_id, @final_price)"; try { connection.Open(); @@ -61,7 +98,7 @@ public class OrderRepository command.Parameters.AddWithValue("@client_id", order.ClientId); command.Parameters.AddWithValue("@zone_id", order.ZoneId); command.Parameters.AddWithValue("@order_date", order.OrderDate); - command.Parameters.AddWithValue("@work_price", order.WorkPrice); + command.Parameters.AddWithValue("@service_id", order.ServiceId); command.Parameters.AddWithValue("@employee_id", order.EmployeeId); command.Parameters.AddWithValue("@discount_id", order.DiscountId); command.Parameters.AddWithValue("@final_price", order.FinalPrice); @@ -81,7 +118,7 @@ public class OrderRepository public bool UpdateOrder(Order order) { string sql = - "update `order` set client_id = @client_id, zone_id = @zone_id, order_date = @order_date, work_price = @work_price, employee_id = @employee_id, discount_id = @discount_id, final_price = @final_price"; + "update `order` set client_id = @client_id, zone_id = @zone_id, order_date = @order_date, service_id = @service_id, employee_id = @employee_id, discount_id = @discount_id, final_price = @final_price"; try { connection.Open(); @@ -90,7 +127,7 @@ public class OrderRepository command.Parameters.AddWithValue("@client_id", order.ClientId); command.Parameters.AddWithValue("@zone_id", order.ZoneId); command.Parameters.AddWithValue("@order_date", order.OrderDate); - command.Parameters.AddWithValue("@work_price", order.WorkPrice); + command.Parameters.AddWithValue("@service_id", order.ServiceId); command.Parameters.AddWithValue("@employee_id", order.EmployeeId); command.Parameters.AddWithValue("@discount_id", order.DiscountId); command.Parameters.AddWithValue("@final_price", order.FinalPrice); diff --git a/Database/ServiceRepository.cs b/Database/ServiceRepository.cs new file mode 100644 index 0000000..4f9eab6 --- /dev/null +++ b/Database/ServiceRepository.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using BathHouseManagmet.Models; +using Microsoft.Extensions.Options; +using MySqlConnector; + +namespace BathHouseManagmet.Database; + +public class ServiceRepository +{ + MySqlConnection connection; + + public ServiceRepository(IOptions connect) + { + connection = new MySqlConnection(connect.Value.ConnectionString); + } + + public List GetServices() + { + List result = new(); + string sql = "select * from `service`"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + result.Add(new Service + { + Id = reader.GetInt32("id"), + Name = reader.GetString("name"), + Description = reader.GetString("description"), + Price = reader.GetInt32("price") + }); + } + } + connection.Close(); + } + catch (Exception e) + { + Console.WriteLine(e); + } + return result; + } + + public bool InsertService(Service service) + { + string sql = "insert into `service` (`id`, `name`, `description`, `price`) values (0, @name, @description, @price)"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@id", service.Id); + command.Parameters.AddWithValue("@name", service.Name); + command.Parameters.AddWithValue("@description", service.Description); + command.Parameters.AddWithValue("@price", service.Price); + command.ExecuteNonQuery(); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } + + public bool UpdateService(Service service) + { + string sql = "update `service` set name = @name, description = @description, price = @price"; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.Parameters.AddWithValue("@name", service.Name); + command.Parameters.AddWithValue("@description", service.Description); + command.Parameters.AddWithValue("@price", service.Price); + command.ExecuteNonQuery(); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } + + public bool DeleteService(Service service) + { + string sql = "delete from `service` where `id` =" + service.Id; + try + { + connection.Open(); + using (var command = new MySqlCommand(sql, connection)) + { + command.ExecuteNonQuery(); + } + connection.Close(); + } + catch (Exception e) + { + connection.Close(); + return false; + } + connection.Close(); + return true; + } +} \ No newline at end of file diff --git a/Models/Order.cs b/Models/Order.cs index 6c96f17..05ceefc 100644 --- a/Models/Order.cs +++ b/Models/Order.cs @@ -8,8 +8,15 @@ public class Order public int ClientId { get; set; } public int ZoneId { get; set; } public DateTime OrderDate { get; set; } - public int WorkPrice { get; set; } + public int ServiceId { get; set; } public int EmployeeId { get; set; } public int DiscountId { get; set; } public int FinalPrice { get; set; } + public Client Client { get; set; } + public Employee Employee { get; set; } + public Zone Zone { get; set; } + public Position Position { get; set; } + public Discount Discount { get; set; } + public Service Service { get; set; } + } \ No newline at end of file diff --git a/Models/Service.cs b/Models/Service.cs new file mode 100644 index 0000000..8018718 --- /dev/null +++ b/Models/Service.cs @@ -0,0 +1,9 @@ +namespace BathHouseManagmet.Models; + +public class Service +{ + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public int Price { get; set; } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 4594170..2047a6e 100644 --- a/Program.cs +++ b/Program.cs @@ -25,6 +25,12 @@ sealed class Program s.Configure(c.Configuration.GetSection("DatabaseConnection")); s.AddTransient(); s.AddTransient(); + s.AddTransient(); + s.AddTransient(); + s.AddTransient(); + s.AddTransient(); + s.AddTransient(); + s.AddTransient(); }).Build(); BuildAvaloniaApp(host.Services) .StartWithClassicDesktopLifetime(args); diff --git a/ViewModels/MainWindowViewModel.cs b/ViewModels/MainWindowViewModel.cs index 1c57edc..9df03bc 100644 --- a/ViewModels/MainWindowViewModel.cs +++ b/ViewModels/MainWindowViewModel.cs @@ -1,6 +1,25 @@ -namespace BathHouseManagmet.ViewModels; +using System; +using System.Collections.Generic; +using BathHouseManagmet.Database; +using BathHouseManagmet.Models; +using CommunityToolkit.Mvvm.ComponentModel; + +namespace BathHouseManagmet.ViewModels; public partial class MainWindowViewModel : ViewModelBase { + private readonly IServiceProvider _serviceProvider; + private readonly EmployeeRepository _employeeRepository; + private readonly OrderRepository _orderRepository; + [ObservableProperty] List orders; + + public MainWindowViewModel(IServiceProvider serviceProvider, EmployeeRepository employeeRepository, OrderRepository orderRepository) + { + _serviceProvider = serviceProvider; + _employeeRepository = employeeRepository; + _orderRepository = orderRepository; + + Orders = orderRepository.GetOrders(); + } } \ No newline at end of file diff --git a/Views/MainWindow.axaml b/Views/MainWindow.axaml index bfaca2a..e6bbdfd 100644 --- a/Views/MainWindow.axaml +++ b/Views/MainWindow.axaml @@ -8,5 +8,28 @@ x:DataType="vm:MainWindowViewModel" Icon="/Assets/avalonia-logo.ico" Title="BathHouseManagment"> - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/obj/Debug/net10.0/Avalonia/resources b/obj/Debug/net10.0/Avalonia/resources index 0dfd102..253638a 100644 Binary files a/obj/Debug/net10.0/Avalonia/resources and b/obj/Debug/net10.0/Avalonia/resources differ diff --git a/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfo.cs b/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfo.cs index 88e348a..97c457c 100644 --- a/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfo.cs +++ b/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("BathHouseManagmet")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4d0b4a63d29885a351c12ee66035741bb67c868f")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+55e84ef57c6abfe4ef4f4ef588ea91f719ce8536")] [assembly: System.Reflection.AssemblyProductAttribute("BathHouseManagmet")] [assembly: System.Reflection.AssemblyTitleAttribute("BathHouseManagmet")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfoInputs.cache b/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfoInputs.cache index 372a912..aade2f0 100644 --- a/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfoInputs.cache +++ b/obj/Debug/net10.0/BathHouseManagmet.AssemblyInfoInputs.cache @@ -1 +1 @@ -00710766fbaba364e5f0fd3c7dc3d271457e9a7b5c0166076f7bdc3704b53eb6 +af96d54e4de83c2d92c24c535a5ffbc3bfff4696e1e3b1ef13b37dfd8a84647a