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(); }
// core methods public async static Task <CUser_Seller> Retrieve(Int32 user_id) { CUser_Seller ret = null; try { String sql = "SELECT * FROM `user_seller` WHERE `user_id` = @user_id"; MySqlCommand cmd = new MySqlCommand(sql, Program.conn); cmd.Parameters.AddWithValue("@user_id", user_id); DbDataReader reader = await cmd.ExecuteReaderAsync(); cmd.Dispose(); if (!(await reader.ReadAsync())) { if (!reader.IsClosed) { reader.Close(); } CUtils.LastLogMsg = "Seller with user_id '" + user_id + "' not found!"; return(ret); } ret = new CUser_Seller(user_id, (await reader.IsDBNullAsync(reader.GetOrdinal("name"))) ? String.Empty : reader.GetString(reader.GetOrdinal("name")), (await reader.IsDBNullAsync(reader.GetOrdinal("sales"))) ? 0 : reader.GetInt32(reader.GetOrdinal("sales")), (await reader.IsDBNullAsync(reader.GetOrdinal("raters"))) ? 0 : reader.GetInt32(reader.GetOrdinal("raters")), (await reader.IsDBNullAsync(reader.GetOrdinal("rating"))) ? 0.0 : reader.GetDouble(reader.GetOrdinal("rating"))); if (!reader.IsClosed) { reader.Close(); } CUtils.LastLogMsg = null; } catch (Exception ex) { #if DEBUG Console.WriteLine(ex.Message + " " + ex.StackTrace); #endif CUtils.LastLogMsg = "Unahandled Exception!"; } return(ret); }
private async void Customer_Home_Product_Open_Load(object sender, EventArgs e) { // Fill Default Fields textBox_Name.Text = item.name; comboBox_Catagory.Items.Add(await CCatagory.Retrieve(item.catagory_id)); comboBox_Catagory.SelectedIndex = 0; richTextBox_Description.Text = item.description; progressBar_Rating.Value = (Int32)(item.rating * 100.0); location_list = await CLocation.RetrieveLocationList(); comboBox_Pincode.Items.AddRange(location_list.ToArray()); imgSize = item.image.Size; pictureBox_Picture.Image = item.image; // Fill Product Fields List <CProduct_Field> extlist = await CProduct_Field.RetrieveProductFieldList(item.id); foreach (CProduct_Field x in extlist) { tableLayoutPanel3.RowCount++; tableLayoutPanel3.RowStyles.Add(new RowStyle()); Label extLabel = new Label() { TabIndex = 0, Font = new Font("Microsoft Sans Serif", 9.75F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0))), Text = x.field_name, Size = new Size(16, 16), Dock = DockStyle.Fill }; TextBox extTextBox = new TextBox() { TabIndex = 1, Text = x.field_value, Size = new Size(16, 16), Dock = DockStyle.Fill, ReadOnly = true }; tableLayoutPanel3.Controls.Add(extLabel, 0, tableLayoutPanel3.RowCount - 1); tableLayoutPanel3.Controls.Add(extTextBox, 1, tableLayoutPanel3.RowCount - 1); } // Retrieve Sellers With Products List <CSeller_Inventory> list1 = await CSeller_Inventory.RetrieveSellerInventoryListByProduct(item.id); if (list1.Count < 1) { comboBox_Pincode.Enabled = false; button_Check.Enabled = false; textBox_Quantity.Enabled = false; button_AddToCart.Enabled = false; } dataGridView_SellerList.Columns.Add("seller_id", "Seller ID"); dataGridView_SellerList.Columns.Add("name", "Seller Name"); dataGridView_SellerList.Columns.Add("price", "Price"); dataGridView_SellerList.Columns.Add("quantity", "Available"); dataGridView_SellerList.Columns.Add("warranty", "Warranty"); dataGridView_SellerList.Columns.Add("shipping_time", "Shipping Time"); // Invisible Containers inside Data Grid dataGridView_SellerList.Columns.Add("extra_1", "extra_1"); dataGridView_SellerList.Columns.Add("extra_2", "extra_2"); dataGridView_SellerList.Columns["extra_1"].Visible = false; dataGridView_SellerList.Columns["extra_2"].Visible = false; for (Int16 i = 0; i < list1.Count; ++i) { CSeller_Inventory x = list1[i]; CUser_Seller y = await CUser_Seller.Retrieve(x.seller_id); dataGridView_SellerList.Rows.Add ( new object[] { x.seller_id, y.name, x.price, x.quantity, x.warranty, null, x, y, } ); } // Disable Form Auto Size Later Size temp = this.Size; this.AutoSize = false; this.Size = temp; // Enable Size Manager & Force Reset Size Customer_Home_Product_Open_SizeChanged_Custom(null, null); this.SizeChanged += new EventHandler(Customer_Home_Product_Open_SizeChanged_Custom); }
private async void tabControl_MAIN_SelectedIndexChanged(object sender, EventArgs e) { if (tabControl_MAIN.SelectedTab.Text.Equals("Cart")) { dataGridView_Cart.Rows.Clear(); Double total = 0; List <CCustomer_Cart> cart_list = await CCustomer_Cart.RetrieveCustomerCartList(CUser.cur_user.id); foreach (CCustomer_Cart x in cart_list) { CProduct y = await CProduct.Retrieve(x.product_id); CUser_Seller z = await CUser_Seller.Retrieve(x.seller_id); CSeller_Inventory yz = await CSeller_Inventory.Retrieve(z.user_id, y.id); dataGridView_Cart.Rows.Add ( new object[] { y.name, z.name, yz.price, x.quantity, yz.warranty, x, y, z, yz } ); total += yz.price * x.quantity; } textBox_Cart_GrandTotal.Text = total.ToString(); } else if (tabControl_MAIN.SelectedTab.Text.Equals("Orders")) { dataGridView_Orders.Rows.Clear(); List <COrder> order_list = await COrder.RetrieveOrdertByCustomerID(CUser.cur_user.id); DistanceMatrixRequest req = new DistanceMatrixRequest(); req.ApiKey = Program.szGoogleMapsAPI_key; req.Mode = DistanceMatrixTravelModes.driving; foreach (COrder x in order_list) { CProduct y = await CProduct.Retrieve(x.product_id); CSeller_Inventory z = await CSeller_Inventory.Retrieve(x.seller_id, x.product_id); CLocation c = await CLocation.Retrieve(x.pincode); String address = x.street + ", " + c.city + ", " + c.state + ", " + c.country + ", " + x.pincode; // Calculate ETA req.Origins = new string[] { z.pincode.ToString() }; req.Destinations = new string[] { x.pincode.ToString() }; DistanceMatrixResponse resp = await GoogleMapsApi.GoogleMaps.DistanceMatrix.QueryAsync(req); TimeSpan ts = resp.Rows.ElementAt <Row>(0).Elements.ElementAt <Element>(0).Duration.Value; ts = ts - (DateTime.Now - x.started_at.AddDays(1)); dataGridView_Orders.Rows.Add ( new object[] { x.id, y.name, z.price, x.quantity, address, x.started_at, (ts.Days) + " Day(s) " + (ts.Hours) + " Hour(s)", x.order_status, x, y, z, c } ); } } }