예제 #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            quant      = 0;
            this.total = 0;
            string id, code, des, up, qty, name;
            int    t = 0;

            if (ri >= 0)
            {
                addQuantity aq = new addQuantity();
                aq.po    = this;
                aq.limit = int.Parse(dgvProd.Rows[ri].Cells[4].Value.ToString());
                aq.ShowDialog();
                if (quant != 0)
                {
                    for (int i = 0; i < dgvCart.Rows.Count; i++)
                    {
                        id = dgvProd.Rows[ri].Cells[0].Value.ToString();
                        if (dgvCart.Rows[i].Cells[0].Value.ToString() == id)
                        {
                            // qty = dgvProd.Rows[ri].Cells[4].Value.ToString();
                            dgvCart.Rows[i].Cells[4].Value = int.Parse(dgvCart.Rows[i].Cells[4].Value.ToString()) + quant;
                            t++;
                        }
                    }
                    if (t == 0)
                    {
                        id   = dgvProd.Rows[ri].Cells[0].Value.ToString();
                        code = dgvProd.Rows[ri].Cells[1].Value.ToString();
                        des  = dgvProd.Rows[ri].Cells[2].Value.ToString();
                        up   = dgvProd.Rows[ri].Cells[3].Value.ToString();
                        qty  = quant.ToString();
                        name = dgvProd.Rows[ri].Cells[5].Value.ToString();
                        string[] row = new string[] { id, code, des, up, qty, name };
                        dgvCart.Rows.Add(row);
                        dgvCart.ClearSelection();
                        dgvProd.ClearSelection();
                    }
                    dgvProd.Rows[ri].Cells[4].Value = int.Parse(dgvProd.Rows[ri].Cells[4].Value.ToString()) - quant;
                    for (int i = 0; i < dgvCart.Rows.Count; i++)
                    {
                        this.total += Convert.ToDecimal(dgvCart.Rows[i].Cells[3].Value.ToString()) * int.Parse(dgvCart.Rows[i].Cells[4].Value.ToString());
                    }
                    lblTotal.Text = total.ToString("c");
                }
            }
            else
            {
                MessageBox.Show("Please Select a product befor proceeding!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #2
0
        private void btnAddToCart_Click(object sender, EventArgs e)
        {
            int t  = 0;
            int ri = 0;

            ri = dgvInv.CurrentRow.Index;
            if (ri >= 0)
            {
                int         lim = int.Parse(dgvInv.Rows[ri].Cells[2].Value.ToString());
                addQuantity add = new addQuantity();
                add.limit  = lim;
                add.offSet = 3;
                add.pos    = this;
                add.ShowDialog();
                if (quant != 0)
                {
                    dgvInv.Rows[ri].Cells[2].Value = int.Parse(dgvInv.Rows[ri].Cells[2].Value.ToString()) - quant;
                    for (int i = 0; dgvCart.Rows.Count > i; i++)
                    {
                        if (dgvInv.Rows[ri].Cells[0].Value.ToString() == dgvCart.Rows[i].Cells[0].Value.ToString())
                        {
                            dgvCart.Rows[i].Cells[2].Value = int.Parse(dgvCart.Rows[i].Cells[2].Value.ToString()) + quant;

                            t = 1;
                        }
                    }
                    if (t != 1 && quant != 0)
                    {
                        dgvCart.Rows.Add(dgvInv.Rows[ri].Cells[0].Value.ToString(), dgvInv.Rows[ri].Cells[1].Value.ToString(), quant, dgvInv.Rows[ri].Cells[3].Value.ToString());
                        quant = 0;
                    }
                }
                else
                {
                    MessageBox.Show("You can't add 0 items.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            if (dgvCart.Rows.Count > 0)
            {
                total = 0;
                for (int i = 0; i < dgvCart.Rows.Count; i++)
                {
                    total = total + (int.Parse(dgvCart.Rows[i].Cells[2].Value.ToString()) * (decimal)Convert.ToDecimal(dgvCart.Rows[i].Cells[3].Value.ToString()));
                    //MessageBox.Show(dgvCart.Rows[i].Cells[2].Value.ToString() + dgvCart.Rows[i].Cells[3].Value.ToString());
                    lblTotal.Text = total.ToString("c");
                }
            }
        }
예제 #3
0
        private void btnAddToCart_Click(object sender, EventArgs e)
        {
            int ri = dgvCurBid.CurrentRow.Index;

            if (ri >= 0)
            {
                if (dgvCurBid.Rows[ri].Cells[7].Value.ToString() != "" && dgvCurBid.Rows[ri].Cells[8].Value.ToString() != "")
                {
                    addQuantity add = new addQuantity();
                    add.offSet = 2;
                    add.limit  = int.Parse(dgvCurBid.Rows[ri].Cells[7].Value.ToString());
                    add.bo     = this;
                    add.ShowDialog();
                    if (quant != 0)
                    {
                        conn.Open();
                        string           check = "SELECT * FROM cart WHERE bid_offer_id = '" + dgvCurBid.Rows[ri].Cells[5].Value.ToString() + "' and STATUS <> 1";
                        MySqlCommand     comm  = new MySqlCommand(check, conn);
                        MySqlDataAdapter adp   = new MySqlDataAdapter(comm);
                        comm.ExecuteNonQuery();
                        DataTable dt = new DataTable();
                        adp.Fill(dt);
                        int counter = 0;
                        if (dt.Rows.Count == 1)
                        {
                            int ins = quant;
                            ins += int.Parse(dt.Rows[0][2].ToString());
                            string updCart = "UPDATE cart SET qty = '" + ins + "' WHERE cart_id = '" + dt.Rows[0][0].ToString() + "'";
                            comm = new MySqlCommand(updCart, conn);
                            comm.ExecuteNonQuery();
                            counter = 1;
                        }
                        else
                        {
                            string ins = "INSERT INTO cart VALUES(NULL, '" + dgvCurBid.Rows[ri].Cells[5].Value.ToString() + "', '" + quant + "', '" + DateTime.Now.ToString("yyyy-MM-dd") + "', 0);";
                            comm = new MySqlCommand(ins, conn);
                            comm.ExecuteNonQuery();
                            counter = 0;
                        }
                        int    newQty = int.Parse(dgvCurBid.Rows[ri].Cells[7].Value.ToString()) - quant;
                        string upd    = "UPDATE bid_offer SET qty_offer = '" + newQty + "' WHERE bid_offer_id = '" + dgvCurBid.Rows[ri].Cells[5].Value.ToString() + "'";
                        comm = new MySqlCommand(upd, conn);
                        comm.ExecuteNonQuery();
                        conn.Close();
                        MessageBox.Show("Successfully added to cart!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        selItem();
                    }
                    else
                    {
                        MessageBox.Show("Please Select 1 or more than the quantity offered in the bids offered!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("CURRENTLY NO OFFER IN THIS ITEM!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Please Select an Item First!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            quant = 0;
        }