EpsTransaction.cs 7.2 KB

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