public AirMerchandise EditMerchandiseGroupMarkup(AirMerchandise flightMerchandise)
    {
        string groupCode = GlobalBaseUtility.GetGroupCode();

        if (groupCode == null)
        {
            return flightMerchandise;
        }

        flightMerchandise = EditMerchandiseMarkup(flightMerchandise, groupCode);

        return flightMerchandise;
    }
    private AirMerchandise EditGroupMarkup(AirMerchandise currentAirMerchandise, GroupMarkup groupMarkup)
    {
        //AdultMarkup
        //�������
        if (groupMarkup.AdultMarkup.MarkupType == ConfigurationConst.GroupMarkType.Money)
        {
            currentAirMerchandise.SetAdultBaseFare(currentAirMerchandise.AdultBaseFare + groupMarkup.AdultMarkup.Markup);
        }

            //�ٷֱ�
        else if (groupMarkup.AdultMarkup.MarkupType == ConfigurationConst.GroupMarkType.Percent)
        {
            currentAirMerchandise.SetAdultBaseFare(currentAirMerchandise.AdultBaseFare * (1 + groupMarkup.AdultMarkup.Markup));
        }

        //ChildMarkup
        //�������
        if (((int)decimal.Parse(currentAirMerchandise.ChildBaseFare.ToString())) != 0)
        {
            if (groupMarkup.ChildMarkup.MarkupType == ConfigurationConst.GroupMarkType.Money)
            {
                currentAirMerchandise.SetChildBaseFare(currentAirMerchandise.ChildBaseFare + groupMarkup.ChildMarkup.Markup);
            }

                //�ٷֱ�
            else if (groupMarkup.ChildMarkup.MarkupType == ConfigurationConst.GroupMarkType.Percent)
            {
                currentAirMerchandise.SetChildBaseFare(currentAirMerchandise.ChildBaseFare * (1 + groupMarkup.ChildMarkup.Markup));
            }
        }

        return currentAirMerchandise;
    }
    private AirMerchandise EditMerchandiseMarkup(AirMerchandise flightMerchandise,string groupCode)
    {
        //string groupCode = "test1118";
        AirMerchandise currentMerchandise;
        AirMaterial currentAirMaterial;

        currentMerchandise = null;

        //
        GroupMarkup groupMarkup = WebSiteService.GetGroupMarkup(groupCode);
        if (groupMarkup == null || groupMarkup.GroupCode != groupCode)
        {
            return flightMerchandise;
        }

        //����Merchandise
        for (int merchandiseIndex = 0; merchandiseIndex < flightMerchandise.Items.Count; merchandiseIndex++)
        {
            currentMerchandise = (AirMerchandise)flightMerchandise.Items[merchandiseIndex];

            currentMerchandise = EditGroupMarkup(currentMerchandise, groupMarkup);

            //������ǰMerchandise��AirMaterial
            if (currentMerchandise.Items != null)
            {
                for (int materialIndex = 0; materialIndex < currentMerchandise.Items.Count; materialIndex++)
                {
                    currentAirMaterial = (AirMaterial)currentMerchandise.Items[materialIndex];

                    currentAirMaterial = EditGroupMarkup(currentAirMaterial, groupMarkup);

                }
            }

        }

        return flightMerchandise;
    }
    private bool IsContactAgentItem(AirMerchandise item)
    {
        if (item.Items != null && item.Items.Count > 0)
        {
            return false;
        }

        return ((bool)item.Profile.GetParam("SHOULD_CALL"));
    }
 private bool IsAirlinesTheSame(AirMerchandise leftItem, AirMerchandise curretnItem)
 {
     return ((TERMS.Business.Centers.ProductCenter.Profiles.AirProfile)leftItem.Profile).Airlines[0].Code
         == ((TERMS.Business.Centers.ProductCenter.Profiles.AirProfile)curretnItem.Profile).Airlines[0].Code;
 }
    private void CopyMarkup(AirMerchandise copyFrom, AirMaterial copyTo)
    {
        //TERMS.Common.Markup newMarkup = new TERMS.Common.Markup();

        //newMarkup = new TERMS.Common.Markup(TERMS.Common.PassengerType.Adult, new TERMS.Common.FareAmount(copyFrom.AdultMarkup));
        //newMarkup.SetAmount(TERMS.Common.PassengerType.Child, new TERMS.Common.FareAmount(copyFrom.ChildMarkup));
        //copyTo.Price.AddMarkup(newMarkup);

        //copyTo.SetAdultBaseFare(copyFrom.AdultBaseFare);
        //copyTo.SetAdultTax(copyFrom.AdultTax);
        //copyTo.SetChildBaseFare(copyFrom.ChildBaseFare);
        //copyTo.SetChildTax(copyFrom.ChildTax);
        if (copyFrom != null && copyFrom.Price != null && copyTo != null )
        {
            copyTo.Price = (Price)copyFrom.Price.Clone();
        }
    }
    private AirMerchandise SearchAir(Terms.Sales.Business.AirSearchCondition searchCondition)
    {
        searchCondition.UserInfo = UserInfo;
        //bool isOpenCommNetFareTicket = false;
        bool isOpenAllFareTypeAir = false;
        bool isOnlyShowPubFareTicket = true;
        bool hasMajorAirlinesForAvailable = false;
        bool hasMajorAirlinesForSelect = false;
        bool isAvailableOnly = false;

        if (ConfigurationManager.AppSettings.Get("IsOpenAllFareTypeAir") != null)
            isOpenAllFareTypeAir = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("IsOpenAllFareTypeAir").ToString());

        if (ConfigurationManager.AppSettings.Get("IsOnlyShowPubFareTicket") != null)
            isOnlyShowPubFareTicket = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("IsOnlyShowPubFareTicket").ToString());

        if (ConfigurationManager.AppSettings.Get("HasMajorAirlinesForAvailable") != null)
            hasMajorAirlinesForAvailable = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("HasMajorAirlinesForAvailable").ToString());

        if (ConfigurationManager.AppSettings.Get("HasMajorAirlinesForSelect") != null)
            hasMajorAirlinesForSelect = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("HasMajorAirlinesForSelect").ToString());

        if (ConfigurationManager.AppSettings.Get("IsAvailableOnly") != null)
            isAvailableOnly = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("IsAvailableOnly").ToString());

        //by cjc, ��ʱ��ʾ���еĻ�Ʊ

        searchCondition.IsLogin = Utility.IsLogin;

        //��Cache�в��ҽ��
        AirMerchandise airMerchandise = (AirMerchandise)MVMerchandisePool.Find(searchCondition);

        if (airMerchandise == null)
        {
            DateTime SearchingBeginningTime = DateTime.Now;

            AirProductSearcher searcher = new AirProductSearcher();

            DateTime depDate = searchCondition.GetAddTripCondition()[0].DepartureDate;
            DateTime rtnDate = new DateTime();
            string fromAirportCode = searchCondition.GetAddTripCondition()[0].Departure.Code;
            string toAirportCode = searchCondition.GetAddTripCondition()[0].Destination.Code;
            string rtnFromAirportCode = string.Empty;
            string rtnToAirportCode = string.Empty;
            int adultNumber = searchCondition.GetPassengerNumber(TERMS.Common.PassengerType.Adult);
            int childNumber = searchCondition.GetPassengerNumber(TERMS.Common.PassengerType.Child);
            IList<AirProduct> airs = new List<AirProduct>();
            DateTime dtBeginTime = new DateTime();

            //log begin 20090312 Leon
            try
            {
                dtBeginTime = System.DateTime.Now;
                log.Info(m_LogRandomID + " >Search  From Terms Product Begin Start time : " + dtBeginTime);

                if (searchCondition.FlightType.ToLower().Equals("oneway"))
                    log.Info(m_LogRandomID + " >===================== OneWay =====================");
                else if (searchCondition.FlightType.ToLower().Equals("roundtrip"))
                    log.Info(m_LogRandomID + " >===================== Roundtrip =====================");
                else
                    log.Info(m_LogRandomID + " >===================== OpenJW =====================");
            }
            catch
            { }

            //ת����ѯ����
            TERMS.Common.Search.AirSearchCondition termsSearchCondition;

            if (searchCondition.FlightType.ToLower().Equals("oneway"))
            {
                termsSearchCondition = new TERMS.Common.Search.AirSearchCondition(fromAirportCode, true, toAirportCode, true, depDate, true, adultNumber, childNumber, 0);
            }
            else if (searchCondition.FlightType.ToLower().Equals("roundtrip"))
            {
                rtnDate = searchCondition.GetAddTripCondition()[1].DepartureDate;
                termsSearchCondition = new TERMS.Common.Search.AirSearchCondition(fromAirportCode, true, toAirportCode, true, depDate, true, rtnDate, true, adultNumber, childNumber, 0);
            }
            else  //Open Jaw
            {
                rtnDate = searchCondition.GetAddTripCondition()[1].DepartureDate;
                rtnFromAirportCode = searchCondition.GetAddTripCondition()[1].Departure.Code;
                rtnToAirportCode = searchCondition.GetAddTripCondition()[1].Destination.Code;
                termsSearchCondition = new TERMS.Common.Search.AirSearchCondition(fromAirportCode, true, toAirportCode, true, depDate, true, rtnFromAirportCode, true, rtnToAirportCode, true, rtnDate, true, adultNumber, childNumber, 0);
            }

            //ָ�����չ�˾
            if (searchCondition.Airlines != null && searchCondition.Airlines.Length > 0)
                termsSearchCondition.AddAirlines(searchCondition.Airlines);

            //�ƶ��յ�
            for (int i = 0; i < termsSearchCondition.Trips.Count; i++)
                termsSearchCondition.Trips[i].Cabin = searchCondition.AirTripCondition[i].Cabin;

            //��������ָ����ѯ��ʾ����
            if (!isOpenAllFareTypeAir)
            {
                //if isOpenAllFareTypeAir is false ,  un-login condition come into effect.
                if (!Utility.IsLogin)
                {
                    termsSearchCondition.HasMajorAirlinesForAvailable = hasMajorAirlinesForAvailable;
                    termsSearchCondition.HasMajorAirlinesForSelect = hasMajorAirlinesForSelect;
                    termsSearchCondition.IsAvailableOnly = isAvailableOnly;

                    //if un-login and only show PUB fare
                    if (isOnlyShowPubFareTicket)
                    {
                        termsSearchCondition.HasMajorAirlinesForAvailable = true;
                        termsSearchCondition.HasMajorAirlinesForSelect = true;
                        termsSearchCondition.FareType = TERMS.Common.AirFareType.Published;
                        termsSearchCondition.IsAvailableOnly = true;
                    }
                    else
                    {
                        termsSearchCondition.FareType = TERMS.Common.AirFareType.All;
                    }
                }
                else
                {
                    //��¼����ʾ���л�Ʊ����
                    termsSearchCondition.HasMajorAirlinesForAvailable = true;
                    termsSearchCondition.HasMajorAirlinesForSelect = true;
                    termsSearchCondition.FareType = TERMS.Common.AirFareType.All;
                    termsSearchCondition.IsAvailableOnly = false;
                }
            }
            else
            {
                //��ʾ���л�Ʊ����
                termsSearchCondition.HasMajorAirlinesForAvailable = true;
                termsSearchCondition.HasMajorAirlinesForSelect = true;
                termsSearchCondition.FareType = TERMS.Common.AirFareType.All;
                termsSearchCondition.IsAvailableOnly = false;
            }

            //ִ�в�ѯ
            airs = searcher.Search(termsSearchCondition, UserInfo.Entity);

            log.Info(m_LogRandomID + " >Search From Terms Product End time : " + ((TimeSpan)System.DateTime.Now.Subtract(dtBeginTime)).ToString());
            dtBeginTime = System.DateTime.Now;

            if (airs.Count == 0 || airs[0].Items == null) return null;
            TERMS.Business.Centers.ProductCenter.Profiles.AirProfile oldProfile = (TERMS.Business.Centers.ProductCenter.Profiles.AirProfile)airs[0].Profile;
            oldProfile.SetParam("ADULT_NUMBER", adultNumber);
            oldProfile.SetParam("CHILD_NUMBER", childNumber);
            oldProfile.SetParam("IS_LOGIN", Utility.IsLogin);

            //log begin 20090312 Leon
            try
            {
                log.Info(m_LogRandomID + " >Become Merchandise Begin Begin Start time : " + dtBeginTime);

                if (airMerchandise != null && airMerchandise.Items != null)
                    log.Info(m_LogRandomID + " > " + airs[0].ItemGetter.Log.Text);
                else
                    log.Info(m_LogRandomID + " >No Result");

                log.Info(m_LogRandomID + " >Become Merchandise Begin End time : " + ((TimeSpan)System.DateTime.Now.Subtract(dtBeginTime)).ToString());
            }
            catch
            { }

            airMerchandise = new AirMerchandise(oldProfile, airs[0]);
            MVMerchandisePool.Cache(searchCondition.Clone(), airMerchandise); //Cache

            //��¼Searchʱ��
            DateTime SearchingEndingTime = DateTime.Now;
            SearchingLogger searchingLogger = new SearchingLogger();
            searchingLogger.Log(SearchingBeginningTime, SearchingEndingTime, searchCondition);
        }

        return airMerchandise;
    }