76 lines
1.9 KiB
C#
76 lines
1.9 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Demka_Snova_1.Hardik.Conect;
|
|
using Demka_Snova_1.Hardik.Conect.Dao;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Demka_Snova_1.OknaFunciy;
|
|
|
|
public partial class AddZakazWindow : Window
|
|
{
|
|
private static int nextId = 50;
|
|
private List<ordersDao> ordersList;
|
|
private Random random = new Random();
|
|
|
|
public AddZakazWindow()
|
|
{
|
|
InitializeComponent();
|
|
LoadOrders();
|
|
}
|
|
|
|
private void LoadOrders()
|
|
{
|
|
using (var db = new DatabaseConnection())
|
|
{
|
|
ordersList = db.GetAllOrders();
|
|
nextId = ordersList.Count > 0 ? ordersList.Max(o => o.ID) + 1 : 50;
|
|
}
|
|
}
|
|
|
|
private void FormatZakaz_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
string client = ClientTextBox.Text;
|
|
string usluga = UslugaTextBox.Text;
|
|
|
|
if (!decimal.TryParse(ProkatTextBox.Text, out decimal prokat))
|
|
{
|
|
ShowError("Некорректное значение для проката.");
|
|
return;
|
|
}
|
|
|
|
var order = new ordersDao
|
|
{
|
|
ID = nextId++,
|
|
CodeZakaz = $"{random.Next(10000, 99999)}.{random.Next(10000, 99999)}",
|
|
Date = DateOnly.FromDateTime(DateTime.Now),
|
|
Time = TimeOnly.FromDateTime(DateTime.Now),
|
|
CodeClient = client,
|
|
Usluga = usluga,
|
|
Status = "Новый",
|
|
DateClose = null,
|
|
Prokat = prokat
|
|
};
|
|
|
|
ordersList.Add(order);
|
|
}
|
|
|
|
private void Exitka(object sender, RoutedEventArgs e)
|
|
{
|
|
new MainWindow().Show();
|
|
this.Close();
|
|
}
|
|
|
|
private async void ShowError(string message)
|
|
{
|
|
var dialog = new Window
|
|
{
|
|
Title = "Ошибка",
|
|
Content = message,
|
|
Width = 300,
|
|
Height = 200
|
|
};
|
|
await dialog.ShowDialog(this);
|
|
}
|
|
} |