работает!!!
parent
2bd7a1507e
commit
9fd6904a39
|
|
@ -19,7 +19,7 @@ namespace AutoService.Models
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
OpenConnection();
|
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 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);";
|
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();
|
using var transaction = connection.BeginTransaction();
|
||||||
|
|
@ -37,9 +37,17 @@ namespace AutoService.Models
|
||||||
mc.ExecuteNonQuery();
|
mc.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
using (var mc = new MySqlCommand(sql2, connection, transaction))
|
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)
|
foreach (var work in works)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
using AutoService.Models;
|
using AutoService.Models;
|
||||||
|
using Avalonia.Controls;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
|
@ -19,6 +21,8 @@ namespace AutoService.ViewModels
|
||||||
|
|
||||||
private readonly IProceedRepository _proceedRepository;
|
private readonly IProceedRepository _proceedRepository;
|
||||||
|
|
||||||
|
public Button Btn { get; set; }
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private ObservableCollection<Work> works;
|
private ObservableCollection<Work> works;
|
||||||
|
|
||||||
|
|
@ -63,8 +67,20 @@ namespace AutoService.ViewModels
|
||||||
TotalPrice=(int)TotalPrice
|
TotalPrice=(int)TotalPrice
|
||||||
};
|
};
|
||||||
_proceedRepository.SaveOrder(Works, order);
|
_proceedRepository.SaveOrder(Works, order);
|
||||||
|
Btn.IsEnabled = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
[RelayCommand]
|
||||||
|
public void ReturnToMain()
|
||||||
|
{
|
||||||
|
var vm = _serviceProvider.GetRequiredService<MainWindowVM>();
|
||||||
|
var win = _serviceProvider.GetRequiredService<MainWindow>();
|
||||||
|
win.DataContext = vm;
|
||||||
|
win.Show();
|
||||||
|
_currentWindow.Close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void SetWindow(ReceiptWindow window)
|
public void SetWindow(ReceiptWindow window)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ namespace AutoService.ViewModels
|
||||||
var win = _serviceProvider.GetRequiredService<ReceiptWindow>();
|
var win = _serviceProvider.GetRequiredService<ReceiptWindow>();
|
||||||
win.DataContext = vm;
|
win.DataContext = vm;
|
||||||
vm.SetWindow(win);
|
vm.SetWindow(win);
|
||||||
|
vm.Btn = win.ProceedBtn;
|
||||||
win.Show();
|
win.Show();
|
||||||
_currentWindow.Close();
|
_currentWindow.Close();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@
|
||||||
<TextBlock Text="Итого к оплате: "/>
|
<TextBlock Text="Итого к оплате: "/>
|
||||||
<TextBlock Text="{Binding TotalPrice}"/>
|
<TextBlock Text="{Binding TotalPrice}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Button Content="Подтвердить!" Command="{Binding ProceedTransactionCommand}"/>
|
<Button Content="Подтвердить!" Command="{Binding ProceedTransactionCommand}" x:Name="ProceedBtn"/>
|
||||||
|
<Button Content="Вернуться в окно выбора услуг" Command="{Binding ReturnToMainCommand}"/>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Window>
|
</Window>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue