protected void btnSaveAll_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } Int64 SupplierId = SuppliersSessionHelper.SupplierId(); (new Query(SupplierProduct.TableSchema).Where(SupplierProduct.Columns.SupplierId, SupplierId).Delete()).Execute(); ProductCollection pcol = ProductCollection.FetchByQuery(new Query(Product.TableSchema).Where(Product.Columns.IsDeleted, false)); foreach (Product item in pcol) { SupplierProduct sp = new SupplierProduct(); sp.SupplierId = SupplierId; sp.ProductId = item.ProductId; sp.Gift = ""; sp.Save(); check_price_deviation(sp); } LoadItem(); }
protected void btnSave_Click(object sender, EventArgs e) { if (!Page.IsValid) { return; } bool result = false; string[] arr = hfProductIds.Value.Split(','); foreach (DataGridItem item in dgProducts.Items) { object obj = dgProducts.DataKeys[item.ItemIndex]; if (obj != null && !arr.Contains(obj.ToString())) { continue; } CheckBox cb = item.FindControl("cbIsExist") as CheckBox; TextBox txtGift = item.FindControl("txtGift") as TextBox; TextBox txtPrice = item.FindControl("txtPrice") as TextBox; Int64 ProductId = obj != null?Convert.ToInt64(obj) : 0; SupplierProduct sp = SupplierProduct.FetchByID(SuppliersSessionHelper.SupplierId(), ProductId); if (sp != null && cb != null && cb.Checked) { if (txtGift != null) { sp.Gift = txtGift.Text; } if (txtPrice != null && !String.IsNullOrEmpty(txtPrice.Text)) { sp.Price = Convert.ToDecimal(txtPrice.Text); } if (sp.Price > 0) { sp.Save(); result = true; check_price_deviation(sp); } } else if (sp == null && cb != null && cb.Checked) { sp = new SupplierProduct(); if (txtGift != null) { sp.Gift = txtGift.Text; } if (txtPrice != null && !String.IsNullOrEmpty(txtPrice.Text)) { sp.Price = Convert.ToDecimal(txtPrice.Text); } sp.SupplierId = SuppliersSessionHelper.SupplierId(); sp.ProductId = ProductId; sp.CreateDate = DateTime.UtcNow; sp.Save(); result = true; check_price_deviation(sp); } else if (sp != null && cb != null && !cb.Checked) { SupplierProduct.Delete(SuppliersSessionHelper.SupplierId(), ProductId); result = true; } } if (result) { Master.MessageCenter.DisplaySuccessMessage(ProductsStrings.GetText("SaveSuccess")); } LoadItem(); }
protected void btnImport_Click(object sender, EventArgs e) { if (CsvDataTable != null) { int count = 0; try { foreach (DataRow productRow in CsvDataTable.Rows) { if (productRow["Comments"].ToString() != "") { SupplierProduct suplierprod = null; Product prod = null; if ((productRow["Comments"].ToString()).Equals(ProductsStrings.GetText(@"MessageCodeRemoveProductFromSupplier"))) { //Delete product from Supplier prod = Product.FetchByCode(productRow["ProductCode"].ToString()); if (prod != null) { suplierprod = SupplierProduct.FetchByID(SuppliersSessionHelper.SupplierId(), prod.ProductId); if (suplierprod != null) //delete { SupplierProduct.Delete(SuppliersSessionHelper.SupplierId(), suplierprod.ProductId); count++; } } } else if ((productRow["Comments"].ToString()).Equals(ProductsStrings.GetText(@"MessageCodeInsertProductToSupplier"))) { //Insert product to supplier prod = Product.FetchByCode(productRow["ProductCode"].ToString()); if (prod != null) { if (!ProductController.IsSupplierProduct(prod.ProductId, SuppliersSessionHelper.SupplierId())) { SupplierProduct sp = new SupplierProduct(); sp.SupplierId = SuppliersSessionHelper.SupplierId(); sp.ProductId = prod.ProductId; sp.CreateDate = DateTime.UtcNow; sp.Price = Convert.ToDecimal(productRow["Price"]); sp.Gift = ""; sp.Save(); check_price_deviation(sp); count++; } } } else if ((productRow["Comments"].ToString()).Equals(ProductsStrings.GetText(@"MessageCodeUppdatePriceInSupplier"))) { //Update price prod = Product.FetchByCode(productRow["ProductCode"].ToString()); if (prod != null) { if (ProductController.IsSupplierProduct(prod.ProductId, SuppliersSessionHelper.SupplierId())) { SupplierProduct sp = new SupplierProduct(); sp.SupplierId = SuppliersSessionHelper.SupplierId(); sp.Price = Convert.ToDecimal(productRow["Price"]); sp.ProductId = prod.ProductId; sp.CreateDate = DateTime.UtcNow; sp.Gift = ""; sp.Update(); check_price_deviation(sp); count++; } } } } } lblImportResult.Text = ProductsStrings.GetText(@"MessageImportSuccess"); } catch (Exception ex) { lblImportResult.Text = ProductsStrings.GetText(@"MessageImportFailedUnknown"); } phImportResult.Visible = true; lblTotalImported.Text = count.ToString(); btnImport.Enabled = false; // btnAcceptFile.Visible = false; phErrors.Visible = false; phProductsList.Visible = false; } }