Beispiel #1
0
		static IQueryable<Journal> GetFiltered(Filter filter, DatabaseContext context)
		{
			IQueryable<Journal> result = context.Journal;
			if (filter.JournalTypes.Any())
				result = result.Where(x => filter.JournalTypes.Contains(x.JournalType));

			if (filter.ConsumerUIDs.Any())
				result = result.Where(x => filter.ConsumerUIDs.Contains(x.ObjectUID));

			if (filter.DeviceUIDs.Any())
				result = result.Where(x => filter.DeviceUIDs.Contains(x.ObjectUID));

			if (filter.UserUIDs.Any())
				result = result.Where(x => filter.UserUIDs.Contains(x.UserUID));

			if (filter.TariffUIDs.Any())
				result = result.Where(x => filter.TariffUIDs.Contains(x.ObjectUID));

			result = result.Where(x => x.DateTime > filter.StartDate && x.DateTime < filter.EndDate);

			if (filter.IsSortAsc)
				result = result.OrderBy(x => x.DateTime);
			else
				result = result.OrderByDescending(x => x.DateTime);

			return result;
		}
		void Update()
		{
			if (Filter == null)
				Filter = new Filter();
			else
			{
				switch (Filter.StateType)
				{
					case StateType.LastHours:
						Filter.EndDate = DateTime.Now;
						Filter.StartDate = DateTime.Now.AddHours(-Filter.Count);
						break;

					case StateType.LastDays:
						Filter.EndDate = DateTime.Now;
						Filter.StartDate = DateTime.Now.AddDays(-Filter.Count);
						break;
				}
			}

			var count = DbCache.GetJournalCount(Filter);
			if (count.HasValue)
			{
				TotalPageNumber =  count.Value / Filter.PageSize + 1;
				CurrentPageNumber = 1;
			}
		}
Beispiel #3
0
		public DateTimeViewModel(Filter filter)
		{
			StateTypes = new ObservableCollection<StateType>(Enum.GetValues(typeof(StateType)).Cast<StateType>());
			SelectedStateType = filter.StateType;
			Count = filter.Count;
			IsSortAsc = filter.IsSortAsc;
			PageSize = filter.PageSize;
			StartDateTime = new DateTimePairViewModel(filter.StartDate);
			EndDateTime = new DateTimePairViewModel(filter.EndDate);
		}
		public FilterJournalViewModel(Filter filter )
		{
			ClearCommand = new RelayCommand(OnClear);

			Title = "Настройки фильтра";
			DateTimeViewModel = new DateTimeViewModel(filter);
			FilterEventsViewModel = new FilterEventsViewModel(filter);
			FilterConsumersViewModel = new FilterConsumersViewModel(filter);
			FilterDevicesViewModel = new FilterDevicesViewModel(filter);
			FilterTariffsViewModel = new FilterTariffsViewModel(filter);
			FilterUsersViewModel = new FilterUsersViewModel(filter);
		}
		public FilterConsumersViewModel(Filter filter)
		{
			BuildTree();
			AllConsumers.ForEach(x=> 
				{
					if (filter.ConsumerUIDs.Contains(x.Consumer.UID))
						x.IsChecked = true;
				});
			if (RootcConsumer != null)
			{
				RootcConsumer.IsExpanded = true;
				foreach (var child in RootcConsumer.Children)
					child.IsExpanded = true;
			}
		}
Beispiel #6
0
		public static int? GetJournalCount(Filter filter)
		{
			try
			{
				using (var context = DatabaseContext.Initialize())
				{
					return GetFiltered(filter, context).Count();
				}
			}
			catch (Exception e)
			{
				MessageBoxService.ShowException(e);
				return null;
			}
		}
		void OnShowFilter()
		{
			var filterJournalViewModel = new FilterJournalViewModel(Filter);
			if(DialogService.ShowModalWindow(filterJournalViewModel))
			{
				Filter = new Filter();
				Filter.JournalTypes = filterJournalViewModel.FilterEventsViewModel.GetJournalTypes();
				Filter.ConsumerUIDs = filterJournalViewModel.FilterConsumersViewModel.GetConsumerUIDs();
				Filter.DeviceUIDs = filterJournalViewModel.FilterDevicesViewModel.GetDeviceUIDs();
				Filter.TariffUIDs = filterJournalViewModel.FilterTariffsViewModel.GetTariffUIDs();
				Filter.UserUIDs = filterJournalViewModel.FilterUsersViewModel.GetUserUIDs();
				filterJournalViewModel.DateTimeViewModel.Save(Filter);
				Update();
			}
		}
Beispiel #8
0
		public static List<Journal> GetJournalPage(Filter filter, int page)
		{
			try
			{
				using (var context = DatabaseContext.Initialize())
				{
					var journalItems = GetFiltered(filter, context);
					return journalItems.Skip((page - 1) * filter.PageSize).Take(filter.PageSize).ToList();
				}
			}

			catch (Exception e)
			{
				MessageBoxService.ShowException(e);
				return null;
			}
		}
		public FilterDevicesViewModel(Filter filter)
		{
			BildTree();
			if (AllDevices != null)
			{
				AllDevices.ForEach(x =>
				{
					if (filter.DeviceUIDs.Contains(x.Device.UID))
						x.IsChecked = true;
				});
			}
			
			if (RootDevice != null)
			{
				RootDevice.IsExpanded = true;
				foreach (var child in RootDevice.Children)
					child.IsExpanded = true;
			}
		}
Beispiel #10
0
		public void Save(Filter filter)
		{
			switch (SelectedStateType)
			{
				case StateType.LastHours:
					filter.StartDate = DateTime.Now.AddHours(-Count);
					break;

				case StateType.LastDays:
					filter.StartDate = DateTime.Now.AddDays(-Count);
					break;

				case StateType.FromDate:
					filter.StartDate = StartDateTime.DateTime;
					break;

				case StateType.RangeDate:
					filter.StartDate = StartDateTime.DateTime;
					filter.EndDate = EndDateTime.DateTime;
					break;
			}
			filter.StateType = SelectedStateType;
			filter.Count = Count;
			filter.IsSortAsc = IsSortAsc;
			filter.PageSize = PageSize;
		}