private const int OutTimeConn = 10000; //连接时间超时  5秒

        public BaseResponse SendMessage(BaseRequest bmr, string WebsiteCode, string TellerCode)
        {
            TimeoutObject.Reset();
            BaseResponse result = null;

            _socket.BeginConnect(new IPEndPoint(IPAddress.Parse(RemoteIP), RemotePort), delegate(IAsyncResult ar) { TimeoutObject.Set(); }, _socket);
            if (TimeoutObject.WaitOne(OutTimeConn, false))
            {
                _socket.ReceiveTimeout = OutTime;
                _socket.SendTimeout    = OutTime;
                string str = bmr.ObjectToMessage();
                _socket.Send(Encod.GetBytes(str));
                len = _socket.Receive(buffer);

                if (len > 0)
                {
                    string strbuff = Encod.GetString(buffer);
                    switch (bmr.BusinessCode)
                    {
                    case "01": result = new Response01(buffer); break;

                    case "02": result = new Response02(buffer); break;

                    case "03": result = new Response03(buffer); break;

                    case "04": result = new Response04(buffer); break;

                    case "05": result = new Response05(buffer); break;

                    case "06": result = new Response06(buffer); break;

                    case "07": result = new Response07(buffer); break;

                    case "08": result = new Response08(buffer); break;

                    case "09": result = new Response09(buffer); break;

                    default: return(null);
                    }
                }
                bmr.SaveMessage(WebsiteCode, TellerCode);
                if (result != null)
                {
                    result.BankCode = bmr.BankCode;
                    result.SaveMessage(WebsiteCode, TellerCode);
                }
                return(result);
            }
            else
            {
                if (_socket.Connected)
                {
                    _socket.Shutdown(SocketShutdown.Both);
                    _socket.Close();
                }
                throw new Exception("所提供的服务器连接超时");
            }
        }
Example #2
0
        /// <summary>
        /// 添加记录
        /// </summary>
        public override void OKExecute()
        {
            try
            {
                string strAskMessage = "付款凭证编号:" + PayResponse.PaymentID + "\r\n应支付款金额:" + PayResponse.PaymentAmount + "\r\n收款人账号:" + PayResponse.ReceiverAccount + "\r\n收款人名称:" + PayResponse.ReceiverName +
                                       "\r\n付款人账号:" + PayResponse.PayerAccount + "\r\n付款人名称:" + PayResponse.PayerName;
                if (Check() && VMHelp.AskMessage(strAskMessage + "\r\n确认进行存款?"))
                {
                    model  = new FundPayment();
                    model2 = new FundsRegulatoryClient.SqlTransSvr.FundPayment();
                    // model. = Guid.NewGuid().ToString();
                    model2.BusinessCode     = CurrentObj.BusinessCode = model.BusinessCode = FinancialRegulation.Tools.PublicData.FundPay; //交易代码
                    model2.BankCode         = CurrentObj.BankCode = model.BankCode = VMHelp.BankCode;
                    model2.PaymentAmount    = CurrentObj.PaymentAmount = model.PaymentAmount = PayResponse.PaymentAmount;                  //支付金额
                    model2.FirmOperatorName = model.FirmOperatorName = CurrentObj.FirmOperatorName;                                        //企业经办人
                    model2.FirmOperatorID   = model.FirmOperatorID = CurrentObj.FirmOperatorID;                                            //经办人证件号
                    model2.PaymentBank      = model.PaymentBank = CurrentObj.PaymentBank = VMHelp.BankName;                                //支付银行
                    model2.BankSiteID       = CurrentObj.BankSiteID = model.BankSiteID = VMHelp.PointCode;                                 //网点号
                    model2.BankSerialNumber = model.BankSerialNumber = BankSerialNumber;                                                   // 银行流水号
                    model2.SerialNumber     = model.SerialNumber = CurrentObj.SerialNumber = VMHelp.ServiceNo;                             //当前流水号
                    model2.BankTellerID     = CurrentObj.BankTellerID = model.BankTellerID = VMHelp.UserCode;                              //柜员号
                    model2.PaymentInstr     = model.PaymentInstr = CurrentObj.PaymentInstr;                                                //付款说明
                    model2.PayState         = model.PayState = Tools.PublicData.PayA;
                    model2.PaymentID        = model.PaymentID = CurrentObj.PaymentID = PayResponse.PaymentID;                              //支付凭证编号
                    model2.ReceiverAccount  = model.ReceiverAccount = PayResponse.ReceiverAccount;
                    model2.ReceiverName     = model.ReceiverName = PayResponse.ReceiverName;
                    model2.ReceiveBank      = model.ReceiveBank = PayResponse.ReceiverBankName;
                    model2.PayName          = model.PayName = PayResponse.PayerName;
                    model2.PayAccount       = model.PayAccount = PayResponse.PayerAccount;
                    model2.PaymentBank      = model.PaymentBank = PayResponse.PayBank;
                    model2.ProjectCode      = model.ProjectCode = PayResponse.ProjectID;
                    // model2.FirmName = model.FirmName = "";//公司名称
                    //model._DE_cklb = Tools.PublicData.Deposit_Lf;
                    //CurrentObj.BusinessTime = VMHelp.NowTime.ToString();

                    if (df != null)
                    {
                        model2.PayID       = model.PayID = df.PayID;
                        model2.PaymentTime = model.PaymentTime = DateTime.Parse(VMHelp.NowTime);//缴款日期
                    }
                    else
                    {
                        model2.PayID       = model.PayID = VMHelp.GUID;
                        model2.PaymentTime = model.PaymentTime = model.PaymentConfirmTime = DateTime.Parse(VMHelp.NowTime);//缴款日期
                    }
                    FundsRegulatoryClient.JG_AccountManageSrv.JG_AccountManageInfo ami = new FundsRegulatoryClient.JG_AccountManageSrv.JG_AccountManageInfo();
                    ami.AM_JgAccount = model.PayAccount;
                    ObservableCollection <FundsRegulatoryClient.JG_AccountManageSrv.JG_AccountManageInfo> acc = accountClient.Select(ami);
                    if (acc.Count < 1 || acc[0].AM_UseFlag == "销户")
                    {
                        VMHelp.ShowMessage("付款账户不存在或已销户", false);
                        return;
                    }
                    ////获取企业名称
                    model2.FirmName = model.FirmName = acc[0].AM_CorpName;
                    FundsRegulatoryClient.InterestService.DayBalance db = new FundsRegulatoryClient.InterestService.DayBalance();
                    db.DB_ID   = acc[0].AM_ID;
                    db.DB_Time = DateTime.Parse(DateTime.Now.ToShortDateString());
                    ObservableCollection <FundsRegulatoryClient.InterestService.DayBalance> dblist = new ObservableCollection <FundsRegulatoryClient.InterestService.DayBalance>();
                    dblist = InterestClient.SelectJG_DayBalanceInfo(db);
                    if (dblist.Count < 0)
                    {
                        VMHelp.ShowMessage("支付失败,数据无今日余额", false);
                        return;
                    }
                    if (dblist[0].DB_Balance < model.PaymentAmount)
                    {
                        VMHelp.ShowMessage("账户余额不足,无法支付", false);
                        return;
                    }
                    response = SendMessage <Response05>(CurrentObj, VMHelp.PointCode, VMHelp.UserCode);//发送Messageresponse.ReturnCode =="00"
                    if (response.ReturnCode == Tools.PublicData.ResponseSuccess || response.ReturnCode == Tools.PublicData.PaymentSuccess)
                    {
                        if (response.ReturnCode == Tools.PublicData.PaymentSuccess && !VMHelp.AskMessage("付款凭证已完成付款,是否存数据库?"))
                        {
                            return;
                        }
                        if (df != null)
                        {
                            FundsRegulatoryClient.SqlTransSvr.DayBalance temp = new FundsRegulatoryClient.SqlTransSvr.DayBalance();
                            temp.DB_Balance      = dblist[0].DB_Balance;
                            temp.DB_InterestRate = dblist[0].DB_InterestRate;
                            temp.DB_Balance      = temp.DB_Balance - model.PaymentAmount;
                            temp.ID      = dblist[0].ID;
                            temp.DB_ID   = acc[0].AM_ID;
                            temp.DB_Time = DateTime.Parse(DateTime.Now.ToShortDateString());
                            if (sqlTran.Update_DbAndPF(temp, model2, 2))
                            {
                                VMHelp.ShowMessage(true);//"付款凭证已经完成支付",
                                windowOK();
                            }
                            else
                            {
                                VMHelp.ShowMessage("操作失败原因:\r\n 1、支付表更新失败 \r\n 2、余额表更新失败", false);
                                return;
                            }
                        }
                        else
                        {
                            //if (dblist[0].DB_Balance < model.PaymentAmount)
                            //{
                            //    VMHelp.ShowMessage("账户余额不足,无法支付", false);
                            //    return;
                            //}
                            FundsRegulatoryClient.SqlTransSvr.DayBalance temp = new FundsRegulatoryClient.SqlTransSvr.DayBalance();
                            temp.DB_Balance      = dblist[0].DB_Balance;
                            temp.DB_InterestRate = dblist[0].DB_InterestRate;
                            temp.DB_Balance      = temp.DB_Balance - model.PaymentAmount;
                            temp.ID      = dblist[0].ID;
                            temp.DB_ID   = acc[0].AM_ID;
                            temp.DB_Time = DateTime.Parse(DateTime.Now.ToShortDateString());
                            if (sqlTran.Update_DbAndPF(temp, model2, 1))
                            {
                                VMHelp.ShowMessage(true);//"付款凭证已经完成支付",
                                windowOK();
                            }
                            else
                            {
                                VMHelp.ShowMessage("操作失败原因:\r\n 1、支付表添加失败 \r\n 2、余额表更新失败", false);
                                return;
                            }
                        }
                    }
                    else //if (response.ReturnCode == Tools.PublicData.PaymentFail)
                    {
                        VMHelp.ShowMessage("付款凭证不存在", false);
                    }
                }
            }
            catch (Exception e)
            {
                SendExcetpion(e);
            }
        }