Пример #1
0
        private void GetGridRoomResultDataSource(GridSortCommandEventArgs sortEventArgs)
        {
            int    pageNumber        = gridRoomResult.CurrentPageIndex + 1;
            string sortExpress       = string.Empty;
            string sortExpressInvert = string.Empty;

            foreach (GridSortExpression item in gridRoomResult.MasterTableView.SortExpressions)
            {
                GridSortOrder newSortOrder = item.SortOrder;
                if (sortEventArgs != null && item.FieldName == sortEventArgs.SortExpression)
                {
                    newSortOrder = sortEventArgs.NewSortOrder;
                }

                if (!string.IsNullOrEmpty(sortExpress) && newSortOrder != GridSortOrder.None)
                {
                    sortExpress       += ", ";
                    sortExpressInvert += ", ";
                }
                if (newSortOrder == GridSortOrder.Ascending)
                {
                    sortExpress       += item.FieldName + " ASC";
                    sortExpressInvert += item.FieldName + " DESC";
                }
                else if (newSortOrder == GridSortOrder.Descending)
                {
                    sortExpress       += item.FieldName + " DESC";
                    sortExpressInvert += item.FieldName + " ASC";
                }
            }

            if (sortEventArgs != null && !sortExpress.Contains(sortEventArgs.SortExpression))
            {
                if (!string.IsNullOrEmpty(sortExpress) && sortEventArgs.NewSortOrder != GridSortOrder.None)
                {
                    sortExpress       += ", ";
                    sortExpressInvert += ", ";
                }
                if (sortEventArgs.NewSortOrder == GridSortOrder.Ascending)
                {
                    sortExpress       += sortEventArgs.SortExpression + " ASC";
                    sortExpressInvert += sortEventArgs.SortExpression + " DESC";
                }
                else if (sortEventArgs.NewSortOrder == GridSortOrder.Descending)
                {
                    sortExpress       += sortEventArgs.SortExpression + " DESC";
                    sortExpressInvert += sortEventArgs.SortExpression + " ASC";
                }
            }

            if (string.IsNullOrEmpty(sortExpress))
            {
                sortExpress       = "DateCreated DESC";
                sortExpressInvert = "DateCreated ASC";
            }

            int cityId     = Convert.ToInt32(cbbCity.SelectedValue);
            int?districtId = Convert.ToInt32(cbbDistrict.SelectedValue);

            if (districtId <= 0)
            {
                districtId = null;
            }
            int     roomTypeId = Convert.ToInt32(cbbRoomType.SelectedValue);
            decimal?priceFrom  = null;

            if (txtPriceFrom.Value.HasValue)
            {
                priceFrom = Convert.ToDecimal(txtPriceFrom.Value);
            }
            decimal?priceTo = null;

            if (txtPriceTo.Value.HasValue)
            {
                priceTo = Convert.ToDecimal(txtPriceTo.Value);
            }
            DateTime?dateFrom = null;

            if (datDateFrom.SelectedDate.HasValue)
            {
                dateFrom = datDateFrom.SelectedDate.Value;
            }
            DateTime?dateTo = null;

            if (datDateTo.SelectedDate.HasValue)
            {
                dateTo = datDateTo.SelectedDate.Value;
                dateTo = dateTo.Value.AddDays(1).AddSeconds(-1);
            }

            int gender = radMale.Checked ? 1 : 0;

            gridRoomResult.VirtualItemCount = Business.BusinessMethods.CountPost((int)PostTypes.StayWith, roomTypeId, null, 232, cityId, districtId, null, null, null, gender,
                                                                                 priceFrom, priceTo, dateFrom, dateTo, null, null, UtilityHelper.FormatKeywords(txtKeywords.Text), false);
            List <Post> searchResults = Business.BusinessMethods.SearchPostPaging((int)PostTypes.StayWith, roomTypeId, null, 232, cityId, districtId, null, null, null, gender,
                                                                                  priceFrom, priceTo, dateFrom, dateTo, null, null, UtilityHelper.FormatKeywords(txtKeywords.Text), false, gridRoomResult.PageSize, pageNumber, sortExpress, sortExpressInvert);

            gridRoomResult.DataSource = searchResults;

            //Build Meta Description for Google Search Engine :
            StringBuilder builder = new StringBuilder();

            foreach (Post post in searchResults)
            {
                builder.Append(post.Address + " giá : " + post.PriceString + ". \n");
            }
            this.Page.MetaDescription = builder.ToString();
        }