public Customer_Home_Product_Open(CProduct arg) { item = arg; prev = null; InitializeComponent(); }
public Customer_Home_Product_Open(CProduct arg, Form arg2) { item = arg; prev = arg2; this.StartPosition = FormStartPosition.Manual; this.Location = prev.Location; InitializeComponent(); }
private async void button_Product_Search_Click(object sender, EventArgs e) { if (comboBox_Product_Search.SelectedIndex < 0) { return; } String text = textBox_Product_Search.Text; CCatagory cat_obj = (CCatagory)comboBox_Product_Search.SelectedItem; List <CProduct> list = await CProduct.SearchProductList(cat_obj.id, text); dataGridView_Product.DataSource = new BindingSource(list, null); foreach (DataGridViewColumn x in dataGridView_Product.Columns) { if (x.Name.Equals("id")) { x.DisplayIndex = 0; x.HeaderText = "ID"; } else if (x.Name.Equals("name")) { x.DisplayIndex = 1; x.HeaderText = "Name"; } else if (x.Name.Equals("minprice")) { x.DisplayIndex = 2; x.HeaderText = "Price"; } else if (x.Name.Equals("sales")) { x.DisplayIndex = 3; x.HeaderText = "Sales"; } else if (x.Name.Equals("rating")) { x.DisplayIndex = 4; x.HeaderText = "Rating"; } else if (x.Name.Equals("quantity")) { x.DisplayIndex = 5; x.HeaderText = "Available"; } else { x.Visible = false; } } }
public async static Task <CProduct> Retrieve(Int32 catagory_id, String name) { CProduct ret = null; try { String sql = "SELECT * FROM `product` WHERE `catagory_id` = @catagory_id and `name` = @name LIMIT 1"; MySqlCommand cmd = new MySqlCommand(sql, Program.conn); cmd.Parameters.AddWithValue("@catagory_id", catagory_id); cmd.Parameters.AddWithValue("@name", name); DbDataReader reader = await cmd.ExecuteReaderAsync(); cmd.Dispose(); if (!(await reader.ReadAsync())) { if (!reader.IsClosed) { reader.Close(); } CUtils.LastLogMsg = "Product with catagory_id '" + catagory_id + "' and name '" + name + "' not found!"; return(ret); } ret = new CProduct(reader.GetInt32(reader.GetOrdinal("id")), catagory_id, name, reader.GetString(reader.GetOrdinal("description")), (await reader.IsDBNullAsync(reader.GetOrdinal("minprice"))) ? 0 : reader.GetDouble(reader.GetOrdinal("minprice")), (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 : reader.GetDouble(reader.GetOrdinal("rating")), (await reader.IsDBNullAsync(reader.GetOrdinal("quantity"))) ? 0 : reader.GetInt32(reader.GetOrdinal("quantity")), (await reader.IsDBNullAsync(reader.GetOrdinal("image"))) ? global::OPS.Properties.Resources.noimage : CUtils.GetImageFromReader(reader, reader.GetOrdinal("image"))); 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 Seller_Home_Product_Add_Load(object sender, EventArgs e) { // Fill Default Fields item = null; extField = new List <extFieldStruct>(); ButtonState = false; cat_list = await CCatagory.RetrieveCatagoryList(0); comboBox_Catagory.Items.AddRange(cat_list.ToArray()); location_list = await CLocation.RetrieveLocationList(); comboBox_Pincode.Items.AddRange(location_list.ToArray()); imgSize = pictureBox_Picture.Size; // Disable Form Auto Size Later Size temp = this.Size; this.AutoSize = false; this.Size = temp; // Enable Size Manager & Force Reset Size Seller_Home_Product_Add_SizeChanged_Custom(null, null); this.SizeChanged += new EventHandler(Seller_Home_Product_Add_SizeChanged_Custom); }
private async void button_Main_Click(object sender, EventArgs e) { if (!ButtonState) { // Check Constraints if (String.IsNullOrWhiteSpace(textBox_Name.Text)) { MessageBox.Show("Invalid Name!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (comboBox_Catagory.SelectedIndex < 0) { MessageBox.Show("Invalid Catagory!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (String.IsNullOrWhiteSpace(richTextBox_Description.Text)) { MessageBox.Show("Invalid Description!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } foreach (extFieldStruct x in extField) { if (String.IsNullOrWhiteSpace(x.textBox.Text)) { { MessageBox.Show("Invalid " + x.label.Text + "!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } } if (pictureBox_Picture.Image == null || pictureBox_Picture.Image.Equals(global::OPS.Properties.Resources.noimage)) { MessageBox.Show("Invalid Image!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Register Product if (!(await CProduct.Register(((CCatagory)comboBox_Catagory.SelectedItem).id, textBox_Name.Text, richTextBox_Description.Text, pictureBox_Picture.Image))) { 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; } item = await CProduct.Retrieve(((CCatagory)comboBox_Catagory.SelectedItem).id, textBox_Name.Text); if (item == null) { 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; } // Lock Product Specifications textBox_Name.ReadOnly = true; comboBox_Catagory.Enabled = false; richTextBox_Description.ReadOnly = true; foreach (extFieldStruct x in extField) { x.textBox.ReadOnly = true; } button_Browse.Visible = false; // Change Form & Button State tableLayoutPanel2.Visible = true; button_Main.Text = "Add To Inventory"; ButtonState = true; } else { if (!CUtils.IsNumeric(textBox_Price.Text)) { MessageBox.Show("Invalid Price!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!CUtils.IsNumeric(textBox_Quantity.Text)) { MessageBox.Show("Invalid Quantity!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (comboBox_Pincode.SelectedIndex < 0) { MessageBox.Show("Invalid Pincode!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!CUtils.IsNumeric(textBox_Warranty.Text)) { MessageBox.Show("Invalid Warranty!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Console.WriteLine("QUAT=" + Int32.Parse(textBox_Quantity.Text)); if (!(await CSeller_Inventory.Register(CUser.cur_user.id, item.id, Double.Parse(textBox_Price.Text), Int32.Parse(textBox_Quantity.Text), ((CLocation)comboBox_Pincode.SelectedItem).pincode, Double.Parse(textBox_Warranty.Text)))) { if (CUtils.LastLogMsg.Equals("Inventory Already Exists!")) { CSeller_Inventory inv = await CSeller_Inventory.Retrieve(CUser.cur_user.id, item.id); if (inv != null) { if (!(await inv.Commit(inv.price, inv.quantity + Int32.Parse(textBox_Quantity.Text), inv.pincode, inv.warranty))) { MessageBox.Show("Successfully Added to Inventory!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Visible = false; this.Dispose(); return; } } MessageBox.Show("Cause: Unknown", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } 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; } MessageBox.Show("Successfully Added to Inventory!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Visible = false; this.Dispose(); } }
private async void tabControl_MAIN_SelectedIndexChanged(object sender, EventArgs e) { if (tabControl_MAIN.SelectedTab.Text.Equals("Inventory")) { dataGridView_Inventory.Rows.Clear(); List <CSeller_Inventory> inv_list = await CSeller_Inventory.RetrieveSellerInventoryList(CUser.cur_user.id); foreach (CSeller_Inventory x in inv_list) { CProduct y = await CProduct.Retrieve(x.product_id); dataGridView_Inventory.Rows.Add ( new object[] { x.product_id, y.name, x.price, x.quantity, x.pincode, x.warranty, x, y } ); } } else if (tabControl_MAIN.SelectedTab.Text.Equals("Orders")) { dataGridView_Orders.Rows.Clear(); List <COrder> order_list = await COrder.RetrieveOrdertBySellerID(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 } ); } } }