private static RChinaCard GetChinaCard(RChinaCardByte Data) { RChinaCard ChinaCard = new RChinaCard(); ChinaCard.Name = Encoding.Unicode.GetString(Data.Name); ChinaCard.Name = ChinaCard.Name.Replace("\0", ""); ChinaCard.Name = ChinaCard.Name.Trim(); ChinaCard.Sex = "男"; if (Data.Sex == 0x30) { ChinaCard.Sex = "女"; } string na = Encoding.Unicode.GetString(Data.Nation); string[] nationality = { "汉", "蒙古", "回", "藏", "维吾尔", "苗", "彝", "壮", "布依", "朝鲜", "满", "侗", "瑶", "白", "土家", "哈尼", "哈萨克", "傣", "黎", "傈僳", "佤", "畲", "高山", "拉祜", "水", "东乡", "纳西", "景颇", "柯尔克孜", "土", "达斡尔", "仫佬", "羌", "布朗", "撒拉", "毛南", "仡佬", "锡伯", "阿昌", "普米", "塔吉克", "怒", "乌孜别克", "俄罗斯", "鄂温克", "德昂","保安", "裕固", "京", "塔塔尔", "独龙", "鄂伦春", "赫哲", "门巴", "珞巴", "基诺" }; int c = Convert.ToInt16(na); if (c > 0) { c--; } if (c < nationality.Length) { ChinaCard.Nation = nationality[c]; } ChinaCard.Birthday = StringToDateTime(ASCii2Char(Data.Birthday)); ChinaCard.Address = Encoding.Unicode.GetString(Data.Address); ChinaCard.Card = ASCii2Char(Data.Card); ChinaCard.Dept = Encoding.Unicode.GetString(Data.Dept); ChinaCard.DateFrm = StringToDateTime(ASCii2Char(Data.DateFrm)); ChinaCard.DateTo = StringToDateTime(ASCii2Char(Data.DateTo)); return(ChinaCard); }
private void DoFormCardEvent() { Boolean Ack; RTCPCardData CardData; byte vopenDoor = 0; UInt16 time = 5; string card = ""; string voice = ""; string name = ""; string note = ""; string etime = ""; byte times = 0; byte Second, Minute, Hour, Day, Month; int Year; int Valuelen = BufferRX[Loc_Len + 1] + BufferRX[Loc_Len + 0] * 256 - 6 - 10 - 7 - 16 - 4; if (Valuelen > 2048) { Valuelen = 0; } RAcsEvent Event = new RAcsEvent(); CardData = (RTCPCardData)ByteToStruct(BufferRX, typeof(RTCPCardData)); Event.SerialNo = Encoding.ASCII.GetString(CardData.Serial); Serial = Event.SerialNo; Event.ID = Encoding.ASCII.GetString(CardData.ID); Event.Reader = Convert.ToByte(CardData.Reader & 0x01); Event.Door = CardData.door; Event.EventType = CardData.DataType; Second = CardData.DateTime[5]; Minute = (CardData.DateTime[4]); Hour = (CardData.DateTime[3]); Day = (CardData.DateTime[2]); Month = (CardData.DateTime[1]); Year = (CardData.DateTime[0]) + 2000; Event.Datetime = GetDatetime(Second, Minute, Hour, Day, Month, Year); Event.Value = Convert.ToString(CardData.Card); switch (Event.EventType) { case NET_DATA_TYPE_CARD: Event.Value = Convert.ToString(CardData.Card); // Convert.ToString(CardData.Value); card = Convert.ToString(CardData.Card); break; case NET_DATA_TYPE_ORCode: Event.Value = Encoding.UTF8.GetString(CardData.Value); if (!string.IsNullOrEmpty(Event.Value)) { Event.Value = Event.Value.Trim().Replace("\n", string.Empty).Replace("\r", string.Empty).Replace("\0", string.Empty); } break; // case NET_DATA_TYPE_DATA: Event.Value = Encoding.ASCII.GetString(CardData.Value); if (!string.IsNullOrEmpty(Event.Value)) { Event.Value = Event.Value.Trim().Replace("\n", string.Empty).Replace("\r", string.Empty).Replace("\0", string.Empty); } break; // case NET_DATA_TYPE_CHINA: RChinaCardByte ChinaCardData = (RChinaCardByte)ByteToStruct(CardData.Value, typeof(RChinaCardByte)); RChinaCard ChinaCard = GetChinaCard(ChinaCardData); if (!string.IsNullOrEmpty(ChinaCard.Name)) { Event.Value = ChinaCard.Name + " " + ChinaCard.Card; } //if (ChinaCardData.HasImage == 0x01) // SaveEmpwltPhotoBytes(ChinaCard.Card , ChinaCardData.Photo); break; case NET_DATA_TYPE_PIN: Event.Value = Convert.ToString(CardData.Value); if (!string.IsNullOrEmpty(Event.Value)) { Event.Value = Event.Value.Trim().Replace("\n", "").Replace("\r", "").Replace("\0", ""); } break; case NET_DATA_TYPE_FINGER: case NET_DATA_TYPE_BIGDATA: int len = BufferRX[5] * 256 + BufferRX[6] - (6 + 10 + 1 + 1 + 4 + 1 + 16 + 4); // clear head byte[] vdata = new byte[len]; Array.Copy(CardData.Value, 0, vdata, 0, len); Event.Value = BitConverter.ToString(vdata).Replace("-", " "); if (!string.IsNullOrEmpty(Event.Value)) { Event.Value = Event.Value.Trim().Replace("\n", string.Empty).Replace("\r", string.Empty).Replace("\0", string.Empty); } break; // case NET_DATA_TYPE_BASE64: CardData.Value[Valuelen] = 0; Event.Value = Encoding.ASCII.GetString(CardData.Value, 0, Valuelen); if (!string.IsNullOrEmpty(Event.Value)) { Event.Value = Event.Value.Trim().Replace("\n", string.Empty).Replace("\r", string.Empty).Replace("\0", string.Empty); } break; // case NET_DATA_TYPE_RFID: Event.Value = bytesToHexString(CardData.Value); if (!string.IsNullOrEmpty(Event.Value)) { Event.Value = Event.Value.Trim().Replace("\n", string.Empty).Replace("\r", string.Empty).Replace("\0", string.Empty); } break; // } Event.Online = true; Event.EType = 1; Ack = true; vopenDoor = 0; byte relay = Event.Reader; OnEventHandler(Event, ref time, ref card, ref voice, ref name, ref note, ref etime, ref relay, ref vopenDoor, ref Ack); if (Ack) { AnsEvent(0x54, relay, vopenDoor, time, Event.Reader, 5, card, voice, name, note, etime); } }