Blagodat/OknaFunciy/AddZakazWindow.axaml.cs

76 lines
1.9 KiB
C#
Raw Normal View History

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