/// <summary> /// Update datagirdview after food is selected /// </summary> private void UpdateGridView(int id, int quantity) { Items selectedItem = null; if (ItemData.CheckUniqueItem(ListOfUpdateFood, id) == true) { selectedItem = ItemData.GetAnItem(id, ListOFFoods); ItemData.SellItem(selectedItem.ID, quantity, ListOFFoods); ListOfUpdateFood.Add(selectedItem); //Add items into list of sold foods to keep track the quantity ListOfSoldFoods.Add(new Items(selectedItem.ID, selectedItem.Name, selectedItem.Price, quantity)); } else { selectedItem = ItemData.GetAnItem(id, ListOfUpdateFood); ItemData.SellItem(selectedItem.ID, quantity, ListOfUpdateFood); //Update the quantity for the list of sold food Items soldItem = ItemData.GetAnItem(id, ListOfSoldFoods); soldItem.Quantity += quantity; } subtotal += selectedItem.Price * quantity; //Add row into the datagridview DataGridViewRow newrow = new DataGridViewRow(); newrow.CreateCells(dataGridViewFood); newrow.Cells[0].Value = selectedItem.ID; newrow.Cells[1].Value = selectedItem.Name; newrow.Cells[2].Value = quantity; newrow.Cells[3].Value = selectedItem.Price; newrow.Cells[4].Value = selectedItem.Price * quantity; dataGridViewFood.Rows.Add(newrow); }
/// <summary> /// Update datagirdview after a material is selected /// </summary> private void UpdateGridView(int id, int quantity, DateTime returnDate) { Items selectedItem = null; if (ItemData.CheckUniqueItem(ListOfMaterialsInInvoice, id, returnDate) == true) { selectedItem = ItemData.GetAnItem(id, ListOfMaterials); ItemData.SellItem(selectedItem.ID, quantity, ListOfMaterials); ListOfUpdateMaterials.Add(selectedItem); //Add items into list of loaned material to keep track the quantity ListOfLoanedMaterials.Add(new Items(selectedItem.ID, selectedItem.Name, selectedItem.Price, quantity)); //Add items into Material_Invoice_Item ListOfMaterialsInInvoice.Add(new Material_Invoice_Items(quantity, selectedItem.ID, InvoiceID, returnDate, false)); } else { selectedItem = ItemData.GetAnItem(id, ListOfUpdateMaterials); ItemData.SellItem(selectedItem.ID, quantity, ListOfUpdateMaterials); //Update the quantity for the list of sold food Items soldItem = ItemData.GetAnItem(id, ListOfLoanedMaterials); soldItem.Quantity += quantity; foreach (var f in ListOfMaterialsInInvoice) { f.Quantity += quantity; } } int nbofDates = (returnDate - currentDate).Days; subtotal += selectedItem.Price * quantity; //Add row into the datagridview DataGridViewRow newrow = new DataGridViewRow(); newrow.CreateCells(dataGridViewMaterial); newrow.Cells[0].Value = selectedItem.ID; newrow.Cells[1].Value = selectedItem.Name; newrow.Cells[2].Value = returnDate.ToString("dd-MM-yyyy"); newrow.Cells[3].Value = quantity; newrow.Cells[4].Value = selectedItem.Price.ToString("0.00"); newrow.Cells[5].Value = (selectedItem.Price * quantity * nbofDates).ToString("0.00"); dataGridViewMaterial.Rows.Add(newrow); }