Exemple #1
0
        //解析字符串,返回一个IToyzDateTimeObjcet接口的对象
        public static IToyzObjcet ParseToyz(string regexp)
        {
            IToyzObjcet toyz = null;

            if (string.IsNullOrEmpty(regexp))
            {
                return(toyz);
            }

            //判断查询前序
            if (regexp.StartsWith("between@"))
            {
                string   query     = regexp.Split('@')[1]; //找出查询条件
                string[] subQuerys = query.Split(',');     //拆分查询条件,获取参数数组
                if (subQuerys.Length == 2)
                {
                    string subQuery0 = subQuerys[0];
                    string subQuery1 = subQuerys[1];
                    if (ObjectUtil.IsNumberQuery(subQuery0) && ObjectUtil.IsNumberQuery(subQuery1))
                    {
                        int min = int.Parse(subQuery0.Trim('(', ')'));
                        int max = int.Parse(subQuery1.Trim('(', ')'));
                        toyz = new ToyzNumberRangeObject(min, max);
                    }
                }
            }
            else if (regexp.StartsWith("gt@") || regexp.StartsWith("lt@"))
            {
                string   query     = regexp.Split('@')[1]; //找出查询条件
                string[] subQuerys = query.Split(',');     //拆分查询条件,获取参数数组
                if (subQuerys.Length == 1)
                {
                    string subQuery0 = subQuerys[0];
                    //string subQuery1 = subQuerys[1];
                    if (ObjectUtil.IsNumberQuery(subQuery0))
                    {
                        int min = regexp.StartsWith("lt@")?int.MinValue:int.Parse(subQuery0.Trim('(', ')'));
                        int max = regexp.StartsWith("gt@") ? int.MaxValue:int.Parse(subQuery0.Trim('(', ')'));
                        toyz = new ToyzNumberRangeObject(min, max);
                    }
                }
            }


            return(toyz);
        }
        //解析字符串,返回一个IToyzDateTimeObjcet接口的对象
        public static IToyzObjcet ParseToyzDateTime(string val)
        {
            IToyzObjcet toyz = null;

            if (CACHE_TOYZ_DATETIME.ContainsKey(val))
            {
                return(CACHE_TOYZ_DATETIME[val]);
            }


            //判断查询前序
            if (val.StartsWith("month@"))
            {
                string   query     = val.Split('@')[1]; //找出查询条件
                string[] subQuerys = query.Split(',');  //拆分查询条件,获取参数数组
                if (subQuerys.Length == 1)              //如果只带一个参数
                {
                    string subQuery = subQuerys[0];
                    if (ObjectUtil.IsDateQuery(subQuery))                                 //如果第一个参数是日期
                    {
                        DateTime monthdatetime = DateTime.Parse(subQuery.Trim('[', ']')); // 格式转换之前要去掉"[]"
                        toyz = new ToyzMonthObject(monthdatetime);
                    }
                }
                else if (subQuerys.Length == 2)
                {
                    string subQuery0 = subQuerys[0];
                    string subQuery1 = subQuerys[1];
                    if (ObjectUtil.IsNumberQuery(subQuery0) && ObjectUtil.IsNumberQuery(subQuery1))
                    {
                        int year  = int.Parse(subQuery0.Trim('(', ')'));
                        int month = int.Parse(subQuery1.Trim('(', ')'));
                        toyz = new ToyzMonthObject(year, month);
                    }
                }
            }
            else if (val.StartsWith("week@"))
            {
                string   query     = val.Split('@')[1];
                string[] subQuerys = query.Split(',');
                if (subQuerys.Length == 1)
                {                                                                        //如果只带一个参数
                    string subQuery = subQuerys[0];
                    if (ObjectUtil.IsDateQuery(subQuery))                                //如果第一个参数是日期
                    {
                        DateTime weekdatetime = DateTime.Parse(subQuery.Trim('[', ']')); // 格式转换之前要去掉"[]"
                        toyz = new ToyzMonthObject(weekdatetime);
                    }
                }
            }
            else if (val.StartsWith("range@"))
            {
                string   query     = val.Split('@')[1];
                string[] subQuerys = query.Split(',');
                if (subQuerys.Length == 2)
                {
                    string subQuery0 = subQuerys[0];
                    string subQuery1 = subQuerys[1];
                    if (ObjectUtil.IsDateQuery(subQuery0) && ObjectUtil.IsDateQuery(subQuery1))
                    {
                        DateTime begindate = DateTime.Parse(subQuery0.Trim('[', ']'));
                        DateTime enddate   = DateTime.Parse(subQuery1.Trim('[', ']'));
                        toyz = new ToyzRangeDateObject(begindate, enddate);
                    }
                    else if (ObjectUtil.IsDateQuery(subQuery0) && ObjectUtil.IsNumberQuery(subQuery1))
                    {
                        DateTime begindate = DateTime.Parse(subQuery0.Trim('[', ']'));
                        int      diff      = int.Parse(subQuery1.Trim('(', ')'));
                        toyz = new ToyzRangeDateObject(begindate, diff);
                    }
                }
            }

            //MonthObject month = new MonthObject(3,3);

            //格式为 week@[yyyy-MM-dd]  初始化WeekObject(DateTime dt)

            //格式为 month@[yyyy-MM-dd]  初始化MonthObject(DateTime dt)

            //格式为 month@(yyyy),(mm)     初始化MonthObject(int year,int month)

            //格式为  range@[yyyy-MM-dd],[yyyy-MM-dd]  初始化RangeDateObject(DateTime dt,DateTime dt)

            //格式为  range@[yyyy-MM-dd],(diff)    初始化RangeDateObject(DateTime dt,int diff)

            if (toyz != null)
            {
                CACHE_TOYZ_DATETIME.Add(val, toyz);
            }

            return(toyz);
        }
        public ActionResult ViewHotelSearch(string viewName, string cityName, DateTime?checkInDate, DateTime?checkOutDate, string keyword, string hotelId
                                            , string star, string priceRegexp, string geoLlId, string geoClId, string geoDid, string brandName, string orderbyCode, string orderbyType
                                            , decimal?startLng, decimal?endLng, decimal?startLat, decimal?endLat, string geoMode, int?radius
                                            )
        {
            ELongApiBiz elongBiz = ELongApiBiz.GetInstant();
            GeoBiz      geoBiz   = GeoBiz.GetInstant();

            string cityId = geoBiz.GetGeoByCityName(cityName).cityCode;
            ToyzNumberRangeObject            priceRange = null;
            GetHotelConditionForGetHotelList condition  = new GetHotelConditionForGetHotelList();

            condition.CheckInDate  = checkInDate ?? this.getDefaultCheckInDate();
            condition.CheckOutDate = checkOutDate ?? this.getDefaultCheckOutDate();
            condition.CityId       = cityId;
            //condition.HotelName = keyword;
            condition.MaxRows   = this.getPager().size;
            condition.PageIndex = this.getPager().page;

            if (string.IsNullOrEmpty(geoMode) || geoMode == "0")
            {
                if (!string.IsNullOrEmpty(keyword))
                {
                    condition.HotelName = keyword;
                }

                if (!string.IsNullOrEmpty(hotelId))
                {
                    condition.HotelId = hotelId;
                    condition.CityId  = null;
                }

                if (!string.IsNullOrEmpty(brandName))
                {
                    condition.HotelName = brandName;
                }
                if (!string.IsNullOrEmpty(star))
                {
                    condition.StarCode = star;
                }

                if (!string.IsNullOrEmpty(priceRegexp))
                {
                    priceRegexp = HttpUtility.UrlDecode(priceRegexp);
                    IToyzObjcet toyzPrice = NumberUtil.ParseToyz(priceRegexp);
                    priceRange = toyzPrice as ToyzNumberRangeObject;
                    if (priceRange != null)
                    {
                        condition.LowestRate  = priceRange.min;
                        condition.HighestRate = priceRange.max;
                    }
                }

                if (!string.IsNullOrEmpty(geoLlId))
                {
                    condition.LandmarkLocationID = geoLlId;
                }
                else if (!string.IsNullOrEmpty(geoClId))
                {
                    condition.CommercialLocationId = geoClId;
                }
                else if (!string.IsNullOrEmpty(geoDid))
                {
                    condition.DistrictId = geoDid;
                }
            }
            else if (geoMode == "1")
            {
                condition.StartLatitude  = startLat ?? 0;
                condition.StartLongitude = startLng ?? 0;
                condition.EndLatitude    = endLat ?? 0;
                condition.EndLongitude   = endLng ?? 0;

                condition.PositionModeCode = geoMode;
            }
            else if (geoMode == "2")
            {
                condition.StartLatitude    = startLat ?? 0;
                condition.StartLongitude   = startLng ?? 0;
                condition.EndLatitude      = condition.StartLatitude;
                condition.EndLongitude     = condition.StartLongitude;
                condition.PositionModeCode = geoMode;
                condition.Radius           = radius ?? 0;
            }



            if (!string.IsNullOrEmpty(orderbyCode))
            {
                condition.OrderByCode   = orderbyCode;
                condition.OrderTypeCode = orderbyType;
            }
            else
            {
                condition.OrderTypeCode = "desc";
            }



            PageList <HotelForGetHotelList> hotels = elongBiz.getHotelList(condition);

            /*
             * if(priceRegexp!=null){
             *  foreach (HotelForGetHotelList hotel in hotels) {
             *      foreach()
             *      RoomForGetHotelList[] rooms = hotel.Rooms;
             *  }
             */



            IList <string> hotelIds = new List <string>();

            foreach (HotelForGetHotelList hotel in hotels)
            {
                hotelIds.Add(hotel.HotelId);
            }


            ICriteria icr = BaseZdBiz.CreateCriteria <HotelDetailModel>();

            icr.Add(Restrictions.In("id", hotelIds.ToArray()));

            IList <HotelDetailModel> hotelDetails = icr.List <HotelDetailModel>();

            icr = BaseZdBiz.CreateCriteria <HotelFeatrueInfoModel>();
            icr.Add(Restrictions.In("hotelId", hotelIds.ToArray()));
            IList <HotelFeatrueInfoModel> hotelFeats = icr.List <HotelFeatrueInfoModel>();

            Dictionary <string, HotelDetailModel>      dictHotelDetails = hotelDetails.ToDictionary(p => p.id);
            Dictionary <string, HotelFeatrueInfoModel> dictHotelFeat    = hotelFeats.ToDictionary(p => p.hotelId);

            ViewData[typeof(PageList <HotelForGetHotelList>).Name]       = hotels;
            ViewData[typeof(Dictionary <string, HotelDetailModel>).Name] = dictHotelDetails;
            ViewData[typeof(HotelFeatrueInfoModel).Name] = dictHotelFeat;
            ViewData[typeof(ToyzNumberRangeObject).Name] = priceRange;
            return(View(viewName));
        }