Example #1
0
        //显示通知
        protected virtual void ShowEventMsg(string strMsg, MsgType type)
        {
            switch (type)
            {
            case MsgType.FaceOk:
                ClearValue();
                if (IsAudio)
                {
                    Dispatcher.InvokeAsync(() => FaceFun.PlayMp3("sound\\检票成功.mp3"));
                }
                IdCardFunc.Beep();
                break;

            case MsgType.FaceErr:
                HideShow(2);
                ClearValue();
                if (IsAudio)
                {
                    Dispatcher.InvokeAsync(() => FaceFun.PlayMp3("sound\\检票失败.mp3"));
                }
                break;
            }
        }
        /// <summary> 读写IC卡 </summary>
        private int CheckICard()
        {
            FaceFun.TimeStart();
            var icInfo = new IdCardFunc.TicketCardInfo();
            int i      = IdCardFunc.GetTicketData_New(ref icInfo);

            if (i == 0)
            {
                if (IsIdSame && (Cvr.Info.Number != icInfo.IDCard))
                {
                    ShowEventMsg("身份证号码与票面不符合!", MsgType.Info);
                }
                else
                {
                    tempTime = DateTime.Now;
                    //检查白名单验证
                    if (!CheckWhite(icInfo.IDCard))
                    {
                        return(1);
                    }
                    //写入本地记录并且通知
                    var info = new SessionsInfo
                    {
                        SessionId    = MyMatch.SessionId,
                        CreateDate   = DateTime.Now,
                        Name         = MyMatch.SessionName,
                        IdNo         = icInfo.IDCard,
                        IdCardPhoto  = IrAdvanced.ReadBytesFromFile(FaceFun.BaseDir + "\\pic.bmp"),
                        TakePhoto    = PhotoOk,
                        FaceData     = FaceFun.StructToBytes(CameraRft),
                        IdAddress    = "",
                        TicketType   = 1,
                        TicketNo     = icInfo.CardNo,
                        Area         = icInfo.StadiumArea,
                        Row          = icInfo.Row,
                        Seat         = icInfo.Position,
                        TelNo        = IrAdvanced.ReadString("TelNo"),
                        TelArea      = IrAdvanced.ReadString("TelArea"),
                        BuyName      = icInfo.Name,
                        BuyPhoto     = null,
                        BuyDate      = null,
                        ValidateType = 2,
                        SyncTime     = null,
                        Status       = 0,
                        Remark       = "",
                        UserName     = AftUserName,
                    };
                    if (FaceFun.AddSessions(info) > 0)
                    {
                        Dispatcher.InvokeAsync(() =>
                        {
                            ShowEventMsg("检票成功", MsgType.FaceOk);
                            MyArea.Text = string.Format("区域:{0}{1}排{2}座", info.Area, info.Row, info.Seat);
                            MyNum.Text  = "票号:" + info.TicketNo;
                            MyType.Text = "类型:年票";
                            MyTime.Text = "时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                        });
                    }
                }
            }
            else if (i == 16)
            {
                i.ToString().ToSaveLog("已刷卡:");
                var str = (tempTime == null) ? "拒绝入场" : string.Format("{0}入场", tempTime);
                ShowEventMsg("一天只能入场一次!\n" + str, MsgType.InfoErr);
                ShowEventMsg("检票失败", MsgType.FaceErr);
                Thread.Sleep(500);
            }
            else if (i == 1)    //未放卡
            {
                tempTime = null;
            }
            else
            {
                i.ToString().ToSaveLog("IC卡读卡失败:");
                Thread.Sleep(300);
            }
            FaceFun.TimeStop("IC读写耗时:");
            return(i);
        }
        /// <summary> 读写IC卡 </summary>
        private int CheckICard()
        {
            FaceFun.TimeStart();
            var icInfo = new IdCardFunc.TicketCardInfo();
            int i      = IdCardFunc.GetTicketData_New(ref icInfo);

            if (i == 0)
            {
                if (icInfo.IDCard.IsNullOrEmpty())
                {
                    "读卡成功,但身份证号码为空.".ToSaveLog(); return(1);
                }
                //黑名单检查
                if (IsCheckBlack && FaceFun.IsInBlack(icInfo.IDCard))
                {
                    LeftImg.Visibility = Visibility.Visible;
                }
                //判断是否超过时限
                var now  = DateTime.Now;
                var time = IrAdvanced.StringToDateTime(icInfo.Reserved2);
                if ((time.Year <= now.Year && time.Month <= now.Month && time.Day < now.Day))
                {
                    //读取数据库白名单记录
                    white = FaceFun.CheckWhiteName(icInfo.IDCard);
                    if (white != null)
                    {
                        Bitmap photobitmap = IrAdvanced.GetBitmapFormByte(white.Value.IdCardPhoto);
                        Dispatcher.Invoke(() =>
                        {
                            BitmapImage photoImg = IrAdvanced.GetBitmapImageFormByte(white.Value.IdCardPhoto);
                            CvrImgMain.Source    = CvrImg.Source = photoImg;
                        });
                        Rft2 = Face.FaceTz(photobitmap);
                        if (Face.TzIr.ToInt32() == 0)
                        {
                            icPass = true;
                            ShowEventMsg("正在进行人脸识别", MsgType.Info);
                        }
                        else
                        {
                            ShowEventMsg("无法识别该照片人脸特征码", MsgType.InfoErr);
                        }
                    }
                    else
                    {
                        ShowEventMsg("白名单不存在此年票记录.", MsgType.InfoErr);
                    }
                }
                else
                {
                    Dispatcher.InvokeAsync(() =>
                    {
                        ShowEventMsg(string.Format("一天只能入场一次!\n{0}已使用", icInfo.Reserved2), MsgType.InfoErr);
                        MyArea.Text = string.Format("区域:{0}区{1}排{2}座", icInfo.StadiumArea, icInfo.Row, icInfo.Position);
                        MyNum.Text  = "票号:" + icInfo.CardNo;
                        MyType.Text = "类型:年票";
                        MyTime.Text = "时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                        ShowEventMsg("检票失败", MsgType.FaceErr);
                    });
                }
            }
            FaceFun.TimeStop("IC读写耗时:");
            return(i);
        }
        /// <summary> 读写IC卡 </summary>
        private int CheckICard()
        {
            try
            {
                "准备请求读卡".ToSaveLog("CheckIcard:");
                FaceFun.TimeStart();
                var icInfo = new IdCardFunc.TicketCardInfo();
                int i      = IdCardFunc.GetTicketData_New(ref icInfo);
                if (i == 0)
                {
                    tempTime = DateTime.Now;
                    icInfo.IDCard.ToSaveLog("读取到IC卡:");
                    //判断是否超过时限
                    if (!icInfo.IDCard.IsNullOrEmpty())
                    {
                        Dispatcher.Invoke(() => MyIdNo.Text = icInfo.IDCard);
                    }
                    var flag = true;
                    Dispatcher.Invoke(() =>
                    { //黑名单检查
                        if (IsCheckBlack && FaceFun.IsInBlack(MyIdNo.Text))
                        {
                            LeftImg.Visibility = Visibility.Visible;
                        }
                        if (IsCheckIdNo && MyIdNo.Text.IsNullOrEmpty())
                        {
                            flag = false;
                        }
                    });
                    if (!flag)
                    {
                        ShowEventMsg("请录入身份证号码.", MsgType.TipErr); return(1);
                    }
                    //检查白名单验证
                    if (!CheckWhite(icInfo.IDCard))
                    {
                        return(1);
                    }
                    PhotoOk = null;
                    lock (Obj)
                    {
                        if (MyCapture != null)
                        {
                            "拍照获取Photo.".ToSaveLog("");
                            using (var myMap = MyCapture.QueryFrame())
                            {
                                if (myMap != null)
                                {
                                    PhotoOk = FaceFun.BitmapToByte(myMap.Bitmap);
                                }
                                else
                                {
                                    "未取得摄像头Mat数据".ToSaveLog("OnlyQrView.BarCode_OnKeyUp:");
                                }
                            }
                        }
                    }
                    //写入本地记录并且通知
                    var info = new SessionsInfo
                    {
                        SessionId    = MyMatch.SessionId,
                        CreateDate   = DateTime.Now,
                        Name         = MyMatch.SessionName,
                        IdNo         = icInfo.IDCard,
                        IdCardPhoto  = null,
                        TakePhoto    = PhotoOk,
                        FaceData     = null,
                        IdAddress    = "",
                        TicketType   = 1,
                        TicketNo     = icInfo.CardNo,
                        Area         = icInfo.StadiumArea,
                        Row          = icInfo.Row,
                        Seat         = icInfo.Position,
                        TelNo        = IrAdvanced.ReadString("TelNo"),
                        TelArea      = IrAdvanced.ReadString("TelArea"),
                        BuyName      = icInfo.Name,
                        BuyPhoto     = null,
                        BuyDate      = null,
                        ValidateType = 4,
                        SyncTime     = null,
                        Status       = 0,
                        Remark       = "",
                        UserName     = AftUserName,
                    };
                    if (FaceFun.AddSessions(info) > 0)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            MyArea.Text = string.Format("区域:{0}区{1}排{2}座", info.Area, info.Row, info.Seat);
                            MyNum.Text  = "票号:" + info.TicketNo;
                            MyType.Text = "类型:年票";
                            MyTime.Text = "时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                        });
                        ShowEventMsg("检票成功", MsgType.FaceOk);
                        Thread.Sleep(500);
                    }

                    FaceFun.TimeStop("IC读写耗时:");
                }
                else if (i == 16)
                {
                    i.ToString().ToSaveLog("已刷卡:");
                    var str = (tempTime == null) ? "拒绝入场" : string.Format("{0}入场", tempTime);
                    ShowEventMsg("一天只能入场一次!\n" + str, MsgType.FaceErr);
                    Thread.Sleep(500);
                }
                else if (i == 1)    //未放卡
                {
                    tempTime = null;
                }
                else
                {
                    i.ToString().ToSaveLog("IC卡读卡失败:");
                    Thread.Sleep(300);
                }

                icPass = false;
                return(i);
            }
            catch (Exception ex)
            {
                ex.ToSaveLog("CheckICard失败:");
            }
            icPass = false;
            return(0);
        }