Walaa wrote:
I'm not sure what your UoW is doing. Could you please describe or show a code snippet of what you add to the UoW.
Dear Walaa Here is my full save code
private void SaveData()
{
var adaptersmartcatrd = new DataAccessAdapter();
var unitofwork = new UnitOfWork2();
adaptersmartcatrd.StartTransaction(IsolationLevel.Serializable, "PrepaidCard");
try
{
const decimal Postpaiduse = 0;
Int32 TransactionTypeId = 0;
decimal Prepaidbalance = !string.IsNullOrEmpty(tbxamount.Text) ||
tbxamount.Text == @"0".Trim()
? Convert.ToDecimal(tbxamount.Text)
: 0;
const decimal Depositamount = 100;
SmartCardUserno = cmbuserno.Text;
string[] Userno = SmartCardUserno.Split(' ');
DataTable TransactionTypeDt = TransactionType.returnTransactionType();
if (TransactionTypeDt.Rows.Count > 0)
{
TransactionTypeId =
Convert.ToInt32(TransactionTypeDt.Rows[0]["TransactiontypeId"]);
}
if (Prepaidbalance >= 100)
{
DataTable BillCounterDt = ClubCentricBISpecific.SmartCard.BillCounterSmartCard();
int BillNo = Convert.ToInt32(BillCounterDt.Rows[0]["Billnumber"]);
int BillCounterNo = Convert.ToInt32(BillCounterDt.Rows[0]["BillcounterId"]);
BillNo = BillNo + 1;
var billcounter = new BillcounterEntity();
adaptersmartcatrd.FetchEntity(billcounter);
billcounter.BillcounterId = BillCounterNo;
billcounter.IsNew = false;
billcounter.Billnumber = BillNo;
unitofwork.AddForSave(billcounter, true);
var SmartCard = new SmartcardEntity();
SmartCard.Cardid = Convert.ToInt32(CardRandomID);
SmartCard.Postpaiduse = Postpaiduse;
SmartCard.Prepaidbalance = Prepaidbalance - Depositamount;
SmartCard.Depositamount = Depositamount;
SmartCard.Isprepaid = GlobalVariable.optionYes;
SmartCard.Ispostandprepaid = GlobalVariable.optionNo;
SmartCard.Createddate = ServerDateTime.getcurrentserverdatewithtime();
SmartCard.CreateduserId = StandardMessage.loginuserid;
SmartCard.EmployeeId = EmployeeId;
SmartCard.Roomno = RoomId;
SmartCard.AffiliatememberId = AffiliatememberId;
SmartCard.MemberId = MemberId;
SmartCard.CorporateId = CorporateId;
SmartCard.AffiliateclubId = null;
SmartCard.Userno = Userno[0].ToUpper();
unitofwork.AddForSave(SmartCard, true);
var receiptSmartCard = new ReceiptsmartcardEntity();
receiptSmartCard.Cardid = Convert.ToInt32(CardRandomID);
receiptSmartCard.TransactiontypeId = TransactionTypeId;
receiptSmartCard.Receiptdate = ServerDateTime.getcurrentserverdatewithtime();
receiptSmartCard.Receiptnumber = BillNo;
receiptSmartCard.Previousbalance = 0;
receiptSmartCard.Amount = Prepaidbalance >= 100
? Prepaidbalance - Depositamount
: 0;
receiptSmartCard.Createddate = ServerDateTime.getcurrentserverdatewithtime();
receiptSmartCard.CreateduserId = StandardMessage.loginuserid;
unitofwork.AddForSave(receiptSmartCard, true);
unitofwork.Commit(adaptersmartcatrd);
{
MessageBox.Show(StandardMessage.datasavesuccess);
DoRefresh();
}
flashLabel.Text = "";
}
else
{
flashLabel.Text = "Amount Should be > 100";
}
}
catch (Exception ex)
{
GlobalErrorHandler.LogMessage(ex.Message + ex.StackTrace);
MessageBox.Show(StandardMessage.datasavefailure);
adaptersmartcatrd.Rollback();
return;
}
finally
{
adaptersmartcatrd.CloseConnection();
adaptersmartcatrd.Dispose();
}
}