Example #1
0
        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);
            }
        }
Example #2
0
        /// <summary>
        /// 处理未完成交易记录
        /// </summary>
        /// <param name="item"></param>
        /// <param name="w"></param>
        /// <param name="record"></param>
        private bool HandleUnFinishedPayment(YCTItem item, YCTWallet w, YCTPaymentRecord record, OpenCardEventArgs args)
        {
            string tac = item.Reader.RestorePaid(record.LCN, record.FCN, record.XRN, record.FEE, record.BAL);

            if (string.IsNullOrEmpty(tac))
            {
                //处理失败
                int err = item.Reader.LastError;
                if (err == 0xC2)//返回无对应的记录
                {
                    //无对应交易记录 删除记录
                    (new YCTPaymentRecordBll(AppSettings.CurrentSetting.MasterParkConnect)).Delete(record);
                    return(true);
                }
                return(false);
            }

            //处理成功,生成保存上一次的收费记录
            args.ChargeDateTime = record.TIM;
            if (this.OnPaying != null)
            {
                this.OnPaying(this, args);                        //产生上一次的收费事件
            }
            if (args.Payment == null)
            {
                return(false);
            }
            args.UnFinishedPayment = args.Payment;                            //设置上次未完成的收费信息
            args.Payment           = null;                                    //重置收费记录
            args.ChargeDateTime    = null;                                    //重置计费时间

            args.UnFinishedPayment.Paid        = record.TF * 1.00M / 100.00M; //设置实收费用,羊城通记录里的交易金额是分为单位的,所以这里需要转换成元
            args.UnFinishedPayment.PaymentCode = Ralid.Park.BusinessModel.Enum.PaymentCode.Computer;
            args.UnFinishedPayment.PaymentMode = Ralid.Park.BusinessModel.Enum.PaymentMode.YangChengTong;

            //更新未完整交易记录
            YCTPaymentRecord newVal = record.Clone();

            if (record.WalletType == 0x02)
            {
                newVal.TAC = tac;                        //cpu钱包将TAC写到记录中
            }
            newVal.State = YCTPaymentRecordState.PaidOk; //标记为完成
            YCTPaymentRecordBll bll    = new YCTPaymentRecordBll(AppSettings.CurrentSetting.MasterParkConnect);
            CommandResult       result = bll.Update(newVal, record);

            return(result.Result == ResultCode.Successful);
        }
Example #3
0
        private void device_OnReadOBUInfo(object sender, ReadOBUInfoEventArgs e)
        {
            ETCDevice device = sender as ETCDevice;

            if (device == null)
            {
                return;
            }
            EntranceInfo      entrance = ParkBuffer.Current.GetEntrance(device.EntranceID);
            OpenCardEventArgs args     = new OpenCardEventArgs()
            {
                CardID   = e.OBUInfo.CardNo,
                CardType = ETCSetting.CardTyte,
                Entrance = entrance,
                Balance  = (decimal)e.OBUInfo.Balance / 100,
            };

            if (entrance != null)
            {
                var park = ParkBuffer.Current.GetPark(entrance.ParkID);
                //开始处理与已经存在的同车牌号的名单的冲突 bruce 2017-3-22
                var con = new CardSearchCondition();
                con.CarPlateOrLast = e.OBUInfo.CardPlate.Trim();
                con.Status         = Ralid.Park.BusinessModel.Enum.CardStatus.Enabled;
                var cards = new CardBll(AppSettings.CurrentSetting.ParkConnect).GetCards(con).QueryObjects;
                if (cards != null)
                {
                    cards = cards.Where(it => it.CardID != e.OBUInfo.CardNo).ToList();                //选出卡号不一样的记录
                }
                if (cards != null && cards.Count > 0)
                {
                    if (cards.Count == 1) //如果系统中只有一个同一车牌号的名单
                    {
                        var cardinfo = cards.Single(it => it.CardID != e.OBUInfo.CardNo);
                        if ((!park.IsWriteCardMode || cardinfo.OnlineHandleWhenOfflineMode) && cardinfo.IsCardList) //如果是在线车场或卡片按在线处理
                        {
                            args.CardID = cardinfo.CardID;                                                          //用现有名单的卡号去读卡
                        }
                        else  //不能在线处理,提示刷卡
                        {
                            string err = park.ListMode == Ralid.Park.BusinessModel.Enum.ParkListMode.CarPlate ? "人工处理" : "请读车场卡";
                            if (this.OnError != null)
                            {
                                this.OnError(this, new OpenCardEventArgs()
                                {
                                    Entrance = entrance, LastError = err
                                });
                            }
                            return;
                        }
                    }
                    else  //多个同车牌号的名单,提示刷卡
                    {
                        string err = park.ListMode == Ralid.Park.BusinessModel.Enum.ParkListMode.CarPlate ? "人工处理" : "请读车场卡";
                        if (this.OnError != null)
                        {
                            this.OnError(this, new OpenCardEventArgs()
                            {
                                Entrance = entrance, LastError = err
                            });
                        }
                        return;
                    }
                }
                //-------------------------------------------结束卡片冲突处理 bruce 2017-3-22
                if (!entrance.IsExitDevice || (park != null && park.IsNested)) //入口或者嵌套车场,
                {
                    ETCPaymentList pr = null;
                    device.RSUWrite(e.OBUInfo, 0, false, out pr); //这里写卡主要是为了让卡片读卡时产生蜂鸣声
                    if (this.OnReadCard != null)
                    {
                        this.OnReadCard(this, args);
                    }
                }
                else
                {
                    HandlePayment(device, args, e, null);
                }
            }
            else
            {
                HandlePayment(device, args, e, null);
            }
        }
Example #4
0
 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);
                 }
             }
         }
     }
 }