示例#1
0
 private void EndRefund(Hashtable htParams)
 {
     try
     {
         TBankhisexchangeTransFacade facBankTrans = new TBankhisexchangeTransFacade();
         string seqNo = htParams["SEQNO"].ToString() + "R";
         LogService.GlobalInfoMessage(seqNo);
         facBankTrans.UpdateState(seqNo, "HISSTATE", "1");
         LogService.GlobalInfoMessage("退货交易确认成功。");
     }
     catch (Exception e)
     {
         LogService.GlobalInfoMessage("退货交易确认失败。" + e.Message);
         throw;
     }
 }
示例#2
0
        private void BeginRefund(Hashtable htParams)
        {
            try
            {
                #region 组织请求入参
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("TransCode", "09");
                dic.Add("TransMoney", CheckMoney(htParams, "MONEY"));
                dic.Add("TransNo", PadRight("", 6));
                dic.Add("MachineID", PadRight("", 10));
                dic.Add("OperatorID", PadRight(SysOperatorInfo.OperatorID, 10));
                dic.Add("ReferenceNo", PadRight(htParams["REFERENCENO"].ToString(), 15));
                dic.Add("AuthNo", PadRight("", 6));
                dic.Add("OldTransDate", Convert.ToDateTime(htParams["OPERATETIME"]).ToString("YYYYMMDD"));
                dic.Add("CardType", "H");
                dic.Add("IndexNo", PadRight(htParams["POSNO"].ToString(), 76));
                dic.Add("Track2", PadRight("", 37));
                dic.Add("Track3", PadRight("", 104));
                dic.Add("OldTransCode", PadRight("", 2));
                dic.Add("OldTerminalID", PadRight("", 15));
                dic.Add("OldAuthNo", PadRight("", 15));
                dic.Add("PayAccountID", PadRight("", 3));
                dic.Add("StoreID", PadRight("", 20));
                dic.Add("ReceiptID", PadRight("", 30));
                dic.Add("OrderID", PadRight("", 15));
                dic.Add("OldBatchNo", PadRight("", 6));
                dic.Add("OldTransTime", PadRight("", 6));
                dic.Add("OldTransMoney", PadRight("", 12));
                dic.Add("ServerIP", PadRight("", 15));
                dic.Add("ListenPort", PadRight("", 6));
                string strInput = dic.GetValueString();
                #endregion

                #region 平台接口调用
                LogService.GlobalInfoMessage("退货交易调用入参:" + strInput);
                StringBuilder sb = new StringBuilder(1000);
                //int iResult = SingleeMethods.CardTransCBK(strInput, sb, null, IntPtr.Zero);
                int    iResult   = SingleeMethods.CardTransDllWin(strInput, sb);
                string strOutput = sb.ToString();
                LogService.GlobalInfoMessage("退货交易调用出参:" + strOutput);
                #endregion

                #region 解析请求出参
                byte[] bytes   = System.Text.Encoding.Default.GetBytes(strOutput);
                string retCode = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 0, 6));
                string retMsg  = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 6, 40));

                #endregion

                #region 交易结果处理
                if (retCode == "000000")
                {
                    string transNo          = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 46, 6));
                    string authNo           = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 52, 6));
                    string batchNo          = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 58, 6));
                    string bankCardID       = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 64, 19));
                    string expDate          = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 83, 4));
                    string bankNo           = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 87, 2));
                    string referenceNo      = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 89, 12));
                    string terminalNo       = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 101, 15));
                    string merchantID       = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 116, 15));
                    string transMoney       = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 131, 12));
                    string indexNo          = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 143, 16));
                    string customField      = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 159, 74));
                    string sendCardBankCode = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 234, 7));
                    string bankDate         = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 241, 8));
                    string bankTime         = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 249, 6));

                    #region 交易成功
                    LogService.GlobalInfoMessage("退货交易调用成功。" + retMsg);

                    #region 把交易数据写入数据库
                    string seqNo      = htParams["SEQNO"].ToString();
                    string diagnoseID = htParams["DIAGNOSEID"].ToString();
                    string cardID     = htParams["CARDID"].ToString();

                    DateTime dtn;
                    string   strDate = string.Empty;
                    if (!string.IsNullOrEmpty(bankDate.Trim()))
                    {
                        strDate = bankDate.Substring(0, 4) + "-" + bankDate.Substring(4, 2) + "-" + bankDate.Substring(6, 2) + " " + bankTime.Substring(0, 2) + ":" + bankTime.Substring(2, 2);
                    }
                    DateTime payDateTime = DateTime.TryParse(strDate, out dtn) ? dtn : DateTime.Now;
                    decimal  payMoney    = decimal.Parse(transMoney.TrimStart('0'));

                    TBankhisexchangeTransData dataPayment = new TBankhisexchangeTransData()
                    {
                        Hisseqno     = seqNo + "R",
                        Hisstate     = "0",
                        Bankseqno    = transNo,
                        Bankstate    = "1",
                        DIAGNOSEID   = diagnoseID,
                        Hisid        = cardID,
                        Usetype      = "退款",
                        DataSources  = "自助",
                        BusinessType = "POS退款",
                        Operatorid   = SysOperatorInfo.OperatorID,
                        Operatetime  = payDateTime,
                        TerminalNo   = terminalNo,
                        Trfamt       = "-" + payMoney.ToString("0.##"),
                        ITEM1        = bankCardID,
                        ITEM2        = batchNo,
                        ITEM3        = string.Empty,
                        Ohisseqno    = referenceNo,
                        MerchantID   = merchantID,
                    };

                    TBankhisexchangeTransFacade facBankTrans = new TBankhisexchangeTransFacade();
                    facBankTrans.Insert(dataPayment);
                    LogService.GlobalInfoMessage("退款交易数据保存完成。");
                    #endregion
                    #endregion
                }
                else
                {
                    #region 交易失败
                    LogService.GlobalInfoMessage("退货交易调用失败。" + retMsg);
                    throw new Exception(retMsg);
                    #endregion
                }
                #endregion
            }
            catch (Exception e)
            {
                LogService.GlobalInfoMessage("银行退款失败。" + e.Message);
                throw;
            }
        }
示例#3
0
        /// <summary>
        /// 交易方法
        /// </summary>
        /// <param name="TranType">交易类型,1为消费,2消费确认,-2取消消费,5签到,6结算</param>
        /// <param name="htParams">交易参数,HIS流水号,病人ID,金额</param>
        /// <returns></returns>
        public override int Trans(string TranType, Hashtable htParams)
        {
            base.Trans(TranType, htParams);

            #region 消费
            if (TranType == "1")
            {
                #region 组织参数
                PosInOutputData thePosInOutputData = new PosInOutputData();

                DateTime dtCurrenTime = new CommonFacade().GetServerDateTime();
                thePosInOutputData.TransType = "01";

                //获取交易金额,根据是12位的字符串,没有小数点到小数点后两位
                string strMoney = CheckMoney(htParams, "MONEY");
                thePosInOutputData.TransAmount = strMoney;
                thePosInOutputData.TransDate   = dtCurrenTime.ToString("yyyyMMdd");
                thePosInOutputData.TransTime   = dtCurrenTime.ToString("HHmmss");
                string Seqno = Check(htParams, "SEQNO");
                thePosInOutputData.HISLSH = Seqno;

                string strDiagnoseID = Check(htParams, "DIAGNOSEID");
                string CardID        = Check(htParams, "CARDID");

                #endregion

                #region 调用POS接口
                StringBuilder   sbInput       = new StringBuilder(thePosInOutputData.GetInput());
                StringBuilder   sbOutPut      = new StringBuilder(256);
                PosInOutputData theOutputData = null;

                try
                {
                    //调用银行交易的第一次调用
                    int intResult = Pos_ECRCOMM(sbInput, sbOutPut);
                    if (intResult != 1)
                    {
                        if (intResult == -37 || intResult == -38 || intResult == -44)
                        {
                            thePosInOutputData.TransType = "03";
                            sbInput = new StringBuilder(thePosInOutputData.GetInput());

                            //如果第二次调用
                            intResult = Pos_ECRCOMM(sbInput, sbOutPut);

                            if (intResult != 1)
                            {
                                if (intResult == -37 || intResult == -38 || intResult == -44)
                                {
                                    //第三次调用
                                    intResult = Pos_ECRCOMM(sbInput, sbOutPut);
                                    if (intResult != 1)
                                    {
                                        throw new Exception("调用银行POS机接口失败,返回错误代码:" + intResult);
                                    }
                                }
                            }
                        }
                        else
                        {
                            throw new Exception("调用银行POS机接口失败,返回错误代码:" + intResult);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogService.GlobalInfoMessage("调用银行交易方法ECRCOMM失败:" + ex.Message);
                    throw ex;
                }

                try
                {
                    theOutputData = new PosInOutputData(sbOutPut);
                }
                catch (Exception ex)
                {
                    LogService.GlobalInfoMessage("调用银行交易方法成功,解析银行返回字符串失败:" + ex.Message);
                    throw ex;
                }
                #endregion

                #region 保存POS结算结果

                try
                {
                    TBankhisexchangeTransData data = new TBankhisexchangeTransData();

                    //银行行号+批次号+授权号
                    data.Remark = theOutputData.CardType + "|" + theOutputData.BatchNo + "|" + theOutputData.ApprovalCode;

                    //银行卡号
                    data.ITEM1 = theOutputData.CardNumber;

                    //凭证号
                    data.Bankseqno = theOutputData.ReceiptNo;

                    //金额
                    data.Trfamt = Check(htParams, "MONEY");

                    //商户号
                    data.Buscd = theOutputData.MerchantID;

                    //终端号
                    data.TerminalNo = theOutputData.TerminalID;

                    //批次号
                    data.ITEM2 = theOutputData.BatchNo;

                    //交易日期
                    data.Operatetime = theOutputData.YHJYSJ;
                    data.Operatorid  = SysOperatorInfo.OperatorID;

                    //交易参考号
                    data.Ohisseqno = theOutputData.RefNo;

                    data.Usetype    = "充值";
                    data.Hisid      = CardID;
                    data.DIAGNOSEID = strDiagnoseID;
                    data.Hisseqno   = Seqno;

                    data.DataSources  = "自助";
                    data.BusinessType = "POS充值";
                    data.Bankstate    = "0";
                    data.Hisstate     = "0";

                    TBankhisexchangeTransFacade facade = new TBankhisexchangeTransFacade();
                    facade.Insert(data);
                    LogService.GlobalInfoMessage("调用银行支付交易成功,写入数据库成功!");
                    htParams.Add("CARDNO", theOutputData.CardNumber);
                    htParams.Add("BANKSEQNO", theOutputData.RefNo + "|" + theOutputData.ReceiptNo);
                }
                catch (Exception ex)
                {
                    LogService.GlobalInfoMessage("保存POS直联记录表T_BANKHISEXCHANGE_TRANS失败:" + ex.Message);
                    DeleteBankTran(thePosInOutputData, theOutputData);
                    throw ex;
                }
                #endregion
            }

            #endregion

            #region 消费确认
            if (TranType == "2")
            {
                //更新交易中间层的记录标识T_BANKHISEXCHANGE_RECORD
                TBankhisexchangeTransFacade facade = new TBankhisexchangeTransFacade();
                string Seqno = Check(htParams, "SEQNO");
                facade.UpdateState(Seqno, "HISSTATE", "1");
            }
            #endregion

            #region 消费撤消
            if (TranType == "-2")
            {
                //根据交易流水号查询HIS中已经存在的交易记录
                string Seqno         = Check(htParams, "SEQNO");
                string strDiagnoseID = Check(htParams, "DIAGNOSEID");
                string CardID        = Check(htParams, "CARDID");

                TBankhisexchangeTransFacade            facade = new TBankhisexchangeTransFacade();
                EntityList <TBankhisexchangeTransData> list   = facade.Get("HISSEQNO = '" + Seqno + "'");
                if (list.Count > 0)
                {
                    #region 如果已经存在,则调用撤消方法

                    #region 组织相关参数
                    LogService.GlobalInfoMessage("HIS处理失败,请用银行的撤消交易开始!");


                    PosInOutputData thePosInOutputData = new PosInOutputData();

                    DateTime dtCurrenTime = new CommonFacade().GetServerDateTime();
                    thePosInOutputData.TransType = "02";

                    //获取交易金额,根据是12位的字符串,没有小数点到小数点后两位

                    decimal decMoney = 0;
                    decimal.TryParse(list[0].Trfamt, out decMoney);

                    string strMoney = GetMoneyString(list[0].Trfamt);
                    thePosInOutputData.TransAmount = strMoney;
                    thePosInOutputData.TransDate   = dtCurrenTime.ToString("yyyyMMdd");
                    thePosInOutputData.TransTime   = dtCurrenTime.ToString("HHmmss");
                    Seqno = list[0].Hisseqno + "R";
                    thePosInOutputData.HISLSH    = Seqno;
                    thePosInOutputData.ReceiptNo = list[0].Bankseqno;

                    #endregion

                    #region 调用POS接口
                    StringBuilder   sbInput       = new StringBuilder(thePosInOutputData.GetInput());
                    StringBuilder   sbOutPut      = new StringBuilder(150);
                    PosInOutputData theOutputData = null;

                    try
                    {
                        //调用银行交易
                        int intResult = Pos_ECRCOMM(sbInput, sbOutPut);
                        if (intResult != 1)
                        {
                            throw new Exception("调用银行POS机接口失败,返回错误代码:" + intResult);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogService.GlobalInfoMessage("调用银行交易方法ECRCOMM失败:" + ex.Message);
                        throw ex;
                    }

                    try
                    {
                        theOutputData = new PosInOutputData(sbOutPut);
                    }
                    catch (Exception ex)
                    {
                        LogService.GlobalInfoMessage("调用银行交易方法成功,解析银行返回字符串失败:" + ex.Message);
                        throw ex;
                    }
                    #endregion

                    #region 保存POS结算结果

                    try
                    {
                        TBankhisexchangeTransData data = new TBankhisexchangeTransData();

                        //银行行号+批次号+授权号
                        data.Remark = theOutputData.CardType + "|" + theOutputData.BatchNo + "|" + theOutputData.ApprovalCode;

                        //银行卡号
                        data.ITEM1 = theOutputData.CardNumber;

                        //凭证号
                        data.Bankseqno = theOutputData.ReceiptNo;

                        //金额
                        data.Trfamt = (decMoney * (-1)).ToString();

                        //商户号
                        data.Buscd = theOutputData.MerchantID;

                        //终端号
                        data.TerminalNo = theOutputData.TerminalID;

                        //批次号
                        data.ITEM2 = theOutputData.BatchNo;

                        //交易日期
                        data.Operatetime = theOutputData.YHJYSJ;
                        data.Operatorid  = SysOperatorInfo.OperatorID;

                        //交易参考号
                        data.Ohisseqno = theOutputData.RefNo;

                        data.Usetype    = "充值冲正";
                        data.Hisid      = CardID;
                        data.DIAGNOSEID = strDiagnoseID;
                        data.Hisseqno   = Seqno;

                        data.DataSources  = "自助";
                        data.BusinessType = "POS冲正";
                        data.Bankstate    = "1";
                        data.Hisstate     = "1";

                        facade.Insert(data);
                        LogService.GlobalInfoMessage("调用银行支付交易成功,写入数据库成功!");
                        //htParams.Add("CARDNO", theOutputData.CardNumber);
                        //htParams.Add("BANKSEQNO", theOutputData.RefNo + "|" + theOutputData.ReceiptNo);
                    }
                    catch (Exception ex)
                    {
                        LogService.GlobalInfoMessage("保存POS直联记录表T_BANKHISEXCHANGE_TRANS失败:" + ex.Message);
                        //DeleteBankTran(thePosInOutputData, theOutputData);
                        throw ex;
                    }
                    #endregion

                    #endregion
                }
                else
                {
                    LogService.GlobalInfoMessage("HIS结算失败,调用银行冲正查询数据未找到,条件:" + "HISSEQNO = '" + Seqno + "'");
                }
            }
            #endregion

            #region 签到
            if (TranType == "5")
            {
            }
            #endregion

            #region 结算
            if (TranType == "6")
            {
            }
            #endregion

            return(0);
        }
示例#4
0
        private void BeginPay(Hashtable htParams)
        {
            String strErrorMsg = string.Empty;

            try
            {
                #region 组织请求入参
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("TransCode", "01");
                dic.Add("TransMoney", CheckMoney(htParams, "MONEY"));
                dic.Add("TransNo", PadRight("", 6));
                dic.Add("MachineID", PadRight("", 10));
                dic.Add("OperatorID", PadRight(SysOperatorInfo.OperatorID, 10));
                dic.Add("ReferenceNo", PadRight("", 15));
                dic.Add("AuthNo", PadRight("", 6));
                dic.Add("OldTransDate", PadRight("", 8));
                dic.Add("CardType", "H");
                dic.Add("IndexNo", PadRight(htParams["POSNO"].ToString(), 76));
                dic.Add("Track2", PadRight("", 37));
                dic.Add("Track3", PadRight("", 104));
                dic.Add("OldTransCode", PadRight("", 2));
                dic.Add("OldTerminalID", PadRight("", 15));
                dic.Add("OldAuthNo", PadRight("", 15));
                dic.Add("PayAccountID", PadRight("", 3));
                dic.Add("StoreID", PadRight("", 20));
                dic.Add("ReceiptID", PadRight("", 30));
                dic.Add("OrderID", PadRight("", 15));
                dic.Add("OldBatchNo", PadRight("", 6));
                dic.Add("OldTransTime", PadRight("", 6));
                dic.Add("OldTransMoney", PadRight("", 12));
                dic.Add("ServerIP", PadRight("", 15));
                dic.Add("ListenPort", PadRight("", 6));
                string strInput = dic.GetValueString();
                #endregion

                #region 平台接口调用
                LogService.GlobalInfoMessage("消费交易调用入参:" + strInput);
                StringBuilder sb = new StringBuilder(1000);
                //int iResult = SingleeMethods.CardTransCBK(strInput, sb, new SingleeMethods.EnterPasswordCallBack(EnterPasswordHandler), frmPwd.Handle);
                int    iResult   = SingleeMethods.CardTransDllWin(strInput, sb);
                string strOutput = sb.ToString();
                LogService.GlobalInfoMessage("消费交易调用出参:" + strOutput);
                #endregion

                #region 解析请求出参

                byte[] bytes   = System.Text.Encoding.Default.GetBytes(strOutput);
                string retCode = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 0, 6));
                string retMsg  = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 6, 40));

                #endregion

                #region 交易结果处理
                if (retCode == "000000")
                {
                    string transNo          = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 46, 6));
                    string authNo           = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 52, 6));
                    string batchNo          = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 58, 6));
                    string bankCardID       = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 64, 19));
                    string expDate          = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 83, 4));
                    string bankNo           = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 87, 2));
                    string referenceNo      = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 89, 12));
                    string terminalNo       = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 101, 15));
                    string merchantID       = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 116, 15));
                    string transMoney       = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 131, 12));
                    string indexNo          = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 143, 16));
                    string customField      = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 159, 74));
                    string sendCardBankCode = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 234, 7));
                    string bankDate         = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 241, 8));
                    string bankTime         = System.Text.Encoding.Default.GetString(SingleeMethods.SubByte(bytes, 249, 6));

                    #region 交易成功
                    LogService.GlobalInfoMessage("消费交易调用成功。" + retMsg);

                    #region 广播出参
                    htParams.Add("REFERENCENO", referenceNo);
                    htParams.Add("BANKCARDID", bankCardID);
                    htParams.Add("BANKSEQNO", transNo);
                    #endregion


                    #region 把交易数据写入数据库
                    string seqNo      = htParams["SEQNO"].ToString();
                    string diagnoseID = htParams["DIAGNOSEID"].ToString();
                    string cardID     = htParams["CARDID"].ToString();

                    //string strDateTime = DateTime.Now.ToString();
                    //if (!string.IsNullOrEmpty(bankDate.Trim()))
                    //{
                    //    strDateTime=bankDate.Substring(0, 4) + "-" + bankDate.Substring(4, 2) + "-" + bankDate.Substring(6, 2) + " " + bankTime.Substring(0, 2) + ":" + bankTime.Substring(2, 2) + ":" + bankTime.Substring(4, 2);

                    //}
                    //DateTime payDateTime = Convert.ToDateTime(strDateTime);
                    try
                    {
                        DateTime dtn;
                        string   strDate = string.Empty;
                        if (!string.IsNullOrEmpty(bankDate.Trim()))
                        {
                            strDate = bankDate.Substring(0, 4) + "-" + bankDate.Substring(4, 2) + "-" + bankDate.Substring(6, 2) + " " + bankTime.Substring(0, 2) + ":" + bankTime.Substring(2, 2);
                        }
                        DateTime payDateTime = DateTime.TryParse(strDate, out dtn) ? dtn : DateTime.Now;

                        decimal payMoney = decimal.Parse(transMoney.TrimStart('0'));

                        TBankhisexchangeTransData dataPayment = new TBankhisexchangeTransData()
                        {
                            InterfaceName = "锡盟新利银医接口",
                            Hisseqno      = seqNo,
                            Hisstate      = "0",
                            Bankseqno     = transNo,
                            Bankstate     = "1",
                            DIAGNOSEID    = diagnoseID,
                            Hisid         = cardID,
                            Usetype       = "消费",
                            DataSources   = "自助",
                            BusinessType  = "POS扣款",
                            Operatorid    = SysOperatorInfo.OperatorID,
                            Operatetime   = payDateTime,
                            TerminalNo    = terminalNo,
                            Trfamt        = payMoney.ToString("0.##"),
                            ITEM1         = bankCardID,
                            ITEM2         = batchNo,
                            ITEM3         = string.Empty,
                            Ohisseqno     = referenceNo,
                            MerchantID    = merchantID,
                        };

                        TBankhisexchangeTransFacade facBankTrans = new TBankhisexchangeTransFacade();
                        facBankTrans.Insert(dataPayment);
                        LogService.GlobalInfoMessage("消费交易数据保存完成。");
                    }
                    catch (Exception ex)
                    {
                        LogService.GlobalInfoMessage("消费交易数据保存失败");
                        #region 打印交易凭证
                        //PrintInfo(htParams);
                        SkynetMessage.MsgInfo("预交金充值失败,需要撤销银行交易,请按POS机提示操作,点击确定后,请重新插入银行卡");
                        Revoke(htParams);
                        #endregion
                        //throw new Exception(string.Format("消费交易数据保存失败!已调用撤销方法!,错误:{0}",ex.Message));
                        throw new Exception(string.Format("银行交易失败,充值金额已退回卡,请重新充值!"));
                    }

                    #endregion
                    #endregion
                }
                #region 交易失败
                else if (retCode == "C41003")
                {
                    strErrorMsg = "取消交易,请重新操作!";
                }
                else if (retCode == "C85006")
                {
                    strErrorMsg = "密码错误,请重新操作!";
                }
                else if (retCode == "C40006")
                {
                    strErrorMsg = "读卡错误,请检查卡片是否插错!";
                }
                else if (retCode == "C99999")
                {
                    strErrorMsg = "银行卡余额不足,交易失败!";
                }
                else
                {
                    strErrorMsg = string.Format("消费交易调用失败:{0}", retMsg);
                }
                if (!string.IsNullOrEmpty(strErrorMsg))
                {
                    LogService.GlobalInfoMessage(strErrorMsg);
                    //SkynetMessage.MsgInfo(strErrorMsg);

                    //Voice voice = new Voice();
                    //voice.PlayText(strErrorMsg);
                    //voice.EndJtts();
                    throw new Exception(strErrorMsg);
                }
                #endregion
                #endregion
            }
            catch (Exception e)
            {
                LogService.GlobalInfoMessage(e.Message);
                //SkynetMessage.MsgInfo(e.Message);
                throw new Exception(string.Format("{0}", e.Message));
            }
        }
        /// <summary>
        /// 交易方法
        /// </summary>
        /// <param name="TranType">交易类型,1为消费,2消费确认,-2取消消费,5签到,6结算</param>
        /// <param name="htParams">交易参数,HIS流水号,病人ID,金额</param>
        /// <returns></returns>
        public override int Trans(string TranType, Hashtable htParams)
        {
            base.Trans(TranType, htParams);

            #region 消费
            if (TranType == "1")
            {
                #region 组织参数
                //POS机号使用自助机的编号
                string strInput = Check(htParams, "POSNO").Trim().PadRight(8, ' ').Substring(0, 8);

                //POS机操作员
                strInput += SysOperatorInfo.OperatorCode.Trim().PadRight(8, ' ');

                //交易类型
                strInput += "00";

                //获取交易金额,根据是12位的字符串,没有小数点到小数点后两位
                string strMoney = CheckMoney(htParams, "MONEY");
                strInput += strMoney;

                //原交易日期
                strInput += "".PadRight(8, ' ');

                //原交易参考号
                strInput += "".PadRight(12, ' ');

                //原凭证号
                strInput += "".PadRight(6, ' ');

                //LRC校验
                Random rm    = new Random();
                int    intrm = rm.Next(100, 999);
                strInput += intrm.ToString();

                string strDiagnoseID = Check(htParams, "DIAGNOSEID");
                string Seqno         = Check(htParams, "SEQNO");
                string CardID        = Check(htParams, "CARDID");

                #endregion

                #region 调用POS接口
                StringBuilder sbInput       = new StringBuilder(strInput);
                StringBuilder sbOutPut      = new StringBuilder(150);
                OutputData    theOutputData = null;

                try
                {
                    //调用银行交易
                    Pos_BankAll(sbInput, sbOutPut);

                    theOutputData = new OutputData(sbOutPut);
                }
                catch (Exception ex)
                {
                    LogService.GlobalInfoMessage("调用银行交易方法bankall失败:" + ex.Message);
                    throw ex;
                }
                #endregion

                #region 保存POS结算结果

                try
                {
                    DateTime ServerDate            = new CommonFacade().GetServerDateTime();
                    TBankhisexchangeTransData data = new TBankhisexchangeTransData();

                    //银行行号+批次号+授权号
                    data.Remark = theOutputData.BankCode + "|" + theOutputData.BatchNo + "|" + theOutputData.LicenseNo;

                    //银行卡号
                    data.ITEM1 = theOutputData.CardNo;

                    //凭证号
                    data.Bankseqno = theOutputData.VoucherNo;

                    //金额
                    data.Trfamt = theOutputData.TranMoney.ToString();

                    //商户号
                    data.Buscd = theOutputData.MchId;

                    //终端号
                    data.TerminalNo = theOutputData.TerminalNo;

                    //批次号
                    data.ITEM2 = theOutputData.BatchNo;

                    //交易日期
                    data.Operatetime = theOutputData.YHJYSJ;
                    data.Operatorid  = SysOperatorInfo.OperatorID;

                    //交易参考号
                    data.Ohisseqno = theOutputData.RefNo;

                    data.Usetype    = "充值";
                    data.Hisid      = CardID;
                    data.DIAGNOSEID = strDiagnoseID;
                    data.Hisseqno   = Seqno;

                    data.DataSources  = "自助";
                    data.BusinessType = "POS充值";
                    data.Bankstate    = "0";
                    data.Hisstate     = "0";

                    TBankhisexchangeTransFacade facade = new TBankhisexchangeTransFacade();
                    facade.Insert(data);
                    LogService.GlobalInfoMessage("调用银行支付交易成功,写入数据库成功!");
                    htParams.Add("CARDNO", theOutputData.CardNo);
                    htParams.Add("BANKSEQNO", theOutputData.RefNo + "|" + theOutputData.VoucherNo);
                }
                catch (Exception ex)
                {
                    LogService.GlobalInfoMessage("保存POS直联记录表T_BANKHISEXCHANGE_TRANS失败:" + ex.Message);
                    DeleteBankTran(htParams, theOutputData.VoucherNo);
                    throw ex;
                }
                #endregion
            }

            #endregion

            #region 消费确认
            if (TranType == "2")
            {
                //更新交易中间层的记录标识T_BANKHISEXCHANGE_RECORD
                TBankhisexchangeTransFacade facade = new TBankhisexchangeTransFacade();
                string Seqno = Check(htParams, "SEQNO");
                facade.UpdateState(Seqno, "HISSTATE", "1");
            }
            #endregion

            #region 消费撤消
            if (TranType == "-2")
            {
                //根据交易流水号查询HIS中已经存在的交易记录
                string Seqno         = Check(htParams, "SEQNO");
                string strDiagnoseID = Check(htParams, "DIAGNOSEID");
                string CardID        = Check(htParams, "CARDID");

                TBankhisexchangeTransFacade            facade = new TBankhisexchangeTransFacade();
                EntityList <TBankhisexchangeTransData> list   = facade.Get("HISSEQNO = '" + Seqno + "'");
                if (list.Count > 0)
                {
                    #region 如果已经存在,则调用撤消方法

                    #region 组织相关参数
                    LogService.GlobalInfoMessage("HIS处理失败,请用银行的撤消交易开始!");
                    //POS机号使用自助机的编号
                    string strInput = Check(htParams, "POSNO").Trim().PadRight(8, ' ').Substring(0, 8);

                    //POS机操作员
                    strInput += SysOperatorInfo.OperatorCode.Trim().PadRight(8, ' ');

                    //交易类型
                    strInput += "01";

                    //获取交易金额,根据是12位的字符串,没有小数点到小数点后两位
                    string strMoney = CheckMoney(htParams, "MONEY");
                    strInput += strMoney;

                    //原交易日期
                    strInput += "".PadRight(8, ' ');

                    //原交易参考号
                    strInput += "".PadRight(12, ' ');

                    //原凭证号
                    strInput += list[0].Bankseqno;

                    //LRC校验
                    Random rm    = new Random();
                    int    intrm = rm.Next(100, 999);
                    strInput += intrm.ToString();

                    #endregion

                    #region 调用POS接口
                    StringBuilder sbInput       = new StringBuilder(strInput);
                    StringBuilder sbOutPut      = new StringBuilder(150);
                    OutputData    theOutputData = null;

                    try
                    {
                        //调用银行交易
                        Pos_BankAll(sbInput, sbOutPut);

                        theOutputData = new OutputData(sbOutPut);
                    }
                    catch (Exception ex)
                    {
                        LogService.GlobalInfoMessage("调用银行交易方法bankall失败:" + ex.Message);
                        throw ex;
                    }
                    #endregion

                    #region 保存POS结算结果
                    try
                    {
                        facade.UpdateState(Seqno, "HISSTATE", "-1");

                        DateTime ServerDate            = new CommonFacade().GetServerDateTime();
                        TBankhisexchangeTransData data = new TBankhisexchangeTransData();

                        //银行行号+批次号+授权号
                        data.Remark = theOutputData.BankCode + "|" + theOutputData.BatchNo + "|" + theOutputData.LicenseNo;

                        //银行卡号
                        data.ITEM1 = theOutputData.CardNo;

                        //凭证号
                        data.Bankseqno = theOutputData.VoucherNo;

                        //金额
                        data.Trfamt = (theOutputData.TranMoney * -1).ToString();

                        //商户号
                        data.Buscd = theOutputData.MchId;

                        //终端号
                        data.TerminalNo = theOutputData.TerminalNo;

                        //批次号
                        data.ITEM2 = theOutputData.BatchNo;

                        //交易日期
                        data.Operatetime = theOutputData.YHJYSJ;
                        data.Operatorid  = SysOperatorInfo.OperatorID;

                        //交易参考号
                        data.Ohisseqno = theOutputData.RefNo;

                        data.Usetype    = "冲正";
                        data.Hisid      = CardID;
                        data.DIAGNOSEID = strDiagnoseID;

                        data.Hisseqno = Seqno + "R";

                        data.DataSources  = "自助";
                        data.BusinessType = "POS充值";
                        data.Bankstate    = "0";
                        data.Hisstate     = "-2";

                        facade.Insert(data);
                        LogService.GlobalInfoMessage("调用银行支付交易成功,写入数据库成功!");
                    }
                    catch (Exception ex)
                    {
                        LogService.GlobalInfoMessage("保存POS直联记录表T_BANKHISEXCHANGE_TRANS失败:" + ex.Message);
                        throw ex;
                    }
                    #endregion

                    #endregion
                }
                else
                {
                    LogService.GlobalInfoMessage("HIS结算失败,调用银行冲正查询数据未找到,条件:" + "HISSEQNO = '" + Seqno + "'");
                }
            }
            #endregion

            #region 签到
            if (TranType == "5")
            {
                string PosNo = Check(htParams, "POSNO").Trim();
                //判断当天是否已经进行签到,如果签到不再进行签到
                DateTime ServerDate = new CommonFacade().GetServerDateTime();
                string   Currdate   = ServerDate.ToString("yyyyMMdd");
                HealthCardAuthkeyFacade theAuthKeyfacade = new HealthCardAuthkeyFacade();
                HealthCardAuthkeyData   theEntitydata    = theAuthKeyfacade.GetByPrimaryKey(PosNo, Currdate);
                if (theEntitydata != null)
                {
                    return(0);
                }
                try
                {
                    Trans("6", htParams);
                }
                catch (Exception ex)
                {
                    LogService.GlobalInfoMessage("调用 POS结算业务失败:" + ex.Message);
                }
                #region 组织参数
                //POS机号使用自助机的编号
                string strInput = Check(htParams, "POSNO").Trim().PadRight(8, ' ').Substring(0, 8);

                //POS机操作员
                strInput += SysOperatorInfo.OperatorCode.Trim().PadRight(8, ' ');

                //交易类型
                strInput += "05";

                //获取交易金额
                strInput += "000000000000";

                //原交易日期
                strInput += "".PadRight(8, ' ');

                //原交易参考号
                strInput += "".PadRight(12, ' ');

                //原凭证号
                strInput += "".PadRight(6, ' ');

                //LRC校验
                Random rm    = new Random();
                int    intrm = rm.Next(100, 999);
                strInput += intrm.ToString();

                #endregion

                #region 调用POS接口
                StringBuilder sbInput       = new StringBuilder(strInput);
                StringBuilder sbOutPut      = new StringBuilder(150);
                OutputData    theOutputData = null;

                try
                {
                    //调用银行交易
                    Pos_BankAll(sbInput, sbOutPut);

                    theOutputData = new OutputData(sbOutPut);

                    theEntitydata          = new HealthCardAuthkeyData();
                    theEntitydata.Orgcode  = PosNo;
                    theEntitydata.Username = Currdate;
                    theEntitydata.Authkey  = theOutputData.MchId + "|" + theOutputData.TranTime;
                    theAuthKeyfacade.Insert(theEntitydata);

                    LogService.GlobalInfoMessage("调用银行交易方法bankall签到交易成功!");
                }
                catch (Exception ex)
                {
                    LogService.GlobalInfoMessage("调用银行交易方法bankall签到失败:" + ex.Message);
                    throw ex;
                }
                #endregion
            }
            #endregion

            #region 结算
            if (TranType == "6")
            {
                #region 组织参数
                //POS机号使用自助机的编号
                string strInput = Check(htParams, "POSNO").Trim().PadRight(8, ' ').Substring(0, 8);

                //POS机操作员
                strInput += SysOperatorInfo.OperatorCode.Trim().PadRight(8, ' ');

                //交易类型
                strInput += "06";

                //获取交易金额
                strInput += "000000000000";

                //原交易日期
                strInput += "".PadRight(8, ' ');

                //原交易参考号
                strInput += "".PadRight(12, ' ');

                //原凭证号
                strInput += "".PadRight(6, ' ');

                //LRC校验
                Random rm    = new Random();
                int    intrm = rm.Next(100, 999);
                strInput += intrm.ToString();

                #endregion

                #region 调用POS接口
                StringBuilder sbInput       = new StringBuilder(strInput);
                StringBuilder sbOutPut      = new StringBuilder(150);
                OutputData    theOutputData = null;

                try
                {
                    //调用银行交易
                    Pos_BankAll(sbInput, sbOutPut);

                    theOutputData = new OutputData(sbOutPut);
                    LogService.GlobalInfoMessage("调用银行交易方法bankall结算交易成功!");
                }
                catch (Exception ex)
                {
                    LogService.GlobalInfoMessage("调用银行交易方法bankall结算失败:" + ex.Message);
                    throw ex;
                }
                #endregion
            }
            #endregion

            return(0);
        }