From 9fd6904a399cfdae6829cceeb9d3f8eb317462cd Mon Sep 17 00:00:00 2001 From: ultrageese Date: Thu, 2 Apr 2026 12:41:17 +1000 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82!!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutoService/Models/ProceedRepository.cs | 14 +++++++++++--- AutoService/ViewModels/ReceiptWindowVM.cs | 16 ++++++++++++++++ AutoService/ViewModels/WorksWindowVM.cs | 1 + AutoService/Views/ReceiptWindow.axaml | 4 +++- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/AutoService/Models/ProceedRepository.cs b/AutoService/Models/ProceedRepository.cs index ab115c7..2b5fd69 100644 --- a/AutoService/Models/ProceedRepository.cs +++ b/AutoService/Models/ProceedRepository.cs @@ -19,7 +19,7 @@ namespace AutoService.Models try { OpenConnection(); - string sql1 = "INSERT INTO orders (id, client_name, car_model, service_id, total_amount, discount_percent, order_date) VALUES(0, @ClientName, @AutoModel, @ServiceId, @TotalAmount, @DiscountPercent, '@Date);"; + string sql1 = "INSERT INTO orders (id, client_name, car_model, service_id, total_amount, discount_percent, order_date) VALUES(0, @ClientName, @AutoModel, @ServiceId, @TotalAmount, @DiscountPercent, @Date);"; string sql2 = "SELECT LAST_INSERT_ID() as id;"; string sql3 = "INSERT INTO auto_service_db.order_items (id, order_id, work_id, work_price) VALUES(0, @OrderId, @WorkId, @WorkPrice);"; using var transaction = connection.BeginTransaction(); @@ -37,9 +37,17 @@ namespace AutoService.Models mc.ExecuteNonQuery(); } using (var mc = new MySqlCommand(sql2, connection, transaction)) - using (var reader = mc.ExecuteReader()) { - newId = reader.GetInt32("id"); + var result = mc.ExecuteScalar(); + if (result != null) + { + newId = Convert.ToInt32(result); + } + else + { + throw new Exception("Это печально всё"); + } + } foreach (var work in works) { diff --git a/AutoService/ViewModels/ReceiptWindowVM.cs b/AutoService/ViewModels/ReceiptWindowVM.cs index 54aa043..1970293 100644 --- a/AutoService/ViewModels/ReceiptWindowVM.cs +++ b/AutoService/ViewModels/ReceiptWindowVM.cs @@ -1,6 +1,8 @@ using AutoService.Models; +using Avalonia.Controls; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -19,6 +21,8 @@ namespace AutoService.ViewModels private readonly IProceedRepository _proceedRepository; + public Button Btn { get; set; } + [ObservableProperty] private ObservableCollection works; @@ -63,8 +67,20 @@ namespace AutoService.ViewModels TotalPrice=(int)TotalPrice }; _proceedRepository.SaveOrder(Works, order); + Btn.IsEnabled = false; } + [RelayCommand] + public void ReturnToMain() + { + var vm = _serviceProvider.GetRequiredService(); + var win = _serviceProvider.GetRequiredService(); + win.DataContext = vm; + win.Show(); + _currentWindow.Close(); + + } + public void SetWindow(ReceiptWindow window) { diff --git a/AutoService/ViewModels/WorksWindowVM.cs b/AutoService/ViewModels/WorksWindowVM.cs index 6b8084d..0b99d6d 100644 --- a/AutoService/ViewModels/WorksWindowVM.cs +++ b/AutoService/ViewModels/WorksWindowVM.cs @@ -52,6 +52,7 @@ namespace AutoService.ViewModels var win = _serviceProvider.GetRequiredService(); win.DataContext = vm; vm.SetWindow(win); + vm.Btn = win.ProceedBtn; win.Show(); _currentWindow.Close(); } diff --git a/AutoService/Views/ReceiptWindow.axaml b/AutoService/Views/ReceiptWindow.axaml index 2f5deb1..0533a8d 100644 --- a/AutoService/Views/ReceiptWindow.axaml +++ b/AutoService/Views/ReceiptWindow.axaml @@ -28,6 +28,8 @@ -