Exemple #1
0
 public CCustomer_Cart(CCustomer_Cart src)
 {
     this._customer_id = src.customer_id;
     this._product_id  = src.product_id;
     this._seller_id   = src.seller_id;
     this._quantity    = src.quantity;
 }
Exemple #2
0
        private async void button_Pay_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(richTextBox_Street.Text))
            {
                MessageBox.Show("Invalid Street!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (comboBox_Pincode.SelectedIndex < 0)
            {
                MessageBox.Show("Invalid Pincode!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (!Regex.IsMatch(textBox_Contact.Text, "^[0-9]{10}$"))
            {
                MessageBox.Show("Invalid Contact Number!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (!Regex.IsMatch(textBox_DebitCard.Text,
                               "^(?:4[0-9]{12}(?:[0-9]{3})?)$"
                               ))
            {
                MessageBox.Show("Invalid Card Number!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            foreach (CCustomer_Cart x in cart_items)
            {
                await COrder.Register(x.customer_id,
                                      x.product_id,
                                      x.seller_id,
                                      x.quantity,
                                      Int64.Parse(textBox_Contact.Text),
                                      richTextBox_Street.Text,
                                      ((CLocation)(comboBox_Pincode.SelectedItem)).pincode,
                                      GTotal);

                await CCustomer_Cart.Remove(x.customer_id, x.product_id, x.seller_id, true);

                // Update Sales in Product
                MySqlCommand tempcmd = new MySqlCommand();
                tempcmd.Connection  = Program.conn;
                tempcmd.CommandText = "UPDATE `product` SET sales = sales + @quantity WHERE id = @product_id";
                tempcmd.Parameters.AddWithValue("@quantity", x.quantity);
                tempcmd.Parameters.AddWithValue("@product_id", x.product_id);
                await tempcmd.ExecuteNonQueryAsync();

                tempcmd.Dispose();
            }
            if (CUtils.LastLogMsg != null)
            {
                MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("Successfully Ordered!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                prev.Visible = true;
                this.Visible = false;
                this.Dispose();
            }
        }
        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();
        }
Exemple #4
0
        private async void button_Cart_Delete_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow x in dataGridView_Cart.Rows)
            {
                CCustomer_Cart y = (CCustomer_Cart)(x.Cells["extra_1"].Value);
                await CCustomer_Cart.Remove(y.customer_id, y.product_id, y.seller_id);

                dataGridView_Cart.Rows.Remove(x);
            }
        }
Exemple #5
0
        private void button_Cart_Checkout_Click(object sender, EventArgs e)
        {
            List <CCustomer_Cart> temp = new List <CCustomer_Cart>();

            foreach (DataGridViewRow x in dataGridView_Cart.Rows)
            {
                CCustomer_Cart y = (CCustomer_Cart)(x.Cells["extra_1"].Value);
                temp.Add(y);
            }
            new Checkout(temp, this, Double.Parse(textBox_Cart_GrandTotal.Text)).Visible = true;
            this.Visible = false;
        }
Exemple #6
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();
        }
Exemple #7
0
        public async static Task <CCustomer_Cart> Retrieve(Int32 customer_id,
                                                           Int32 product_id,
                                                           Int32 seller_id)
        {
            CCustomer_Cart ret = null;

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

                cmd.Dispose();
                if (!(await reader.ReadAsync()))
                {
                    if (!reader.IsClosed)
                    {
                        reader.Close();
                    }
                    CUtils.LastLogMsg = "Cart with customer_id '" + customer_id + "' and product_id '" + product_id + "' and seller_id '" + seller_id + "' not found!";
                    return(ret);
                }
                ret = new CCustomer_Cart(customer_id,
                                         product_id,
                                         seller_id,
                                         (await reader.IsDBNullAsync(reader.GetOrdinal("quantity"))) ? 0 : reader.GetInt32(reader.GetOrdinal("quantity")));
                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);
        }
Exemple #8
0
        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
                    }
                    );
                }
            }
        }