void PackageSearchResult2dForm_InitializeControls(object sender, EventArgs e)
    {
        this.Transaction.IntKey = Convert.ToInt32(Request.Params["ConditionID"]);
        if (Utility.IsLogin)
        {
            divLongin.Visible = true;
            UserLogin1.Visible = false;
            divHead.Visible = false;

            //if (Utility.IsSubAgent)
            //{
            //    divSubagent.Visible = true;
            //    phAgentFlightMarkup.Visible = true;
            //}
            //else
            //{
            //    divSubagent.Visible = false;
            //    phAgentFlightMarkup.Visible = false;
            //}
        }
        else
        {
            divLongin.Visible = false;
            UserLogin1.Visible = true;
            UserLogin1.NextUrl = "~/Page/Package/PackageTravelerForm.aspx";
            UserLogin1.ReturnUrl = "~/Page/Package/PackageSearchResult2dForm.aspx";
            divHead.Visible = true;
        }
        this.FlightHeader1.FlagCode = 1;
        this.FlightHeader1.SubIndex = 0;
        ChangeTravelers1.ReturnURL = "PackageSearchResult2dForm.aspx";
        this.DefaultFlightDetails1.URL = "PackageSearchResult2dForm.aspx?PostBack=false";
        UserLogin1.loginClick = DoContinueProcess;
        if (this.Request["PostBack"] != null)
        {
            InitSet();
            this.DefaultFlightDetails1.FlightDetails = AirMaterialList;
            this.FlightHeader1.ReBind();
            this.ShowPackageHotels1.pgMerchandise = pgMerchandise;
            this.ShowPackageHotels1.BindHotels();

            //如果Hotel的checkin checkout 的差大于5天 edit by tll
            SetChooseDisable();

            SearchToBinder();
            BinderPrice();
        }
        else
        {
            if (!IsPostBack)
            {
                InitSet();
                SearchToBinder();
                BinderPrice();
            }
        }
    }
    private void SearchToBinder()
    {
        //if (Utility.SelectAirGroup == null)
        //{
        //    ComponentGroup group = new ComponentGroup();
        //    AirComponentGroup airGroup = (AirComponentGroup)((ComponentGroup)PackageMerchandise.ComponentGroup.Items[1].Component).Items[ParentIndex].Component;
        //    ComponentGroupItem componentGroupItem = new ComponentGroupItem(airGroup.Items[SonIndex].Component);
        //    AirComponentGroup lastGroup = new AirComponentGroup((AirProfile)airGroup.Profile);
        //    lastGroup = (AirComponentGroup)airGroup.Clone();
        //    lastGroup.Items.Add(componentGroupItem);
        //    group.Profile = PackageMerchandise.ComponentGroup.Profile;
        //    group.Items.Clear();
        //    group.Items.Add(new ComponentGroupItem(lastGroup));
        //    Utility.SelectAirGroup = group;

        //    if (Utility.Transaction.CurrentTransactionObject.Items.Count == 0)
        //    {
        //        SaleMerchandise saleMerchandise = new SaleMerchandise();
        //        saleMerchandise.ComponentGroup = group;
        //        Utility.Transaction.CurrentTransactionObject.AddItem(saleMerchandise);

        //    }
        //    else
        //    {
        //        Utility.Transaction.CurrentTransactionObject.Items[0].Merchandise.ComponentGroup = group;
        //    }
        //}
        if (pgMerchandise != null && pgMerchandise.Items.Count > 0)
        {
            //int index = m_SaleMerchandise.DefaultMerchandise.Length - 1;

            PackageOrderItem packageOrderItem = new PackageOrderItem(new PackageProfile("PackageProfile"));

            int hotelIndex = Convert.ToInt32(((List<int>)pgMerchandise.DefaultIndex[1 + pgMerchandise.CurrentHotelListNumber])[0]);
            List<PackageMaterial> MVHotelList = pgMerchandise.GetPackageMaterials(1 + pgMerchandise.CurrentHotelListNumber);
            packageOrderItem.RoomPrice = ((PackageMaterial)MVHotelList[hotelIndex]).RoomPrice;
            packageOrderItem.Nights = ((PackageMaterial)MVHotelList[hotelIndex]).Nights;
            packageOrderItem.RoomPricePerNight = ((PackageMaterial)MVHotelList[hotelIndex]).RoomPricePerNight;
            packageOrderItem.AirPrice = ((PackageMaterial)MVHotelList[hotelIndex]).AirPrice;
            packageOrderItem.TotalPrice = ((PackageMaterial)MVHotelList[hotelIndex]).TotalPrice;

            AirOrderItem airOrderItem = new AirOrderItem((AirMaterial)pgMerchandise.DefaultMerchandise[0]);

            packageOrderItem.Add(airOrderItem);

            for (int i = 1; i < pgMerchandise.Items.Count; i++)
            {
                for (int k = 0; k < ((List<Hotel>)pgMerchandise.DefaultMerchandise[i]).Count; k++)
                {
                    MVHotel mvHotel = (MVHotel)((List<Hotel>)pgMerchandise.DefaultMerchandise[i])[k];

                    for (int roomIndex = 0; roomIndex < mvHotel.Items.Count; roomIndex++)
                    {
                        MVRoom mvRoom = (MVRoom)mvHotel.Items[roomIndex];

                        //mvRoom.DefaultRoomType.Room.Hotel.SetAddress(new TERMS.Common.Address(mvRoom.DefaultRoomType.Room.Hotel.City, mvRoom.DefaultRoomType.Room.Hotel.Address, mvHotel.GetAddress().ZipCode));

                        HotelOrderItem hotelOrderItem = new HotelOrderItem(mvRoom.DefaultRoomType, mvRoom.Profile);

                        packageOrderItem.Add(hotelOrderItem);
                    }
                }
                if (Utility.Transaction.CurrentTransactionObject != null)
                    Utility.Transaction.CurrentTransactionObject.Items.Clear();
                Utility.Transaction.CurrentTransactionObject.Items.Add(packageOrderItem);
            }
        }

        this.DefaultFlightDetails1.FlightDetails = AirMaterialList;
        this.FlightHeader1.ReBind();
        this.ShowPackageHotels1.pgMerchandise = pgMerchandise;

        this.ShowPackageHotels1.BindHotels();

        //如果Hotel的checkin checkout 的差大于5天 edit by tll
        SetChooseDisable();
    }
Exemplo n.º 3
0
    private PackageMerchandise SearchPackage(Terms.Sales.Business.PackageSearchCondition searchCondition)
    {
        searchCondition.UserInfo = UserInfo;
        searchCondition.AirSearchCondition.UserInfo = UserInfo;
        searchCondition.HotelSearchCondition.UserInfo = UserInfo;

        if (searchCondition.HotelSearchCondition2 != null)
            searchCondition.HotelSearchCondition2.UserInfo = UserInfo;

        //��Cache�в��ҽ�
        PackageMerchandise packageMerchandise = (PackageMerchandise)MVMerchandisePool.Find(searchCondition);

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

            Utility.Transaction.Difference.To = "OnSearch1 End";
            Utility.Transaction.Difference.EndTime = DateTime.Now;
            Utility.Transaction.Difference.From = "Search Package By Find";
            Utility.Transaction.Difference.StarTime = DateTime.Now;

            PackageProductSearcher searcher = new PackageProductSearcher();
            TERMS.Common.Search.PackageSearchCondition pkgCondition = new TERMS.Common.Search.PackageSearchCondition();
            DateTime depDate = searchCondition.AirSearchCondition.GetAddTripCondition()[0].DepartureDate;
            DateTime rtnDate = new DateTime();
            string fromAirportCode = searchCondition.AirSearchCondition.GetAddTripCondition()[0].Departure.Code;
            string toAirportCode = searchCondition.AirSearchCondition.GetAddTripCondition()[0].Destination.Code;
            string rtnFromAirportCode = string.Empty;
            string rtnToAirportCode = string.Empty;
            int adultNumber = searchCondition.AirSearchCondition.GetPassengerNumber(TERMS.Common.PassengerType.Adult);

            int childNumber = searchCondition.AirSearchCondition.GetPassengerNumber(TERMS.Common.PassengerType.Child);
            IList<PackageProduct> pkgs = new List<PackageProduct>();
            if (searchCondition.AirSearchCondition.FlightType.ToLower().Equals("oneway"))
            {
                //û��
            }
            else if (searchCondition.AirSearchCondition.FlightType.ToLower().Equals("roundtrip"))
            {
                rtnDate = searchCondition.AirSearchCondition.GetAddTripCondition()[1].DepartureDate;
                pkgCondition.AirCondition = new TERMS.Common.Search.AirSearchCondition(fromAirportCode, true, toAirportCode, true, depDate, true, rtnDate, true, adultNumber, childNumber, 0);
            }
            else
            {
                rtnDate = searchCondition.AirSearchCondition.GetAddTripCondition()[1].DepartureDate;
                rtnFromAirportCode = searchCondition.AirSearchCondition.GetAddTripCondition()[1].Departure.Code;
                rtnToAirportCode = searchCondition.AirSearchCondition.GetAddTripCondition()[1].Destination.Code;
                pkgCondition.AirCondition = new TERMS.Common.Search.AirSearchCondition(fromAirportCode, true, toAirportCode, true, depDate, true, rtnFromAirportCode, true, rtnToAirportCode, true, rtnDate, true, adultNumber, childNumber, 0);
            }

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

            //����Airlines
            if (searchCondition.AirSearchCondition.Airlines != null && searchCondition.AirSearchCondition.Airlines.Length > 0)
                pkgCondition.AirCondition.AddAirlines(searchCondition.AirSearchCondition.Airlines);

            //����Cabin
            for (int i = 0; i < pkgCondition.AirCondition.Trips.Count; i++)
                pkgCondition.AirCondition.Trips[i].Cabin = searchCondition.AirSearchCondition.AirTripCondition[i].Cabin;

            //ת��Hotel Search Condition
            pkgCondition.HotelCondition = ConvertHotelSearchCondition(searchCondition.HotelSearchCondition);

            pkgs = searcher.Search(pkgCondition);

            //Ϊ�̷߳�����Ӳ��� package
            PackageProduct pkg = package = pkgs[0];
            Utility.Transaction.Difference.To = "Intel Search Over";
            Utility.Transaction.Difference.EndTime = DateTime.Now;
            Utility.Transaction.Difference.From = "Return AIRItem Start";
            Utility.Transaction.Difference.StarTime = DateTime.Now;

            //�����߳� ͬʱ��ѯ Air �� Hotel
            PackageThreadStar();

            //IList<TERMS.Core.Product.Component> aa = pkg.AirGroup.Items;

            if (packageair == null || packageair.Count == 0)
            {
                m_Error = "Searching is not available in Web Searching now. Please choose another travel date or destination.(pa1)";
                return null;
            }

            Utility.Transaction.Difference.To = "Return AIRItem End";
            Utility.Transaction.Difference.EndTime = DateTime.Now;
            Utility.Transaction.Difference.From = "Return HotelItem Start";
            Utility.Transaction.Difference.StarTime = DateTime.Now;

            //IList<TERMS.Core.Product.Component> BB = pkg.HotelGroup.Items;

            if (packagehotel == null || packagehotel.Count == 0)
            {
                m_Error = "Searching is not available in Web Searching now. Please choose another travel date or destination.(ph1)";
                return null;
            }

            Utility.Transaction.Difference.To = "Return HotelItem End";
            Utility.Transaction.Difference.EndTime = DateTime.Now;
            Utility.Transaction.Difference.From = "Convert Start";
            Utility.Transaction.Difference.StarTime = DateTime.Now;

            TERMS.Business.Centers.ProductCenter.Profiles.PackageProfile packageProfile = (TERMS.Business.Centers.ProductCenter.Profiles.PackageProfile)pkg.Profile;

            packageProfile.SetParam("ADULT_NUMBER", adultNumber);
            packageProfile.SetParam("CHILD_NUMBER", childNumber);
            packageProfile.SetParam("CheckIn", searchCondition.HotelSearchCondition.CheckIn);
            packageProfile.SetParam("CheckOut", searchCondition.HotelSearchCondition.CheckOut);
            packageProfile.SetParam("Location", searchCondition.HotelSearchCondition.Location);
            try
            {
                packageMerchandise = new PackageMerchandise(packageProfile, pkg);

                if (packageMerchandise.Items[1] == null || ((HotelMerchandise)packageMerchandise.Items[1]).Items == null || ((HotelMerchandise)packageMerchandise.Items[1]).Items.Count == 0)
                {
                    m_Error = "Searching is not available in Web Searching now. Please choose another travel date or destination.";
                    return null;
                }

                for (int i = 1; i < packageMerchandise.Items.Count; i++)
                {
                    HotelMerchandise hotelMerchandise = (HotelMerchandise)packageMerchandise.Items[i];
                    hotelMerchandise.Profile.CheckInDate = searchCondition.HotelSearchCondition.CheckIn;
                    hotelMerchandise.Profile.CheckOutDate = searchCondition.HotelSearchCondition.CheckOut;//
                    hotelMerchandise = ConvertHotelToMVHotel(searchCondition.HotelSearchCondition, hotelMerchandise);
                }
                //�ж�
                if (packageMerchandise.Items[1] == null || ((HotelMerchandise)packageMerchandise.Items[1]).Items == null || ((HotelMerchandise)packageMerchandise.Items[1]).Items.Count == 0)
                {
                    m_Error = "Searching is not available in Web Searching now. Please choose another travel date or destination.";
                    return null;
                }

                MVMerchandisePool.Cache(searchCondition.Clone(), packageMerchandise); //Cache

                if (searchCondition.OptionalHotelSearchConditions.Count > 0)
                {
                    for (int j = 0; j < searchCondition.OptionalHotelSearchConditions.Count; j++)
                    {
                        packageMerchandise.Items.Add(SearchHotel(searchCondition.OptionalHotelSearchConditions[j]));
                    }
                    packageMerchandise.ReSetPMItems();    // �趨��Ĭ����������
                }
                packageMerchandise.Reset();//��Ϊ��ʼ��packageMerchandise �е� CurrentItem
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message);
            }

            //��¼Searchʱ��
            DateTime SearchingEndingTime = DateTime.Now;
            SearchingLogger searchingLogger = new SearchingLogger();
            searchingLogger.Log(SearchingBeginningTime, SearchingEndingTime, searchCondition);
        }
        else
        {
            if (searchCondition.OptionalHotelSearchConditions.Count == packageMerchandise.CurrentItems.Count - 3)
            {
                packageMerchandise.Items.RemoveAt(packageMerchandise.Items.Count - 1);
                packageMerchandise.CurrentItems.RemoveAt(packageMerchandise.CurrentItems.Count - 1);

                packageMerchandise.CurrentHotelListNumber = 0;
                packageMerchandise.Reset();
                packageMerchandise.ReSetPMItems();
            }

            if (searchCondition.IsReset) //����packageMerchandise �е� CurrentItem
            {
                for (int i = 2; i < packageMerchandise.Items.Count; i++)
                {
                    packageMerchandise.Items.Remove(packageMerchandise.Items[i]);
                }
                packageMerchandise.CurrentHotelListNumber = 0;
                packageMerchandise.Reset();
                packageMerchandise.ReSetPMItems();
            }
        }

        List<int> searchFaildHotelIndexs = new List<int>();

        for (int i = 0; i < searchCondition.OptionalHotelSearchConditions.Count; i++)
        {
            HotelMerchandise hotelMerchandise = (HotelMerchandise)MVMerchandisePool.Find(searchCondition.OptionalHotelSearchConditions[i]);
            if (hotelMerchandise == null)
            {
                hotelMerchandise = SearchHotel(searchCondition.OptionalHotelSearchConditions[i]);

                if (hotelMerchandise == null) //Search Hotelʧ��
                    searchFaildHotelIndexs.Add(i);

                packageMerchandise.Items.Add(hotelMerchandise);
                packageMerchandise.Reset(i + 2);
                packageMerchandise.ReSetPMItems();
            }
            else
            {
                if ((packageMerchandise.Items.Count - 1) >= (i + 2))//�ж��±�(i+2),��Items �����Ƿ����
                    packageMerchandise.Items[i + 2] = hotelMerchandise;
                else
                {
                    packageMerchandise.Items.Add(hotelMerchandise);
                    packageMerchandise.Reset(i + 2);
                    packageMerchandise.ReSetPMItems();
                }
                if (searchCondition.IsReset) //����packageMerchandise �е� CurrentItem[i+2]
                    packageMerchandise.Reset(i + 2);
            }

        }

        if (searchFaildHotelIndexs.Count > 0) //Search Hotelʧ��
        {
            for (int i = 0; i < searchFaildHotelIndexs.Count; i++)
            {
                //���Searchʧ�ܵ�Hotel Search Condition
                searchCondition.OptionalHotelSearchConditions.RemoveAt(searchFaildHotelIndexs[i] - i);
                packageMerchandise.Items.RemoveAt(searchFaildHotelIndexs[i] + 2 - i);
                packageMerchandise.CurrentItems.RemoveAt(searchFaildHotelIndexs[i] + 2 - i);
            }

            packageMerchandise.ReSetPMItems();

            return null;
        }

        searchCondition.IsReset = false;

        Utility.Transaction.Difference.To = "Convert End";
        Utility.Transaction.Difference.EndTime = DateTime.Now;

        Utility.Transaction.Difference.From = "Search End";
        Utility.Transaction.Difference.StarTime = DateTime.Now;

        packageMerchandise.UserInfo = UserInfo.User.UserName;

        return packageMerchandise;
    }