示例#1
0
        private void DeleteBankTran(PosInOutputData thePosInputData, PosInOutputData theOutPutData)
        {
            LogService.GlobalInfoMessage("HIS处理失败,请用银行的撤消交易开始!");

            DateTime        dtCurrenTime   = new CommonFacade().GetServerDateTime();
            PosInOutputData theCancelInput = new PosInOutputData();

            theCancelInput.TransType   = "02";
            theCancelInput.TransAmount = thePosInputData.TransAmount;
            theCancelInput.TransDate   = dtCurrenTime.ToString("yyyyMMdd");
            theCancelInput.TransTime   = dtCurrenTime.ToString("HHmmss");
            theCancelInput.HISLSH      = thePosInputData.HISLSH.Trim() + "R";
            theCancelInput.ReceiptNo   = theOutPutData.ReceiptNo;
            theCancelInput.RefNo       = theOutPutData.RefNo;

            StringBuilder sbInput = new StringBuilder(theCancelInput.GetInput());

            try
            {
                StringBuilder sbOutPut = new StringBuilder(150);
                //调用银行交易
                int intResult = Pos_ECRCOMM(sbInput, sbOutPut);
                if (intResult != 1)
                {
                    throw new Exception("调用银行POS机接口失败,返回错误代码:" + intResult);
                }
            }
            catch (Exception ex)
            {
                LogService.GlobalInfoMessage("调用银行交易方法ECRCOMM失败:" + ex.Message);
                throw ex;
            }
        }
示例#2
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);
        }