private void BtnAddProductSave_Click(object sender, RoutedEventArgs e) { if (checkTextbox() == 0) { var dialogError = new Dialog() { Message = isEdit ? "Xác nhận sửa sản phẩm?" : "Thêm mới sản phẩm đã nhập?" }; dialogError.Owner = Window.GetWindow(this); if (dialogError.ShowDialog() == true) { try { manage.AddProduct(isEdit, ProductId.Text, comboProductTypes.Text, comboboxSupplier.Text, DateTime.Parse(ProductDate.Text), ProductName.Text, int.Parse(ProductPrice.Text), int.Parse(ProductInitialAmount.Text), ProductDescription.Text, imgProduct.Source.ToString()); if (RefreshProductList != null) { RefreshProductList.Invoke(true); } } catch (Exception r) { var dialogError1 = new Dialog() { Message = "Product ID is existed" }; dialogError1.Owner = Window.GetWindow(this); dialogError1.ShowDialog(); } Detail_Product a = new Detail_Product(); a.ID_Product = ProductId.Text; a.NameProduct = ProductName.Text; a.ID_Supplier = db.Supplier.SingleOrDefault(x => x.Name_Sup == comboboxSupplier.Text).ID_sup; a.Description_Pro = ProductDescription.Text; a.Original_Price = Int32.Parse(ProductPrice.Text); a.ID_TypeProduct = db.Type_product.SingleOrDefault(x => x.Type_Product1 == comboProductTypes.Text).ID; if (imgProduct.Source != null) { BitmapImage source = new BitmapImage(new Uri(imgProduct.Source.ToString())); a.Image_Path = source.ToString(); } else { a.Image_Path = null; } var page = new DetailProductPage(a); page.refresh(true); page.RefreshProductList = refreshCombo; NavigationService.Navigate(page); } } }
public void Import(ObservableCollection <ImportProduct> Data) { MANAGEMENT_STORE_Entities db = new MANAGEMENT_STORE_Entities(); if (Data != null) { for (int i = 0; i < Data.Count; i++) { try { dbProduct.AddProduct(false, Data[i].ID, Data[i].Type, Data[i].Supplier, Data[i].input_time, Data[i].Name, Data[i].Orig_price, Data[i].Initial_amount, Data[i].Descrip, Data[i].Image_path); // Tăng số sản phẩm của loại sản phẩm Type_product type = db.Type_product.Find(Data[i].ID_Type); type.Num_Of_Product++; db.SaveChanges(); } catch (Exception ex) { continue; // Không xảy ra lỗi trùng mã vì đã xử lý trước } } Refresh(true); } }