125 lines
4.1 KiB
C#
125 lines
4.1 KiB
C#
|
using Agents.Models;
|
|||
|
using Avalonia;
|
|||
|
using Avalonia.Controls;
|
|||
|
using Avalonia.Interactivity;
|
|||
|
using Avalonia.Markup.Xaml;
|
|||
|
using Avalonia.Media;
|
|||
|
using System;
|
|||
|
using System.Collections.ObjectModel;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
namespace Agents;
|
|||
|
|
|||
|
public partial class AddProduct : Window
|
|||
|
{
|
|||
|
static User11Context db = new User11Context();
|
|||
|
ObservableCollection<Product> ProductsitemSource = new ObservableCollection<Product>(db.Products.OrderByDescending(it=>it.Id));
|
|||
|
ObservableCollection<Producttype> ProducttypesitemSource = new ObservableCollection<Producttype>(db.Producttypes);
|
|||
|
public AddProduct()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
ListProducts.ItemsSource = ProductsitemSource;
|
|||
|
ListProductType.ItemsSource = ProducttypesitemSource;
|
|||
|
}
|
|||
|
void Addproduct(object sender, RoutedEventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
float? i = float.Parse(TextNewCount.Text);
|
|||
|
int? count = Convert.ToInt32(i);
|
|||
|
|
|||
|
|
|||
|
decimal? min = Convert.ToDecimal(TextNewMincostforagent.Text);
|
|||
|
|
|||
|
Producttype? t = db.Producttypes.Where(it => it == ListProductType.SelectedItem).FirstOrDefault();
|
|||
|
if(t != null)
|
|||
|
{
|
|||
|
if (TextNewTitle.Text != "" && TextNewArticlenumber.Text != "" && count != null && min != null)
|
|||
|
{
|
|||
|
if (TextNewArticlenumber.Text != "")
|
|||
|
{
|
|||
|
if (count != null)
|
|||
|
{
|
|||
|
if (min != null)
|
|||
|
{
|
|||
|
Product product = new Product()
|
|||
|
{
|
|||
|
Title = TextNewTitle.Text,
|
|||
|
Producttypeid = t.Id,
|
|||
|
Articlenumber = TextNewArticlenumber.Text,
|
|||
|
Productionpersoncount = count,
|
|||
|
Mincostforagent = (decimal)min,
|
|||
|
|
|||
|
};
|
|||
|
db.Products.Add(product);
|
|||
|
db.SaveChanges();
|
|||
|
|
|||
|
Update();
|
|||
|
|
|||
|
Status.Foreground = Brushes.Green;
|
|||
|
Status.Text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Status.Foreground = Brushes.Red;
|
|||
|
Status.Text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Status.Foreground = Brushes.Red;
|
|||
|
Status.Text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Status.Foreground = Brushes.Red;
|
|||
|
Status.Text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Status.Foreground = Brushes.Red;
|
|||
|
Status.Text = "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Status.Foreground = Brushes.Red;
|
|||
|
Status.Text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
}
|
|||
|
catch
|
|||
|
{
|
|||
|
Status.Foreground = Brushes.Red;
|
|||
|
Status.Text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void DeleteProduct(object sender, RoutedEventArgs e)
|
|||
|
{
|
|||
|
if (ListProducts.SelectedItem != null)
|
|||
|
{
|
|||
|
Product product = db.Products.Where(it => it == ListProducts.SelectedItem).FirstOrDefault();
|
|||
|
db.Products.Remove(product);
|
|||
|
db.SaveChanges();
|
|||
|
|
|||
|
Update();
|
|||
|
|
|||
|
Status.Foreground = Brushes.Green;
|
|||
|
Status.Text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void Update()
|
|||
|
{
|
|||
|
ProductsitemSource = new ObservableCollection<Product>(db.Products.OrderByDescending(it => it.Id));
|
|||
|
ListProducts.ItemsSource = ProductsitemSource;
|
|||
|
}
|
|||
|
void Exit(object sender, RoutedEventArgs e)
|
|||
|
{
|
|||
|
new MainWindow().Show();
|
|||
|
Close();
|
|||
|
}
|
|||
|
}
|