public void ClearSeachedTours()
 {
     RepFindedTours.DataSource = null;
     RepFindedTours.DataBind();
     RepPagesTop.DataSource = null;
     RepPagesTop.DataBind();
     RepPagesBottom.DataSource = null;
     RepPagesBottom.DataBind();
     SearchPages.Clear();
     CurrentPage = 0;
 }
        protected void RepPagesItem_Command(object sender, CommandEventArgs e)
        {
            var linkButton = sender as LinkButton;

            if (linkButton == null)
            {
                throw new ArgumentNullException("sender");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            using (var mtmDc = new MtMainDbDataContext())
            {
                using (var mtsDc = new MtSearchDbDataContext())
                {
                    switch (e.CommandName)
                    {
                    case "PreviosPage":
                        CurrentPage--;
                        break;

                    case "PageToGo":
                        CurrentPage = uint.Parse(e.CommandArgument.ToString());
                        break;

                    case "NextPage":
                        CurrentPage++;
                        break;

                    default:
// ReSharper disable once NotResolvedInText
                        throw new ArgumentOutOfRangeException("e.CommandName", e.CommandName,
                                                              "Событие получено от незарегестрированого элемента.");
                    }

                    if (1 > CurrentPage || CurrentPage > SearchPages.Count)
                    {
                        throw new IndexOutOfRangeException(
                                  String.Format("Индекс текущей страницы поиска вышел за границы диапозона - {0}", CurrentPage));
                    }

                    var searchResult = mtsDc.PagingOnClient(mtmDc, CityKeyFrom.Value, CountryKey.Value, TourKeys, TourDates,
                                                            TourNights,
                                                            HotelKeys, PansionKeys, MainPlaces, AddPlaces, FirstChildYears, SecondChildYears,
                                                            RoomTypeKeys,
                                                            HotelQuotaMask, AviaQuotaMask | QuotesStates.None, RateKey.Value, MaxTourPrice, RowsPerPage,
                                                            SearchPages[CurrentPage],
                                                            CurrentSort);

                    CurrentSort = searchResult.SortType;

                    if (searchResult.IsMorePages && !SearchPages.ContainsKey(CurrentPage + 1))
                    {
                        SearchPages.Add(CurrentPage + 1, searchResult.NextPageRowCounter);
                    }

                    RepPagesTop.DataSource = SearchPages;
                    RepPagesTop.DataBind();
                    RepPagesBottom.DataSource = SearchPages;
                    RepPagesBottom.DataBind();

                    RepFindedTours.DataSource = searchResult.SearchItems;
                    RepFindedTours.DataBind();

                    Web.ScrollToElement(this, RepPagesTop.ClientID);
                    linkButton.Focus();
                }
            }
        }
        public void ShowTours(int cityKeyFrom, int countryKey, int[] tourKeys,
                              DateTime[] tourDates, int[] tourNights, int[] hotelKeys,
                              int[] pansionKeys, ushort?mainPlaces, ushort?addPlaces, ushort?firstChildYears,
                              ushort?secondChildYears, int[] roomTypeKeys, QuotesStates hotelQuotaMask, QuotesStates aviaQuotaMask,
                              int rateKey, uint?maxTourPrice, ushort rowsPerPage)
        {
            if (tourKeys == null || !tourKeys.Any())
            {
                throw new ArgumentNullException("tourKeys");
            }
            if (tourDates == null || !tourDates.Any())
            {
                throw new ArgumentNullException("tourDates");
            }
            if (tourNights == null || !tourNights.Any())
            {
                throw new ArgumentNullException("tourNights");
            }
            if (hotelKeys == null || !hotelKeys.Any())
            {
                throw new ArgumentNullException("hotelKeys");
            }
            if (pansionKeys == null || !pansionKeys.Any())
            {
                throw new ArgumentNullException("pansionKeys");
            }
            if ((roomTypeKeys != null && roomTypeKeys.Any() && mainPlaces.HasValue) || ((roomTypeKeys == null || !roomTypeKeys.Any()) && !mainPlaces.HasValue))
            {
                throw new ArgumentException("Одноверменно не могут быть указаны значение количество взрослых и тип номера", "roomTypeKeys");
            }
            if (addPlaces > 0 && !firstChildYears.HasValue)
            {
                throw new ArgumentNullException("firstChildYears", "Не указан возраст первого ребенка");
            }
            if (addPlaces > 1 && !secondChildYears.HasValue)
            {
                throw new ArgumentNullException("secondChildYears", "Не указан возраст второго ребенка");
            }

            CityKeyFrom      = cityKeyFrom;
            CountryKey       = countryKey;
            TourKeys         = tourKeys;
            TourDates        = tourDates;
            TourNights       = tourNights;
            HotelKeys        = hotelKeys;
            PansionKeys      = pansionKeys;
            MainPlaces       = mainPlaces;
            AddPlaces        = addPlaces;
            FirstChildYears  = firstChildYears;
            SecondChildYears = secondChildYears;
            RoomTypeKeys     = roomTypeKeys;
            HotelQuotaMask   = hotelQuotaMask;
            AviaQuotaMask    = aviaQuotaMask;
            RateKey          = rateKey;
            MaxTourPrice     = maxTourPrice;
            RowsPerPage      = rowsPerPage;

            using (var mtmDc = new MtMainDbDataContext())
            {
                using (var mtsDc = new MtSearchDbDataContext())
                {
                    var searchResult = mtsDc.PagingOnClient(mtmDc, CityKeyFrom.Value, CountryKey.Value, TourKeys, TourDates,
                                                            TourNights,
                                                            HotelKeys, PansionKeys, MainPlaces, AddPlaces, FirstChildYears, SecondChildYears,
                                                            RoomTypeKeys,
                                                            HotelQuotaMask, AviaQuotaMask | QuotesStates.None, RateKey.Value, MaxTourPrice, RowsPerPage, 0, CurrentSort);

                    CurrentSort = searchResult.SortType;
                    SearchPages.Clear();

                    if (!searchResult.SearchItems.Any())
                    {
                        LtMessage.Text =
                            @"<div id='SearchResultsMsg' class='TFS_SearchResultsMsg'><span>К сожалению по вашему запросу ничего не найдено. Попробуйте изменить параметры поиска. Например квоты или количество едущих людей и т.д.</span></div>";
                        Web.ShowMessage(this,
                                        @"К сожалению по вашему запросу ничего не найдено. Попробуйте изменить параметры поиска. Например квоты или количество едущих людей и т.д.");
                        Web.ScrollToElement(this, "SearchResultsMsg");

                        //koshelev
                        //сделал обработку того, что ни один тур не найден
                        RepFindedTours.DataSource = null;
                        RepFindedTours.DataBind();

                        RepPagesTop.DataSource = null;
                        RepPagesTop.DataBind();
                        RepPagesBottom.DataSource = null;
                        RepPagesBottom.DataBind();
                        return;
                    }

                    LtMessage.Text = String.Empty;

                    // добовляем первую страницу
                    SearchPages.Add(1, 0);
                    CurrentPage = 1;

                    // инициализируем следующую страницу
                    if (searchResult.IsMorePages)
                    {
                        SearchPages.Add(CurrentPage + 1, searchResult.NextPageRowCounter);
                    }

                    RepPagesTop.DataSource = SearchPages;
                    RepPagesTop.DataBind();
                    RepPagesBottom.DataSource = SearchPages;
                    RepPagesBottom.DataBind();

                    RepFindedTours.DataSource = searchResult.SearchItems;
                    RepFindedTours.DataBind();
                }
            }
        }