Hello Team,
I am trying to print current sales but the sytem ended up printing both the current and the previous sales from database, am using the report printview
private void SaveBill() { try { if (DGVClientBill.Rows.Count > 0) { // update product qty if (MessageBox.Show("Please confirm if you want to save this record?", stitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { for (int i = 0; i < DGVClientBill.Rows.Count; i++) { con.Open(); SqlCommand cmd = new SqlCommand("insert into tblSales(SDate,SProductName,SPrice,SQty, SAmount,SCustomer)values(@sDate,@sProductName,@sPrice,@sQty, @sAmount,@sCustomer)", con); cmd.Parameters.AddWithValue("@sDate", dtBillindDate.Value.ToString("dd-MM-yyyy")); cmd.Parameters.AddWithValue("@sProductName", DGVClientBill.Rows[i].Cells["dgvProduct"].Value.ToString()); cmd.Parameters.AddWithValue("@sPrice", DGVClientBill.Rows[i].Cells["dgvSellingPrice2"].Value.ToString()); cmd.Parameters.AddWithValue("@sQty", DGVClientBill.Rows[i].Cells["dgvQunatity"].Value.ToString()); cmd.Parameters.AddWithValue("@sAmount", Convert.ToDecimal(DGVClientBill.Rows[i].Cells["dgvTotal"].Value.ToString())); cmd.Parameters.AddWithValue("@sCustomer", txtCustomer.Text); cmd.ExecuteNonQuery(); con.Close(); }
MessageBox.Show("Bill successfully saved !", "POS", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception Ex) { con.Close(); MessageBox.Show(Ex.Message); } }
Print Button
private void button2_Click(object sender, EventArgs e) { SaveBill(); frmPrintReceipt frm = new frmPrintReceipt(this); frm.LoadReport(); frm.ShowDialog();
DGVClientBill.Rows.Clear();
}