Exemplo n.º 1
0
        private async void button_Check_Click(object sender, EventArgs e)
        {
            // Check if Pincode Selected
            if (comboBox_Pincode.SelectedIndex < 0)
            {
                MessageBox.Show("Invalid Pincode!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Calculate & Populate Duration & Sort Seller List
            DistanceMatrixRequest y = new DistanceMatrixRequest();

            y.ApiKey  = Program.szGoogleMapsAPI_key;
            y.Origins = new string[] { comboBox_Pincode.Text };
            y.Mode    = DistanceMatrixTravelModes.driving;
            List <string> Destinations = new List <string>();

            foreach (DataGridViewRow x in dataGridView_SellerList.Rows)
            {
                CSeller_Inventory temp = (CSeller_Inventory)(x.Cells["extra_1"].Value);
                Destinations.Add(temp.pincode.ToString());
            }
            y.Destinations = Destinations.ToArray <string>();
            DistanceMatrixResponse z = await GoogleMapsApi.GoogleMaps.DistanceMatrix.QueryAsync(y);

            for (int i = 0; i < z.Rows.ElementAt <Row>(0).Elements.Count <Element>(); ++i)
            {
                Element x = z.Rows.ElementAt <Row>(0).Elements.ElementAt <Element>(i);
                dataGridView_SellerList.Rows[i].Cells["shipping_time"].Value = (x.Duration.Value.Days + 1) + " Day(s) " + (x.Duration.Value.Hours) + " Hour(s)";
            }
            dataGridView_SellerList.Sort(dataGridView_SellerList.Columns["shipping_time"], ListSortDirection.Ascending);
        }
Exemplo n.º 2
0
 public CSeller_Inventory(CSeller_Inventory src)
 {
     this._seller_id  = src.seller_id;
     this._product_id = src.product_id;
     this._price      = src.price;
     this._quantity   = src.quantity;
     this._pincode    = src.pincode;
     this._warranty   = src.warranty;
 }
Exemplo n.º 3
0
        private async void button_Inventory_Delete_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow x in dataGridView_Inventory.Rows)
            {
                CSeller_Inventory y = (CSeller_Inventory)(x.Cells["extra_1"].Value);
                await CSeller_Inventory.Remove(y.seller_id, y.product_id);

                dataGridView_Inventory.Rows.Remove(x);
            }
        }
Exemplo n.º 4
0
 private async void button_Inventory_Save_Click(object sender, EventArgs e)
 {
     foreach (DataGridViewRow x in dataGridView_Inventory.Rows)
     {
         CSeller_Inventory y = (CSeller_Inventory)(x.Cells["extra_1"].Value);
         await y.Commit(Double.Parse(x.Cells["price"].Value.ToString()),
                        Int32.Parse(x.Cells["quantity"].Value.ToString()),
                        Int32.Parse(x.Cells["pincode"].Value.ToString()),
                        Double.Parse(x.Cells["warranty"].Value.ToString()));
     }
 }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        public async static Task <CSeller_Inventory> Retrieve(Int32 seller_id, Int32 product_id)
        {
            CSeller_Inventory ret = null;

            try
            {
                String       sql = "SELECT * FROM `seller_inventory` WHERE `seller_id` = @seller_id and `product_id` = @product_id LIMIT 1";
                MySqlCommand cmd = new MySqlCommand(sql, Program.conn);
                cmd.Parameters.AddWithValue("@seller_id", seller_id);
                cmd.Parameters.AddWithValue("@product_id", product_id);
                DbDataReader reader = await cmd.ExecuteReaderAsync();

                cmd.Dispose();
                if (!(await reader.ReadAsync()))
                {
                    if (!reader.IsClosed)
                    {
                        reader.Close();
                    }
                    CUtils.LastLogMsg = "Inventory with seller_id '" + seller_id + "' and product_id '" + product_id + "' not found!";
                    return(ret);
                }
                ret = new CSeller_Inventory(seller_id,
                                            product_id,
                                            (await reader.IsDBNullAsync(reader.GetOrdinal("price"))) ? 0.0 : reader.GetDouble(reader.GetOrdinal("price")),
                                            (await reader.IsDBNullAsync(reader.GetOrdinal("quantity"))) ? 0 : reader.GetInt32(reader.GetOrdinal("quantity")),
                                            (await reader.IsDBNullAsync(reader.GetOrdinal("pincode"))) ? 0 : reader.GetInt32(reader.GetOrdinal("pincode")),
                                            (await reader.IsDBNullAsync(reader.GetOrdinal("warranty"))) ? 0.0 : reader.GetDouble(reader.GetOrdinal("warranty")));
                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);
        }
Exemplo n.º 7
0
        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();
            }
        }
Exemplo n.º 8
0
        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
                    }
                    );
                }
            }
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        private async void Seller_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 Inventory if Exists
            invitem = await CSeller_Inventory.Retrieve(CUser.cur_user.id, item.id);

            if (invitem != null)
            {
                textBox_Price.Text     = invitem.price.ToString();
                textBox_Price.ReadOnly = true;
                foreach (CLocation x in comboBox_Pincode.Items)
                {
                    if (x.pincode == invitem.pincode)
                    {
                        comboBox_Pincode.SelectedItem = x;
                        break;
                    }
                }
                comboBox_Pincode.Enabled  = false;
                textBox_Warranty.Text     = invitem.warranty.ToString();
                textBox_Warranty.ReadOnly = true;
            }

            // Disable Form Auto Size Later
            Size temp = this.Size;

            this.AutoSize = false;
            this.Size     = temp;

            // Enable Size Manager & Force Reset Size
            Seller_Home_Product_Open_SizeChanged_Custom(null, null);
            this.SizeChanged += new EventHandler(Seller_Home_Product_Open_SizeChanged_Custom);
        }
Exemplo n.º 11
0
 private async void button_AddToInventory_Click(object sender, EventArgs e)
 {
     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;
     }
     if (invitem != null)
     {
         if (!(await invitem.Commit(invitem.price,
                                    invitem.quantity + Int32.Parse(textBox_Quantity.Text),
                                    invitem.pincode,
                                    invitem.warranty)))
         {
             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 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 == 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 Inventory!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     this.Visible = false;
     this.Dispose();
 }