public ActionResult Edit(ProductComposition productComposition) { db.ProductCompositions.Update(productComposition); // сохраняем в бд все изменения db.SaveChanges(); return(RedirectToAction("index")); }
private bool DeleteItems() { bool boRetValue = false; string stIDs = ""; foreach (DataListItem item in lstItem.Items) { HtmlInputCheckBox chkList = (HtmlInputCheckBox)item.FindControl("chkList"); if (chkList != null) { if (chkList.Checked == true) { stIDs += chkList.Value + ","; boRetValue = true; } } } if (boRetValue) { ProductComposition clsProductComposition = new ProductComposition(); clsProductComposition.Delete(stIDs.Substring(0, stIDs.Length - 1)); clsProductComposition.CommitAndDispose(); } return(boRetValue); }
public ActionResult ConfirmDelete(int id) { ProductComposition productComposition = db.ProductCompositions.Find(id); var products = db.Products.Where(p => p.Id == productComposition.ProductId).First(); var materials = db.Materials.Where(p => p.Id == productComposition.MaterialId).First(); ProductCompositionViewModel viewModel = new ProductCompositionViewModel { ProductName = productComposition.Product.Name, MaterialName = productComposition.Material.Name, Quantity = productComposition.Quantity, }; ProductCompositionsViewModel productCompositionsViewModel = new ProductCompositionsViewModel { ProductCompositionViewModel = viewModel }; if (productComposition == null) { return(View("NotFound")); } else { return(View(productCompositionsViewModel)); } }
private TextBlock GetTextBlock(ProductComposition productCompo, SolidColorBrush colorBrush, FontWeight fontWeight, int fontSize = 12) { DDB ddb = new DDB(User.DataBase, User.Username, User.Password); Product product = ddb.SelectProduct(new string[] { "ref" }, new string[] { $"'{productCompo.RefProduct}'" })[0]; string text = productCompo.RefProduct; if (text.Length > 10) { string tmp = string.Empty; for (int i = 0; i < 10; i++) { tmp += text[i]; } text = $"{tmp} ..."; } return(new TextBlock() { Text = $"{product.Name} {productCompo.Quantity}{product.Unit}", Margin = new Thickness(10), FontSize = fontSize, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Background = new SolidColorBrush(Colors.Transparent), FontWeight = fontWeight, Foreground = colorBrush, FontFamily = titleTB.FontFamily }); }
private void LoadItems() { DataClass clsDataClass = new DataClass(); ProductComposition clsProductComposition = new ProductComposition(); lstItem.DataSource = clsProductComposition.ListAsDataTable(Convert.ToInt64(lblProductID.Text), "CompositionID", SortOption.Ascending).DefaultView; lstItem.DataBind(); clsProductComposition.CommitAndDispose(); }
public ActionResult Create(ProductComposition productComposition) { if (ModelState.IsValid) { db.ProductCompositions.Add(productComposition); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
public ActionResult Delete(int?id) { ProductComposition productComposition = db.ProductCompositions.Find(id); if (productComposition != null) { db.ProductCompositions.Remove(productComposition); db.SaveChanges(); } return(RedirectToAction("index")); }
private Border GetBorder(ProductComposition product) { return(new Border() { Background = new SolidColorBrush(Color.FromRgb(112, 111, 211)), Child = GetTextBlock(product, new SolidColorBrush(Colors.White), FontWeights.Bold, 14), BorderThickness = new Thickness(0), VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(5) }); }
/// <summary> /// Le produit commande est consomme /// </summary> /// <param name="product"></param> /// <param name="productsComposition"></param> private static void ConsumeProduct(Product product, List <ProductComposition> productsComposition) { ProductComposition productComposition = productsComposition.Find(x => x.RefProduct.Equals(product.Reference)); product.CurrentQuantity -= productComposition.Quantity; if (product.CurrentQuantity < product.MinQuantity) { int quantityNeeded = product.MaxQuantity - product.CurrentQuantity; OrderSuplies(product, quantityNeeded, "plus de stockes"); } DDB ddb = new DDB(); ddb.UpdateProduct(product, new string[] { "ref" }, new string[] { "'" + product.Reference + "'" }); ddb.Close(); }
/// <summary> /// Method Edit berfungsi untuk mengubah quantity di dalam product composition /// </summary> /// <param name="productComposition">Parameter productComposition merupakan model dari product composition</param> /// <returns>Quantity berhasil dirubah</returns> public ActionResult Edit(ProductComposition productComposition) { try { var productCompositionData = db.ProductCompositions.Where(x => x.ID == productComposition.ID).SingleOrDefault(); productCompositionData.Quantity = productComposition.Quantity; productCompositionData.IsDefaultComponent = productComposition.IsDefaultComponent; db.SaveChanges(); return(Json(new { success = true, responseText = "Quantity successfully updated" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ViewBag.Exception = ex; } return(View()); }
public ActionResult Create(int productId, ProductViewModel productViewModel, FormCollection collection) { try { // TODO: Add product composition var username = User.Identity.Name; var currentPage = collection.GetValues("currentPage"); //productViewModel.ProductID = string.Join(",", productViewModel.SelectedProductID); foreach (var component in productViewModel.SelectedComponentID) { var existingProductComposition = db.ProductCompositions.Where(x => x.ProductID == productId && x.ComponentID == component).SingleOrDefault(); if (existingProductComposition != null) { ViewBag.ExistProductComposition = "Component that you are input already exist on this product."; ViewBag.ProductID = productId; return(View("ErrorPage")); } else { var newProductComposition = new ProductComposition { ProductID = productId, ComponentID = component, Created = DateTime.Now, CreatedBy = username, LastModified = DateTime.Now, LastModifiedBy = username }; db.ProductCompositions.Add(newProductComposition); db.SaveChanges(); } } return(new RedirectResult(Url.Action("Details", "Product", new { id = productId, tab = "component", page = currentPage[0] }))); } catch (Exception ex) { ViewBag.Exception = ex; return(View("ErrorPage")); } }
private void UpdateItem() { if (isChkListSingle() == true) { string stID = GetFirstID(); if (stID != null) { ProductComposition clsProductComposition = new ProductComposition(); ProductCompositionDetails clsDetails = clsProductComposition.Details(Convert.ToInt64(stID)); clsProductComposition.CommitAndDispose(); cboProductCode.Items.Clear(); cboVariation.Items.Clear(); cboProductUnit.Items.Clear(); cboProductCode.Items.Add(new ListItem(clsDetails.ProductCode, clsDetails.ProductID.ToString())); cboProductCode.SelectedIndex = 0; if (clsDetails.VariationMatrixID == 0) { cboVariation.Items.Add(new ListItem("No Variation", "0")); } else { cboVariation.Items.Add(new ListItem(clsDetails.MatrixDescription, clsDetails.VariationMatrixID.ToString())); } cboVariation.SelectedIndex = 0; cboProductUnit.Items.Add(new ListItem(clsDetails.UnitCode, clsDetails.UnitID.ToString())); cboProductUnit.SelectedIndex = 0; txtQuantity.Text = clsDetails.Quantity.ToString("###0.#0"); lblCompositionID.Text = stID; } } else { string stScript = "<Script>"; stScript += "window.alert('Cannot update more than one record. Please select at least one record to update.')"; stScript += "</Script>"; Response.Write(stScript); } }
private static void CompositeScenario() { //Component var bolo = new CompositeProduct("Bolo"); //Leaf var acucar = new ProductComposition("Açucar"); var farinha = new ProductComposition("Farinha"); var fermento = new ProductComposition("Fermento"); var oleo = new ProductComposition("Oleo"); var chocolate = new ProductComposition("Chocolate"); var granulado = new ProductComposition("Granulado"); var caldaChocolate = new ProductComposition("Calda de Chocolate"); var leite = new ProductComposition("Leite"); var cremeDeLeite = new ProductComposition("Creme de Leite"); //Composite var massa = new CompositeProduct("Massa de bolo"); massa.AddChild(acucar); massa.AddChild(farinha); massa.AddChild(oleo); massa.AddChild(fermento); massa.AddChild(leite); var cobertura = new CompositeProduct("Cobertura de chocolate para bolo"); cobertura.AddChild(chocolate); cobertura.AddChild(acucar); cobertura.AddChild(granulado); cobertura.AddChild(caldaChocolate); cobertura.AddChild(cremeDeLeite); bolo.AddChild(massa); bolo.AddChild(cobertura); bolo.AddChild(bolo); bolo.ShowProducts(2); }
private void SaveRecord() { ProductCompositionDetails clsDetails = new ProductCompositionDetails(); clsDetails.MainProductID = Convert.ToInt64(lblProductID.Text); clsDetails.ProductID = Convert.ToInt64(cboProductCode.SelectedItem.Value); clsDetails.VariationMatrixID = Convert.ToInt64(cboVariation.SelectedItem.Value); clsDetails.Quantity = Convert.ToDecimal(txtQuantity.Text); clsDetails.UnitID = Convert.ToInt32(cboProductUnit.SelectedItem.Value); ProductComposition clsProductComposition = new ProductComposition(); if (lblCompositionID.Text != "0") { clsDetails.CompositionID = Convert.ToInt64(lblCompositionID.Text); clsProductComposition.Update(clsDetails); } else { clsProductComposition.Insert(clsDetails); } clsProductComposition.CommitAndDispose(); }
public ActionResult SynchronizeProductComposition() { List <ComponentsTemp> listOfComponentTemp = db.ComponentsTemps.ToList(); var username = User.Identity.Name; DateTime now = DateTime.Now; try { foreach (ComponentsTemp item in listOfComponentTemp) { Component existComponent = db.Components.Where(x => x.PartNumber == item.ComponentPartNumber).FirstOrDefault(); Products existProduct = db.Products.Where(x => x.PN == item.ProductPartNumber).FirstOrDefault(); if (existComponent != null && existProduct != null) { ProductComposition currentPC = db.ProductCompositions.Where(x => x.ComponentID == existComponent.ID && x.ProductID == existProduct.ID).FirstOrDefault(); if (currentPC != null && currentPC.Quantity < item.Qty) { currentPC.Quantity = item.Qty; currentPC.LastModified = DateTime.Now; currentPC.LastModifiedBy = username; } else if (currentPC == null) { ProductComposition newPC = new ProductComposition(); newPC.ProductID = existProduct.ID; newPC.ComponentID = existComponent.ID; newPC.Quantity = item.Qty; newPC.LastModified = newPC.Created = DateTime.Now; newPC.LastModifiedBy = newPC.CreatedBy = username; db.ProductCompositions.Add(newPC); } if (db.SaveChanges() > 0) { ComponentsTemp ct = db.ComponentsTemps.Where(x => x.ID == item.ID).SingleOrDefault(); ct.IsInsertToPCom = true; ct.LastModified = DateTime.Now; ct.LastModifiedBy = username; db.SaveChanges(); } } else { item.IsComponentExist = existComponent == null?false:true; item.IsProductExist = existProduct == null ? false : true; item.LastModified = now; item.LastModifiedBy = username; db.SaveChanges(); } } return(RedirectToAction("Index")); } catch (Exception ex) { ViewBag.Exception = ex; ViewBag.ErrorMessage = "An error occured while doing this process"; return(View("Error")); } }
private void AddProduct(ProductComposition product) { ProductsStackPanel.Children.Add(GetBorder(product)); }