private void confirmBtn_Click(object sender, EventArgs e) { //if (MessageBox.Show("Are you sure you want to add this item in cart?","", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) // return; var i = new InventoryItemDetailArgs(Id, (int)(quantity.Value), price.Value, discount.Value); OnConfirm.Invoke(this, i); this.Close(); }
private void editConfirmed_Callback(object sender, InventoryItemDetailArgs e) { //throw new NotImplementedException(); var rowToBeModified = cartTable.Rows.Cast <DataGridViewRow>().FirstOrDefault(x => (int)(x.Cells[0].Value) == e.Id); rowToBeModified.Cells[priceCol.Name].Value = e.Price; rowToBeModified.Cells[quantityCol.Name].Value = e.Quantity; rowToBeModified.Cells[discountCol.Name].Value = e.Discount; rowToBeModified.Cells[totalPriceCol.Name].Value = (e.Price - e.Discount) * e.Quantity; }
/// <summary> /// callback for when user finished the setup /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void On_Confirm(object sender, InventoryItemDetailArgs e) { TakeItemsFromCart(e.Id, e.Quantity); using (var p = new POSEntities()) { ///find the item in inventory var i = p.InventoryItems.FirstOrDefault(x => x.Id == e.Id); ///if not found, then dont handle addition of item to cart if (i == null) { return; } ///search for identitcal id in cart var sameRow = cartTable.Rows.Cast <DataGridViewRow>().FirstOrDefault(x => (int)(x.Cells[0].Value) == i.Id); /// if none then add new row if (sameRow == null) { cartTable.Rows.Add(i.Id, i.SerialNumber, i.Product.Item.Name, e.Quantity, e.Price, e.Discount, (e.Price - e.Discount) * e.Quantity, i.Product.Supplier.Name, "Modify"); } ///else add quantity to the current quantity in cart else { int newQuantity = (int)(sameRow.Cells[quantityCol.Name].Value) + e.Quantity; decimal currentPrice = (decimal)(sameRow.Cells[priceCol.Name].Value); decimal currentDiscount = (decimal)(sameRow.Cells[discountCol.Name].Value); sameRow.Cells[quantityCol.Name].Value = newQuantity; sameRow.Cells[totalPriceCol.Name].Value = newQuantity * (currentPrice - currentDiscount); } } ///update the grandtotal totalPrice.Text = string.Format("₱{0:n}", TotalPrice); }