private string GetFlightTime(AirLeg airLeg)
        {
            string duration;

            AirLineMatricsManager airManager = new AirLineMatricsManager();

            return airManager.FormatTimeSpan(airManager.GetFlightTime(airLeg));
        }
        protected void dlSubTrips_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            System.Web.UI.WebControls.Label lblStops = (System.Web.UI.WebControls.Label)e.Item.FindControl("lblStops");
            SubAirTrip subAirTrip = (SubAirTrip)(((System.Object)(((System.Web.UI.WebControls.DataListItem)(e.Item)).DataItem)));

            AirLineMatricsManager airlineMatricsManager = new AirLineMatricsManager();
            lblStops.Text = airlineMatricsManager.GetStopsInsideFlight(subAirTrip).ToString();

            //Duration
            Label lblDuration = (System.Web.UI.WebControls.Label)e.Item.FindControl("lblDuration");
            lblDuration.Text = airlineMatricsManager.FormatTimeSpan(airlineMatricsManager.GetDuration(subAirTrip));
        }
        private string GetDuration(AirMaterial flight)
        {
            string duration = string.Empty;
            TimeSpan flightTime = TimeSpan.Zero;
            TimeSpan connectionTime = TimeSpan.Zero;

            AirLineMatricsManager airManager = new AirLineMatricsManager();

            flightTime = airManager.GetFlightTime(flight);
            connectionTime = airManager.GetDuration(flight);

            return String.Format("{0} ({1}", airManager.FormatTimeSpan(flightTime), airManager.FormatTimeSpan(connectionTime));
        }
    private void ShowFlightByStop(MatrixStopType stopType)
    {
        List<Component> matixFlightList = null;

        matixFlightList = new AirLineMatricsManager().GetFlightListByStop(stopType);

        AvailableFlightList = matixFlightList;

        DoAfterFilter();
    }
    private void SortFlight(AirLineMatricsManager.SortByFlag sortbyFlag)
    {
        SetSortFlag(sortbyFlag);

        AvailableFlightList = GetSortedList(sortbyFlag);
        DoAvailableRebind();

        SetLinkBttonColor();
    }
    private void SetSortUpDownFlag(ref AirLineMatricsManager.SortFlag sortFlag, AirLineMatricsManager.SortFlag current_sortFlag)
    {
        m_sortFlag_Airline = AirLineMatricsManager.SortFlag.None;
        m_sortFlag_Arrival = AirLineMatricsManager.SortFlag.None;
        m_sortFlag_Departure = AirLineMatricsManager.SortFlag.None;
        m_sortFlag_Price = AirLineMatricsManager.SortFlag.None;
        m_sortFlag_Duration = AirLineMatricsManager.SortFlag.None;

        switch (current_sortFlag)
        {
            case AirLineMatricsManager.SortFlag.None:
                sortFlag = AirLineMatricsManager.SortFlag.Asc;
                break;

            case AirLineMatricsManager.SortFlag.Asc:
                sortFlag = AirLineMatricsManager.SortFlag.Desc;
                break;

            case AirLineMatricsManager.SortFlag.Desc:
                sortFlag = AirLineMatricsManager.SortFlag.Asc;
                break;
        }

        m_sortFlag = sortFlag;
    }
    private void ShowAllResult()
    {
        AvailableFlightList = TotalAvailableFlightList;

        AirLineMatricsManager airManager = new AirLineMatricsManager();
        //����
        AvailableFlightList = airManager.GetSortedList(AvailableFlightList, m_sortByFlag, m_sortFlag);

        DoAfterAvailableRebind();

        HiddenBackToAllResultPanel();
    }
    private void SetImageUpDownVisible(LinkButton lb_sort, System.Web.UI.WebControls.Image img_Up, System.Web.UI.WebControls.Image img_Down, AirLineMatricsManager.SortFlag sortFlag)
    {
        m_lb_Sort = lb_sort;

        img_airlineUp.Visible = false;
        img_airlineDown.Visible = false;
        img_arrivalUp.Visible = false;
        img_arrivalDown.Visible = false;
        img_departureUp.Visible = false;
        img_departureDown.Visible = false;
        img_priceUp.Visible = false;
        img_priceDown.Visible = false;
        img_DurationUp.Visible = false;
        img_DurationDown.Visible = false;

        List<LinkButton> lbList = new List<LinkButton>();
        lbList.Add(lb_sortAirline);
        lbList.Add(lb_sortDeparture);
        lbList.Add(lb_sortDuration);
        lbList.Add(lb_sortPrice);
        lbList.Add(lb_sortArrival);

        foreach (LinkButton linkButton in lbList)
        {
            //linkButton.Style["color"] = DEFAULT_COLOR;
        }

        //lb_sort.Style["color"] = "#FF3300";

        switch (sortFlag)
        {
            case AirLineMatricsManager.SortFlag.Asc:
                img_Up.Visible = true;
                img_Down.Visible = false;
                break;

            case AirLineMatricsManager.SortFlag.Desc:
                img_Up.Visible = false;
                img_Down.Visible = true;
                break;
        }
    }
    private void SetSortFlag(AirLineMatricsManager.SortByFlag sortByFlag)
    {
        AirLineMatricsManager.SortFlag current_sortFlag = AirLineMatricsManager.SortFlag.None;
        m_sortByFlag = sortByFlag;

        switch (sortByFlag)
        {
            case AirLineMatricsManager.SortByFlag.Airline:

                current_sortFlag = m_sortFlag_Airline;
                SetSortUpDownFlag(ref m_sortFlag_Airline, current_sortFlag);

                SetImageUpDownVisible(lb_sortAirline, img_airlineUp, img_airlineDown, m_sortFlag_Airline);

                //l

                break;

            case AirLineMatricsManager.SortByFlag.ArrivalDate:

                current_sortFlag = m_sortFlag_Airline;
                SetSortUpDownFlag(ref m_sortFlag_Arrival, current_sortFlag);

                SetImageUpDownVisible(lb_sortArrival, img_arrivalUp, img_arrivalDown, m_sortFlag_Airline);

                break;

            case AirLineMatricsManager.SortByFlag.DepartureDate:

                current_sortFlag = m_sortFlag_Departure;
                SetSortUpDownFlag(ref m_sortFlag_Departure, current_sortFlag);

                SetImageUpDownVisible(lb_sortDeparture, img_departureUp, img_departureDown, m_sortFlag_Departure);

                break;
            case AirLineMatricsManager.SortByFlag.Price:

                current_sortFlag = m_sortFlag_Price;
                SetSortUpDownFlag(ref m_sortFlag_Price, current_sortFlag);

                SetImageUpDownVisible(lb_sortPrice, img_priceUp, img_priceDown, m_sortFlag_Price);

                break;

            case AirLineMatricsManager.SortByFlag.Duration:

                current_sortFlag = m_sortFlag_Duration;
                SetSortUpDownFlag(ref m_sortFlag_Duration, current_sortFlag);

                SetImageUpDownVisible(lb_sortDuration, img_DurationUp, img_DurationDown, m_sortFlag_Duration);

                break;
        }
    }
    private List<Component> GetSortedList(AirLineMatricsManager.SortByFlag sortbyFlag)
    {
        AirLineMatricsManager airLineMatricsManager = new AirLineMatricsManager();
        List<Component> sortedList = null;

        sortedList = airLineMatricsManager.GetSortedList(AvailableFlightList, sortbyFlag, m_sortFlag);

        return sortedList;
    }
    private void CreateFlightDetailList()
    {
        AirMerchandise componentGroup = FlightMerchandise;

        List<Component> flightList = GteReBindContactAgentList(componentGroup.Items);

        SubAirTrip subAirTrip = new SubAirTrip();

        List<Component> flightDetailList = new List<Component>();

        List<Component> selectContactFlightList = new List<Component>();
        List<Component> availableFlightList = new List<Component>();

        //����flightList,�����еĺ�����Ϣ��ӳ�һ��list
        for (int flightIndex = 0; flightIndex < flightList.Count; flightIndex++)
        {
            AirMerchandise flight = (AirMerchandise)flightList[flightIndex];

            //for(int flightItemindex=0; index < flight.Items.Count; index++)
            //{
            //    AirMaterial tempairMaterial = (AirMaterial)flight.Items[flightItemindex];
            //    AirMaterial airMaterial = (AirMaterial)flight.Items[flightItemindex];

            //    for(int subairtripIndex = 0; subairtripIndex<(airMaterial.AirTrip.SubTrips.Count; subairtripIndex++)
            //    {
            //        SubAirTrip subAirTrip = ((AirMaterial)flight.Items[flightItemindex]).AirTrip.SubTrips[subairtripIndex];
            //        tempairMaterial = airMaterial.
            //    }
            //}

            if (flight.Items != null)
            {

                for (int mIndex = 0; mIndex < flight.Items.Count; mIndex++)
                {
                    AirMaterial currentFlight = ((AirMaterial)flight.Items[mIndex]);

                    currentFlight.Profile = flight.Profile;
                    currentFlight.Profile.SetParam(Key_FlightMerchandisIndex, flightIndex);

                    if (IsFlightAvailable(currentFlight))
                    {
                        availableFlightList.Add(currentFlight);
                    }
                    else
                    {
                        selectContactFlightList.Add(currentFlight);
                    }

                    flightDetailList.Add(currentFlight);
                }

                //flightDetailList.AddRange(flight.Items);

                //availableFlightList.AddRange(flight.Items);
            }

            else
            {
                AirMaterial airMaterial = new AirMaterial((AirProfile)flight.Profile);
                CopyMarkup(flight, airMaterial);

                airMaterial.Profile.SetParam(Key_FlightMerchandisIndex, flightIndex);

                //flight.Add(airMaterial);
                flightDetailList.Add(airMaterial);

                selectContactFlightList.Add(airMaterial);
            }
        }

        //����AvailableFlightList
        availableFlightList = new AirLineMatricsManager().GetSortedByPriceFlightList(availableFlightList);
        TotalAvailableFlightList = availableFlightList;
        AvailableFlightList = availableFlightList;

        //����SelectContactFlightList
        TotalSelectContactFlightList = selectContactFlightList;
        SelectContactFlightList = selectContactFlightList;

        TotalFlightList = flightDetailList;
    }
    private void CreateAirMatrixList()
    {
        AllAirMatrixList = new AirLineMatricsManager().EditFlightsToAirMatrixStyle(TotalAvailableFlightList, GetTotalSelectFlightList(TotalSelectContactFlightList));

        AirMatrixList = new AirLineMatricsManager().GetShortedMatrixList(AllAirMatrixList);
    }
    private void BindAfterSelect(int index)
    {
        PagedDataSource pds = new PagedDataSource();

        //pds.DataSource = GteReBindContactAgentList(componentGroup.Items);
        //pds.DataSource = FlightDetailList;

        //AirMerchandise componentGroup = FlightMerchandise;

        //List<Component> flightList = GteReBindContactAgentList(componentGroup.Items);

        //CreateFlightDetailList();

        //CreateAirMatrixList();

        SelectContactFlightList = new AirLineMatricsManager().GetSortedByPriceFlightList(SelectContactFlightList);
        List<Component> flightDetailList = SelectContactFlightList;

        //FlightDetailList = flightDetailList;

        //pds.DataSource = GteReBindContactAgentList(componentGroup.Items);
        pds.DataSource = flightDetailList;

        //pds.PageSize            = FIRST_PAGE_LEN;//PageNumber1.PageSize;
        pds.PageSize = FIRST_PAGE_LEN;//PageNumber1.PageSize;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = index >= 0 ? index : 0;

        PageNumber2.PageAmount = pds.PageCount;
        PageNumber2.CurrentPageIndex = index;

        if (pds.DataSourceCount < FIRST_PAGE_LEN + 1)
        {
            PageNumber2.Visible = false;
            PageNumber2.RefreshDll();
        }
        else
        {
            PageNumber2.Visible = true;
            PageNumber2.RefreshDll();
            PageNumber2.Update();
        }

        PageNumber2.RefreshDll();
        dlSelectContact.DataSource = GetCurrenPageSource(index, flightDetailList);

        dlSelectContact.DataBind();

        notRebind = true;

        //Page.ClientScript.RegisterStartupScript(this.GetType(), "alt", "this.location.href+='#divSelectFare';", true);
    }
    protected void lbHiddenMoreAirlines_Click(object sender, EventArgs e)
    {
        AirMatrixList = new AirLineMatricsManager().GetShortedMatrixList(AllAirMatrixList);
        BindAirMatrix();

        lbShowAllAirlines.Visible = true;
        lbHideMoreAirlines.Visible = false;
        upAirMatrix.Update();
    }