private async void button_AddToCart_Click(object sender, EventArgs e) { // Check Valid Quantity if (!CUtils.IsNumeric(textBox_Quantity.Text)) { MessageBox.Show("Invalid Quantity!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } int quantity = Int32.Parse(textBox_Quantity.Text); // Check Quantity Inventory Exceed int temp2 = (int)(dataGridView_SellerList.SelectedRows[0].Cells["quantity"].Value); if (quantity > temp2) { MessageBox.Show("Quantity Exceeds Seller's Capability!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Try Retrieve Existing Cart CUser_Seller temp = (CUser_Seller)(dataGridView_SellerList.SelectedRows[0].Cells["extra_2"].Value); CCustomer_Cart cartitem = await CCustomer_Cart.Retrieve(CUser.cur_user.id, item.id, temp.user_id); if (cartitem != null) { if (!(await cartitem.Commit(cartitem.quantity + quantity))) { if (CUtils.LastLogMsg != null) { MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Cause: Unknown", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return; } } else if (!(await CCustomer_Cart.Register(CUser.cur_user.id, item.id, temp.user_id, quantity))) // Create New Cart { if (CUtils.LastLogMsg == null || CUtils.LastLogMsg.Equals("Inventory Already Exists!")) { MessageBox.Show("Cause: Unknown", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } MessageBox.Show("Successfully Added to Cart!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Visible = false; this.Dispose(); }
private async void button_Cart_Save_Click(object sender, EventArgs e) { Double total = 0; foreach (DataGridViewRow x in dataGridView_Cart.Rows) { CCustomer_Cart y = (CCustomer_Cart)(x.Cells["extra_1"].Value); await y.Commit(Int32.Parse(x.Cells["quantity"].Value.ToString())); CSeller_Inventory z = (CSeller_Inventory)(x.Cells["extra_4"].Value); total += z.price * y.quantity; } textBox_Cart_GrandTotal.Text = total.ToString(); }