|
@@ -1,14 +1,14 @@
|
|
|
-using Sessioa.Classes;
|
|
|
+using Sessioa.BaseModel;
|
|
|
+using Sessioa.Classes;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
using System.IO;
|
|
|
+using System.Linq;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
-using Sessioa.BaseModel;
|
|
|
-using System.Linq;
|
|
|
|
|
|
namespace Sessioa.Pages
|
|
|
{
|
|
@@ -18,6 +18,7 @@ namespace Sessioa.Pages
|
|
|
public partial class ProductCard : Page
|
|
|
{
|
|
|
User user = null;
|
|
|
+ Product prEdit = null;
|
|
|
List<string> imagePath = new List<string>();
|
|
|
List<ProductCategory> categories = BaseClass.C_Base.ProductCategory.ToList();
|
|
|
|
|
@@ -25,16 +26,54 @@ namespace Sessioa.Pages
|
|
|
|
|
|
List<Provider> providerList = BaseClass.C_Base.Provider.ToList();
|
|
|
int imActual = -1;
|
|
|
+ bool state = true;
|
|
|
+ bool resIm = false;
|
|
|
public ProductCard(User userSign)
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
user = userSign;
|
|
|
+ sett();
|
|
|
+ }
|
|
|
+ public ProductCard(User userSign, Product product)
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ state = false;
|
|
|
+ prEdit = product;
|
|
|
+ user = userSign;
|
|
|
+ TB_Articule.Text = product.ProductArticleNumber;
|
|
|
+ TB_Articule.IsReadOnly = true;
|
|
|
+ TB_Title.Text = product.ProductName;
|
|
|
+ TB_Description.Text = product.ProductDescription;
|
|
|
+ sett();
|
|
|
+ foreach (var imList in imagePath)
|
|
|
+ {
|
|
|
+ imActual++;
|
|
|
+ if (imList == product.ProductPhoto)
|
|
|
+ {
|
|
|
+ resIm = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (resIm == true)
|
|
|
+ ImageProd.Source = new BitmapImage(new Uri(imagePath[imActual], UriKind.Relative));
|
|
|
+
|
|
|
+ CategoryProd.SelectedItem = categories[product.ProductCategory - 1];
|
|
|
+ ManufacturedProd.SelectedItem = manufacturersList[product.ProductManufacturer - 1];
|
|
|
+ ProviderProd.SelectedItem = providerList[product.ProductProvider - 1];
|
|
|
+ TB_Price.Text = product.ProductCost.ToString();
|
|
|
+ if (product.ProductDiscountAmount != null)
|
|
|
+ TB_Discount.Text = product.ProductDiscountAmount.ToString();
|
|
|
+ TB_Count.Text = product.ProductQuantityInStock.ToString();
|
|
|
+ }
|
|
|
+ public void sett()
|
|
|
+ {
|
|
|
FileInfo[] files = new DirectoryInfo($"{Directory.GetCurrentDirectory()}\\Photos").GetFiles();
|
|
|
foreach (FileInfo file in files)
|
|
|
{
|
|
|
imagePath.Add("/Photos/" + file.Name);
|
|
|
Debug.Write(file.Name);
|
|
|
}
|
|
|
+
|
|
|
CategoryProd.ItemsSource = categories;
|
|
|
CategoryProd.DisplayMemberPath = "CategoryTitle";
|
|
|
CategoryProd.SelectedValuePath = "CategoryId";
|
|
@@ -46,20 +85,6 @@ namespace Sessioa.Pages
|
|
|
ProviderProd.ItemsSource = providerList;
|
|
|
ProviderProd.DisplayMemberPath = "Provider1";
|
|
|
ProviderProd.SelectedValuePath = "ProviderId";
|
|
|
-
|
|
|
- }
|
|
|
- public ProductCard(User userSign, Product product)
|
|
|
- {
|
|
|
- InitializeComponent();
|
|
|
- TB_Articule.Text = product.ProductArticleNumber;
|
|
|
- TB_Title.Text = product.ProductName;
|
|
|
- TB_Description.Text = product.ProductDescription;
|
|
|
-
|
|
|
- CategoryProd.ItemsSource = categories;
|
|
|
- CategoryProd.DisplayMemberPath = "CategoryTitle";
|
|
|
- CategoryProd.SelectedValuePath = "CategoryId";
|
|
|
-
|
|
|
- CategoryProd.SelectedItem = categories[product.ProductCategory + 1];
|
|
|
}
|
|
|
|
|
|
private void BT_save_Click(object sender, RoutedEventArgs e)
|
|
@@ -84,7 +109,7 @@ namespace Sessioa.Pages
|
|
|
{
|
|
|
MessageBox.Show("Неверный формат стоимости. Все символы должны быть целочисленными.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
}
|
|
|
- else if (Convert.ToInt32(TB_Price.Text) < 1 || !int.TryParse(TB_Price.Text, out int a))
|
|
|
+ else if (Convert.ToDouble(TB_Price.Text) < 1 || !double.TryParse(TB_Price.Text, out double a))
|
|
|
{
|
|
|
MessageBox.Show("Стоимость не может быть меньше 1.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
}
|
|
@@ -126,39 +151,67 @@ namespace Sessioa.Pages
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Product newProduct = new Product()
|
|
|
+ if (state == true)
|
|
|
{
|
|
|
- ProductArticleNumber = TB_Articule.Text,
|
|
|
- ProductName = TB_Title.Text,
|
|
|
- ProductDescription = TB_Description.Text,
|
|
|
- ProductCategory = CategoryProd.SelectedIndex,
|
|
|
- ProductManufacturer = ManufacturedProd.SelectedIndex,
|
|
|
- ProductProvider = ProviderProd.SelectedIndex,
|
|
|
- ProductCost = Convert.ToInt32(TB_Price.Text),
|
|
|
- ProductQuantityInStock = Convert.ToInt32(TB_Count.Text)
|
|
|
- };
|
|
|
- if (imActual != -1)
|
|
|
- newProduct.ProductPhoto = imagePath[imActual];
|
|
|
- if (TB_Discount.Text.Length > 0)
|
|
|
- {
|
|
|
- newProduct.ProductDiscountAmount = Convert.ToByte(TB_Discount.Text);
|
|
|
- }
|
|
|
+ Product newProduct = new Product()
|
|
|
+ {
|
|
|
+ ProductArticleNumber = TB_Articule.Text,
|
|
|
+ ProductName = TB_Title.Text,
|
|
|
+ ProductDescription = TB_Description.Text,
|
|
|
+ ProductCategory = CategoryProd.SelectedIndex,
|
|
|
+ ProductManufacturer = ManufacturedProd.SelectedIndex,
|
|
|
+ ProductProvider = ProviderProd.SelectedIndex,
|
|
|
+ ProductCost = Convert.ToInt32(TB_Price.Text),
|
|
|
+ ProductQuantityInStock = Convert.ToInt32(TB_Count.Text)
|
|
|
+ };
|
|
|
+ if (imActual != -1)
|
|
|
+ newProduct.ProductPhoto = imagePath[imActual];
|
|
|
+ if (TB_Discount.Text.Length > 0)
|
|
|
+ {
|
|
|
+ newProduct.ProductDiscountAmount = Convert.ToByte(TB_Discount.Text);
|
|
|
+ }
|
|
|
|
|
|
- bool res = false;
|
|
|
+ bool res = false;
|
|
|
|
|
|
- foreach (var item in BaseClass.C_Base.Product.ToList())
|
|
|
- {
|
|
|
- if (item.ProductArticleNumber == newProduct.ProductArticleNumber)
|
|
|
+ foreach (var item in BaseClass.C_Base.Product.ToList())
|
|
|
+ {
|
|
|
+ if (item.ProductArticleNumber == newProduct.ProductArticleNumber)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Продукт с таким артикулом уже существует.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ res = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (res != true)
|
|
|
{
|
|
|
- MessageBox.Show("Продукт с таким артикулом уже существует.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
- res = true;
|
|
|
+ BaseClass.C_Base.Product.Add(newProduct);
|
|
|
+ BaseClass.C_Base.SaveChanges();
|
|
|
+ MessageBoxResult mbr = MessageBox.Show("Продукт добавлен", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ if (mbr == MessageBoxResult.OK)
|
|
|
+ FrameClass.C_Frame.Navigate(new ProductsPage(user));
|
|
|
}
|
|
|
}
|
|
|
- if (res != true)
|
|
|
+ else
|
|
|
{
|
|
|
- BaseClass.C_Base.Product.Add(newProduct);
|
|
|
+ Product edit = BaseClass.C_Base.Product.FirstOrDefault(x => x.ProductArticleNumber == prEdit.ProductArticleNumber);
|
|
|
+ edit.ProductArticleNumber = TB_Articule.Text;
|
|
|
+ edit.ProductName = TB_Title.Text;
|
|
|
+ edit.ProductDescription = TB_Description.Text;
|
|
|
+ edit.ProductCategory = CategoryProd.SelectedIndex + 1;
|
|
|
+ edit.ProductManufacturer = ManufacturedProd.SelectedIndex + 1;
|
|
|
+ edit.ProductProvider = ProviderProd.SelectedIndex + 1;
|
|
|
+ edit.ProductCost = Convert.ToDecimal(TB_Price.Text);
|
|
|
+ edit.ProductQuantityInStock = Convert.ToInt32(TB_Count.Text);
|
|
|
+
|
|
|
+ if (resIm != false)
|
|
|
+ edit.ProductPhoto = imagePath[imActual];
|
|
|
+ if (TB_Discount.Text.Length > 0)
|
|
|
+ {
|
|
|
+ edit.ProductDiscountAmount = Convert.ToByte(TB_Discount.Text);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
BaseClass.C_Base.SaveChanges();
|
|
|
- MessageBoxResult mbr = MessageBox.Show("Продукт добавлен", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ MessageBoxResult mbr = MessageBox.Show("Продукт изменен", "Уведомление", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
if (mbr == MessageBoxResult.OK)
|
|
|
FrameClass.C_Frame.Navigate(new ProductsPage(user));
|
|
|
}
|