void CopyProperties(GKUser user) { Fio = user.Fio; Password = user.Password; UserType = user.UserType; ExpirationDate = user.ExpirationDate; }
public PmfUserDetailsViewModel(PmfUsersViewModel parentViewModel, GKUser user = null) { _parentViewModel = parentViewModel; UserTypes = new ObservableCollection<GKCardType>(Enum.GetValues(typeof(GKCardType)).OfType<GKCardType>()); UserTypes.Remove(GKCardType.Employee); if (user == null) { _isNew = true; Title = "Создание пользователя"; var password = parentViewModel.Users.Count > 0 ? parentViewModel.Users.Max(x => x.User.Password) + 1 : 1; user = new GKUser { Password = password, ExpirationDate = DateTime.Now.AddYears(1), Fio = "Новый пользователь", UserType = GKCardType.Operator }; } else { _oldUser = user; Title = "Редактирование пользователя " + user.Fio; } CopyProperties(user); }
public static OperationResult<bool> AddOrEditCard(GKControllerCardSchedule controllerCardSchedule, SKDCard card, string employeeName, int gkCardNo = 0, bool isNew = true, RubezhDAL.DataClasses.DbService dbService = null) { if (gkCardNo == 0) { if (dbService == null) { using (var skdDatabaseService = new RubezhDAL.DataClasses.DbService()) { gkCardNo = skdDatabaseService.GKCardTranslator.GetFreeGKNo(controllerCardSchedule.ControllerDevice.GetGKIpAddress(), card.Number, out isNew); } } else gkCardNo = dbService.GKCardTranslator.GetFreeGKNo(controllerCardSchedule.ControllerDevice.GetGKIpAddress(), card.Number, out isNew); } var user = new GKUser { GkNo = (ushort)gkCardNo, ExpirationDate = card.EndDate, Fio = employeeName, GkLevel = (byte)card.GKLevel, GkLevelSchedule = (byte)card.GKLevelSchedule, Password = card.Number, UserType = card.GKCardType }; var result = AddOrEditUser(user, controllerCardSchedule.ControllerDevice, isNew, controllerCardSchedule.CardSchedules); if (result.HasError) return result; using (var skdDatabaseService = new RubezhDAL.DataClasses.DbService()) { skdDatabaseService.GKCardTranslator.AddOrEdit(controllerCardSchedule.ControllerDevice.GetGKIpAddress(), gkCardNo, card.Number, employeeName); } return new OperationResult<bool>(true); }
public GKUserViewModel(GKUser user, bool isDevice) { User = user; IsDevice = isDevice; }
public static OperationResult<bool> AddOrEditUser(GKUser user, GKDevice device, bool isNew = true, List<GKCardSchedule> allCardSchedules = null) { if (allCardSchedules == null) allCardSchedules = new List<GKCardSchedule>(); var bytes = new List<byte>(); bytes.AddRange(BytesHelper.ShortToBytes(user.GkNo)); bytes.Add((byte)user.UserType); bytes.Add(user.IsActive ? (byte)0 : (byte)1); var nameBytes = BytesHelper.StringDescriptionToBytes(user.Fio); bytes.AddRange(nameBytes); bytes.AddRange(BytesHelper.IntToBytes((int)user.Password)); bytes.Add(user.GkLevel); bytes.Add(user.GkLevelSchedule); bytes.Add(0); bytes.Add(0); var secondsPeriod = (new DateTime(user.ExpirationDate.Year, user.ExpirationDate.Month, user.ExpirationDate.Day) - new DateTime(2000, 1, 1)).TotalSeconds; bytes.AddRange(BytesHelper.IntToBytes((int)secondsPeriod)); if (allCardSchedules.Count == 0) { var bytesCount = bytes.Count; for (int i = 0; i < 256 - bytesCount; i++) { bytes.Add(0); } } else { for (int packNo = 0; packNo < 65535; packNo++) { var startCardScheduleNo = 0; var cardScheduleCount = 68; if (packNo > 0) { startCardScheduleNo = 68 + (packNo - 1) * 84; cardScheduleCount = 84; } var cardSchedules = allCardSchedules.Skip(startCardScheduleNo).Take(cardScheduleCount).ToList(); if (cardSchedules.Count == 0) { break; } foreach (var cardSchedule in cardSchedules) { bytes.AddRange(BytesHelper.ShortToBytes(cardSchedule.Device.GKDescriptorNo)); } for (int i = 0; i < cardScheduleCount - cardSchedules.Count; i++) { bytes.Add(0); bytes.Add(0); } foreach (var cardSchedule in cardSchedules) { bytes.Add((byte)cardSchedule.ScheduleNo); } for (int i = 0; i < cardScheduleCount - cardSchedules.Count; i++) { bytes.Add(0); } bytes.Add(0); bytes.Add(0); if (startCardScheduleNo + cardScheduleCount < allCardSchedules.Count) { bytes.AddRange(BytesHelper.ShortToBytes((ushort)(packNo + 1))); } else { bytes.Add(0); bytes.Add(0); } } } var packs = new List<List<byte>>(); for (int packNo = 0; packNo <= bytes.Count / 256; packNo++) { int packLenght = Math.Min(256, bytes.Count - packNo * 256); var packBytes = bytes.Skip(packNo * 256).Take(packLenght).ToList(); if (packBytes.Count > 0) { var resultBytes = new List<byte>(); resultBytes.Add((byte)(packNo)); resultBytes.AddRange(packBytes); packs.Add(resultBytes); } } foreach (var pack in packs) { var sendResult = SendManager.Send(device, (ushort)(pack.Count), (byte)(isNew ? 25 : 26), 0, pack); if (sendResult.HasError) { return OperationResult<bool>.FromError(sendResult.Error); } if (sendResult.Bytes.Count > 0) { return OperationResult<bool>.FromError("Неправильный формат при записи карты в прибор"); } } return new OperationResult<bool>(true); }
/// <summary> /// Возвращает число удалённых пропусков /// </summary> /// <param name="device"></param> /// <param name="usersCount"></param> /// <param name="progressCallback"></param> /// <returns></returns> static OperationResult<int> RemoveAllUsersInternal(GKDevice device, int usersCount, GKProgressCallback progressCallback = null) { progressCallback = GKProcessorManager.StartProgress("Удаление пользователей", "", usersCount, true, GKProgressClientType.Administrator); int cardsCount = 0; for (ushort i = 1; i <= usersCount; i++) { var user = new GKUser { Fio = "-", IsActive = false, Password = 1, GkNo = i, UserType = GKCardType.Operator, }; var removeResult = AddOrEditUser(user, device, false); if (!removeResult.HasError) cardsCount++; if (progressCallback != null) { GKProcessorManager.DoProgress("Пользователь " + i, progressCallback); if (progressCallback.IsCanceled) return OperationResult<int>.FromError("Операция отменена", cardsCount); } } GKProcessorManager.StopProgress(progressCallback); return new OperationResult<int>(cardsCount); }
public static OperationResult<List<GKUser>> GetAllUsersTest(GKDevice device, GKProgressCallback progressCallback) { progressCallback = GKProcessorManager.StartProgress("Чтение пользователей прибора " + device.PresentationName, "", 100, true, GKProgressClientType.Administrator); var users = new List<GKUser>(); for (ushort i = 1; i <= 100; i++) { Thread.Sleep(100); var user = new GKUser { GkNo = i, UserType = GKCardType.Administrator, IsActive = true, Fio = "Пользователь " + i, Password = i }; users.Add(user); if (progressCallback.IsCanceled) { return OperationResult<List<GKUser>>.FromError("Операция отменена", users); } GKProcessorManager.DoProgress("Пользователь " + i, progressCallback); } GKProcessorManager.StopProgress(progressCallback); return new OperationResult<List<GKUser>>(users); }
public static OperationResult<List<GKUser>> GetAllUsers(GKDevice device, GKProgressCallback progressCallback, Guid clientUID) { progressCallback = GKProcessorManager.StartProgress("Чтение пользователей прибора " + device.PresentationName, "", 65535, true, GKProgressClientType.Administrator, clientUID); var users = new List<GKUser>(); for (int i = 1; i <= 65535; i++) { byte j = 0; bool hasResponse = true; var bytePacks = new List<List<byte>>(); while (true) { var bytes = new List<byte>(); bytes.Add(j); bytes.AddRange(BytesHelper.ShortToBytes((ushort)(i))); var sendResult = SendManager.Send(device, (ushort)(bytes.Count), 24, 0, bytes); if (sendResult.HasError && device.DriverType != GKDriverType.GKMirror) { return OperationResult<List<GKUser>>.FromError("Во время выполнения операции возникла ошибка", users); } if (sendResult.Bytes.Count == 0) { if (j == 0) hasResponse = false; break; } bytePacks.Add(sendResult.Bytes); j++; } if (!hasResponse) break; int packIndex = -1; GKUser user = null; foreach (var pack in bytePacks) { packIndex++; if (packIndex == 0) { var gkNo = BytesHelper.SubstructShort(pack, 1); user = new GKUser { GkNo = gkNo, UserType = (GKCardType)pack[3], IsActive = pack[4] == 0, Fio = BytesHelper.BytesToStringDescription(pack, 5), Password = (uint)BytesHelper.SubstructInt(pack, 37), GkLevel = pack[41], GkLevelSchedule = pack[42] }; var totalSeconds = BytesHelper.SubstructInt(pack, 45); user.ExpirationDate = new DateTime(2000, 1, 1); user.ExpirationDate = user.ExpirationDate.AddSeconds(totalSeconds); for (int l = 0; l < 68; l++) { var deviceNo = BytesHelper.SubstructShort(pack, 49 + l * 2); if (deviceNo == 0) break; var scheduleNo = pack[185 + l]; user.Descriptors.Add(new GKUserDescriptor { DescriptorNo = deviceNo, ScheduleNo = scheduleNo }); } users.Add(user); } else { for (int l = 0; l < 84; l++) { var deviceNo = BytesHelper.SubstructShort(pack, 1 + l * 2); if (deviceNo == 0) break; var scheduleNo = pack[169 + l]; user.Descriptors.Add(new GKUserDescriptor { DescriptorNo = deviceNo, ScheduleNo = scheduleNo }); } } } if (progressCallback.IsCanceled) { return OperationResult<List<GKUser>>.FromError("Операция отменена", users); } GKProcessorManager.DoProgress("Пользователь " + i, progressCallback, clientUID); } GKProcessorManager.StopProgress(progressCallback, clientUID); return new OperationResult<List<GKUser>>(users); }
public void Update(GKUser user) { User = user; OnPropertyChanged(() => User); }
public PmfUserViewModel(GKUser user) { User = user; }