61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
using Agents.Models;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Media;
|
|
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
|
|
namespace Agents;
|
|
|
|
public partial class ProductEditor : Window
|
|
{
|
|
static User11Context db = new User11Context(); // ïîäêëþ÷åíèå ê ÁÄ
|
|
ObservableCollection<Product> products = new ObservableCollection<Product>(db.Products); // ëèñò ïðîäóêòîâ
|
|
|
|
public ProductEditor()
|
|
{
|
|
InitializeComponent();
|
|
ListProducts.ItemsSource = products;
|
|
}
|
|
|
|
private void ListProducts_SelectionChanged(object? sender, Avalonia.Controls.SelectionChangedEventArgs e)
|
|
{
|
|
Product product = db.Products.Where(it=>it == ListProducts.SelectedItem).First();
|
|
TextNewProductionpersoncount.Text = product.Productionpersoncount.ToString();
|
|
TextNewArticlenumber.Text = product.Articlenumber.ToString();
|
|
TextNewMincostforagent.Text = product.Mincostforagent.ToString();
|
|
}
|
|
|
|
private void ButtonChange(object sender, RoutedEventArgs e) // èçìåíåíèå äàííûõ
|
|
{
|
|
try
|
|
{
|
|
Product product = db.Products.Where(it => it == ListProducts.SelectedItem).First(); // íàõîäèì âûäåëåííûé ïðîäóêò
|
|
|
|
float a = float.Parse(TextNewProductionpersoncount.Text);
|
|
product.Productionpersoncount = Convert.ToInt32(a);
|
|
|
|
product.Articlenumber = TextNewArticlenumber.Text;
|
|
|
|
float i = float.Parse(TextNewMincostforagent.Text);
|
|
product.Mincostforagent = Convert.ToInt32(i);
|
|
db.SaveChanges();
|
|
|
|
Status.Foreground = Brushes.White;
|
|
Status.Text = "Äàííûå ïðîäóêòà èçìåíåíû";
|
|
}
|
|
catch
|
|
{
|
|
Status.Foreground = Brushes.Red;
|
|
Status.Text = "Ïðîèçîøëà îøèáêà";
|
|
}
|
|
}
|
|
|
|
void Exit(object sender, RoutedEventArgs e) // âûõîä
|
|
{
|
|
new MainWindow().Show();
|
|
Close();
|
|
}
|
|
}
|