123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using Dfs.WayneChina.SinochemEps;
- using SinoChemCommonUtilities;
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Wayne.Lib;
- using Wayne.Lib.Log;
- namespace SinochemInternetPlusApp
- {
- public class EpsTransaction
- {
- private SqlCommandUtility sqlCmd;
- private EpsTransactionModel model;
- public static EpsTransaction CreateEpsTrx(int nozzleId, TransactionMode mop, DebugLogger debugLogger)
- {
- EpsTransactionModel newModel = new EpsTransactionModel()
- {
- jihao = nozzleId,
- trx_status = EpsTrxStatus.Unknown,
- mop = mop,
- created_time = DateTime.Now,
- notify_pos = NotifyPosFlag.Unknown,
- };
- var newTrx = new EpsTransaction(newModel, true);
- debugLogger.Add("New eps trx is created with id " + newTrx.model.id);
- return newTrx;
- }
- public static EpsTransaction RestroeEpsTrxFrom(EpsTransactionModel model)
- {
- return new EpsTransaction(model, false);
- }
- private EpsTransaction(EpsTransactionModel theModel, bool isNewTrx)
- {
- model = theModel;
- sqlCmd = new SqlCommandUtility(SinochemEpsApp.PosDatabaseConnString);
- if (isNewTrx)
- {
- //#if SQL_SERVER_2000
- string insertSql = string.Format(" insert into eps_trx (jihao, trx_status, mop, created_time)" +
- " values({0}, {1}, {2}, '{3}'); " +
- " select SCOPE_IDENTITY() ",
- model.jihao, (int)model.trx_status, (int)model.mop, model.created_time);
- object scalar = sqlCmd.Insertdata(insertSql, true);
- model.id = Convert.ToInt32(scalar);
- //#else
- // string insertSql = string.Format(" insert into eps_trx (jihao, trx_status, mop, created_time) " +
- // " OUTPUT INSERTED.id " +
- // " values({0}, {1}, {2}, '{3}'); ",
- // model.jihao, (int)model.trx_status, (int)model.mop, model.created_time);
- // object scalar = sqlCmd.Insertdata(insertSql, true);
- // model.id = Convert.ToInt32(scalar);
- //#endif
- }
- }
- public EpsTransactionModel Model
- {
- get { return model; }
- }
- public void UpdateTrxStatusToDb(EpsTrxStatus status)
- {
- model.trx_status = status;
- string updateSql = string.Format(" update eps_trx " +
- " set trx_status={0} " +
- " where id={1} ",
- (int)model.trx_status,
- model.id);
- sqlCmd.UpdateData(updateSql);
- }
- public void UpdateNotifyPosFlagToDb(NotifyPosFlag notifyPos)
- {
- model.notify_pos = notifyPos;
- string updateSql = string.Format(" update eps_trx " +
- " set notify_pos={0} " +
- " where id={1} ",
- (int)model.notify_pos,
- model.id);
- sqlCmd.UpdateData(updateSql);
- }
- public void SaveToDb()
- {
- string updateSql = string.Format(" update eps_trx " +
- " set jihao={0}, youpin=N'{1}', qty={2}, danjia={3}, amount={4}, xf_date='{5}', xf_time='{6}', liushuino='{7}', " +
- " fzqty='{8}', fzamount={9}, trx_status={10}, mop={11}, car_number=N'{12}', card_no='{13}', ttc='{14}', " +
- " token='{15}', tid='{16}', mac='{17}', balance_before_trx={18}, real_pay_amount={19}, " +
- " auth_time='{20}', bill_id='{21}', created_time='{22}', shift_id='{23}', business_date='{24}', notify_pos={25}, " +
- " cardNo_masked='{26}' " +
- " where id={27} ",
- model.jihao, model.youpin, model.qty, model.danjia, model.amount, model.xf_date, model.xf_time, model.liushuino,
- model.fzqty, model.fzamount, (int)model.trx_status, (int)model.mop, model.car_number, model.card_no, model.ttc,
- model.token, model.tid, model.mac, model.balance_before_trx, model.real_pay_amount,
- model.auth_time, model.bill_id, model.created_time, model.shift_id, model.business_date, (int)model.notify_pos,
- model.cardNo_masked,
- model.id);
- sqlCmd.UpdateData(updateSql);
- }
- public bool MoveFromXiaofei2()
- {
- string querySql = string.Format(" select * from xiaofei2 " +
- " where jihao={0} and liushuino='{1}' and xf_date='{2}' ",
- Model.jihao, Model.liushuino, Model.xf_date);
- Xiaofei2Model xiaofei2Model = sqlCmd.ReadData<Xiaofei2Model>(querySql, DbModelConstructors.ConstructXiaofei2Model);
- if(xiaofei2Model != null)
- {
- Model.youpin = xiaofei2Model.youpin;
- Model.qty = xiaofei2Model.qty;
- Model.danjia = xiaofei2Model.danjia;
- Model.amount = xiaofei2Model.amount;
- Model.xf_date = xiaofei2Model.xf_date;
- Model.xf_time = xiaofei2Model.xf_time;
- Model.fzqty = xiaofei2Model.fzqty;
- Model.fzamount = xiaofei2Model.fzamount;
- SaveToDb();
- string deleteSql = string.Format(" delete from xiaofei2 " +
- " where jihao={0} and liushuino='{1}' and xf_date='{2}'",
- Model.jihao, Model.liushuino, Model.xf_date);
- sqlCmd.DeleteData(deleteSql);
- return true;
- }
- else
- {
- return false;
- }
- }
- public void MoveBackToXiaofei2()
- {
- string insertSql = string.Format(" insert into xiaofei2 (jihao, youpin, qty, danjia, amount, xf_date, xf_time, liushuino, fzqty, fzamount) " +
- " values({0}, '{1}', {2}, {3}, {4}, '{5}', '{6}', '{7}', '{8}', {9}) ",
- Model.jihao, Model.youpin, Model.qty, Model.danjia, Model.amount, Model.xf_date, Model.xf_time,
- Model.liushuino, Model.fzqty, Model.fzamount);
- sqlCmd.Insertdata(insertSql, false);
- }
- }
-
- }
|