Beispiel #1
0
        static OrderFilter()
        {
            Single = new OrderFilter();
            Single.DateFilterTypes = new Dictionary <FilterDateType, string>();
            Single.DateFilterTypes.Add(FilterDateType.create, "Дата создания");
            Single.DateFilterTypes.Add(FilterDateType.review, "Дата рассмотрения");
            Single.DateFilterTypes.Add(FilterDateType.cancel, "Дата снятия");
            Single.DateFilterTypes.Add(FilterDateType.planStart, "Плановое начало");
            Single.DateFilterTypes.Add(FilterDateType.planStop, "Плановое окончание");
            Single.DateFilterTypes.Add(FilterDateType.faktStart, "Фактическое начало");
            Single.DateFilterTypes.Add(FilterDateType.faktStop, "Разрешение наввод");
            Single.DateFilterTypes.Add(FilterDateType.faktEnter, "Закрытие заявки");

            Single.UserFilterTypes = new Dictionary <FilterUserType, string>();
            Single.UserFilterTypes.Add(FilterUserType.review, "Рассмотрел");
            Single.UserFilterTypes.Add(FilterUserType.cancel, "Снял");
            Single.UserFilterTypes.Add(FilterUserType.create, "Создал");
            Single.UserFilterTypes.Add(FilterUserType.close, "Разрешил ввод");
            Single.UserFilterTypes.Add(FilterUserType.complete, "Закрыл");
            Single.UserFilterTypes.Add(FilterUserType.open, "Открыл");

            Single.FilterTypes = new Dictionary <OrderFilterEnum, string>();
            Single.FilterTypes.Add(OrderFilterEnum.defaultFilter, "Активные заявки/Недавно измененные");
            Single.FilterTypes.Add(OrderFilterEnum.active, "Только активные заявки");
            Single.FilterTypes.Add(OrderFilterEnum.userFilter, "Ручная настройка");
        }
		private void lstSelUsers_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
			try {
				filter = DataContext as OrderFilter;
				OrdersUser user=lstSelUsers.SelectedItem as OrdersUser;
				if (filter.SelectedUsers.Contains(user))
					filter.SelectedUsers.Remove(user);
			} catch {
			}
		}
		public IQueryable<Order> getOrders(OrderFilter filter) {
			switch (filter.FilterType) {
				case OrderFilterEnum.userFilter:
					return getOrdersUserFilter(filter);
				case OrderFilterEnum.active:
					return OrdersActive;
				default:
					return Orders;
			}

		}
		public IQueryable<Order> getOrdersUserFilter(OrderFilter filter) {
			Logger.info("Получение списка заказов (фильтр)", Logger.LoggerSource.ordersContext);
			try {
				OrdersUser currentUser=OrdersUser.loadFromCache(HttpContext.Current.User.Identity.Name);
				VotGESOrdersEntities context=new VotGESOrdersEntities();

				List<String> states=filter.OrderStates;
				List<int> users=filter.SelectedUsersArray;
				List<String> orderTypes=filter.OrderTypes;

				List<int> ids=filter.SelectedObjectsArray;
				if (!filter.ShowAllObjectIDs && filter.ShowChildObjects) {
					List<OrderObject> objects=new List<OrderObject>();
					foreach (int id in ids) {
						objects.Add(VotGESOrders.Web.Models.OrderObject.getByID(id));
					}
					foreach (OrderObject obj in objects) {
						obj.appendObjectIDSChildIDS(ids);
					}
				}

				List<int> objectsByName=new List<int>();
				if (!filter.ShowAllObjects) {
					objectsByName = OrderObject.getObjectIDSByFullName(filter.OrderObject);
				}

				IQueryable<Orders> orders= 
				from o in context.Orders
				where
					(filter.ShowAllStates || states.Contains(o.orderState))
					&& (filter.ShowAllTime ||
						(filter.FilterDate == FilterDateType.create && o.orderDateCreate >= filter.DateStart && o.orderDateCreate <= filter.DateEnd) ||
						(filter.FilterDate == FilterDateType.review && o.orderDateReview >= filter.DateStart && o.orderDateReview <= filter.DateEnd) ||
						(filter.FilterDate == FilterDateType.cancel && o.orderDateCancel >= filter.DateStart && o.orderDateCancel <= filter.DateEnd) ||
						(filter.FilterDate == FilterDateType.faktStart && o.faktStartDate >= filter.DateStart && o.faktStartDate <= filter.DateEnd) ||
						(filter.FilterDate == FilterDateType.faktStop && o.faktStopDate >= filter.DateStart && o.faktStopDate <= filter.DateEnd) ||
						(filter.FilterDate == FilterDateType.faktEnter && o.faktCompleteDate >= filter.DateStart && o.faktCompleteDate <= filter.DateEnd) ||
						(filter.FilterDate == FilterDateType.planStart && o.planStartDate >= filter.DateStart && o.planStartDate <= filter.DateEnd) ||
						(filter.FilterDate == FilterDateType.planStop && o.planStopDate >= filter.DateStart && o.planStopDate <= filter.DateEnd))
					&& (filter.ShowAllUsers ||
						(filter.FilterUser == FilterUserType.create && users.Contains(o.userCreateOrderID)) ||
						(filter.FilterUser == FilterUserType.review && users.Contains(o.userReviewOrderID.Value)) ||
						(filter.FilterUser == FilterUserType.cancel && users.Contains(o.userCancelOrderID.Value)) ||
						(filter.FilterUser == FilterUserType.open && users.Contains(o.userOpenOrderID.Value)) ||
						(filter.FilterUser == FilterUserType.close && users.Contains(o.userCloseOrderID.Value)) ||
						(filter.FilterUser == FilterUserType.complete && users.Contains(o.userCompleteOrderID.Value)))
					&& (filter.ShowAllObjectIDs || ids.Contains(o.orderObjectID))
					&& (filter.ShowAllTypes || orderTypes.Contains(o.orderType))
					&& (filter.ShowAllObjects || objectsByName.Contains(o.orderObjectID) || o.orderObjectAddInfo.Contains(filter.OrderObject))
					&& (filter.ShowAllOrderTexts || o.orderText.Contains(filter.OrderText))
					&& (filter.ShowAllNumbers ||
						(o.orderNumber >= filter.StartNumber || filter.StartNumber == 0) &&
						(o.orderNumber <= filter.StopNumber || filter.StopNumber == 0))
					&& (!filter.ShowExpiredOnly ||
						 o.orderClosed && o.planStopDate < o.faktStopDate ||
						 o.orderCompleted && o.planStopDate < o.faktCompleteDate)
				select o;

				List<Order> resultOrders=new List<Order>();
				foreach (Orders orderDB in orders) {
					resultOrders.Add(new Order(orderDB, currentUser, false, null));
				}

				if (filter.ShowRelatedOrders) {
					IEnumerable<double> floorNumbers=from Order o in resultOrders select Math.Floor(o.OrderNumber);
					IEnumerable<double> numbers=from Order o in resultOrders select o.OrderNumber;
					IQueryable<Orders> relOrders=from o in context.Orders where floorNumbers.Contains(Math.Floor(o.orderNumber)) && !numbers.Contains(o.orderNumber) select o;
					foreach (Orders orderDB in relOrders) {
						resultOrders.Add(new Order(orderDB, currentUser, false, null));
					}
				}


				return resultOrders.AsQueryable();
			} catch (Exception e) {
				Logger.error("===Ошибка при получении списка заказов (фильтр) " + e.ToString(), Logger.LoggerSource.ordersContext);
				throw new DomainException(String.Format("Ошибка при получении списка заказов (фильтр)"));
			}
		}