예제 #1
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            if (param.DistanceCardParam == null)
            {
                return;
            }
            if (param.DistanceCardParam.Command == PortEnums.DistanceCommands.WriteACard)
            {
                OverTimeManager.Stop();
                if (IssueInfo == null)
                {
                    return;
                }
                try
                {
                    if (param.DistanceCardParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
                    {
                        IssueInfo.Id = CardManager.Insert(IssueInfo);
                    }
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                }
                finally
                {
                    IssueInfo = null;
                }
            }
        }
예제 #2
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            OverTimeManager.Stop();
            try
            {
                if (param.Command.DCommand == PortEnums.DCommands.Default)
                {
                    if (param.DistanceDeviceParam != null && param.DistanceDeviceParam.Command == PortEnums.DistanceCommands.InitializeDevice)
                    {
                        if (param.DistanceDeviceParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
                        {
                            if (!EncryptNewDevice)
                            {
                                byte[] bys = PortAgreement.DistanceCardEncryption(NewPwd);
                                SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, bys);
                                EncryptNewDevice = true;
                                OverTimeManager.Start();
                                return;
                            }
                            else
                            {
                                ViewCallFunction.ViewEncryptMessage("定距卡加密结束。");
                                ViewCallFunction.ViewEncryptOver();
                            }
                        }
                        else
                        {
                            ViewCallFunction.ViewEncryptMessage("定距卡加密失败,请重新操作。");
                            ViewCallFunction.ViewEncryptOver();
                        }
                        EncryptNewDevice = false;
                    }
                    else if (param.DistanceCardParam != null && param.DistanceCardParam.Command == PortEnums.DistanceCommands.ModifyAllCardPwd)
                    {
                        if (param.DistanceCardParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
                        {
                            DistanceCardParameter distanceParam = param.DistanceCardParam;
                            string msg = $"定距卡:{distanceParam.CardNumber} 密码(口令)加密{(distanceParam.CardTypeParameter.CardType != PortEnums.CardTypes.PwdError ? "成功" : "失败")}";
                            ViewCallFunction.ViewEncryptMessage(msg);
                        }
                        else
                        {
                            DeviceNewPwd();
                        }
                        OverTimeManager.Start();
                    }
                }
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewEncryptOver();
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
예제 #3
0
 public void DataReceived(byte[] by)
 {
     try
     {
         PortDataParameter param = DataParsing.Parsing(by);
         if (param.DistanceCardParam == null)
         {
             return;
         }
         OverTimeManager.Stop();
         if (param.DistanceCardParam.Command == PortEnums.DistanceCommands.ReadACard)
         {
             if (param.DistanceCardParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
             {
                 int state = CardManager.LossLists[0].CardReportLoss;
                 by = DistanceLoss.PersonnelLoseOrRecovery(CardManager.LossLists, state == 1 ? 1 : 2);
                 bool ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                 if (!ret)
                 {
                     ViewCallFunction.ViewCloseLoading();
                 }
                 else
                 {
                     OverTimeManager.Start();
                 }
             }
             else
             {
                 ViewCallFunction.ViewCloseLoading();
                 ViewCallFunction.ViewMessage("未能获取到挂失卡,请重新操作。", "2");
             }
         }
         else if (param.DistanceCardParam.Command == PortEnums.DistanceCommands.WriteACard)
         {
             if (param.DistanceCardParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
             {
                 foreach (CardInfo item in CardManager.LossLists)
                 {
                     item.CardReportLoss = item.CardReportLoss == 1 ? 0 : 1;
                 }
                 CardManager.Update(CardManager.LossLists.ToArray());
                 CardManager.LossLists = null;
                 ViewCallFunction.ViewLoseOver();
             }
             else
             {
                 ViewCallFunction.ViewCloseLoading();
             }
         }
     }
     catch (Exception ex)
     {
         Log4Helper.ErrorInfo(ex.Message, ex);
         ViewCallFunction.ViewCloseLoading();
         ViewCallFunction.ViewAlert(ex.Message);
     }
 }
예제 #4
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            OverTimeManager.Stop();
            try
            {
                if (param.FunctionAddress == PortEnums.DealFunctions.Ic)
                {
                    if (param.Command.ICommand == PortEnums.ICommands.EntryptIcDevice)
                    {
                        if (param.IcParam.Result)
                        {
                            EncryptNewPwd();
                        }
                        else
                        {
                            ViewCallFunction.ViewEncryptMessage("加密失败,请重新操作。");
                            ViewCallFunction.ViewEncryptOver();
                        }
                    }
                    else if (param.Command.ICommand == PortEnums.ICommands.EntryptIcCard)
                    {
                        if (param.IcParam != null)
                        {
                            string msg = $"IC 卡加密{(param.IcParam.Result ? "成功" : "失败")}";
                            ViewCallFunction.ViewEncryptMessage(msg);

                            Task.Factory.StartNew(() =>
                            {
                                for (int i = 0; i < 150; i++)
                                {
                                    Thread.Sleep(10);
                                    if (StopEncrypt)
                                    {
                                        StopEncrypt = false;
                                        OverEncrypt();
                                        return;
                                    }
                                }
                                EncryptNewPwd();
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
예제 #5
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            OverTimeManager.Stop();
            if (param.Command.HCommand == PortEnums.HCommands.NumberModify)
            {
                if (param.HostParam != null)
                {
                    ViewCallFunction.ViewDownloadOver(param.HostParam.Result);
                }
            }
        }
예제 #6
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            OverTimeManager.Stop();
            if (param.FunctionAddress == PortEnums.DealFunctions.ProsennelHost)
            {
                if (param.HostParam != null)
                {
                    ViewCallFunction.ViewDownloadOver(param.HostParam.Result);
                }
            }
        }
예제 #7
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            OverTimeManager.Stop();
            if (param.DistanceDeviceParam.Command == PortEnums.DistanceCommands.InitializeDevice)
            {
                string msg = null;
                if (param.DistanceDeviceParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.Success)
                {
                    msg = "定距发行器加密成功";
                }
                else
                {
                    msg = "定距发行器加密失败";
                }
                ViewCallFunction.ViewEncryptMessage(msg);
                ViewCallFunction.ViewEncryptOver();
            }
        }
예제 #8
0
        public void DataReceived(byte[] by)
        {
            try
            {
                if (by[0] == 9 && by[by.Length - 1] == 12)
                {
                    OverTimeManager.Stop();

                    ViewCallFunction.ViewDownloadOver(by.Length == 24);
                }
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
            }
            finally
            {
                Thread.Sleep(100);
                SerialPortManager.Device2.SerialPortDevice.SetBaudRate(WinApi.B9600);
            }
        }
예제 #9
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            OverTimeManager.Stop();
            try
            {
                if (param.FunctionAddress == PortEnums.DealFunctions.Ic && param.Command.ICommand == PortEnums.ICommands.EntryptIcDevice)
                {
                    if (param.IcParam != null)
                    {
                        string msg = $"IC 设备加密{(param.IcParam.Result ? "成功" : "失败")}";
                        ViewCallFunction.ViewEncryptMessage(msg);
                        ViewCallFunction.ViewEncryptOver();
                    }
                }
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }
예제 #10
0
        public void DataReceived(byte[] by)
        {
            PortDataParameter param = DataParsing.Parsing(by);

            if (param.DistanceCardParam == null)
            {
                return;
            }
            if (param.DistanceCardParam.Command == PortEnums.DistanceCommands.ReadAllCard)
            {
                OverTimeManager.Stop();
                if (param.DistanceCardParam.AuxiliaryCommand == PortEnums.AuxiliaryCommands.End)
                {
                    ViewCallFunction.ViewCloseLoading();
                    return;
                }
                try
                {
                    bool exists = CardManager.CardInfos.Exists(e => e.CardNumber == param.DistanceCardParam.CardNumber);
                    if (exists)
                    {
                        return;
                    }
                    CardInfo info = CardManager.GetCardInfo(param.DistanceCardParam.CardNumber);
                    if (info == null)
                    {
                        info          = new CardInfo();
                        info.CardTime = DateTime.Now;
                    }
                    info.CardNumber   = param.DistanceCardParam.CardNumber;
                    info.CardType     = (int)param.DistanceCardParam.CardTypeParameter.CardType;
                    info.CardLock     = param.DistanceCardParam.CardTypeParameter.CardLock;
                    info.CardDistance = param.DistanceCardParam.CardTypeParameter.Distance;
                    info.Electricity  = param.DistanceCardParam.CardTypeParameter.Electricity;
                    if (info.CardType <= 3)
                    {
                        if (param.DistanceCardParam.FunctionByteParam != null)
                        {
                            if (info.Id > 0 && info.CardType < 3)
                            {
                                info.CardType = (int)param.DistanceCardParam.FunctionByteParam.RegistrationType;
                                if (info.CardType == 1)//人卡或组合卡
                                {
                                    info.ParkingRestrictions = param.DistanceCardParam.FunctionByteParam.ParkingRestrictions;
                                }
                            }
                            info.CardReportLoss = param.DistanceCardParam.FunctionByteParam.Loss;
                            info.ViceCardCount  = param.DistanceCardParam.FunctionByteParam.ViceCardCount;
                            info.Synchronous    = param.DistanceCardParam.FunctionByteParam.Synchronous;
                            info.InOutState     = param.DistanceCardParam.FunctionByteParam.InOutState;
                            info.CardCount      = param.DistanceCardParam.Count;
                        }
                    }
                    CardManager.CardInfos.Add(info);
                    ViewCallFunction.ViewDisplayReadCardInfo(info);
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                }
                finally
                {
                    OverTimeManager.Start();
                }
            }
        }