EpsTransaction.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using SinoChemCommonUtilities;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Wayne.Lib;
  9. using Wayne.Lib.Log;
  10. namespace SinochemInternetPlusApp
  11. {
  12. public class EpsTransaction
  13. {
  14. private SqlCommandUtility sqlCmd;
  15. private EpsTransactionModel model;
  16. public static EpsTransaction CreateEpsTrx(int nozzleId, EpsTransactionMode mop, DebugLogger debugLogger)
  17. {
  18. EpsTransactionModel newModel = new EpsTransactionModel()
  19. {
  20. jihao = nozzleId,
  21. trx_status = EpsTrxStatus.Unknown,
  22. mop = mop,
  23. created_time = DateTime.Now,
  24. notify_pos = NotifyPosFlag.Unknown,
  25. };
  26. var newTrx = new EpsTransaction(newModel, true);
  27. debugLogger.Add("New eps trx is created with id " + newTrx.model.id);
  28. return newTrx;
  29. }
  30. public static EpsTransaction RestroeEpsTrxFrom(EpsTransactionModel model)
  31. {
  32. return new EpsTransaction(model, false);
  33. }
  34. private EpsTransaction(EpsTransactionModel theModel, bool isNewTrx)
  35. {
  36. model = theModel;
  37. sqlCmd = new SqlCommandUtility(GenericSinochemEpsApp.PosDatabaseConnString);
  38. if (isNewTrx)
  39. {
  40. //#if SQL_SERVER_2000
  41. string insertSql = string.Format(" insert into eps_trx (jihao, trx_status, mop, created_time)" +
  42. " values({0}, {1}, {2}, '{3}'); " +
  43. " select SCOPE_IDENTITY() ",
  44. model.jihao, (int)model.trx_status, (int)model.mop, model.created_time);
  45. object scalar = sqlCmd.Insertdata(insertSql, true);
  46. model.id = Convert.ToInt32(scalar);
  47. }
  48. }
  49. public EpsTransactionModel Model
  50. {
  51. get { return model; }
  52. }
  53. public void UpdateTrxStatusToDb(EpsTrxStatus status)
  54. {
  55. model.trx_status = status;
  56. string updateSql = string.Format(" update eps_trx " +
  57. " set trx_status={0} " +
  58. " where id={1} ",
  59. (int)model.trx_status,
  60. model.id);
  61. sqlCmd.UpdateData(updateSql);
  62. }
  63. public void UpdateTrxStatusToDb(EpsTransactionModel trx, EpsTrxStatus trxStatus)
  64. {
  65. if (trx != null)
  66. {
  67. string updateSql = string.Format("update eps_trx set trx_status = {0} where id={1}", (int)trxStatus, trx.id);
  68. sqlCmd.UpdateData(updateSql);
  69. }
  70. }
  71. public void UpdateNotifyPosFlagToDb(NotifyPosFlag notifyPos)
  72. {
  73. model.notify_pos = notifyPos;
  74. string updateSql = string.Format(" update eps_trx " +
  75. " set notify_pos={0} " +
  76. " where id={1} ",
  77. (int)model.notify_pos,
  78. model.id);
  79. sqlCmd.UpdateData(updateSql);
  80. }
  81. public void SaveToDb()
  82. {
  83. string updateSql = string.Format(" update eps_trx " +
  84. " set jihao={0}, youpin=N'{1}', qty={2}, danjia={3}, amount={4}, xf_date='{5}', xf_time='{6}', liushuino='{7}', " +
  85. " fzqty='{8}', fzamount={9}, trx_status={10}, mop={11}, car_number=N'{12}', card_no='{13}', ttc='{14}', " +
  86. " token='{15}', tid='{16}', mac='{17}', balance_before_trx={18}, real_pay_amount={19}, " +
  87. " auth_time='{20}', bill_id='{21}', created_time='{22}', shift_id='{23}', business_date='{24}', notify_pos={25}, " +
  88. " cardNo_masked='{26}', payMethod = '{27}', cardType={28}, nozzleSelected={29}, openId='{30}'" +
  89. " where id={31} ",
  90. model.jihao, model.youpin, model.qty, model.danjia, model.amount, model.xf_date, model.xf_time, model.liushuino,
  91. model.fzqty, model.fzamount, (int)model.trx_status, (int)model.mop, model.car_number, model.card_no, model.ttc,
  92. model.token, model.tid, model.mac, model.balance_before_trx, model.real_pay_amount,
  93. model.auth_time, model.bill_id, model.created_time, model.shift_id, model.business_date, (int)model.notify_pos,
  94. model.cardNo_masked, model.payMethod, (int)model.cardType, model.nozzleSelected, model.openId,
  95. model.id);
  96. sqlCmd.UpdateData(updateSql);
  97. }
  98. public bool MoveFromXiaofei2(DebugLogger debugLogger)
  99. {
  100. string querySql = string.Format(" select * from xiaofei2 " +
  101. " where jihao={0} and liushuino='{1}' ",
  102. model.jihao, model.liushuino);
  103. Xiaofei2Model xiaofei2Model = sqlCmd.ReadData<Xiaofei2Model>(querySql, DbModelConstructors.ConstructXiaofei2Model);
  104. if(xiaofei2Model != null)
  105. {
  106. Model.youpin = xiaofei2Model.youpin;
  107. Model.qty = xiaofei2Model.qty;
  108. Model.danjia = xiaofei2Model.danjia;
  109. Model.amount = xiaofei2Model.amount;
  110. Model.xf_date = xiaofei2Model.xf_date;
  111. Model.xf_time = xiaofei2Model.xf_time;
  112. Model.fzqty = xiaofei2Model.fzqty;
  113. Model.fzamount = xiaofei2Model.fzamount;
  114. SaveToDb();
  115. string deleteSql = string.Format(" delete from xiaofei2 " +
  116. " where jihao={0} and liushuino='{1}' ",
  117. Model.jihao, Model.liushuino);
  118. sqlCmd.DeleteData(deleteSql);
  119. debugLogger.Add("MoveFromXiaofei2 Succeeded");
  120. return true;
  121. }
  122. else
  123. {
  124. debugLogger.Add("MoveFromXiaofei2 failed, cannot found current trx in xiaofei2");
  125. return false;
  126. }
  127. }
  128. public void MoveBackToXiaofei2(DebugLogger debugLogger)
  129. {
  130. try
  131. {
  132. string insertSql = string.Format(" insert into xiaofei2 (jihao, youpin, qty, danjia, amount, xf_date, xf_time, liushuino, fzqty, fzamount, plate_number) " +
  133. " values({0}, '{1}', {2}, {3}, {4}, '{5}', '{6}', '{7}', '{8}', {9}, '{10}') ",
  134. Model.jihao, Model.youpin, Model.qty, Model.danjia, Model.amount, Model.xf_date, Model.xf_time,
  135. Model.liushuino, Model.fzqty, Model.fzamount, Model.car_number);
  136. sqlCmd.Insertdata(insertSql, false);
  137. debugLogger.Add("MoveBackToXiaoFei2 Succeeded");
  138. }
  139. catch (Exception ex)
  140. {
  141. debugLogger.Add("MoveBackToXiaoFei2 Failed" + ex.ToString());
  142. }
  143. }
  144. }
  145. }