diff --git a/HistoryOrdersWindow.axaml b/HistoryOrdersWindow.axaml
new file mode 100644
index 0000000..a35dea6
--- /dev/null
+++ b/HistoryOrdersWindow.axaml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/HistoryOrdersWindow.axaml.cs b/HistoryOrdersWindow.axaml.cs
new file mode 100644
index 0000000..8b96274
--- /dev/null
+++ b/HistoryOrdersWindow.axaml.cs
@@ -0,0 +1,162 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.IO;
+using System.Linq;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Interactivity;
+using Avalonia.Markup.Xaml;
+using dmeo040225.Models;
+using dmeo040225.Services;
+using PdfSharpCore.Drawing;
+using PdfSharpCore.Pdf;
+
+namespace dmeo040225;
+
+public partial class HistoryOrdersWindow : Window
+{
+ ObservableCollection Orders = new ObservableCollection();
+ List dataSourceServices;
+ List dataSourceOrders;
+ public HistoryOrdersWindow()
+ {
+ InitializeComponent();
+ using var context = new DatabaseContext();
+ dataSourceOrders = context.Orders.Select(order => new OrderPresenter
+ {
+ Id = order.Id,
+ Code = order.Code,
+ Orderdata = order.Orderdata,
+ Ordertime = order.Ordertime,
+ UserId = order.UserId,
+ Status = order.Status,
+ Prokattime = order.Prokattime,
+ Services = order.OrdersServices.Select(os => os.Service).ToList(),
+ UserFio = context.Users.FirstOrDefault(u => u.Id == order.UserId).Fio,
+
+ ServicesNames = new ObservableCollection(
+ order.OrdersServices.Select(os => os.Service.Name).ToList()
+ )
+ }).ToList();
+
+ dataSourceServices = context.Services.Select(order => new Service()).ToList();
+
+ ListBoxHistory.ItemsSource = Orders;
+ FilterComboboxUsers.ItemsSource = context.Users.Select(user => user.Fio).ToList();
+ FilterComboboxServices.ItemsSource = context.Services.Select(service => service.Name).ToList();
+ DisplayServices();
+
+ TimerService.Instance.TimeUpdated += UpdateTimerText;
+ TimerService.Instance.TimerExpired += LogoutUser;
+ }
+
+ public class OrderPresenter() : Order
+ {
+ public List Services { get; set; } = new();
+ public String UserFio;
+ public ObservableCollection ServicesNames { get; set; } = new();
+ }
+
+ public void DisplayServices()
+ {
+ var temp = dataSourceOrders;
+ Orders.Clear();
+
+ if (FilterComboboxUsers.SelectionBoxItem != null)
+ {
+ temp = temp.Where(u => u.UserFio == FilterComboboxUsers.SelectionBoxItem.ToString()).ToList();
+ }
+
+ if (FilterComboboxServices.SelectionBoxItem != null)
+ {
+ var selectedServiceName = FilterComboboxServices.SelectionBoxItem.ToString();
+ temp = temp.Where(o => o.Services.Any(s => s.Name == selectedServiceName)).ToList();
+ }
+
+ foreach (var item in temp)
+ {
+ Orders.Add(item);
+ }
+ }
+
+ private void FilterComboboxUsers_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
+ {
+ DisplayServices();
+ }
+
+ private void FilterComboboxServices_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
+ {
+ DisplayServices();
+ }
+
+ private void Back_OnClick(object? sender, RoutedEventArgs e)
+ {
+ Close();
+ }
+
+ private void UpdateTimerText(TimeSpan time)
+ {
+ TimerText.Text = $"Осталось: {time:mm\\:ss}";
+ }
+
+ private void LogoutUser()
+ {
+ Close();
+ var mainWindow = new MainWindow();
+ mainWindow.Show();
+ }
+
+ protected override void OnClosed(EventArgs e)
+ {
+ TimerService.Instance.TimeUpdated -= UpdateTimerText;
+ TimerService.Instance.TimerExpired -= LogoutUser;
+ base.OnClosed(e);
+ }
+
+ private void FormOrder_OnClick(object? sender, RoutedEventArgs e)
+ {
+ if (ListBoxHistory.SelectedItem is OrderPresenter selectedOrder)
+ {
+ var resultSum = 0;
+ var serviceNames = "";
+
+ using var document = new PdfDocument();
+ var page = document.AddPage();
+ var gfx = XGraphics.FromPdfPage(page);
+
+ var font = new XFont("Arial", 14, XFontStyle.Regular);
+
+ foreach (var service in selectedOrder.Services)
+ {
+ resultSum += int.Parse(service.Cost);
+ serviceNames += service.Name + " ";
+ }
+
+ var lines = new List
+ {
+ $"Дата заказа: {selectedOrder.Orderdata}",
+ $"ID пользователя: {selectedOrder.UserId}",
+ $"Код заказа: {selectedOrder.Code}",
+ $"ФИО пользователя: {selectedOrder.UserFio}",
+ $"Время заказа: {selectedOrder.Ordertime}",
+ $"Услуги: {serviceNames}",
+ $"Итоговая сумма: {resultSum}"
+ };
+
+ double x = 50, y = 50;
+ double lineHeight = 20;
+
+ foreach (var line in lines)
+ {
+ gfx.DrawString(line, font, XBrushes.Black, new XPoint(x, y));
+ y += lineHeight;
+ }
+
+ string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), $"Order_{selectedOrder.Id}.pdf");
+ document.Save(filePath);
+
+ Console.WriteLine($"PDF сохранен: {filePath}");
+ }
+ }
+}
\ No newline at end of file
diff --git a/Models/DatabaseContext.cs b/Models/DatabaseContext.cs
index 4652ed0..50128f2 100644
--- a/Models/DatabaseContext.cs
+++ b/Models/DatabaseContext.cs
@@ -61,18 +61,19 @@ public partial class DatabaseContext : DbContext
modelBuilder.Entity(entity =>
{
- entity
- .HasNoKey()
- .ToTable("orders_services");
+ entity.HasKey(e => e.Id).HasName("orders_services_pk");
+ entity.ToTable("orders_services");
+
+ entity.Property(e => e.Id).HasColumnName("id");
entity.Property(e => e.OrderId).HasColumnName("order_id");
entity.Property(e => e.ServiceId).HasColumnName("service_id");
- entity.HasOne(d => d.Order).WithMany()
+ entity.HasOne(d => d.Order).WithMany(p => p.OrdersServices)
.HasForeignKey(d => d.OrderId)
.HasConstraintName("orders_services_order_id_fkey");
- entity.HasOne(d => d.Service).WithMany()
+ entity.HasOne(d => d.Service).WithMany(p => p.OrdersServices)
.HasForeignKey(d => d.ServiceId)
.HasConstraintName("orders_services_service_id_fkey");
});
diff --git a/Models/Order.cs b/Models/Order.cs
index a50b69c..97dec5c 100644
--- a/Models/Order.cs
+++ b/Models/Order.cs
@@ -21,5 +21,7 @@ public partial class Order
public int Prokattime { get; set; }
+ public virtual ICollection OrdersServices { get; set; } = new List();
+
public virtual User User { get; set; } = null!;
}
diff --git a/Models/OrdersService.cs b/Models/OrdersService.cs
index 46da224..962cf64 100644
--- a/Models/OrdersService.cs
+++ b/Models/OrdersService.cs
@@ -9,6 +9,8 @@ public partial class OrdersService
public int ServiceId { get; set; }
+ public int Id { get; set; }
+
public virtual Order Order { get; set; } = null!;
public virtual Service Service { get; set; } = null!;
diff --git a/Models/Service.cs b/Models/Service.cs
index a21c32e..4c24de6 100644
--- a/Models/Service.cs
+++ b/Models/Service.cs
@@ -12,4 +12,6 @@ public partial class Service
public string Code { get; set; } = null!;
public string Cost { get; set; } = null!;
+
+ public virtual ICollection OrdersServices { get; set; } = new List();
}
diff --git a/NewOrder.axaml.cs b/NewOrder.axaml.cs
index 668a475..63ba338 100644
--- a/NewOrder.axaml.cs
+++ b/NewOrder.axaml.cs
@@ -115,15 +115,15 @@ public partial class NewOrder : Window
context.Orders.Add(newOrder);
context.SaveChanges();
- // foreach (var service in services)
- // {
- // var orderService = new OrdersService
- // {
- // OrderId = newOrder.Id,
- // ServiceId = service.Id
- // };
- // context.OrdersServices.Add(orderService);
- // }
+ foreach (var service in services)
+ {
+ var orderService = new OrdersService
+ {
+ OrderId = newOrder.Id,
+ ServiceId = service.Id
+ };
+ context.OrdersServices.Add(orderService);
+ }
context.SaveChanges();
LoadOrderId();
diff --git a/NewOrderWindow.axaml b/NewOrderWindow.axaml
deleted file mode 100644
index 70c4c71..0000000
--- a/NewOrderWindow.axaml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/NewOrderWindow.axaml.cs b/NewOrderWindow.axaml.cs
deleted file mode 100644
index d6f79eb..0000000
--- a/NewOrderWindow.axaml.cs
+++ /dev/null
@@ -1,158 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using Avalonia.Controls;
-using Avalonia.Interactivity;
-using ZXing;
-using ZXing.Common;
-using PdfSharpCore.Drawing;
-using PdfSharpCore.Pdf;
-using SixLabors.ImageSharp;
-using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.ImageSharp.Processing;
-using dmeo040225.Models;
-using dmeo040225.Models;
-
-namespace dmeo040225;
-
-public partial class NewOrderWindow : Window
-{
- public List OrderServicesList { get; }
- public List OrderClientsList { get; }
-
- public NewOrderWindow()
- {
- InitializeComponent();
- LoadOrderId();
- using var context = new DatabaseContext();
-
- OrderClientsList = context.Users.Select(it => it.Fio).ToList();
- OrderClientComboBox.ItemsSource = OrderClientsList;
-
- OrderServicesList = context.Services.Select(it => it.Name).ToList();
- OrderServicesListBox.ItemsSource = OrderServicesList;
- }
-
- private void LoadOrderId()
- {
- using var context = new DatabaseContext();
- var maxId = context.Orders.Any() ? context.Orders.Max(order => order.Id) : 0;
- var newOrderId = maxId + 1;
- OrderIdTextBox.Text = newOrderId.ToString();
- }
-
- private void CreateOrderButton_OnClick(object? sender, RoutedEventArgs e)
- {
- using var context = new DatabaseContext();
-
- var maxId = context.Orders.Any() ? context.Orders.Max(order => order.Id) : 0;
- var newOrderId = maxId + 1;
- var newCodeOrder = $"{newOrderId}/{DateTime.Now:dd.MM.yyyy}";
- var newPeriod = int.TryParse(PeriodTextBox.Text, out int period) ? period : 0;
-
- var selectedClientFio = OrderClientComboBox.SelectedItem as string;
- if (string.IsNullOrEmpty(selectedClientFio))
- {
- Console.WriteLine("Выберите клиента!");
- return;
- }
-
- var client = context.Users.FirstOrDefault(it => it.Fio == selectedClientFio);
- if (client == null)
- {
- Console.WriteLine("Ошибка: клиент не найден!");
- return;
- }
-
- var selectedServices = OrderServicesListBox.SelectedItems.Cast().ToList();
- if (selectedServices.Count == 0)
- {
- Console.WriteLine("Выберите хотя бы одну услугу!");
- return;
- }
-
- var services = context.Services.Where(s => selectedServices.Contains(s.Name)).ToList();
-
- var newOrder = new Order
- {
- Id = newOrderId,
- Code = newCodeOrder,
- Orderdata = DateTime.Now,
- Ordertime = TimeOnly.FromDateTime(DateTime.Now),
- UserId = client.Id,
- Status = "Открыт",
- Prokattime = newPeriod
- };
-
- context.Orders.Add(newOrder);
- context.SaveChanges();
-
- foreach (var service in services)
- {
- var orderService = new OrdersService
- {
- OrderId = newOrder.Id,
- ServiceId = service.Id
- };
- context.OrdersServices.Add(orderService);
- }
-
- context.SaveChanges();
- LoadOrderId();
-
- Console.WriteLine("Заказ создан");
-
- GenerateBarcodeAndSavePdf(newOrderId, DateTime.Now, newPeriod);
- }
-
- public void GenerateBarcodeAndSavePdf(int orderId, DateTime orderDate, int rentalPeriod)
- {
- var random = new Random();
- string uniqueCode = string.Concat(Enumerable.Range(0, 6).Select(_ => random.Next(0, 10)));
-
- string barcodeData = $"{orderId}{orderDate:ddMMyy}{rentalPeriod}{uniqueCode}";
-
- var writer = new BarcodeWriterPixelData
- {
- Format = BarcodeFormat.CODE_128,
- Options = new EncodingOptions
- {
- Height = 229,
- Width = 350,
- Margin = 0
- }
- };
- var pixelData = writer.Write(barcodeData);
-
- using var image = new Image(pixelData.Width, pixelData.Height);
- image.Mutate(ctx =>
- {
- for (int y = 0; y < pixelData.Height; y++)
- {
- for (int x = 0; x < pixelData.Width; x++)
- {
- byte value = pixelData.Pixels[(y * pixelData.Width + x) * 4];
- image[x, y] = new Rgba32(value, value, value, 255);
- }
- }
- });
-
- using var ms = new MemoryStream();
- image.SaveAsPng(ms);
- ms.Position = 0;
-
- using var document = new PdfDocument();
- var page = document.AddPage();
- var gfx = XGraphics.FromPdfPage(page);
-
- using var img = XImage.FromStream(() => new MemoryStream(ms.ToArray()));
- gfx.DrawImage(img, 10, 10, 150, 50);
-
- gfx.DrawString(barcodeData, new XFont("Arial", 10), XBrushes.Black, new XPoint(10, 70));
-
- string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), $"Order_{orderId}.pdf");
- document.Save(filePath);
- Console.WriteLine($"PDF сохранен: {filePath}");
- }
-}
\ No newline at end of file
diff --git a/SellerWindow.axaml b/SellerWindow.axaml
index 1efa227..cde4750 100644
--- a/SellerWindow.axaml
+++ b/SellerWindow.axaml
@@ -17,6 +17,7 @@
+
diff --git a/SellerWindow.axaml.cs b/SellerWindow.axaml.cs
index fc52398..7389709 100644
--- a/SellerWindow.axaml.cs
+++ b/SellerWindow.axaml.cs
@@ -50,13 +50,17 @@ public partial class SellerWindow : Window
NewOrder newOrder = new NewOrder();
newOrder.ShowDialog(this);
}
+
+ private void HistoryOrder_OnClick(object? sender, RoutedEventArgs e)
+ {
+ HistoryOrdersWindow historyOrdersWindow = new HistoryOrdersWindow();
+ historyOrdersWindow.ShowDialog(this);
+ }
private void Back_OnClick(object? sender, RoutedEventArgs e)
{
TimerService.Instance.Reset();
Close();
- // MainWindow mainWindow = new MainWindow();
- // mainWindow.Show();
}
protected override void OnClosed(EventArgs e)
diff --git a/bin/Debug/net8.0/dmeo040225.dll b/bin/Debug/net8.0/dmeo040225.dll
index 72230c8..57dde2a 100644
Binary files a/bin/Debug/net8.0/dmeo040225.dll and b/bin/Debug/net8.0/dmeo040225.dll differ
diff --git a/bin/Debug/net8.0/dmeo040225.pdb b/bin/Debug/net8.0/dmeo040225.pdb
index 585f3d4..6949996 100644
Binary files a/bin/Debug/net8.0/dmeo040225.pdb and b/bin/Debug/net8.0/dmeo040225.pdb differ
diff --git a/obj/Debug/net8.0/Avalonia/Resources.Inputs.cache b/obj/Debug/net8.0/Avalonia/Resources.Inputs.cache
index e37564e..b974a36 100644
--- a/obj/Debug/net8.0/Avalonia/Resources.Inputs.cache
+++ b/obj/Debug/net8.0/Avalonia/Resources.Inputs.cache
@@ -1 +1 @@
-dcee2ff9ab40261eababb0bda80a1213a097f630882dc250b9c305771c0c60e5
+f68245289585a316c95c6a0242ee82c924ad78226a6ee4e9159c267738ab4ad4
diff --git a/obj/Debug/net8.0/Avalonia/dmeo040225.dll b/obj/Debug/net8.0/Avalonia/dmeo040225.dll
index 72230c8..57dde2a 100644
Binary files a/obj/Debug/net8.0/Avalonia/dmeo040225.dll and b/obj/Debug/net8.0/Avalonia/dmeo040225.dll differ
diff --git a/obj/Debug/net8.0/Avalonia/dmeo040225.pdb b/obj/Debug/net8.0/Avalonia/dmeo040225.pdb
index 585f3d4..6949996 100644
Binary files a/obj/Debug/net8.0/Avalonia/dmeo040225.pdb and b/obj/Debug/net8.0/Avalonia/dmeo040225.pdb differ
diff --git a/obj/Debug/net8.0/Avalonia/resources b/obj/Debug/net8.0/Avalonia/resources
index 4047f6a..147f952 100644
Binary files a/obj/Debug/net8.0/Avalonia/resources and b/obj/Debug/net8.0/Avalonia/resources differ
diff --git a/obj/Debug/net8.0/dmeo040225.AssemblyInfo.cs b/obj/Debug/net8.0/dmeo040225.AssemblyInfo.cs
index 30646ed..a61ad89 100644
--- a/obj/Debug/net8.0/dmeo040225.AssemblyInfo.cs
+++ b/obj/Debug/net8.0/dmeo040225.AssemblyInfo.cs
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("dmeo040225")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
-[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+9425badd58264bf54d3df7b654468fb3dae859ad")]
+[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a8277c9d7e311c951210e8ad35e67aecd086b064")]
[assembly: System.Reflection.AssemblyProductAttribute("dmeo040225")]
[assembly: System.Reflection.AssemblyTitleAttribute("dmeo040225")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
diff --git a/obj/Debug/net8.0/dmeo040225.AssemblyInfoInputs.cache b/obj/Debug/net8.0/dmeo040225.AssemblyInfoInputs.cache
index 9a2dd8b..3da03b0 100644
--- a/obj/Debug/net8.0/dmeo040225.AssemblyInfoInputs.cache
+++ b/obj/Debug/net8.0/dmeo040225.AssemblyInfoInputs.cache
@@ -1 +1 @@
-b11ea1593792717964ae904d80c98bb22d4fc3dfa03cb4c0d43a71cbebe1429f
+e1a77b8fdfe801510641ec14b3733bcc12e9d5034f11027fcc8d1ef274e02dc3
diff --git a/obj/Debug/net8.0/dmeo040225.GeneratedMSBuildEditorConfig.editorconfig b/obj/Debug/net8.0/dmeo040225.GeneratedMSBuildEditorConfig.editorconfig
index a0d8db1..7d5a1ef 100644
--- a/obj/Debug/net8.0/dmeo040225.GeneratedMSBuildEditorConfig.editorconfig
+++ b/obj/Debug/net8.0/dmeo040225.GeneratedMSBuildEditorConfig.editorconfig
@@ -31,6 +31,9 @@ build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
[/Users/rinchi/RiderProjects/dmeo040225/dmeo040225/GetOrderWindow.axaml]
build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
+[/Users/rinchi/RiderProjects/dmeo040225/dmeo040225/HistoryOrdersWindow.axaml]
+build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
+
[/Users/rinchi/RiderProjects/dmeo040225/dmeo040225/HistoryWindow.axaml]
build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
@@ -40,9 +43,6 @@ build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
[/Users/rinchi/RiderProjects/dmeo040225/dmeo040225/NewOrder.axaml]
build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
-[/Users/rinchi/RiderProjects/dmeo040225/dmeo040225/NewOrderWindow.axaml]
-build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
-
[/Users/rinchi/RiderProjects/dmeo040225/dmeo040225/OlderWindow.axaml]
build_metadata.AdditionalFiles.SourceItemGroup = AvaloniaXaml
diff --git a/obj/Debug/net8.0/dmeo040225.csproj.CoreCompileInputs.cache b/obj/Debug/net8.0/dmeo040225.csproj.CoreCompileInputs.cache
index 50bf29a..08e6ec5 100644
--- a/obj/Debug/net8.0/dmeo040225.csproj.CoreCompileInputs.cache
+++ b/obj/Debug/net8.0/dmeo040225.csproj.CoreCompileInputs.cache
@@ -1 +1 @@
-8b5634db08a8828528f53df4df6209bd6d04c5d6962844fc6083067c58d2ad06
+3d1af8b94265d0f974c99c7ade78a323d9abeff7a6afeeeb9b7f8c80a3981b0b
diff --git a/obj/Debug/net8.0/dmeo040225.dll b/obj/Debug/net8.0/dmeo040225.dll
index c6c0c04..09464bb 100644
Binary files a/obj/Debug/net8.0/dmeo040225.dll and b/obj/Debug/net8.0/dmeo040225.dll differ
diff --git a/obj/Debug/net8.0/dmeo040225.pdb b/obj/Debug/net8.0/dmeo040225.pdb
index 8874967..5298b69 100644
Binary files a/obj/Debug/net8.0/dmeo040225.pdb and b/obj/Debug/net8.0/dmeo040225.pdb differ
diff --git a/obj/Debug/net8.0/ref/dmeo040225.dll b/obj/Debug/net8.0/ref/dmeo040225.dll
index 8953fff..2df3db1 100644
Binary files a/obj/Debug/net8.0/ref/dmeo040225.dll and b/obj/Debug/net8.0/ref/dmeo040225.dll differ
diff --git a/obj/Debug/net8.0/refint/Avalonia/dmeo040225.dll b/obj/Debug/net8.0/refint/Avalonia/dmeo040225.dll
index 8953fff..2df3db1 100644
Binary files a/obj/Debug/net8.0/refint/Avalonia/dmeo040225.dll and b/obj/Debug/net8.0/refint/Avalonia/dmeo040225.dll differ
diff --git a/obj/Debug/net8.0/refint/dmeo040225.dll b/obj/Debug/net8.0/refint/dmeo040225.dll
index 30e96f8..d463b23 100644
Binary files a/obj/Debug/net8.0/refint/dmeo040225.dll and b/obj/Debug/net8.0/refint/dmeo040225.dll differ
diff --git a/obj/rider.project.model.nuget.info b/obj/rider.project.model.nuget.info
index d1b05dc..ee241ab 100644
--- a/obj/rider.project.model.nuget.info
+++ b/obj/rider.project.model.nuget.info
@@ -1 +1 @@
-17409191325846449
\ No newline at end of file
+17409191358158990
\ No newline at end of file