private void btnEnter_Click(object sender, EventArgs e) { try { if ((Double.Parse(txtChange.Text) < 0) || (txtCash.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.dataGridView1.Rows.Count; i++) { con.Open(); cmd = new MySqlCommand("update tblproduct set qty= qty - " + int.Parse(fpos.dataGridView1.Rows[i].Cells[5].Value.ToString()) + " where pcode = '" + fpos.dataGridView1.Rows[i].Cells[2].Value.ToString() + "'", con); cmd.ExecuteNonQuery(); con.Close(); con.Open(); cmd = new MySqlCommand("update tblcart set status='sold' where id = '" + fpos.dataGridView1.Rows[i].Cells[1].Value.ToString() + "'", con); cmd.ExecuteNonQuery(); con.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) { MessageBox.Show("INSUFFICIENT AMOUNT. PLEASE ENTER THE CORRECT AMOUNT", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btnSave_Click(object sender, EventArgs e) { try { if (MessageBox.Show("ADD DISCOUNT?,CLICK YES TO CONFIRM", stitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { con.Open(); cmd = new MySqlCommand("update tblcart set disc = @disc, disc_percent = @disc_percent where id=@id", con); cmd.Parameters.AddWithValue("@disc", Double.Parse(txtAmount.Text)); cmd.Parameters.AddWithValue("@disc_percent", Double.Parse(txtPercentage.Text)); cmd.Parameters.AddWithValue("@id", int.Parse(lblID.Text)); cmd.ExecuteNonQuery(); con.Close(); f.LoadCart(); this.Dispose(); } } catch (Exception ex) { con.Close(); MessageBox.Show(ex.Message); } }
private void txtQty_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar == 13) && (txtQty.Text != string.Empty)) { string id = ""; int cart_qty = 0; bool found = false; con.Open(); cmd = new MySqlCommand("select * from tblcart where transno = @transno and pcode = @pcode", con); cmd.Parameters.AddWithValue("@transno", fpos.lbltransno.Text); cmd.Parameters.AddWithValue("@pcode", pcode); dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { found = true; id = dr["id"].ToString(); cart_qty = int.Parse(dr["qty"].ToString()); } else { found = false; } dr.Close(); con.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; } con.Open(); cmd = new MySqlCommand("update tblcart set qty = (qty + " + int.Parse(txtQty.Text) + ") where id = '" + id + "'", con); cmd.ExecuteNonQuery(); con.Close(); fpos.txtSearch.Clear(); fpos.txtSearch.Focus(); fpos.LoadCart(); this.Dispose(); } else { if (qty < int.Parse(txtQty.Text)) { MessageBox.Show("UNABLE TO PROCEED. REMAINING QTY ON HAND IS " + qty, "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } con.Open(); cmd = new MySqlCommand("insert into tblcart(transno,pcode,price,qty,sdate,cashier) VALUES(@transno,@pcode,@price,@qty,@sdate,@cashier)", con); cmd.Parameters.AddWithValue("@transno", transno); cmd.Parameters.AddWithValue("@pcode", pcode); cmd.Parameters.AddWithValue("@price", price); cmd.Parameters.AddWithValue("@qty", int.Parse(txtQty.Text)); cmd.Parameters.AddWithValue("@sdate", DateTime.Now); cmd.Parameters.AddWithValue("@cashier", fpos.lblUsername.Text); cmd.ExecuteNonQuery(); con.Close(); fpos.txtSearch.Clear(); fpos.txtSearch.Focus(); fpos.LoadCart(); this.Dispose(); } } }