private void device_OnReadCardInfo(object sender, ReadCardInfoEventArgs e) { ETCDevice device = sender as ETCDevice; if (device == null) { return; } EntranceInfo entrance = ParkBuffer.Current.GetEntrance(device.EntranceID); OpenCardEventArgs args = new OpenCardEventArgs() { CardID = e.CardInfo.CardNo, CardType = ETCSetting.CardTyte, Entrance = entrance, Balance = (decimal)e.CardInfo.Balance / 100, }; if (entrance != null) { var p = ParkBuffer.Current.GetPark(entrance.ParkID); if (!entrance.IsExitDevice || (p != null && p.IsNested)) //入口或者嵌套车场, { if (this.OnReadCard != null) { this.OnReadCard(this, args); } } else { HandlePayment(device, args, null, e); } } else { HandlePayment(device, args, null, e); } }
private void HandlePayment(ETCDevice device, OpenCardEventArgs e, ReadOBUInfoEventArgs obuInfo, ReadCardInfoEventArgs cardInfo) { if (this.OnPaying != null) { this.OnPaying(this, e); //产生收费事件 } if (e.Payment == null) { if (this.OnReadCard != null) { this.OnReadCard(this, e); } return; } if (e.Payment.GetPaying() <= 0) //不用收费直接返回收款成功事件 { WriteCardResponse r = null; ETCPaymentList list = null; if (obuInfo != null) { r = device.RSUWrite(obuInfo.OBUInfo, 0, true, out list); } else { r = device.ReaderWrite(cardInfo.CardInfo, 0, true, out list); } e.Payment.PaymentCode = Ralid.Park.BusinessModel.Enum.PaymentCode.Computer; e.Payment.PaymentMode = Ralid.Park.BusinessModel.Enum.PaymentMode.GDETC; if (this.OnPaidOk != null) { this.OnPaidOk(this, e); } } else //扣费 { //判断余额是否够扣费,否则返回"余额不足",注意钱包单位是分的,这里要转成分比较 if (e.Payment.GetPaying() <= e.Balance) { int paid = (int)(e.Payment.GetPaying() * 100); ETCPaymentList list = null; WriteCardResponse r = null; if (obuInfo != null) { r = device.RSUWrite(obuInfo.OBUInfo, paid, true, out list); } else { r = device.ReaderWrite(cardInfo.CardInfo, paid, true, out list); } if (r.ErrorCode == 0) { var res = device.ListUpLoad(list); //上传流水 var record = new Ralid.Park.BusinessModel.Model.ETCPaymentRecord() { LaneNo = device.LaneNo, Device = obuInfo != null ? 0 : 1, AddTime = DateTime.Now, Data = JsonConvert.SerializeObject(list), UploadTime = res.ErrorCode == 0 ? (DateTime?)DateTime.Now : null, }; new ETCPaymentRecordBll(AppSettings.CurrentSetting.ParkConnect).Insert(record); //在数据库中保存流水记录 e.Paid = e.Payment.GetPaying(); e.Payment.PaymentCode = Ralid.Park.BusinessModel.Enum.PaymentCode.Computer; e.Payment.PaymentMode = Ralid.Park.BusinessModel.Enum.PaymentMode.GDETC; e.Balance = (decimal)r.Balance / 100; if (obuInfo != null && obuInfo.OBUInfo.CardNo != e.CardID) { e.Payment.Memo = "ETC" + obuInfo.OBUInfo.CardNo; //说明收费的卡号与ETC卡是同一个车牌号 } if (this.OnPaidOk != null) { this.OnPaidOk(this, e); } } else { e.LastError = "扣款失败"; if (this.OnPaidFail != null) { this.OnPaidFail(this, e); } } } else { if (obuInfo != null) { e.LastError = "余额不足"; if (this.OnPaidFail != null) { this.OnPaidFail(this, e); } } else //ETC读卡器上余额不足时产生读卡事件,在收费电脑上显示明细 { if (this.OnReadCard != null) { this.OnReadCard(this, e); } } } } }