public static string GLogType(int opertationType) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 4; i++) { if (0 != Zd2911Utils.BitCheck(opertationType, i)) { switch (i) { case 0: sb.Append("F "); break; case 1: sb.Append("P "); break; case 2: sb.Append("C "); break; case 3: sb.Append("I "); break; } } } return(sb.ToString()); }
private void EnrollDetailForm_Load(object sender, EventArgs e) { txt_UserId.Text = user.DIN.ToString(); Enroll enroll = user.Enrolls[0]; SetPrivilege(); for (int i = 0; i < Zd2911Utils.MaxFingerprintCount; i++) { if (0 != Zd2911Utils.BitCheck((int)enroll.EnrollType, i)) { clb_Fp.SetItemChecked(i, true); } } if (0 != Zd2911Utils.BitCheck((int)enroll.EnrollType, 10)) { clb_Fp.SetItemChecked(10, true); } if (0 != Zd2911Utils.BitCheck((int)enroll.EnrollType, 11)) { clb_Fp.SetItemChecked(11, true); } }
/// <summary> /// /// </summary> /// <param name="opertationType"></param> /// <returns></returns> public static List <CheckInOptions> GLogType(int opertationType) { var options = new List <CheckInOptions>(); for (int i = 0; i < 4; i++) { if (0 != Zd2911Utils.BitCheck(opertationType, i)) { switch (i) { case 0: options.Add(CheckInOptions.FingerPrint); break; case 1: options.Add(CheckInOptions.Password); break; case 2: options.Add(CheckInOptions.Card); break; case 3: options.Add(CheckInOptions.Wiegand); break; } } } return(options); }
public static Contract.Model.UserInfo ToModel(User deviceUser) { var userInfo = new Contract.Model.UserInfo() { UserId = (int)deviceUser.DIN }; try { userInfo.UserName = deviceUser.UserName; userInfo.Role = (UserRole)deviceUser.Privilege; userInfo.Comment = deviceUser.Comment; userInfo.UserStatus = deviceUser.Enable; userInfo.DepartmentId = deviceUser.Department; userInfo.AccessTimeZoneId = deviceUser.AccessTimeZone; var enroll = deviceUser.Enrolls.First(); var services = new List <CredentialService>(); if (!string.IsNullOrWhiteSpace(enroll.Password)) { services.Add(new PasswordService() { Enabled = true, Password = ConvertObject.ToPrettyString(enroll.Password) }); } if (!string.IsNullOrWhiteSpace(enroll.CardID)) { services.Add(new CredentialCardService() { Enabled = true, CardNumber = enroll.CardID }); } int enrollType = (Int32)enroll.EnrollType; for (int index = 0; index < Zd2911Utils.MaxFingerprintCount; index++) { if (Zd2911Utils.BitCheck(enrollType, index) != 0) { byte[] fpBytes = enroll.Fingerprint.Skip(index * Zd2911Utils.MaxFingerprintLength).Take(Zd2911Utils.MaxFingerprintLength).ToArray(); services.Add(new FingerPrintService() { Enabled = true, FingerPrintData = ConvertObject.ConvertByteToHex(fpBytes) }); } } userInfo.CredentialServices = services; return(userInfo); } catch (Exception ex) { Log.Error(ex); throw; } }
private bool UploadSound(byte[] soundBuffer) { int chunkHeaderLen = 0; byte[] chunkHeader = Zd2911Utils.CreateChunkHeader(soundBuffer, dataChunk); int len = BitConverter.ToInt32(chunkHeader, 4); int downSize = len + 4; byte[] downData = new byte[downSize]; Array.Copy(chunkHeader, 4, downData, 0, 4); Array.Copy(soundBuffer, dataChunk + chunkHeaderLen, downData, 4, len); int unit = 1024 * 60, i; bool result = false; int n = (int)downSize / unit; object extraProperty = new object(); object extraData = new object(); for (i = 0; i < n; i++) { byte[] dataBytes = new byte[unit]; Array.Copy(downData, i * unit, dataBytes, 0, unit); List <int> soundParam = new List <int>(); soundParam.Add(cbo_SoundType.SelectedIndex + 8); soundParam.Add(i * unit); extraProperty = soundParam; extraData = dataBytes; result = deviceConnection.SetProperty(DeviceProperty.UploadSound, extraProperty, device, extraData); if (false == result) { return(false); } } n = downSize % unit; if (n > 0) { byte[] dataBytes = new byte[n]; Array.Copy(downData, i * unit, dataBytes, 0, n); List <int> soundParam = new List <int>(); soundParam.Add(cbo_SoundType.SelectedIndex + 8); soundParam.Add(i * unit); extraProperty = soundParam; extraData = dataBytes; result = deviceConnection.SetProperty(DeviceProperty.UploadSound, extraProperty, device, extraData); if (false == result) { return(false); } } return(result); }
private bool CheckWaveFormat(byte[] buffer, ref int offSet) { offSet = 0; string riff = Encoding.ASCII.GetString(buffer, 0, 4); string wave = Encoding.ASCII.GetString(buffer, 8, 4); string fmt = Encoding.ASCII.GetString(buffer, 12, 4); if (false == riff.Equals("RIFF") || false == wave.Equals("WAVE") || false == fmt.Equals("fmt ")) { MessageBox.Show("Incorrect Wave Format", "Pormpt", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } int waveFormatSize = BitConverter.ToInt32(buffer, 16); byte[] waveBytes = new byte[18]; Array.Copy(buffer, 20, waveBytes, 0, waveBytes.Length); UInt16 formatTag = BitConverter.ToUInt16(waveBytes, 0); if (1 != formatTag) { MessageBox.Show("Audio Format is not PCM", "Pormpt", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } UInt16 channels = BitConverter.ToUInt16(waveBytes, 2); if (1 != channels) { MessageBox.Show("Channels is not Stereo", "Pormpt", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } UInt32 samplesPerSec = BitConverter.ToUInt32(waveBytes, 4); if (22050 != samplesPerSec) { MessageBox.Show("Audio sample rate is not 22.05KHZ", "Pormpt", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } UInt16 bitsPerSample = BitConverter.ToUInt16(waveBytes, 14); if (16 != bitsPerSample) { MessageBox.Show("Audio sample size is not 8bit", "Pormpt", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } int chunkHeaderLen = 0; int tmpOffSet = 20 + waveFormatSize; byte[] chunkHeader = Zd2911Utils.CreateChunkHeader(buffer, tmpOffSet); string fact = Encoding.ASCII.GetString(chunkHeader, 0, 4); int len = BitConverter.ToInt32(chunkHeader, 4); if (fact.Equals("fact")) { offSet = offSet + chunkHeaderLen + len; } offSet = tmpOffSet; chunkHeader = Zd2911Utils.CreateChunkHeader(buffer, offSet); string data = Encoding.ASCII.GetString(chunkHeader, 0, 4); len = BitConverter.ToInt32(chunkHeader, 4); if (false == data.Equals("data")) { MessageBox.Show("Incorrect Wave Format", "Pormpt", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } if (1024 * 75 < len) { MessageBox.Show("Data size is too big. Must be less than 75K byte", "Pormpt", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } return(true); }
public static void UpdateSystemInfo(ref User deviceUser, Contract.Model.UserInfo userInfo) { if (!string.IsNullOrWhiteSpace(userInfo.UserName)) { deviceUser.UserName = userInfo.UserName; } if (userInfo.Role != null) { deviceUser.Privilege = (Int32)userInfo.Role; } if (!string.IsNullOrWhiteSpace(userInfo.Comment)) { deviceUser.Comment = userInfo.Comment; } if (userInfo.UserStatus != null) { deviceUser.Enable = userInfo.UserStatus.Value; } if (userInfo.DepartmentId != null) { deviceUser.Department = userInfo.DepartmentId.Value; } if (userInfo.AccessTimeZoneId != null) { deviceUser.AccessTimeZone = userInfo.AccessTimeZoneId.Value; } if (userInfo.CredentialServices != null) { var enroll = deviceUser.Enrolls.First(); int enrollType = (int)enroll.EnrollType; foreach (var service in userInfo.CredentialServices) { if (service is PasswordService) { var passwordService = service as PasswordService; if (passwordService.Enabled) { if (Zd2911Utils.BitCheck(enrollType, (int)EnrollType.Password) == 0) { enrollType += Zd2911Utils.SetBit(0, (int)EnrollType.Password); } enroll.Password = passwordService.Password; } } else if (service is CredentialCardService) { var credentialCardService = service as CredentialCardService; if (credentialCardService.Enabled) { if (Zd2911Utils.BitCheck(enrollType, (int)EnrollType.Card) == 0) { enrollType += Zd2911Utils.SetBit(0, (int)EnrollType.Card); //password is 10, fp0-fp9, card is 11 } enroll.CardID = credentialCardService.CardNumber; } } else if (service is FingerPrintService) { var fpService = service as FingerPrintService; if (fpService.Enabled) { if (Zd2911Utils.BitCheck(enrollType, fpService.Index) == 0) { enrollType += Zd2911Utils.SetBit(0, fpService.Index); } byte[] bytesFromText = ConvertObject.ConvertStringToBytes(fpService.FingerPrintData); Array.Copy(bytesFromText, 0, enroll.Fingerprint, fpService.Index * Zd2911Utils.MaxFingerprintLength, bytesFromText.Length); } } } enroll.EnrollType = (EnrollType)enrollType; } }