Example #1
0
 private void btnConfirm_Click(object sender, EventArgs e)
 {
     if ((int.Parse(txtPercent.Text) < 0) || (int.Parse(txtPercent.Text) > 100))
     {
         MessageBox.Show("Please enter valid amount of discount", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         try {
             cn.Open();
             cm = new SqlCommand("Update tblCart set disc = @disc, disc_percent= @disc_percent where id = @id", cn);
             cm.Parameters.AddWithValue("@disc", double.Parse(txtAmount.Text));
             cm.Parameters.AddWithValue("@disc_percent", double.Parse(txtPercent.Text));
             cm.Parameters.AddWithValue("@id", int.Parse(lblID.Text));
             cm.ExecuteNonQuery();
             cn.Close();
             f.loadCart();
             this.Dispose();
         }
         catch (Exception ex)
         {
             cn.Close();
             MessageBox.Show(ex.Message);
         }
     }
 }
Example #2
0
        private void btnEnter_Click(object sender, EventArgs e)
        {
            try
            {
                if ((double.Parse(txtChange.Text) < 0) || (txtChange.Text == String.Empty))
                {
                    MessageBox.Show("Insufficient amount. Please enter the correct amount!", "warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else
                {
                    for (int i = 0; i < fpos.dataGridSale.Rows.Count; i++)
                    {
                        cn.Open();
                        string query = string.Format("update tblproduct set qty = qty - '{0}' where pcode = '{1}'", int.Parse(fpos.dataGridSale.Rows[i].Cells[6].Value.ToString()), fpos.dataGridSale.Rows[i].Cells[2].Value.ToString());
                        cm = new SqlCommand(query, cn);
                        cm.ExecuteNonQuery();
                        cn.Close();

                        cn.Open();
                        cm = new SqlCommand("update tblCart set status = 'Sold' where id = '" + fpos.dataGridSale.Rows[i].Cells[1].Value.ToString() + "'", cn);
                        cm.ExecuteNonQuery();
                        cn.Close();
                    }
                    frmReceipt frm = new frmReceipt(fpos);
                    //frm.Loadreport(txtCash.Text, txtChange.Text);
                    frm.ShowDialog();
                    MessageBox.Show("Payment successfully saved!", "Payment", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    fpos.getTransNo();
                    fpos.loadCart();
                    this.Dispose();
                }
            }
            catch (Exception ex)
            {
                cn.Close();
                MessageBox.Show(ex.Message);
            }
        }
Example #3
0
        private void dataGridProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string colName = dataGridProduct.Columns[e.ColumnIndex].Name;
                if (colName == "Select")
                {
                    frmQty frm = new frmQty(f);

                    int    qty      = int.Parse(dataGridProduct.Rows[e.RowIndex].Cells[9].Value.ToString());
                    double disc_per = double.Parse(dataGridProduct.Rows[e.RowIndex].Cells[8].Value.ToString());
                    double cost     = double.Parse(dataGridProduct.Rows[e.RowIndex].Cells[6].Value.ToString());
                    frm.ProductDetail(dataGridProduct.Rows[e.RowIndex].Cells[1].Value.ToString(), double.Parse(dataGridProduct.Rows[e.RowIndex].Cells[7].Value.ToString()), f.lblTransNo.Text, cost, qty, disc_per);
                    f.loadCart();
                    frm.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #4
0
        private void txtQty_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
            {
                e.Handled = true;
            }
            if ((e.KeyChar == 13) && (txtQty.Text != String.Empty))
            {
                String id       = "";
                int    cart_qty = 0;
                bool   found    = false;

                if (qty < int.Parse(txtQty.Text))
                {
                    MessageBox.Show("Unable to proceed. remaining qty on hand is " + qty, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                cn.Open();
                cm = new SqlCommand("Select * from tblcart where transno = @transno and pcode =@pcode", cn);
                cm.Parameters.AddWithValue("@transno", fpos.lblTransNo.Text);
                cm.Parameters.AddWithValue("@pcode", pcode);
                dr = cm.ExecuteReader();
                dr.Read();
                if (dr.HasRows)
                {
                    found    = true;
                    id       = dr["id"].ToString();
                    cart_qty = int.Parse(dr["qty"].ToString());
                }
                else
                {
                    found = false;
                }
                dr.Close();
                cn.Close();
                if (found == true)
                {
                    if (qty < int.Parse(txtQty.Text) + cart_qty)
                    {
                        MessageBox.Show("Unable to proceed. remaining qty on hand is " + qty, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    cn.Close();
                    cn.Open();
                    cm = new SqlCommand("update tblCart set qty = (qty + " + int.Parse(txtQty.Text) + ") where id = '" + id + "'", cn);
                    cm.ExecuteNonQuery();
                    cn.Close();

                    fpos.txtSearchProduct.Clear();
                    fpos.txtSearchProduct.Focus();
                    fpos.loadCart();
                    this.Dispose();
                }
                else
                {
                    cn.Close();
                    cn.Open();
                    cm = new SqlCommand("insert into tblCart (transno, pcode,cost, price,disc_percent, qty, sdate, cashier)values(@transno, @pcode,@cost, @price,@disc_percent, @qty, @sdate, @cashier)", cn);
                    cm.Parameters.AddWithValue("@transno", transno);
                    cm.Parameters.AddWithValue("@pcode", pcode);
                    cm.Parameters.AddWithValue("@cost", cost);
                    cm.Parameters.AddWithValue("@price", price);
                    cm.Parameters.AddWithValue("@disc_percent", disc_per);
                    cm.Parameters.AddWithValue("@qty", int.Parse(txtQty.Text));
                    cm.Parameters.AddWithValue("@sdate", DateTime.Now);
                    cm.Parameters.AddWithValue("@cashier", fpos.lblUser.Text);
                    cm.ExecuteNonQuery();
                    cn.Close();

                    fpos.txtSearchProduct.Clear();
                    fpos.txtSearchProduct.Focus();
                    fpos.loadCart();
                    this.Dispose();
                }
            }
        }