public TourMerchandise SearchTourByTourCode(string tourCode, string Language)
    {
        TourMerchandise tourMerchandise = null;

        TourMerchandise tourMerchandiseAll = null;

        if (Utility.IsSubAgent)
            tourMerchandiseAll = (TourMerchandise)MVMerchandisePool.Find("SUBTour");
        else
            tourMerchandiseAll = (TourMerchandise)MVMerchandisePool.Find("Tour");

        if (tourMerchandiseAll == null)
        {
            tourMerchandiseAll = SearchTour(Language);
        }

        if (tourMerchandiseAll != null)
        {
            tourMerchandise = new TourMerchandise();

            tourMerchandise.TourProductList = tourMerchandiseAll.TourProductList;

            for (int i = 0; i < tourMerchandiseAll.Items.Count; i++)
            {
                TourMaterial tourMaterial = (TourMaterial)tourMerchandiseAll.Items[i];
                TourMaterial tourMaterialCN = (TourMaterial)tourMerchandiseAll.TourMCN[i];

                TourProfile tourprofile = (TourProfile)tourMaterial.Profile;

                if (tourprofile.Code.Trim().ToUpper() == tourCode.Trim().ToUpper())
                {
                    tourMerchandise.Add(tourMaterial);
                    tourMerchandise.TourMCN.Add(tourMaterialCN);
                    break; ;
                }
            }
        }

        else
            return null;

        tourMerchandise.LanguageFlag = Language;

        return tourMerchandise;
    }
    //public TourMerchandise SearchTour(Terms.Sales.Business.TourSearchCondition searchCondition, List<string> citys, string Language)
    //{
    //    searchCondition.UserInfo = UserInfo;
    //    //��Cache�в��ҽ�
    //    TourMerchandise tourMerchandise = (TourMerchandise)MVMerchandisePool.Find(citys);
    //    if (tourMerchandise == null)
    //    {
    //        TourProductSearcher searcher = new TourProductSearcher();
    //        TERMS.Common.Search.TourSearchCondition tourSearchCondition = new TERMS.Common.Search.TourSearchCondition();
    //        tourSearchCondition.SetCity(searchCondition.City);
    //        tourSearchCondition.SetRegion(searchCondition.Region);
    //        tourSearchCondition.SetCountry(searchCondition.Counrty);
    //        tourSearchCondition.IsLandOnly = searchCondition.IsLandOnly;
    //        tourSearchCondition.TravelDaysFrom = searchCondition.TravelDaysFrom;
    //        tourSearchCondition.TravelDaysTo = searchCondition.TravelDaysTo;
    //        tourSearchCondition.PriceType = searchCondition.PriceType;
    //        tourSearchCondition.SetDepartureRange(searchCondition.TravelBeginDate.AddDays(-7), searchCondition.TravelBeginDate.AddDays(300));
    //        IList<TourProduct> tps = new List<TourProduct>();
    //        tps = searcher.Search(tourSearchCondition, citys, userInfo.Entity);
    //        if (tps != null && tps.Count > 0)
    //        {
    //            TourMerchandise tourMerchandiseNew = new TourMerchandise((List<TourProduct>)tps);
    //            if (Utility.IsSubAgent)
    //            {
    //                GetSpecialTourPrice(tourMerchandise, searchCondition.IsLandOnly);
    //            }
    //            MVMerchandisePool.Cache(citys, tourMerchandiseNew); //Cache
    //            tourMerchandise = tourMerchandiseNew;
    //        }
    //        else
    //            return null;
    //    }
    //    tourMerchandise.LanguageFlag = Language;
    //    return tourMerchandise;
    //}
    public TourMerchandise SearchTour(Terms.Sales.Business.TourSearchCondition searchCondition, List<string> citys, string Language)
    {
        //searchCondition.UserInfo = UserInfo;

        TourMerchandise tourMerchandise = null;

        TourMerchandise tourMerchandiseAll = null;

        if (Utility.IsSubAgent)
            tourMerchandiseAll = (TourMerchandise)MVMerchandisePool.Find("SUBTour");
        else
            tourMerchandiseAll = (TourMerchandise)MVMerchandisePool.Find("Tour");

        if (tourMerchandiseAll == null)
        {
            tourMerchandiseAll = SearchTour(Language);
        }

        if (tourMerchandiseAll != null)
        {
            tourMerchandise = new TourMerchandise();

            tourMerchandise.TourProductList = tourMerchandiseAll.TourProductList;

            for (int i = 0; i < tourMerchandiseAll.Items.Count; i++)
            {
                TourMaterial tourMaterial = (TourMaterial)tourMerchandiseAll.Items[i];
                TourMaterial tourMaterialCN = (TourMaterial)tourMerchandiseAll.TourMCN[i];

                TourProfile tourprofile = (TourProfile)tourMaterial.Profile;

                TERMS.Common.City StartCity = tourprofile.StartCity;
                TERMS.Common.City EndCity = tourprofile.EndCity;
                List<TERMS.Common.City> PassCities = (List<TERMS.Common.City>)tourprofile.PassCities;

                if (searchCondition.TravelDaysFrom != 0 && searchCondition.TravelDaysTo != 0 &&
                (tourprofile.Days < searchCondition.TravelDaysFrom || tourprofile.Days > searchCondition.TravelDaysTo))
                {
                    continue;
                }

                if (citys.Contains(StartCity.Code))
                {
                    tourMerchandise.Add(tourMaterial);
                    tourMerchandise.TourMCN.Add(tourMaterialCN);
                    continue;
                }
                if (citys.Contains(EndCity.Code))
                {
                    tourMerchandise.Add(tourMaterial);
                    tourMerchandise.TourMCN.Add(tourMaterialCN);
                    continue;
                }
                for (int index = 0; index < PassCities.Count; index++)
                {
                    if (citys.Contains(PassCities[index].Code))
                    {
                        tourMerchandise.Add(tourMaterial);
                        tourMerchandise.TourMCN.Add(tourMaterialCN);

                        break;
                    }
                }
            }
        }
        else
            return null;

        //tourMerchandise.Items.Sort(CompareByStartFromLandOnlyFareAndTourCode);

        tourMerchandise.LanguageFlag = Language;

        return tourMerchandise;
    }
    public void GetSpecialTourPrice(TourMerchandise tourmerchandise, bool islandOnly)
    {
        string emailPath = string.Empty;

        emailPath = @"/Config/SpecialTourPrice.xml";

        if (File.Exists(System.AppDomain.CurrentDomain.BaseDirectory + emailPath))
        {
            DataSet ds = new DataSet();

            ds.ReadXml(System.AppDomain.CurrentDomain.BaseDirectory + emailPath);

            if (ds != null)
            {
                DataTable dt = ds.Tables[0];

                string tourcode = string.Empty;

                string strSql = string.Empty;

                decimal decPrice = decimal.Zero;

                string roomType = string.Empty;

                decimal decSelling = decimal.Zero;

                for (int i = 0; i < tourmerchandise.Items.Count ; i++)
                {
                    TourProfile tourProfile = (TourProfile)((TourMaterial)tourmerchandise.Items[i] ).Profile;

                    List<DateTime> dates = new List<DateTime>();

                    for (int ii = 0; ii < tourProfile.Seasons.Count; ii++)
                    {
                        if (tourProfile.Seasons[ii].Periods.Count > 0)
                        {
                                dates.Add(tourProfile.Seasons[ii].Periods[0].PeriodFrom);
                        }
                    }

                    tourcode = tourProfile.Code;

                    strSql = " TourCode = '" + tourcode + "'";

                    DataRow[] drs = dt.Select(strSql);

                    if (drs != null && drs.Length > 0)
                    {
                        for (int j = 0; j < drs.Length; j++)
                        {
                            decPrice = Convert.ToDecimal(drs[j]["Price"].ToString().Trim());

                            roomType = drs[j]["RoomType"].ToString().Trim();

                            for (int dataCount = 0; dataCount < dates.Count; dataCount++)
                            {
                                decSelling = tourProfile.GetPrice(dates[dataCount], roomType, islandOnly, false).GetAmount(TERMS.Common.PassengerType.Adult);

                                if (decSelling > decimal.Zero)
                                {
                                    tourProfile.GetPrice(dates[dataCount], roomType, islandOnly,
                                        false).SetAmount(TERMS.Common.PassengerType.Adult, new TERMS.Common.FareAmount(decSelling + decPrice));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    public TourMerchandise SearchTour(string Language)
    {
        //��Cache�в��ҽ�
        TourMerchandise tourMerchandise = null;
        if (Utility.IsSubAgent)
            tourMerchandise = (TourMerchandise)MVMerchandisePool.Find("SUBTour");
        else
            tourMerchandise = (TourMerchandise)MVMerchandisePool.Find("Tour");

        if (tourMerchandise == null)
        {
            TourProductSearcher searcher = new TourProductSearcher();
            IList<TourProduct> tps = new List<TourProduct>();

            tps = searcher.Search(UserInfo.Entity);

            if (tps != null && tps.Count > 0)
            {
                tourMerchandise = new TourMerchandise((List<TourProduct>)tps);

                if (Utility.IsSubAgent)
                {
                    GetSpecialTourPrice(tourMerchandise, true);
                }

                if (Utility.IsSubAgent)
                {
                    MVMerchandisePool.Cache("SUBTour", tourMerchandise);
                }
                else
                {

                    MVMerchandisePool.Cache("Tour", tourMerchandise); //Cache
                }
            }
            else
                return null;
        }

        tourMerchandise.LanguageFlag = Language;

        return tourMerchandise;
    }
 public void InitCheck(TourMerchandise tourMerchandise, DateTime date)
 {
     TourProfile tourProfile = (TourProfile)((TourMaterial)tourMerchandise.DefaultTourMaterial).Profile;
     decimal ChildWithOutPrice = (Decimal)tourProfile.GetPrice(date, RoomTypes[0], ((TourSearchCondition)Transaction.CurrentSearchConditions).IsLandOnly, false).GetAmount(TERMS.Common.PassengerType.Infant);
     if (ChildWithOutPrice == null || ChildWithOutPrice == 0M)
     {
         this.ddlChildWithOut1.Enabled = false;
         this.ddlChildWithOut2.Enabled = false;
         this.ddlChildWithOut3.Enabled = false;
         this.ddlChildWithOut4.Enabled = false;
     }
 }