예제 #1
0
		public static bool DeleteSchedule(GKSchedule item)
		{
			var operationResult = ClientManager.RubezhService.DeleteGKSchedule(item);
			if (operationResult.HasError)
				MessageBoxService.ShowWarning(operationResult.Error);
			return operationResult.Result;
		}
예제 #2
0
		/// <summary>
		/// Перезаписать вае графики конкретного ГК
		/// </summary>
		/// <param name="device"></param>
		/// <returns></returns>
		public static OperationResult<bool> RewriteAllSchedules(GKDevice device, Guid clientUID)
		{
			var progressCallback = GKProcessorManager.StartProgress("Перезапись графиков в " + device.PresentationName, "Стирание графиков", 1, false, GKProgressClientType.Administrator, clientUID);
			var removeResult = RemoveAllSchedules(device);
			if (removeResult.HasError)
				return OperationResult<bool>.FromError(removeResult.Errors);

			var schedules = new List<GKSchedule>();
			using (var databaseService = new RubezhDAL.DataClasses.DbService())
			{
				var schedulesResult = databaseService.GKScheduleTranslator.Get();
				if (schedulesResult.HasError)
					return OperationResult<bool>.FromError(schedulesResult.Errors);
				schedules = schedulesResult.Result;
			}

			progressCallback = GKProcessorManager.StartProgress("Запись графиков в " + device.PresentationName, "", schedules.Count + 1, false, GKProgressClientType.Administrator, clientUID);
			var emptySchedule = new GKSchedule();
			emptySchedule.Name = "Никогда";
			var setResult = GKSetSchedule(device, emptySchedule);
			if (setResult.HasError)
				return OperationResult<bool>.FromError(setResult.Errors);
			GKProcessorManager.DoProgress("Запись пустого графика ", progressCallback, clientUID);
			int i = 1;
			foreach (var schedule in schedules)
			{
				setResult = GKSetSchedule(device, schedule);
				if (setResult.HasError)
					return OperationResult<bool>.FromError(setResult.Errors);
				GKProcessorManager.DoProgress("Запись графика " + i, progressCallback, clientUID);
				i++;
			}
			GKProcessorManager.StopProgress(progressCallback, clientUID);
			return new OperationResult<bool>(true);
		}
예제 #3
0
		public void Update(GKSchedule schedule)
		{
			Schedule = schedule;
			OnPropertyChanged(() => Schedule);
			OnPropertyChanged(() => Name);
			OnPropertyChanged(() => Description);
			Update();
		}
예제 #4
0
		public ScheduleViewModel(GKSchedule schedule)
		{
			Calendar = new CalendarViewModel(schedule);
			WriteCommand = new RelayCommand(OnWrite);
			AddCommand = new RelayCommand(OnAdd, CanAdd);
			DeleteCommand = new RelayCommand(OnDelete, CanDelete);

			Schedule = schedule;
			Update();
		}
예제 #5
0
		public SchedulePartViewModel(GKSchedule schedule, GKSchedulePart schedulePart)
		{
			Schedule = schedule;
			DayNo = schedulePart.DayNo;
			AvailableDaySchedules = new ObservableCollection<GKDaySchedule>();
			foreach (var dayInterval in GKModuleLoader.DaySchedulesViewModel.GetDaySchedules())
			{
				AvailableDaySchedules.Add(dayInterval);
			}
			_selectedDaySchedule = AvailableDaySchedules.FirstOrDefault(x => x.UID == schedulePart.DayScheduleUID);
			if (_selectedDaySchedule == null)
				_selectedDaySchedule = AvailableDaySchedules.FirstOrDefault();
			Update();
		}
예제 #6
0
		public RubezhAPI.GK.GKSchedule Translate(GKSchedule tableItem)
		{
			var result = new RubezhAPI.GK.GKSchedule();
			result.UID = tableItem.UID;
			result.No = tableItem.No;
			result.Name = tableItem.Name;
			result.Description = tableItem.Description;
			result.ScheduleType = (RubezhAPI.GK.GKScheduleType)tableItem.Type;
			result.SchedulePeriodType = (RubezhAPI.GK.GKSchedulePeriodType)tableItem.PeriodType;
			result.StartDateTime = tableItem.StartDateTime;
			result.HoursPeriod = tableItem.HoursPeriod;
			result.HolidayScheduleNo = tableItem.HolidayScheduleNo;
			result.WorkHolidayScheduleNo = tableItem.WorkingHolidayScheduleNo;
			result.ScheduleParts =
				tableItem.ScheduleGKDaySchedules.Select(x => new GKSchedulePart() { DayScheduleUID = x.DayScheduleUID.GetValueOrDefault(), DayNo = x.DayNo }).ToList();
			result.SelectedDays = tableItem.ScheduleDays.Select(x => x.DateTime).ToList();
			result.Year = tableItem.Year;
			return result;
		}
예제 #7
0
		public CalendarViewModel(GKSchedule calendar)
		{
			Schedule = calendar;
			Months = new ObservableCollection<MonthViewModel>();
			Months.Add(JanuaryMonth = new MonthViewModel(MonthType.January, Schedule));
			Months.Add(FebruaryMonth = new MonthViewModel(MonthType.February, Schedule));
			Months.Add(MarchMonth = new MonthViewModel(MonthType.March, Schedule));
			Months.Add(AprilMonth = new MonthViewModel(MonthType.April, Schedule));
			Months.Add(MayMonth = new MonthViewModel(MonthType.May, Schedule));
			Months.Add(JuneMonth = new MonthViewModel(MonthType.June, Schedule));
			Months.Add(JulyMonth = new MonthViewModel(MonthType.July, Schedule));
			Months.Add(AugustMonth = new MonthViewModel(MonthType.August, Schedule));
			Months.Add(SeptemberMonth = new MonthViewModel(MonthType.September, Schedule));
			Months.Add(OctoberMonth = new MonthViewModel(MonthType.October, Schedule));
			Months.Add(NovemberMonth = new MonthViewModel(MonthType.November, Schedule));
			Months.Add(DecemberMonth = new MonthViewModel(MonthType.December, Schedule));
			PreviousYearCommand = new RelayCommand(OnPreviousYear);
			NextYearCommand = new RelayCommand(OnNextYear);
			UpdateMonths();
		}
예제 #8
0
		public MonthViewModel(MonthType monthType, GKSchedule calendar)
		{
			Schedule = calendar;
			MonthType = monthType;
			Update(Schedule.Year);
		}
예제 #9
0
		/// <summary>
		/// Стереть график из всех ГК
		/// </summary>
		/// <param name="schedule"></param>
		/// <returns></returns>
		public static OperationResult<bool> RemoveSchedule(int scheduleNo)
		{
			var schedule = new GKSchedule();
			schedule.No = scheduleNo;
			return SetSchedule(schedule);
		}
예제 #10
0
		public ScheduleDetailsViewModel(GKSchedule schedule = null)
		{
			_schedules = GKScheduleHelper.GetSchedules();
			if (_schedules == null)
				_schedules = new List<GKSchedule>();
			if (schedule == null)
			{
				Title = "Создание нового графика доступа";
				IsNew = true;

				Schedule = new GKSchedule()
				{
					Name = "Новый график доступа",
					No = 1
				};
				if (_schedules.Count != 0)
					Schedule.No = (ushort)(_schedules.Select(x => x.No).Max() + 1);
			}
			else
			{
				Title = string.Format("Свойства графика доступа: {0}", schedule.PresentationName);
				Schedule = schedule;
			}

			ScheduleTypes = new ObservableCollection<GKScheduleType>(Enum.GetValues(typeof(GKScheduleType)).Cast<GKScheduleType>());
			SelectedScheduleType = Schedule.ScheduleType;

			SchedulePeriodTypes = new ObservableCollection<GKSchedulePeriodType>(Enum.GetValues(typeof(GKSchedulePeriodType)).Cast<GKSchedulePeriodType>());
			SelectedSchedulePeriodType = Schedule.SchedulePeriodType;

			Holidays = new ObservableCollection<GKSchedule>();
			foreach (var holidaySchedule in _schedules)
			{
				if (holidaySchedule.ScheduleType == GKScheduleType.Holiday)
				{
					Holidays.Add(holidaySchedule);
				}
			}
			SelectedHoliday = Holidays.FirstOrDefault(x => x.No == Schedule.HolidayScheduleNo);

			WorkHolidays = new ObservableCollection<GKSchedule>();
			foreach (var workHolidaySchedule in _schedules)
			{
				if (workHolidaySchedule.ScheduleType == GKScheduleType.WorkHoliday)
				{
					WorkHolidays.Add(workHolidaySchedule);
				}
			}
			SelectedWorkHoliday = WorkHolidays.FirstOrDefault(x => x.No == Schedule.WorkHolidayScheduleNo);

			CopyProperties();

			var availableNames = new HashSet<string>();
			var availableDescription = new HashSet<string>();
			foreach (var existingSchedule in _schedules)
			{
				availableNames.Add(existingSchedule.Name);
				availableDescription.Add(existingSchedule.Description);
			}
			AvailableNames = new ObservableCollection<string>(availableNames);
			AvailableDescription = new ObservableCollection<string>(availableDescription);
		}
예제 #11
0
		public OperationResult<bool> DeleteGKSchedule(Guid clientUID, GKSchedule item)
		{
			return SafeOperationCall(clientUID, () => RubezhService.DeleteGKSchedule(clientUID, item), "DeleteGKSchedule");
		}
예제 #12
0
		public OperationResult<bool> SaveGKSchedule(Guid clientUID, GKSchedule item, bool isNew)
		{
			return SafeOperationCall(clientUID, () => RubezhService.SaveGKSchedule(clientUID, item, isNew), "SaveGKSchedule");
		}
예제 #13
0
		public OperationResult<bool> DeleteGKSchedule(GKSchedule item)
		{
			return SafeOperationCall(() =>
			{
				var rubezhService = RubezhServiceFactory.Create(TimeSpan.FromMinutes(10));
				using (rubezhService as IDisposable)
					return rubezhService.DeleteGKSchedule(RubezhServiceFactory.UID, item);
			}, "DeleteGKSchedule");
		}
예제 #14
0
		/// <summary>
		/// Записать график в конкретный ГК
		/// </summary>
		/// <param name="device"></param>
		/// <param name="schedule"></param>
		/// <returns></returns>
		static OperationResult<bool> GKSetSchedule(GKDevice device, GKSchedule schedule)
		{
			var count = 0;
			var daySchedules = new List<GKDaySchedule>();
			using (var databaseService = new RubezhDAL.DataClasses.DbService())
			{
				var schedulesResult = databaseService.GKDayScheduleTranslator.Get();
				if (schedulesResult.HasError)
					return OperationResult<bool>.FromError(schedulesResult.Errors);
				daySchedules = schedulesResult.Result;
			}
			if (schedule.ScheduleType == GKScheduleType.Access)
			{
				foreach (var schedulePart in schedule.ScheduleParts)
				{
					var daySchedule = daySchedules.FirstOrDefault(x => x.UID == schedulePart.DayScheduleUID);
					if (daySchedule != null)
					{
						count += daySchedule.DayScheduleParts.Count;
					}
				}
			}
			else
			{
				count = schedule.SelectedDays.Count;
			}

			int secondsPeriod = 0;
			switch (schedule.ScheduleType)
			{
				case GKScheduleType.Access:
					switch (schedule.SchedulePeriodType)
					{
						case GKSchedulePeriodType.Weekly:
						case GKSchedulePeriodType.Dayly:
							secondsPeriod = schedule.ScheduleParts.Count * 60 * 60 * 24;
							break;
						case GKSchedulePeriodType.Custom:
							secondsPeriod = schedule.HoursPeriod * 60 * 60;
							break;
						case GKSchedulePeriodType.NonPeriodic:
							secondsPeriod = 0;
							break;
					}
					break;

				case GKScheduleType.Holiday:
				case GKScheduleType.WorkHoliday:
					secondsPeriod = 0;
					break;
			}

			var bytes = new List<byte>();
			bytes.Add((byte)schedule.No);
			var nameBytes = BytesHelper.StringDescriptionToBytes(schedule.Name);
			bytes.AddRange(nameBytes);
			bytes.Add((byte)schedule.HolidayScheduleNo);
			bytes.AddRange(BytesHelper.ShortToBytes((ushort)(count * 2)));
			bytes.AddRange(BytesHelper.IntToBytes(secondsPeriod));
			bytes.Add((byte)schedule.WorkHolidayScheduleNo);
			bytes.Add(0);
			bytes.Add(0);
			bytes.Add(0);
			bytes.Add(0);
			bytes.Add(0);
			bytes.Add(0);
			bytes.Add(0);

			var startDateTime = schedule.StartDateTime;
			if (schedule.ScheduleType == GKScheduleType.Access && schedule.SchedulePeriodType == GKSchedulePeriodType.Weekly)
			{
				if (startDateTime.DayOfWeek == DayOfWeek.Monday)
					startDateTime = startDateTime.AddDays(0);
				if (startDateTime.DayOfWeek == DayOfWeek.Tuesday)
					startDateTime = startDateTime.AddDays(-1);
				if (startDateTime.DayOfWeek == DayOfWeek.Wednesday)
					startDateTime = startDateTime.AddDays(-2);
				if (startDateTime.DayOfWeek == DayOfWeek.Thursday)
					startDateTime = startDateTime.AddDays(-3);
				if (startDateTime.DayOfWeek == DayOfWeek.Friday)
					startDateTime = startDateTime.AddDays(-4);
				if (startDateTime.DayOfWeek == DayOfWeek.Saturday)
					startDateTime = startDateTime.AddDays(-5);
				if (startDateTime.DayOfWeek == DayOfWeek.Sunday)
					startDateTime = startDateTime.AddDays(-6);
			}
			var timeSpan = new DateTime(startDateTime.Year, startDateTime.Month, startDateTime.Day) - new DateTime(2000, 1, 1);
			var scheduleStartSeconds = timeSpan.TotalSeconds;

			if (schedule.ScheduleType == GKScheduleType.Access)
			{
				foreach (var schedulePart in schedule.ScheduleParts.OrderBy(x => x.DayNo))
				{
					var daySchedule = daySchedules.FirstOrDefault(x => x.UID == schedulePart.DayScheduleUID);
					if (daySchedule != null)
					{
						foreach (var daySchedulePart in daySchedule.DayScheduleParts.OrderBy(x => x.StartMilliseconds))
						{
							bytes.AddRange(BytesHelper.IntToBytes((int)(scheduleStartSeconds + 24 * 60 * 60 * schedulePart.DayNo + daySchedulePart.StartMilliseconds / 1000)));
							bytes.AddRange(BytesHelper.IntToBytes((int)(scheduleStartSeconds + 24 * 60 * 60 * schedulePart.DayNo + daySchedulePart.EndMilliseconds / 1000)));
						}
					}
				}
			}
			else
			{
				foreach (var day in schedule.SelectedDays.OrderBy(x => x.Date))
				{
					bytes.AddRange(BytesHelper.IntToBytes((int)((day - new DateTime(2000, 1, 1)).TotalSeconds)));
					bytes.AddRange(BytesHelper.IntToBytes((int)((day - new DateTime(2000, 1, 1) + TimeSpan.FromDays(1)).TotalSeconds)));
				}
			}

			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), 28, 0, pack);
				if (sendResult.HasError)
				{
					return OperationResult<bool>.FromError(sendResult.Error);
				}
			}

			return new OperationResult<bool>(true);
		}
예제 #15
0
		/// <summary>
		/// Записать один график во все ГК
		/// </summary>
		/// <param name="schedule"></param>
		/// <returns></returns>
		public static OperationResult<bool> SetSchedule(GKSchedule schedule)
		{
			try
			{
				foreach (var device in GKManager.Devices.Where(x => x.DriverType == GKDriverType.GK))
				{
					var result = GKSetSchedule(device, schedule);
					if (result.HasError)
						return OperationResult<bool>.FromError(result.Error);
				}
				return new OperationResult<bool>(true);
			}
			catch (Exception e)
			{
				return OperationResult<bool>.FromError(e.Message);
			}
		}
예제 #16
0
		public static bool SaveSchedule(GKSchedule item, bool isNew)
		{
			var operationResult = ClientManager.RubezhService.SaveGKSchedule(item, isNew);
		    Common.ThrowErrorIfExists(operationResult);
			return operationResult.Result;
		}
예제 #17
0
		/// <summary>
		/// Сохранить график в БД и записать во все ГК
		/// </summary>
		/// <param name="schedule"></param>
		/// <param name="isNew"></param>
		/// <returns>Возвращает False, только если произошла ошибка в БД</returns>
		public OperationResult<bool> SaveGKSchedule(Guid clientUID, GKSchedule schedule, bool isNew)
		{
			if (isNew)
				AddJournalMessage(JournalEventNameType.Добавление_нового_графика_ГК, schedule.Name, schedule.UID, clientUID, journalObjectType: JournalObjectType.GKShedule);
			else
				AddJournalMessage(JournalEventNameType.Редактирование_графика_ГК, schedule.Name, schedule.UID, clientUID, journalObjectType: JournalObjectType.GKShedule);

			using (var databaseService = new RubezhDAL.DataClasses.DbService())
			{
				var dbResult = databaseService.GKScheduleTranslator.Save(schedule);
				if (dbResult.HasError)
					return OperationResult<bool>.FromError(dbResult.Error, false);
			}
			var result = GKScheduleHelper.SetSchedule(schedule);
			return OperationResult<bool>.FromError(result.Error, true);
		}
예제 #18
0
		/// <summary>
		/// Удалить график и перезаписать все ГК
		/// </summary>
		/// <param name="schedule"></param>
		/// <returns>Возвращает False, только если произошла ошибка в БД</returns>
		public OperationResult<bool> DeleteGKSchedule(Guid clientUID, GKSchedule schedule)
		{
			AddJournalMessage(JournalEventNameType.Удаление_графика_ГК, schedule.Name, schedule.UID, clientUID, journalObjectType: JournalObjectType.GKShedule);
			using (var databaseService = new RubezhDAL.DataClasses.DbService())
			{
				var dbResult = databaseService.GKScheduleTranslator.Delete(schedule);
				if (dbResult.HasError)
					return OperationResult<bool>.FromError(dbResult.Error, false);
			}
			var result = GKScheduleHelper.RemoveSchedule(schedule.No);
			return OperationResult<bool>.FromError(result.Error, true);
		}
예제 #19
0
		public OperationResult<bool> GKSetSchedule(Guid clientUID, GKSchedule schedule)
		{
			var result = GKScheduleHelper.SetSchedule(schedule);
			return OperationResult<bool>.FromError(result.Error, true);
		}
예제 #20
0
		public CommonScheduleViewModel(GKSchedule gkSchedule)
		{
			No = gkSchedule.No;
			Name = gkSchedule.Name;
			Description = gkSchedule.Description;
		}
예제 #21
0
		public DayViewModel(int no, MonthType monthType, GKSchedule calendar)
		{
			Schedule = calendar;
			var dateTime = new DateTime(Schedule.Year, (int)monthType, no);
			DayOfWeek = dateTime.DayOfWeek;
			MonthType = monthType;
			No = no;
			SelectCommand = new RelayCommand(OnSelect);
		}