mkhurram92
Member
- Joined
- Mar 12, 2021
- Messages
- 5
- Programming Experience
- Beginner
Hi Everyone,
I have a method which is storing values in database and after that it is print invoice. I'm printing a form for invoice printing. I want to make sure that if it's saving it should print. Otherwise rollback all chanages. Following is syntex of the method.
Here is PrintInvoice Method
On the other hand in Invoice I have a method which is updating sales table during same transaction. On that method my program is hanged and giving me timeout error. Here is method on Invoice
Is there any other way to achieve this without having any issue in transaction ?
Thanks in Advance,
Regards,
I have a method which is storing values in database and after that it is print invoice. I'm printing a form for invoice printing. I want to make sure that if it's saving it should print. Otherwise rollback all chanages. Following is syntex of the method.
-
DatabaseAddedUpdateBarcodeSalesToday:
private void DatabaseAddedUpdateBarcodeSalesToday() { sqlConnection.Open(); sqlTransaction = sqlConnection.BeginTransaction(); try { AddToDatabase(); sqlTransaction.Commit(); } catch (Exception exp) { MesageBox.Show(exp.Message.ToString(), "Transaction Failed"); sqlTransaction.Rollback(); } }
AddToDatabase():
private void AddToDatabase()
{
sqlCommand = new SqlCommand("Insert Into Sales(barcode_id,customer_id, pos_id,qty)values(@barcode_id,@customer_id, (Select id From POS Where Name=@name),@qty);
sqlCommand.Parameters.AddWithValue("@barcode_id", temp_barcode);
sqlCommand.Parameters.AddWithValue("@customer_id", 1);
sqlCommand.Parameters.AddWithValue("@qty", 1);
sqlDataReader = sqlCommand.ExecuteReader();
sqlDataReader.Close();
}
Here is PrintInvoice Method
printInvoice():
private void printInvoice()
{
Invoice invi = new Invoice();
invi.invi_barcode = temp_barcode;
invi.user_id = userId;
invi.Show();
}
UpdateBarcode:
private void UpdateBarcode(string p, string strI){
try{
sqlCommandInvoice = new SqlCommand("Update Sales Set mgroupId = @mGroup Where Barcode_Id = @Barcode_Id", sqlConnectionInvoice);
sqlCommandInvoice.Parameters.AddWithValue("@mGroup", strI);
sqlCommandInvoice.Parameters.AddWithValue("@Barcode_Id", p);
sqlConnectionInvoice.Open();
sqlDataReaderInvoice = sqlCommandInvoice.ExecuteReader();
sqlDataReaderInvoice.Close();
sqlConnectionInvoice.Close();
BARCODE_UPDATE = true;
}
catch (Exception exp)
{
MessageBox.Show(exp.Message.ToString(), "Error");
}
Thanks in Advance,
Regards,