using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

public partial class step1_round : System.Web.UI.Page
{
    DataTable dsODxml_FlightSegment_OneWay_Depart;
    AirEpointSupport obj_airsupport = new AirEpointSupport();
    int portalid,agentid;
    double inrtosgd ;
    protected void Page_Load(object sender, EventArgs e)
    {
        //inrtosgd = Convert.ToDouble(Session["SingaporeDollar"]);
       
        //portalid = Convert.ToInt32(Session["portalid"]);
        try
        {
            if (Session["BookinRequest_OriginDestinationOption_OneWay_Depart"] == null || Session["DestinationFrom"] == null)
            {
                Response.Redirect("../../User/Index.aspx?s=timeout", false);
            }
            if (!IsPostBack)
            {
                string ss = Convert.ToString(Session["Trip"]);
                lbl_source.Text = Convert.ToString(Session["DestinationFrom"]);
                lbl_destination.Text = Convert.ToString(Session["DestinationTo"]);
                if (Convert.ToString(Session["Trip"]) == "One")
                {
                        div_round.Visible = false;
                        lbl_price.Text = Session["Currency"].ToString() + " " + Math.Round(Convert.ToDecimal(Session["Dom_Ticket_Price"]) * Convert.ToDecimal(Session["convertor"])).ToString();
                        Get_selected_Depart_flight_route_information_and_Generate_runtime_table();
                        inrlabel.Visible = true;
                        sgdlabel.Visible = false;
                }
                else if (Convert.ToString(Session["Trip"]) == "Round")
                {
                        sgdlabel.Visible = false;
                        inrlabel.Visible = true;
                        lbl_price.Text = Session["Currency"].ToString()+" "+Math.Round(Convert.ToDecimal(Session["Dom_Ticket_Price"]) * Convert.ToDecimal(Session["convertor"])).ToString();
                        div_round.Visible = true;
                        lbl_source_round.Text = Convert.ToString(Session["DestinationTo"]);
                        lbl_destination_round.Text = Convert.ToString(Session["DestinationFrom"]);
                        Get_selected_Depart_flight_route_information_and_Generate_runtime_table();
                    string OriginDestinationOptionxml_FlightSegment_Return = Convert.ToString(Session["BookinRequest_OriginDestinationOption_OneWay_Return"]);
                    DataTable dsODxml_FlightSegment_Return = new DataTable();
                    dsODxml_FlightSegment_Return = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Return"];
                    if (dsODxml_FlightSegment_Return.Rows.Count != 0)
                    {
                        string dynTable = "";
                        string duration;
                        dynTable = " <table cellpadding=\"0\"cellspacing=\"0\" border=\"1\" width=\"100%\" style=\"border-collapse:collapse;border-color:#ccc;\">";
                        dynTable += "<tr bgcolor=\"#D1DBF3\">  <th width=\"10%\" height=\"30px\" style=\"border-bottom:1px solid #ccc;\">   Airline</th><th width=\"15%\"  style=\"border-bottom:1px solid #ccc;\">Flight# </th><th width=\"30%\" style=\"border-bottom:1px solid #ccc;\"> Departure</th>";
                        dynTable += " <th width=\"30%\" style=\"border-bottom:1px solid #ccc;\"> Arrival</th>   <th width=\"8%\" style=\"border-bottom:1px solid #ccc;\">    Duration     </th>  <th width=\"7%\" style=\"border-bottom:1px solid #ccc;\">Class </th>  </tr>";

                        for (int tRows = 0; tRows < dsODxml_FlightSegment_Return.Rows.Count; tRows++)
                        {
                            Image imageAirLineUrl = new Image();
                            string flightName = string.Empty;
                            DataSet ds = obj_airsupport.GetAirImageDetails();
                            var imageurl = from ImgurlDetail in ds.Tables["AirLineImageUrlDetail"].AsEnumerable()
                                           where ImgurlDetail.Field<string>("AirlineCode") == Convert.ToString(dsODxml_FlightSegment_Return.Rows[tRows]["CarrierCode"]).Trim()
                                           select new
                                           {
                                               airlineimgeurl = ImgurlDetail["filename"].ToString(),
                                               airlinename = ImgurlDetail["AirlineName"].ToString()
                                           };
                            if (imageurl.Count() > 0)
                            {
                                imageAirLineUrl.ImageUrl = "../../AirLineImage/" + imageurl.AsEnumerable().ElementAt(0).airlineimgeurl;
                                flightName = imageurl.AsEnumerable().ElementAt(0).airlinename;
                            }
                            else
                            {
                                imageAirLineUrl.ImageUrl = "../../AirLineImage/blank.jpg";
                            }

                            string ImageURL = imageAirLineUrl.ImageUrl;
                            dynTable += "<tr valign=\"top\"> <td><img width=\"60px\" height=\"25px\"  src=\"" + ImageURL + "\"</img></td>";
                            dynTable += " <td>" + flightName + "<br />" + (dsODxml_FlightSegment_Return.Rows[tRows]["CarrierCode"]) + "-" + (dsODxml_FlightSegment_Return.Rows[tRows]["FlightNo"]) + "</td>   ";
                            dynTable += "<td>" + Convert.ToString(dsODxml_FlightSegment_Return.Rows[tRows]["DepartureDateTime"]).Substring(11, 5) + "," + (Convert.ToString(dsODxml_FlightSegment_Return.Rows[tRows]["DepartureDateTime"]).Substring(0, 10)) + "<br />" + (dsODxml_FlightSegment_Return.Rows[tRows]["Source"]) + "(" + (dsODxml_FlightSegment_Return.Rows[tRows]["Source"]) + ")<br />      </td>";
                            dynTable += "<td>" + Convert.ToString(dsODxml_FlightSegment_Return.Rows[tRows]["ArrivalDateTime"]).Substring(11, 5) + "," + (Convert.ToString(dsODxml_FlightSegment_Return.Rows[tRows]["ArrivalDateTime"]).Substring(0, 10)) + "<br />" + (dsODxml_FlightSegment_Return.Rows[tRows]["Destination"]) + "(" + (dsODxml_FlightSegment_Return.Rows[tRows]["Destination"]) + ")<br />   </td>";
                            duration = Convert.ToString(dsODxml_FlightSegment_Return.Rows[tRows]["Duration"]);
                            string classs = Convert.ToString(Session["Class"]);
                            if (classs == "E")
                            {
                                classs = "Economy";
                            }
                            else
                            {
                                classs = "Business";
                            }
                            dynTable += "<td> " + duration + "</td>";
                            dynTable += "<td>" + classs + "</td>";
                            dynTable += "</tr>";
                        }
                        dynTable += "</table>";
                        LiteralFlight_info_Return.Text = dynTable;
                    }
                }   
            }
        }
        catch (Exception ex)
        {
            obj_airsupport.WriteToLog(ex.Message, "step1", "Page Load__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../../User/Index.aspx?s=exception");
        }
    }
    protected   void Button1_Click(object sender, EventArgs e)
    {
        if (CheckBox1.Checked)
        {
          Response.Redirect("step3.aspx");
        }
        else
        {
            RegisterClientScriptBlock("alert","<script>alert('Please select Terms and Condition');</script>");
        }
    }

    public void Get_selected_Depart_flight_route_information_and_Generate_runtime_table()
    {
        try
        {
            #region Get selected Depart flight route information and Generate runtime table
            dsODxml_FlightSegment_OneWay_Depart = new DataTable();
            dsODxml_FlightSegment_OneWay_Depart = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Depart"];
            if (dsODxml_FlightSegment_OneWay_Depart.Rows.Count != 0)
            {
                string dynTable = "";
                Session["Stop_quantity"] = dsODxml_FlightSegment_OneWay_Depart.Rows.Count;
                dynTable = " <table cellpadding=\"0\"cellspacing=\"0\" border=\"1\" width=\"100%\" style=\"border-collapse:collapse;border-color:#ccc;\">";
                dynTable += "<tr bgcolor=\"#D1DBF3\">  <th width=\"10%\" height=\"30px\" style=\"border-bottom:1px solid #ccc;\">   Airline</th><th width=\"15%\"  style=\"border-bottom:1px solid #ccc;\">Flight# </th><th width=\"30%\" style=\"border-bottom:1px solid #ccc;\"> Departure</th>";
                dynTable += " <th width=\"30%\" style=\"border-bottom:1px solid #ccc;\"> Arrival</th>   <th width=\"8%\" style=\"border-bottom:1px solid #ccc;\">    Duration     </th>  <th width=\"7%\" style=\"border-bottom:1px solid #ccc;\">Class </th>  </tr>";              
                string duration;
                for (int tRows = 0; tRows < dsODxml_FlightSegment_OneWay_Depart.Rows.Count; tRows++)
                {
                    Image imageAirLineUrl = new Image();
                    string flightName = string.Empty;
                    DataSet ds = obj_airsupport.GetAirImageDetails();
                    var imageurl = from ImgurlDetail in ds.Tables["AirLineImageUrlDetail"].AsEnumerable()
                                   where ImgurlDetail.Field<string>("AirlineCode") == Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["CarrierCode"]).Trim()
                                   select new
                                   {
                                       airlineimgeurl = ImgurlDetail["filename"].ToString(),
                                       airlinename = ImgurlDetail["AirlineName"].ToString()
                                   };
                    if (imageurl.Count() > 0)
                    {
                        imageAirLineUrl.ImageUrl = "../../AirLineImage/" + imageurl.AsEnumerable().ElementAt(0).airlineimgeurl;
                        flightName = imageurl.AsEnumerable().ElementAt(0).airlinename;
                    }
                    else
                    {
                        imageAirLineUrl.ImageUrl = "../../AirLineImage/blank.jpg";
                    }
                    string ImageURL = imageAirLineUrl.ImageUrl;
                    dynTable += "<tr valign=\"top\"> <td><img width=\"60px\" height=\"25px\"  src=\"" + ImageURL + "\"</img></td>";
                    dynTable += " <td>" + flightName + "<br />" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["CarrierCode"]) + "-" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["FlightNo"]) + "</td>   ";
                    dynTable += "<td>" + Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["DepartureDateTime"]).Substring(11, 5) + "," + (Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["DepartureDateTime"]).Substring(0, 10)) + "<br />" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["Source"]) + "(" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["Source"]) + ")<br />      </td>";
                    dynTable += "<td>" + Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["ArrivalDateTime"]).Substring(11, 5) + "," + (Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["ArrivalDateTime"]).Substring(0, 10)) + "<br />" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["Destination"]) + "(" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["Destination"]) + ")<br />   </td>";
                    duration = Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["Duration"]);
                    string classs = Convert.ToString(Session["Class"]);
                    if (classs == "E")
                    {
                        classs = "Economy";
                    }
                    else
                    {
                        classs = "Business";
                    }
                    dynTable += "<td> "+duration+"</td>";
                    dynTable += "<td>" + classs + "</td>";
                    dynTable += "</tr>";
                }
                dynTable += "</table>";
                Literal_FlightInformation.Text = dynTable;
            }
            #endregion
        }
        catch (Exception ex)
        {
            obj_airsupport.WriteToLog(ex.Message, "step1", "Get_selected_Depart_flight_route_information_and_Generate_runtime_table__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../../User/Index.aspx?s=exception");
        }
    }
}
