private void insertProduct() { tblProduct = adpProduct.GetData(); Cache["tblProduct"] = tblProduct; string name = txtProductName.Text; decimal price = decimal.Parse(txtPrice.Text); int quant = int.Parse(txtQuantity.Text); int categID = int.Parse(ddlCategory.SelectedValue); int result = adpProduct.Insert(name, price, quant, categID); if (result == 1) { lblErrorMessage.Text = "Product Inserted "; lblErrorMessage.ForeColor = System.Drawing.Color.Yellow; txtProductName.Text = ""; txtProductNumber.Text = ""; ddlCategory.SelectedIndex = -1; txtPrice.Text = ""; txtQuantity.Text = ""; } else { lblErrorMessage.Text = "Product NOT Inserted"; lblErrorMessage.ForeColor = System.Drawing.Color.Red; } Refresh(); }
private void loadFields() { int id = int.Parse(txtProductNumber.Text); tblProduct = adpProduct.GetDataBy(id); Cache["tblProduct"] = tblProduct; var row = tblProduct; if (row.Count > 0) { if (row != null) { string name = row[0].ProductName.ToString(); txtProductName.Text = name.Trim(); txtPrice.Text = row[0].ProductPrice.ToString(); txtQuantity.Text = row[0].ProductInStock.ToString(); int deptid = row[0].ProductCategory; ddlCategory.SelectedValue = deptid.ToString(); } } else { lblErrorMessage.Text = " Product ID " + id + " is not found"; lblErrorMessage.ForeColor = System.Drawing.Color.Red; } }
public async Task <IActionResult> PostTableProduct([FromBody] TableProduct tableProduct) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.TableProducts.Add(tableProduct); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (TableProductExists(tableProduct.Code)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetTableProduct", new { id = tableProduct.Code }, tableProduct)); }
public async Task <IActionResult> PutTableProduct([FromRoute] string id, [FromBody] TableProduct tableProduct) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tableProduct.Code) { return(BadRequest()); } _context.Entry(tableProduct).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TableProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <TableProduct> > PostTableProduct(TableProduct tableProduct) { _context.TableProduct.Add(tableProduct); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTableProduct", new { id = tableProduct.Id }, tableProduct)); }
public async Task <IActionResult> PutTableProduct(int id, TableProduct tableProduct) { if (id != tableProduct.Id) { return(BadRequest()); } _context.Entry(tableProduct).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TableProductExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private void addProductIntoTable() { String prix = PrixTextBox.Text.Replace(".", ","); decimal prixDecimal; String code = CodeTextBox.Text; String reassort = ReassortSelectBox.Text; String type = TypeSelectBox.Text; String titre = TitreTextBox.Text; String auteur = AuteurTextBox.Text; String editeur = EditeurTextBox.Text; if (prix.Length == 0) { MessageBox.Show("Le prix est manquant !"); return; } else if (!decimal.TryParse(prix, out prixDecimal)) { MessageBox.Show("Le prix est mal formaté !"); return; } else if (titre.Length == 0) { MessageBox.Show("Le titre est manquant !"); return; } var formattedPrice = string.Format("{0:0.00}", prixDecimal); TableProduct tableProduct = new TableProduct { Prix = formattedPrice, Code = code, Reassort = reassort, Type = type, Titre = titre, Auteur = auteur, Editeur = editeur }; this.ProduitsCollection.Add(tableProduct); PrixTextBox.Text = ""; CodeTextBox.Text = ""; TitreTextBox.Text = ""; AuteurTextBox.Text = ""; EditeurTextBox.Text = ""; Dispatcher.BeginInvoke( DispatcherPriority.ContextIdle, new Action(delegate() { PrixTextBox.Focus(); })); calculateOnUi(true, false, true, false, false, false); }
public ProductNameSelectList(TableProduct tableProduct) { this.VisibleOptionText = tableProduct.Name.Name + " - " + tableProduct.Description + " - " + tableProduct.Brand.Brand + " - $" + Math.Round(tableProduct.InitialPricePerSellableUnit, 2) + " - " + tableProduct.Container.Container + " " + tableProduct.Size + "Ct."; this.Name = tableProduct.Name.Name; this.Brand = tableProduct.Brand.Brand; this.ProductID = tableProduct.ProductID; this.UPC_A = tableProduct.UPC_A; this.InitialPricePerSellableUnit = Math.Round(tableProduct.InitialPricePerSellableUnit, 2); this.Description = tableProduct.Description; this.Container = tableProduct.Container.Container; this.Size = tableProduct.Size; }
protected void ddlCategoryProd_SelectedIndexChanged(object sender, EventArgs e) { int categId = int.Parse(ddlCategoryProd.SelectedValue); tblProduct = adpProduct.GetDataByCategory(categId); ddlProductName.DataSource = tblProduct; ddlProductName.DataTextField = "ProductName"; ddlProductName.DataValueField = "ProductId"; ddlProductName.DataBind(); ddlProductName.Items.Insert(0, new ListItem("Select a Product", "-1")); }
public void UpdateProductTable() { foreach (GridViewRow row in grdOrder.Rows) { int quantity = int.Parse(row.Cells[6].Text); int productId = int.Parse(row.Cells[3].Text); tblProduct = adpProduct.GetDataBy(productId); int prodInStock = tblProduct[0].ProductInStock - quantity; adpProduct.UpdateByProductID(prodInStock, productId); } Response.Redirect("~/OrderForm.aspx"); }
protected void Update_Click(object sender, EventArgs e) { tblProduct = adpProduct.GetData(); Cache["tblProduct"] = tblProduct; if (string.IsNullOrEmpty(txtProductNumber.Text)) { lblErrorMessage.Text = "Please Insert the Product Number"; lblErrorMessage.ForeColor = System.Drawing.Color.Red; } else { if (validFields()) { updateRow(); } } }
public bool createProduct(Product productToCreat) { //i don't need a transaction since i do only one insert operation //submitChanges manages rollback try { TableProduct createdProduct = new TableProduct(productToCreat.name, productToCreat.description, productToCreat.price, productToCreat.tax, productToCreat.qty, productToCreat.barcode, productToCreat.brand.ID, productToCreat.category.ID, productToCreat.image); this.connection.products.InsertOnSubmit(createdProduct); connection.SubmitChanges(); } catch (Exception e) { return(false); } return(true); }
private Products getProductInformation() { Products prod = new Products(); int id = int.Parse(ddlProductName.SelectedValue); tblProduct = adpProduct.GetDataBy(id); var row = tblProduct; if (row != null) { prod.PName = row[0].ProductName.ToString(); prod.PProductID = row[0].ProductId; prod.PPrice = row[0].ProductPrice; prod.PQuantity = row[0].ProductInStock; prod.PProductCateg = row[0].ProductCategory; } return(prod); }
public static void Initialize(Database context) { if (!context.Users.Any()) { context.Users.Add(new User { Login = "******", Password = "******", Role = "Маркетолог", Name = "Иванов И.И." }); } context.SaveChanges(); if (!context.Divisions.Any()) { context.Divisions.Add(new Division { Name = "Основной отдел" }); context.Divisions.Add(new Division { Name = "Вспомогательный отдел" }); } context.SaveChanges(); if (!context.ProductGroups.Any()) { context.ProductGroups.Add(new ProductGroup { Name = "Группа 1", Norm = 10 }); context.ProductGroups.Add(new ProductGroup { Name = "Группа 2", Norm = 15 }); } context.SaveChanges(); if (!context.Clients.Any()) { context.Clients.Add(new Client { Name = "Клиент 1", Type = "Тип 1" }); } context.SaveChanges(); if (!context.Products.Any()) { var firstGroup = context.ProductGroups.FirstOrDefault(); var lastGroup = context.ProductGroups.OrderBy(rec => rec.Id).LastOrDefault(); var product1 = new Product { Name = "Продукция 1", AdvertData = "Реклама 1", Price = 30, Brand = "Марка 1", Manufacturer = "Производитель 1", City = "Город 1", ProductGroup = firstGroup }; context.Products.Add(product1); var product2 = new Product { Name = "Продукция 2", AdvertData = "Реклама 2", Price = 40, Brand = "Марка 2", Manufacturer = "Производитель 2", City = "Город 2", ProductGroup = lastGroup }; context.Products.Add(product2); var product3 = new Product { Name = "Продукция 3", AdvertData = "Реклама 2", Price = 40, Brand = "Марка 2", Manufacturer = "Производитель 2", City = "Город 2", ProductGroup = lastGroup }; context.Products.Add(product3); var product4 = new Product { Name = "Продукция 4", AdvertData = "Реклама 3", Price = 40, Brand = "Марка 3", Manufacturer = "Производитель 1", City = "Город 2", ProductGroup = lastGroup }; context.Products.Add(product4); var firstClient = context.Clients.FirstOrDefault(); var tableProduct1 = new TableProduct { Product = product1, Amount = 10, Sale = new Sale { Date = DateTime.Now.AddDays(-10), Client = firstClient } }; context.TableProducts.Add(tableProduct1); var tableProduct2 = new TableProduct { Product = product1, Amount = 15, Sale = new Sale { Date = DateTime.Now.AddDays(-9), Client = firstClient } }; context.TableProducts.Add(tableProduct2); var tableProduct3 = new TableProduct { Product = product2, Amount = 5, Sale = new Sale { Date = DateTime.Now.AddDays(-8), Client = firstClient } }; context.TableProducts.Add(tableProduct3); var tableProduct4 = new TableProduct { Product = product3, Amount = 20, Sale = new Sale { Date = DateTime.Now.AddDays(-7), Client = firstClient } }; context.TableProducts.Add(tableProduct4); var tableProduct5 = new TableProduct { Product = product4, Amount = 10, Sale = new Sale { Date = DateTime.Now.AddDays(-6), Client = firstClient } }; context.TableProducts.Add(tableProduct5); var tableProduct6 = new TableProduct { Product = product4, Amount = 13, Sale = new Sale { Date = DateTime.Now.AddDays(-5), Client = firstClient } }; context.TableProducts.Add(tableProduct6); var tableProduct7 = new TableProduct { Product = product4, Amount = 18, Sale = new Sale { Date = DateTime.Now.AddDays(-5), Client = firstClient } }; context.TableProducts.Add(tableProduct7); } context.SaveChanges(); if (!context.Suppliers.Any()) { var supplier = new Supplier { Name = "Поставщик 1", INN = "123" }; context.Suppliers.Add(supplier); var lastSupplier = new Supplier { Name = "Поставщик 2", INN = "456" }; context.Suppliers.Add(lastSupplier); var firstGroup = context.ProductGroups.FirstOrDefault(); var lastGroup = context.ProductGroups.OrderBy(rec => rec.Id).LastOrDefault(); if (firstGroup != null) { supplier.ProductGroups = new List <ProductGroup>(); supplier.ProductGroups.Add(firstGroup); lastSupplier.ProductGroups = new List <ProductGroup>(); lastSupplier.ProductGroups.Add(lastGroup); } } context.SaveChanges(); }