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("所提供的服务器连接超时"); } }
public override void OKExecute() { try { if (IsSearch == null) { VMHelp.ShowMessage("未查询", false); return; } if (!(bool)IsSearch || !Check()) { return; } Request08 refundRequest = new Request08(); refundRequest.BusinessCode = Tools.PublicData.Refund; refundRequest.BankCode = VMHelp.BankCode; refundRequest.PaymentID = CurrentObj.PaymentID; refundRequest.RefundAmount = CurrentObj.RefundAmount; refundRequest.RefundInstr = CurrentObj.RefundInstr; response = SendMessage <Response08>(refundRequest, VMHelp.PointCode, VMHelp.UserCode); if (response.ReturnCode != Tools.PublicData.ResponseSuccess) { VMHelp.ShowMessage(Tools.HelpClass.Current.MsgDIC[response.ReturnCode], false); return; } //if (response.ReturnCode == Tools.PublicData.DepositSuccess && !VMHelp.AskMessage("付款凭证已经完成支付,是否存数据库?")) //{ // return; //} if (!DayBalanceAndRefundAndState()) { VMHelp.ShowMessage("操作失败,原因:" + "\r\n 1、数据库中无今日余额 \r\n 2、今日余额更新失败 \r\n 3、存款或支付表状态更新失败", false); return; } this.Models.Add(CurrentObj); VMHelp.ShowMessage(true); windowClose(); } catch (Exception e) { SendExcetpion(e); } }