private void btnDelete_Click(object sender, EventArgs e) { try { ClassLibrary.Product product = new ClassLibrary.Product(); object id = dataGridView1.CurrentRow.Cells["PRODUCT_id"].Value; DataRow selectedRow = dtProducts.Rows.Find(id); DialogResult dlgResult = MessageBox.Show ("Are you sure you want to delete \nselected product and it's builtsheet?", "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dlgResult == DialogResult.Yes) { product.Id = Convert.ToInt32(id); product.Delete(); DisplayAllProducts(); } else if (dlgResult == DialogResult.No) { // No, stop } } catch (Exception ex) { DialogResult dlgResult = MessageBox.Show ("Cannot delete the record!\n the product is in an order, please delete the order first", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public void Initialize() { var productsList = new List <ClassLibrary.Product>(); var product1 = new ClassLibrary.Product("Parfum", "Este un parfum", System.DateTime.Now.AddDays(-2), 450, 25); var product2 = new ClassLibrary.Product("Bicicleta", "Este scumpa", System.DateTime.Now.AddDays(-4), 320, 25); var product3 = new ClassLibrary.Product("Morcovi", "E legume", System.DateTime.Now.AddDays(-5), 320, 25); var product4 = new ClassLibrary.Product("Pat", "Este un pat de apa", System.DateTime.Now.AddDays(-2), 320, 25); var product5 = new ClassLibrary.Product("Salam", "Este expirat", System.DateTime.Now.AddDays(2), 320, 25); var product6 = new ClassLibrary.Product("calculator", "Are tastatura", System.DateTime.Now.AddDays(-10), 320, 25); var product7 = new ClassLibrary.Product("Mouse", "Nu are fir", System.DateTime.Now.AddDays(-11), 320, 25); var product8 = new ClassLibrary.Product("Scaun", "Are 4 picioare", System.DateTime.Now.AddDays(-12), 320, 25); var product9 = new ClassLibrary.Product("Birou", "Este in centru", System.DateTime.Now.AddDays(-20), 320, 25); var product10 = new ClassLibrary.Product("Camera", "Nu are obiectiv", System.DateTime.Now.AddDays(-22), 320, 25); var product11 = new ClassLibrary.Product("Ceapa", "Este iute", System.DateTime.Now.AddDays(-44), 100, 25); productsList.Add(product1); productsList.Add(product2); productsList.Add(product3); productsList.Add(product4); productsList.Add(product6); productsList.Add(product7); productsList.Add(product8); productsList.Add(product9); productsList.Add(product10); productsList.Add(product11); productRepository = new ClassLibrary.ProductRepository(productsList); }
private void btnAdd_Click(object sender, EventArgs e) { ClassLibrary.Product pr = new ClassLibrary.Product(); pr.AddProduct(txtName.Text, Convert.ToDecimal(txtCost.Text), Convert.ToDecimal(txtPrice.Text), txtColor.Text, txtDescription.Text); }
public static void AddItem(ClassLibrary.Product product, int Amount) { bool add = true; if (cartList.Count == 0) { cartList.Add(new ClassLibrary.CartItem { Product = product, Amount = (int)Amount }); } foreach (var item in cartList) { if (product.Id == item.Product.Id) { item.Amount += Amount; add = false; break; } } if (add) { cartList.Add(new ClassLibrary.CartItem { Product = product, Amount = (int)Amount }); } }
public IActionResult AddProduct(ClassLibrary.Product prod, int?Amount, string url) { if (Amount != null && Amount > 0) { Cart.AddItem(prod, (int)Amount); } return(Redirect(url)); }
public void AddProduct(ClassLibrary.Product product) { var client = new RestClient(localHost); var request = new RestRequest("api/Backoffice", Method.POST); request.AddJsonBody(product); client.Execute(request); }
public void AddProduct(ClassLibrary.Product product) { _dbContext.Products.Add(new Product { ProductId = product.ProductId, Name = product.Name, Price = product.Price, ImageFilePath = product.ImageFilePath, CategoryId = product.CategoryId }); _dbContext.SaveChanges(); }
public ClassLibrary.Product AddProdToBd(ClassLibrary.Product product) { using (var connection = new SqlConnection(connectionString)) { connection.Open(); connection.Query("insert into Product(Name,Description,Price,ImgName)" + "values('" + product.Name + "','" + product.Description + "'," + product.Price + ",'" + product.ImgName + "')"); return(product); } }
public void DisplayAllProducts() { ClassLibrary.Product product = new ClassLibrary.Product(); dtProducts = product.GetAll().Tables[0]; dataGridView1.DataSource = dtProducts; //set the product_id column as primary key so you can search the table later dtProducts.PrimaryKey = new DataColumn[] { dtProducts.Columns["PRODUCT_id"] }; dataGridView1.DataSource = dtProducts; dataGridView1.Columns["PRODUCT_picture"].Visible = false; dataGridView1.Columns["PRODUCT_cost"].DefaultCellStyle.Format = "c"; dataGridView1.Columns["PRODUCT_price"].DefaultCellStyle.Format = "c"; dataGridView1.Columns["PRODUCT_id"].HeaderText = "ID"; dataGridView1.Columns["PRODUCT_name"].HeaderText = "Name"; dataGridView1.Columns["PRODUCT_cost"].HeaderText = "Cost"; dataGridView1.Columns["PRODUCT_price"].HeaderText = "Price"; dataGridView1.Columns["PRODUCT_color"].HeaderText = "Color"; dataGridView1.Columns["PRODUCT_description"].HeaderText = "Description"; dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; }
//------------------------------------------------------------------- private void btnSaveToDatabase_Click(object sender, EventArgs e) { decimal result; if ( (txtName.Text == "") || (txtPrice.Text == "") || (txtCost.Text == "") || (txtDescription.Text == "") ) { MessageBox.Show("please fill all the empty fields"); } else if (!decimal.TryParse(txtPrice.Text.Replace("$", ""), out result)) { MessageBox.Show("please enter a valid number for 'price'"); } else if (!decimal.TryParse(txtCost.Text.Replace("$", ""), out result)) { MessageBox.Show("please enter a valid number for 'Cost'"); } else { try { ClassLibrary.Product product = new ClassLibrary.Product(); product.Color = txtColor.Text; product.Cost = Convert.ToDecimal(txtCost.Text.Replace("$", "")); product.Description = txtDescription.Text; product.Name = txtName.Text; product.Price = Convert.ToDecimal(txtPrice.Text.Replace("$", "")); //ADDING MODE if (drCustomer == null) { if (imageName != null) { product.Pic = imageName; //copy image to the root directory of the application System.IO.File.Copy(imagePath, picturesPath + imageName, true); } else { product.Pic = ""; } //add product int LastAddedId = product.Add(); // product buildsheet ClassLibrary.BuildOfMaterial BuildOfMaterial = new ClassLibrary.BuildOfMaterial(); BuildOfMaterial.ProductId = LastAddedId; foreach (ProductBuildSheet bom in BOM) { BuildOfMaterial.PartID = bom.PartID; BuildOfMaterial.PartQuantity = bom.Quantity; BuildOfMaterial.Add(); } } //EDITING MODE else { //add image if (imageName != null) { product.Pic = imageName; //copy image to the root directory of the application System.IO.File.Copy(imagePath, picturesPath + imageName, true); } else { //use the same image name you got when form was loaded product.Pic = drCustomer.ItemArray[6].ToString(); } //update product information product.Id = Convert.ToInt32(drCustomer.ItemArray[0]); product.Update(); //update product buildsheet ClassLibrary.BuildOfMaterial BuildOfMaterial = new ClassLibrary.BuildOfMaterial(); BuildOfMaterial.ProductId = product.Id; BuildOfMaterial.Delete(); foreach (ProductBuildSheet bom in BOM) { BuildOfMaterial.PartID = bom.PartID; BuildOfMaterial.PartQuantity = bom.Quantity; BuildOfMaterial.Add(); } } frmDisProducts.DisplayAllProducts(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } Close(); } }
public void Post([FromBody] ClassLibrary.Product product) { db.AddProdToBd(product); }
//---------------------------------------------------------------------------------------------- private void frmAddOrderCustomer_Load(object sender, EventArgs e) { //make order list ord = new BindingList <OrderDetails>(); //add customers to the combobox ClassLibrary.Customer customer = new ClassLibrary.Customer(); dsCustomer = customer.GetAll(); dtCustomer = dsCustomer.Tables[0]; cmbCustomers.DataSource = dtCustomer; cmbCustomers.DisplayMember = "CUSTOMER_name"; cmbCustomers.ValueMember = "CUSTOMER_id"; //add products to the combobox ClassLibrary.Product product = new ClassLibrary.Product(); dsProduct = product.GetAll(); dtProduct = dsProduct.Tables[0]; cmbProducts.DataSource = dtProduct; cmbProducts.DisplayMember = "PRODUCT_name"; //ADDING MODE if (drOrder == null) { dateTimePicker1.Enabled = false; } //EDITING MODE else { //if orderid is in the sorder table ClassLibrary.SupplierOrder sorder = new ClassLibrary.SupplierOrder(); sorder.OrderId = Convert.ToInt32(drOrder.ItemArray[0]); DataTable dt = sorder.GetSorderByOrderId().Tables[0]; //disables forms items if (dt.Rows.Count != 0) { MakeOrderUnEditable(); saveDeliveryDate = true; dateTimePicker1.Enabled = true; } //select the customer combobox string custId = drOrder.ItemArray[1].ToString(); try { cmbCustomers.SelectedIndex = cmbCustomers.FindStringExact(custId); } catch (Exception ex) { } //display date dateTimePicker1.Text = drOrder.ItemArray[5].ToString(); //display total price totalPrice = Convert.ToDecimal(drOrder.ItemArray[3]); txtPrice.Text = String.Format("{0:c}", totalPrice); txtStatus.Text = drOrder.ItemArray[4].ToString(); //display orderdetails ClassLibrary.CustomerOrderDetails orderdetails = new ClassLibrary.CustomerOrderDetails(); orderdetails.OrderId = Convert.ToInt32(drOrder.ItemArray[0]); DataTable thisTable = orderdetails.GetOrderDetailsByOrderId().Tables[0]; try { foreach (DataRow row in thisTable.Rows) { string price = String.Format("{0:c}", Convert.ToDecimal(row.ItemArray[3])); //add to generic list ord.Add(new OrderDetails { ProductID = Convert.ToInt32(row.ItemArray[0]), ProductName = row.ItemArray[1].ToString(), Quantity = Convert.ToInt32(row.ItemArray[2]), Price = price, }); } dataGridView1.DataSource = ord; } catch (Exception ex) { } } }