EpsTransaction.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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, TransactionMode 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(App.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. //#else
  48. // string insertSql = string.Format(" insert into eps_trx (jihao, trx_status, mop, created_time) " +
  49. // " OUTPUT INSERTED.id " +
  50. // " values({0}, {1}, {2}, '{3}'); ",
  51. // model.jihao, (int)model.trx_status, (int)model.mop, model.created_time);
  52. // object scalar = sqlCmd.Insertdata(insertSql, true);
  53. // model.id = Convert.ToInt32(scalar);
  54. //#endif
  55. }
  56. }
  57. public EpsTransactionModel Model
  58. {
  59. get { return model; }
  60. }
  61. public void UpdateTrxStatusToDb(EpsTrxStatus status)
  62. {
  63. model.trx_status = status;
  64. string updateSql = string.Format(" update eps_trx " +
  65. " set trx_status={0} " +
  66. " where id={1} ",
  67. (int)model.trx_status,
  68. model.id);
  69. sqlCmd.UpdateData(updateSql);
  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}' " +
  89. " where id={27} ",
  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,
  95. model.id);
  96. sqlCmd.UpdateData(updateSql);
  97. }
  98. public bool MoveFromXiaofei2()
  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. return true;
  120. }
  121. else
  122. {
  123. return false;
  124. }
  125. }
  126. public void MoveBackToXiaofei2()
  127. {
  128. string insertSql = string.Format(" insert into xiaofei2 (jihao, youpin, qty, danjia, amount, xf_date, xf_time, liushuino, fzqty, fzamount) " +
  129. " values({0}, '{1}', {2}, {3}, {4}, '{5}', '{6}', '{7}', '{8}', {9}) ",
  130. Model.jihao, Model.youpin, Model.qty, Model.danjia, Model.amount, Model.xf_date, Model.xf_time,
  131. Model.liushuino, Model.fzqty, Model.fzamount);
  132. sqlCmd.Insertdata(insertSql, false);
  133. }
  134. }
  135. }