Пример #1
0
 private DateTime ReadDate(byte[] data)
 {
     if (data.Length == 3)
     {
         if (data[0] == 0x00 && data[1] == 0x00 && data[2] == 0x00)
         {
             return(FromDate);
         }
         else if (data[0] == 0xFF && data[1] == 0xFF && data[2] == 0xFF)
         {
             return(FromDate);
         }
         else
         {
             return(new DateTime(2000 + BCDConverter.BCDtoInt(data[0]), BCDConverter.BCDtoInt(data[1]), BCDConverter.BCDtoInt(data[2])));
         }
     }
     else
     {
         throw new InvalidCastException("指定的转换无效,字节数组必需为三个字节");
     }
 }
Пример #2
0
        /// <summary>
        /// 设置卡片信息
        /// </summary>
        /// <param name="card"></param>
        /// <param name="data"></param>
        /// <param name="keepStaus"></param>
        /// <returns></returns>
        private void SetCardInfo(CardInfo info, byte[] data, bool keepStaus)
        {
            int block0 = 0 * 16;
            int block1 = 1 * 16;
            int block2 = 2 * 16;

            byte[] tempbytes = new byte[4];

            #region 块0
            info.CardVersion = data[block0 + 0];

            if (!keepStaus)
            {
                info.Status = (data[block0 + 1] & 0x80) == 0x80 ? CardStatus.Enabled : CardStatus.Disabled;
            }

            //List<CardType> cardTypes = null;
            switch (data[block0 + 1] & 0x0F)
            {
            case 0x00:
                info.CardType = CardType.VipCard;
                break;

            case 0x01:
                info.CardType = CardType.OwnerCard;
                break;

            case 0x02:
                info.CardType = CardType.MonthRentCard;
                break;

            case 0x03:
                info.CardType = CardType.PrePayCard;
                break;

            case 0x04:
                info.CardType = CardType.TempCard;
                break;

            case 0x05:
                info.CardType = CardType.UserDefinedCard1.GetFirstCardTypeFromBase;
                break;

            case 0x06:
                info.CardType = CardType.UserDefinedCard2.GetFirstCardTypeFromBase;
                break;

            case 0x0E:
                info.CardType = CardType.OperatorCard;
                break;

            default:
                info.CardType = CardType.TempCard;
                break;
            }
            info.CarType = (byte)((data[block0 + 1] >> 4) & 0x03);

            info.OnlineHandleWhenOfflineMode = (data[block0 + 2] & 0x01) != 0x01;
            info.CanRepeatIn       = (data[block0 + 2] & 0x04) != 0x04;
            info.CanRepeatOut      = (data[block0 + 2] & 0x08) != 0x08;
            info.WithCount         = (data[block0 + 2] & 0x10) == 0x10;
            info.CanEnterWhenFull  = (data[block0 + 2] & 0x20) != 0x20;
            info.HolidayEnabled    = (data[block0 + 2] & 0x40) == 0x40;
            info.EnableWhenExpired = (data[block0 + 2] & 0x80) != 0x80;

            info.AccessID = data[block0 + 3];

            if (data[block0 + 4] == 0x00 && data[block0 + 5] == 0x00 && data[block0 + 6] == 0x00)
            {
                info.ActivationDate = DateTime.MaxValue;
            }
            else if (data[block0 + 4] == 0xFF && data[block0 + 5] == 0xFF && data[block0 + 6] == 0xFF)
            {
                info.ActivationDate = DateTime.MinValue;
            }
            else
            {
                info.ActivationDate = new DateTime(2000 + BCDConverter.BCDtoInt(data[block0 + 4]), BCDConverter.BCDtoInt(data[block0 + 5]), BCDConverter.BCDtoInt(data[block0 + 6]));
            }

            if (data[block0 + 6] == 0x00 && data[block0 + 8] == 0x00 && data[block0 + 9] == 0x00)
            {
                info.ValidDate = DateTime.MinValue;
            }
            else if (data[block0 + 7] == 0xFF && data[block0 + 8] == 0xFF && data[block0 + 9] == 0xFF)
            {
                info.ValidDate = DateTime.MaxValue;
            }
            else
            {
                info.ValidDate = new DateTime(2000 + BCDConverter.BCDtoInt(data[block0 + 7]), BCDConverter.BCDtoInt(data[block0 + 8]), BCDConverter.BCDtoInt(data[block0 + 9]));
            }

            #endregion

            #region 块1
            info.ParkingStatus  = (data[block1 + 0] & 0x01) != 0x01 ? ParkingStatus.In : 0;
            info.ParkingStatus |= (data[block1 + 0] & 0x02) != 0x02 ? ParkingStatus.IndoorIn : 0;
            info.ParkingStatus |= (data[block1 + 0] & 0x08) != 0x08 ? ParkingStatus.PaidBill : 0;
            info.ParkingStatus |= (data[block1 + 0] & 0x40) != 0x40 ? ParkingStatus.NestedParkMarked : 0;

            if (data[block1 + 1] == 0x00 && data[block1 + 2] == 0x00 && data[block1 + 3] == 0x00 && data[block1 + 4] == 0x00)
            {
                //第1层车场入场时间无效
            }
            else
            {
                tempbytes[0]      = data[block1 + 1];
                tempbytes[1]      = data[block1 + 2];
                tempbytes[2]      = data[block1 + 3];
                tempbytes[3]      = data[block1 + 4];
                info.LastDateTime = FromDate.AddSeconds(SEBinaryConverter.BytesToLong(tempbytes));
            }

            if (data[block1 + 5] == 0x00 && data[block1 + 6] == 0x00 && data[block1 + 7] == 0x00 && data[block1 + 8] == 0x00)
            {
                //缴费时间无效
            }
            else
            {
                tempbytes[0]      = data[block1 + 5];
                tempbytes[1]      = data[block1 + 6];
                tempbytes[2]      = data[block1 + 7];
                tempbytes[3]      = data[block1 + 8];
                info.PaidDateTime = FromDate.AddSeconds(SEBinaryConverter.BytesToLong(tempbytes));
            }

            tempbytes[0] = data[block1 + 9];
            tempbytes[1] = data[block1 + 10];
            tempbytes[2] = data[block1 + 11];
            tempbytes[3] = 0x00;
            info.ParkFee = SEBinaryConverter.BytesToInt(tempbytes) / 100.00M;

            tempbytes[0]      = data[block1 + 12];
            tempbytes[1]      = data[block1 + 13];
            tempbytes[2]      = data[block1 + 14];
            tempbytes[3]      = 0x00;
            info.TotalPaidFee = SEBinaryConverter.BytesToInt(tempbytes) / 100.00M;
            //info.TotalFee = SEBinaryConverter.BytesToInt(tempbytes) / 100.00M;


            #endregion

            #region 块2
            tempbytes[0] = data[block2 + 0];
            tempbytes[1] = data[block2 + 1];
            tempbytes[2] = data[block2 + 2];
            tempbytes[3] = 0x00;
            info.Balance = SEBinaryConverter.BytesToInt(tempbytes) / 100.00M;

            Array.Resize(ref tempbytes, 9);
            Array.Copy(data, block2 + 6, tempbytes, 0, 9);
            if (BytesIsAllZero(tempbytes))
            {
                info.CarPlate = string.Empty;
            }
            else
            {
                info.CarPlate     = Encoding.GetEncoding("gb2312").GetString(tempbytes);
                info.LastCarPlate = info.CarPlate;////脱机模式时,卡片的最后一次识别车牌保存在卡片里的车牌号码中
            }
            #endregion
        }