Exemple #1
0
		void OnAdd()
		{
			var userDetailsViewModel = new UserDetailsViewModel();
			if (DialogService.ShowModalWindow(userDetailsViewModel))
			{
				FiresecManager.GuardUsers.Add(userDetailsViewModel.GuardUser);
				var userViewModel = new UserViewModel(userDetailsViewModel.GuardUser);
				AvailableUsers.Add(userViewModel);
				ServiceFactory.SaveService.FSChanged = true;
			}
		}
		public GuardConfigurationViewModel(Device selectedDevice,
			ObservableCollection<UserViewModel> deviceUsers,
			ObservableCollection<UserViewModel> availableUsers,
			ObservableCollection<Zone> userZones,
			ObservableCollection<Zone> deviceZones)
		{
			Title = "Список охранных пользователей прибора: " + selectedDevice.Driver.ShortName;
			SaveCaption = "Применить";
			deviceUsersViewModel = deviceUsers;
			availableUsersViewModel = availableUsers;
			userZonesViewModel = userZones;
			deviceZonesViewModel = deviceZones;
			SelectedDevice = selectedDevice;

			Users = new ObservableCollection<UserViewModel>();

			//if (FiresecManager.IsFS2Enabled)
			//{
			//    FS2DeviceGetGuardUserListHelper.Run(SelectedDevice);
			//    var guardUsers = FS2DeviceGetGuardUserListHelper.Result;
			//    if (guardUsers != null)
			//    {
			//        for (int i = 0; i < guardUsers.Count; i++)
			//        {
			//            var user = new User();
			//            guardUsers[i].Id = i + 1;
			//            var userViewModel = new UserViewModel(guardUsers[i]);
			//            Users.Add(userViewModel);
			//        }
			//    }
			//}
			//else
			{
				DeviceGetGuardUserListHelper.Run(SelectedDevice);
				var result = DeviceGetGuardUserListHelper.Result;
				if (result != null)
				{
					int CountUsers = byte.Parse(result.ToString().Substring(0, 3));
					for (int i = 0; i < CountUsers; i++)
					{
						var guardUser = new GuardUser();
						guardUser.Id = i + 1;
						guardUser.Name = result.Substring(174 * i + 115, 20);
						guardUser.Password = result.Substring(174 * i + 147, 6);
						var indexOfF = guardUser.Password.IndexOf('F');
						if (indexOfF >= 0)
							guardUser.Password = guardUser.Password.Remove(indexOfF);
						guardUser.CanUnSetZone = (result[174 * i + 107] == '1');
						guardUser.CanSetZone = (result[174 * i + 108] == '1');
						guardUser.KeyTM = result.Substring(174 * i + 135, 12);
						for (int j = 0; j < 64; j++)
						{
							if (result.Substring(174 * i + 153, 64)[j] == '1')
							{
								Zone zone = FiresecManager.Zones.FirstOrDefault(x => FiresecManager.FiresecConfiguration.GetZoneLocalSecNo(x) == j + 1);
								if (zone != null)
									guardUser.ZoneUIDs.Add(zone.UID);
							}
						}
						var userViewModel = new UserViewModel(guardUser);
						Users.Add(userViewModel);
					}
				}
			}

			if (Users.Count > 0)
				SelectedUser = Users.FirstOrDefault();
		}