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.Data.SqlClient;
using System.IO;

using System.Xml;

public partial class Domestic_ticket_booking : System.Web.UI.Page
{

    DataSet _DS_FlightSegmentOneWay = new DataSet();
    DataSet _DS1_FlightSegmentOneWay = new DataSet();
    DataSet _DS2_FlightSegmentOneWay = new DataSet();
    DataSet _DS_Agent_Details = new DataSet();
    DataSet _DS_Booking_Can_Tran_Amount_Table = new DataSet();
    AirEpointSupport obj_airsupport = new AirEpointSupport();

    string msg;

    int currentyear;
    DataSet ds;
    int flag = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["booking_request"] == null)
            {
                Response.Redirect("../User/Index.aspx?s=timeout", false);
            }

            if (!IsPostBack)
            {
                if (Session["PaymentStatus"] == null || Convert.ToString(Session["PaymentStatus"]) == "N")
                {
                    Response.Redirect("../User/Index.aspx?s=pay", false);
                }
                if (Convert.ToString(Session["PaymentStatus"]) == "Y")
                {
                    Session.Remove("PaymentStatus");
                    GetBookingStatus();
                    fillinformations();
                    lbl_source_airportname1.Text = Convert.ToString(Session["DestinationFrom"]);
                    lbl_destination_airportname1.Text = Convert.ToString(Session["DestinationTo"]);
                    string info = "";
                    ticketdetails_round.Visible = false;
                    if (Convert.ToString(Session["Trip"]) == "Round")
                    {
                        ticketdetails_round.Visible = true;
                        lbl_source_airportname_forround1.Text = Convert.ToString(Session["DestinationTo"]);
                        lbl_destination_airportname_forround1.Text = Convert.ToString(Session["DestinationFrom"]);
                    }
                    string status = Convert.ToString(ViewState["requestedPNR_Status"]);
                    if (status == "Pending")
                    {
                        lbl_booking_status.Text = "Under Process";
                        lbl_booking_status_round.Text = "Under Process";
                        lbl_pnr.Text = "Not Available";
                        lbl_pnr_round.Text = "Not Available";
                        lbl_ticket_no.Text = "Not Available";
                        lbl_ticket_no_round.Text = "Not Available";
                        btncancel.Visible = false;
                        btnprint.Visible = false;
                        btnretry.Visible = true;
                    }

                    else if (status == "SUCCESS")
                    {
                        lbl_booking_status.Text = "Confirmed";
                        lbl_booking_status_round.Text = "Confirmed";
                        lbl_pnr.Text = Convert.ToString(ViewState["pnr_no"]);
                        lbl_pnr_round.Text = Convert.ToString(ViewState["pnr_no_R"]);
                        lbl_ticket_no.Text = Convert.ToString(ViewState["confirmation_id"]);
                        lbl_ticket_no_round.Text = Convert.ToString(ViewState["confirmation_id_R"]);
                        btnprint.Text = "Print Ticket";
                        btnprint.Visible = true;
                        btncancel.Text = "Cancel Ticket";
                        btncancel.Visible = true;
                        btnretry.Visible = false;

                        
                    }

                    else if (status == "Cancelled")
                    {
                        lbl_booking_status.Text = "Failed";
                        lbl_booking_status_round.Text = "Failed";
                        lbl_pnr.Text = "N/A";
                        lbl_pnr_round.Text = "N/A";
                        lbl_ticket_no.Text = "N/A";
                        lbl_ticket_no_round.Text = "N/A";
                        btncancel.Visible = false;
                        btnprint.Visible = false;
                        btnretry.Visible = false;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "Pageload__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
        }
    }

    public void GetUserContactInfo()
    {
        try
        {
            lbl_name.Text = Convert.ToString(Session["Contact_Title"]) + " " + Convert.ToString(Session["Contact_FirstName"]) + " " + Convert.ToString(Session["Contact_lastName"]);
            lbl_email.Text = Convert.ToString(Session["RequiredMainEmailid"]);
                lbl_address.Text = Convert.ToString(Session["Contact_Address"]) + " " + Convert.ToString(Session["Contact_City"]);
                lbl_state.Text = Convert.ToString(Session["Contact_State"]);
                lbl_country.Text = Convert.ToString(Session["Contact_Country"]);
                lbl_phonerno.Text = Convert.ToString(Session["Contact_PhoneNo"]);
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "GetUserContactInfo__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
        }
    }
    private void GetBookingStatus()
    {
        int flagstatus = 0;

        try
        {
            string cdate = DateTime.Now.ToString("yyy-MM-dd");
            string ctime = DateTime.Now.ToString("HH_mm_ss");
            string time_date = cdate + "_" + ctime;
            #region Booking_Response,E-ticketRequest,Booking_Status
            if (Convert.ToString(Session["booking_request"]) != "")
            { 
                AirEpointSupport obj_AirEpointSupport = new AirEpointSupport();
                obj_AirEpointSupport.WriteXmlLog(Convert.ToString(Session["booking_request"]), "Domestic_Booking_Request__" + Convert.ToString(Session["partnerRefId"]));
                Hermes obj_her = new Hermes();
                Session["get_booking_details"] = obj_her.Dom_Flight_Booking(Convert.ToString(Session["booking_request"]));
                string tempres = Session["get_booking_details"].ToString();
                obj_AirEpointSupport.WriteXmlLog(tempres, "Domestic_Booking_Response__" + Convert.ToString(Session["partnerRefId"]));
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(Convert.ToString(Session["get_booking_details"]));
                
                XmlNodeList xnode = doc.ChildNodes;
                foreach (XmlNode node1 in xnode)
                {
                    if (node1.Name == "Bookingresponse")
                    {
                        XmlNodeList xnode1 = node1.ChildNodes;
                        foreach (XmlNode node2 in xnode1)
                        {
                            if (node2.Name.ToUpper() == "RESULTCODE")
                            {
                                if (node2.NextSibling!=null)
                                {
                                    if (node2.InnerText == "1")
                                    {
                                        ViewState["status"] = "SUCCESS";
                                        foreach (XmlNode node3 in xnode1)
                                        {
                                            if (xnode1.Count == 3)
                                            {
                                                if (node3.Name == "Item")
                                                {
                                                    if (node3.NextSibling != null)
                                                    {
                                                        Create_Table_From_Booking_Response_Depart(node3.InnerXml);
                                                    }
                                                    else
                                                        Create_Table_From_Booking_Response_Return(node3.InnerXml);
                                                }
                                            }
                                            else

                                                if (node3.Name == "Item")
                                                {
                                                    Create_Table_From_Booking_Response_Depart(node3.InnerXml);
                                                }
                                        }
                                    }
                                    else
                                    {
                                        ViewState["status"] = "Pending";
                                    }
                                }
                                else
                                {
                                    XmlNodeList xnode_err = node2.ChildNodes;
                                    foreach (XmlNode node_err in xnode_err)
                                    {
                                        if (node_err.Name.ToUpper() == "STATUS")
                                        {
                                            ViewState["statuscode"] = node_err.InnerText;
                                            ViewState["status"] = "Failed";
                                        }
                                        //if (node_err.Name.ToUpper() == "ERROR")
                                        //{
                                        //    ViewState["statuscode"] = node_err.InnerText;

                                        //}
                                    }
                                }
                            
                            }
                        }

                    }
                }

                if (ViewState["status"].ToString() == "Pending")
                {
                    flagstatus = 2;
                    Session["NewTransid"] = "NewTranid";
                    Session["ticket_flag"] = flagstatus;
                    ViewState["errormessage"] = "";
                    string errormsg = Convert.ToString(ViewState["errormessage"]);
                    ViewState["get_bookingstatus"] = null;
                    ViewState["status"] = "Pending";
                    ViewState["payment_error"] = "Pending";
                    string status1 = Convert.ToString(ViewState["status"]);
                    GetBookingStatusDetailsOf_Eticket_ResponseStatus();
                }
                else if (ViewState["status"].ToString() == "SUCCESS")
                {
                    flagstatus = 1;
                    Session["ticket_flag"] = flagstatus;
                    Session["Ticket_exit"] = "SUCCESS";
                    string transid = Convert.ToString(Session["Transid"]);
                    Session["NewTransid"] = transid;
                    GetBookingStatusDetailsOf_Eticket_ResponseStatus();
                }
                else if (ViewState["status"].ToString() == "Failed")
                {
                    flagstatus = 2;
                    Session["NewTransid"] = "NewTranid";
                    Session["ticket_flag"] = flagstatus;
                    ViewState["errormessage"] = "Transaction Failed.";
                    string errormsg = Convert.ToString(ViewState["errormessage"]);
                    ViewState["get_bookingstatus"] = null;
                    ViewState["status"] = "Failed";
                    ViewState["payment_error"] = "Failed";
                    string status1 = Convert.ToString(ViewState["status"]);
                    GetBookingStatusDetailsOf_Eticket_ResponseStatus();
                }
            }
            #endregion

        }

        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "GetBookingStatus__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }

    }

    #region GetBookingSatusOf(EticketRequest) Information Response Status

    public void GetBookingStatusDetailsOf_Eticket_ResponseStatus()
    {
        try
        {         
                            if (ViewState["status"].ToString() == "Pending")
                            {
                                ViewState["requestedPNR_Status"] = "Pending";
                                ViewState["requestedPnr_Errormsg"] = "Payment received Ticket booking is under process";
                                UpdateAllBOOKING_InformationRelatedTable();
                            } 
                            else if (ViewState["status"].ToString() == "SUCCESS")
                             {
                                ViewState["requestedPNR_Status"] = "SUCCESS";
                                ViewState["requestedPnr_Errormsg"] = "Payment received, Ticket booked successfully";
                                UpdateAllBOOKING_InformationRelatedTable();
                             }
                            else if (ViewState["status"].ToString() == "Failed")
                            {
                                ViewState["requestedPNR_Status"] = "Failed";
                                ViewState["requestedPnr_Errormsg"] = "Payment received, Ticket Not booked successfully";
                                UpdateAllBOOKING_InformationRelatedTable();
                            }

                           
        }

        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "GetBookingStatusDetailsOf_Eticket_ResponseStatus__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/IndexDom.aspx?s=exception");
            flag++;

        }
    }


    #endregion

    #region Update all Table related to GetBookingSatusResponse(EticketRequest)

    public void UpdateAllBOOKING_InformationRelatedTable()
    {
        try
        {
            string requestedPNR_Status = Convert.ToString(ViewState["requestedPNR_Status"]);
            #region Update Tables BookingInformation if requestedPNR_Status is Pending
            if (requestedPNR_Status == "Pending")
            {
                Booking_Information_Update();
                Page.RegisterStartupScript("XXX", "<script> alert('Your booking is still under process. Please check again after some time.')</script>");
            }

            #endregion


            #region Update Tables BookingInformation if requestedPNR_Status is Cancelled
            if (requestedPNR_Status == "Cancelled")
            {


                Booking_Information_Update();
                SqlParameter[] par = new SqlParameter[]
                {
                    new SqlParameter("@agentid",Convert.ToString(Session["agid"])),
                    new SqlParameter("@partnerrefid",Convert.ToString(Session["partnerRefId"]) )
                };

               // decimal AmountDeducted = Convert.ToDecimal(SqlHelper.ExecuteScaler(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_Getdeductedamount", par));
                B2B objb2b = new B2B();
                objb2b.Credit_Agent_Amount_Insertin_ATT(Session["WhitelabelId"].ToString(), Convert.ToString(Session["agid"]), Convert.ToString(Session["partnerRefId"]), "");
                Session["agent_amount"] = Convert.ToDecimal(objb2b.CheckAgentBalance(Convert.ToString(Session["agid"]),Convert.ToString(Session["HURL"])));  //get the latest amount   
            }


            #endregion

            #region Update Tables BookingInformation and OriginDestinationOption_OneWay,Air_FlightSegmentOneWay,Air,Child,Infant if requestedPNR_Status is SUCCESS
            if (requestedPNR_Status == "SUCCESS")
            { 
                    Booking_Information_And_OriginDestinationOption_OneWay_Update();
 

                    Page.RegisterStartupScript("XXX", "<script> alert('Congratulations! Your ticket is booked successfully. Click “Print Ticket” to print ticket.')</script>");
            }
            #endregion

            #region Update Tables BookingInformation if requestedPNR_Status is Failed
            if (requestedPNR_Status == "Failed")
            {

                Session["Transid"] = "";
                Booking_Information_Update();
                SqlParameter[] par = new SqlParameter[]
                {
                    new SqlParameter("@agentid",Convert.ToString(Session["agid"])),
                    new SqlParameter("@partnerrefid",Convert.ToString(Session["partnerRefId"]) )
                };

                // decimal AmountDeducted = Convert.ToDecimal(SqlHelper.ExecuteScaler(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_Getdeductedamount", par));
                B2B objb2b = new B2B();
                objb2b.Credit_Agent_Amount_Insertin_ATT(Session["WhitelabelId"].ToString(), Convert.ToString(Session["agid"]), Convert.ToString(Session["partnerRefId"]), "");
                Session["agent_amount"] = Convert.ToDecimal(objb2b.CheckAgentBalance(Convert.ToString(Session["agid"]), ""));  //get the latest amount 

                ScriptManager.RegisterStartupScript(this, GetType(), "ShowAlert", "window.alert('Your ticket booking process have been failed .Please Try After Some Time!!');document.location.href='../User/Index.aspx';", true);
                return;
            }


            #endregion

        }

        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "UpdateAllBOOKING_InformationRelatedTable__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;

        }
    }

    #endregion

    #region Update Booking_Information table according to GetBookingSatusResponse result
    public void Booking_Information_Update()
    {

        try
        {
            SqlParameter[] param_BkngInformation = new SqlParameter[]
               {
                    new SqlParameter("@ResultBkngInf_Output",SqlDbType.Int,4),
                    new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                    new SqlParameter("@transid",Convert.ToString(Session["Transid"])),
                    new SqlParameter("@Status",Convert.ToString(ViewState["requestedPNR_Status"])),
                    new SqlParameter("@error",Convert.ToString(ViewState["requestedPnr_Errormsg"])),
              };

            param_BkngInformation[0].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_BkngInformation_Update", param_BkngInformation);
            string ResultBkngInfStatus = Convert.ToString(param_BkngInformation[0].Value);

            if (ResultBkngInfStatus == "1")
            {
               
            }
            else if (ResultBkngInfStatus == "0")
            {
                // //LabelUpdateStatus.Text = "BookingInformation Records not update successfully";
            }

        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "Booking_Information_Update__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }
    }
    
 
    #endregion

    #region Update Booking_Information and OriginDestinationOption_OneWay and Air_Booking_Can_Tran table according to GetBookingSatusResponse result
    public void Booking_Information_And_OriginDestinationOption_OneWay_Update()
    {

        try
        {
            string ResultBkngInf_OrgnDOneWayStatus = null;
            SqlParameter[] paramBkngInf_OringDOneWay = new SqlParameter[]
               {
           
                //--------------------------------BOOKING_Information and OriginDestinationOption_OneWay and Air_Booking_Can_Tran  Table parameter Start------------------------------------------------------//
                    new SqlParameter("@ResultBkngInf_OrgnOneWay_Output",SqlDbType.Int,4),
                    new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                    new SqlParameter("@transid",Convert.ToString(Session["Transid"])),                                       
                    new SqlParameter("@Status",Convert.ToString(ViewState["requestedPNR_Status"])),
                    new SqlParameter("@error",Convert.ToString(ViewState["requestedPnr_Errormsg"])),
                //--------------------------------BOOKING_Information and OriginDestinationOption_OneWay and Air_Booking_Can_TranTable parameter End------------------------------------------------------//
 
              };

            paramBkngInf_OringDOneWay[0].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Bknginfo_OriginD_Oneway_Update", paramBkngInf_OringDOneWay);
            ResultBkngInf_OrgnDOneWayStatus = Convert.ToString(paramBkngInf_OringDOneWay[0].Value);
            if (ResultBkngInf_OrgnDOneWayStatus == "1")
            {
               transaction_details_Update();
            }
            else if (ResultBkngInf_OrgnDOneWayStatus == "0")
            {
                //LabelUpdateStatus.Text = "BkngInfo,OriginDOneway Records not update successfully";
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "Booking_Information_And_OriginDestinationOption_OneWay_Update__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }

    }
    #endregion

    #region Update transaction_details table
    public void transaction_details_Update()
    {
     
        try
        {
            string Result_agent_transaction_detailsStatus = null;
            DataSet dsUpdateagent_transaction_details = new DataSet();
            SqlParameter[] param_agent_transaction_details = new SqlParameter[]
               {
           
                //--------------------------------agent_transaction_details  Table parameter Start------------------------------------------------------//
                    new SqlParameter("@Result_agent_transaction_details_Output",SqlDbType.Int,4),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),                                                  
                    new SqlParameter("@Tran_status",Convert.ToString(ViewState["requestedPNR_Status"])),
                    new SqlParameter("@Remark",Convert.ToString(ViewState["requestedPnr_Errormsg"])),
                //--------------------------------agent_transaction_details parameter End------------------------------------------------------//
 
              };

            param_agent_transaction_details[0].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_transaction_details_Update", param_agent_transaction_details);
            Result_agent_transaction_detailsStatus = Convert.ToString(param_agent_transaction_details[0].Value);
            if (Result_agent_transaction_detailsStatus == "1")
            {
                FlightSegmentOneWay_Update();
            }
            else if (Result_agent_transaction_detailsStatus == "0")
            {
               
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "transaction_details_Update__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }

    }
    #endregion

    #region Update Air_FlightSegmentOneWay and ReturnSegment table according to GetBookingSatusResponse result
    public void FlightSegmentOneWay_Update()
    {
        
        try
        {
            string ResultFlightSegmentOneWayStatus = null;
            DataTable dsUpdateFlightSegmentOneWay = new DataTable();
            dsUpdateFlightSegmentOneWay = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Depart"];
            DataSet Air_Line = new DataSet();
            Air_Line=(DataSet)Session["Booking_AirLine"];

            if (dsUpdateFlightSegmentOneWay.Rows.Count != 0)
            {
                for (int i = 0; i < dsUpdateFlightSegmentOneWay.Rows.Count; i++)
                {
                    SqlParameter[] paramFlightSegmentOneWay = new SqlParameter[]
                  {
           
                //--------------------------------FlightSegmentOneWay Table parameter Start------------------------------------------------------//
                    new SqlParameter("@ResultFlightSegmentOneWay_Output",SqlDbType.Int,4),
                    new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                     new SqlParameter("@DepartureAirportCode",Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[i]["Source"])),
                     new SqlParameter("@ArrivalAirportCode",Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[i]["Destination"])),
                     new SqlParameter("@FlightNumber",Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[i]["FlightNo"])),
                     new SqlParameter("@OperatingAirlineCode ",Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[i]["CarrierCode"])),
                    new SqlParameter("@pnrnumber",Convert.ToString(Air_Line.Tables[0].Rows[0]["AirlinePNR"])),
                    new SqlParameter("@Confirmation_Id",Convert.ToString(Session["Transid"])),
                    //new SqlParameter("@Confirmation_Id",Convert.ToString(Air_Line.Tables[0].Rows[0]["AirlinePNR"])),
                                 
                    
                //--------------------------------FlightSegmentOneWay Table parameter End------------------------------------------------------//
 
              };
                    paramFlightSegmentOneWay[0].Direction = ParameterDirection.Output;
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_FlightSegmentOneWay_Update", paramFlightSegmentOneWay);
                    ResultFlightSegmentOneWayStatus = Convert.ToString(paramFlightSegmentOneWay[0].Value);
                    //---------------Edit By Vk---------------------------
                    ViewState["pnr_no"] = Convert.ToString(Air_Line.Tables[0].Rows[0]["AirlinePNR"]);
                    ViewState["confirmation_id"] = Convert.ToString(Session["Transid"]);
                    ViewState["DepartureAirportCode"] = Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[0]["Source"]);
                    ViewState["ArrivalAirportCode"] = Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[dsUpdateFlightSegmentOneWay.Rows.Count - 1]["Destination"]);
                    ViewState["Departdate"] = Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[0]["DepartureDateTime"]);
                    string Depart_date_time = Convert.ToString(ViewState["Departdate"]);
                    string[] Depart_dat = Depart_date_time.Split(' ');
                    ViewState["Depart_date"] = Convert.ToString(Depart_dat[0]);

                    //-------------------------------------------

                }
                if (Convert.ToString(Session["Trip"]) == "One")
                {
                     Adult_And_Adult_Ticket_Info_Insert();
                }
                else if (Convert.ToString(Session["Trip"]) == "Round")
                {
                    FlightSegmentReturn_Update();

                }
            
            }

        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "FlightSegmentOneWay_Update__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }

    }

    public void FlightSegmentReturn_Update()
    {
     
        try
        {
            string ResultFlightSegmentOneWayStatus = null;
            DataTable dsUpdateFlightSegmentOneWay = new DataTable();
            dsUpdateFlightSegmentOneWay = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Return"];
            DataSet Air_Line = new DataSet();
            Air_Line = (DataSet)Session["Booking_AirLine_Return"];
            if (dsUpdateFlightSegmentOneWay.Rows.Count != 0)
            {
                for (int i = 0; i < dsUpdateFlightSegmentOneWay.Rows.Count; i++)
                {
                    SqlParameter[] paramFlightSegmentOneWay = new SqlParameter[]
                  {
           
                //--------------------------------FlightSegmentOneWay Table parameter Start------------------------------------------------------//
                    new SqlParameter("@ResultFlightSegmentOneWay_Output",SqlDbType.Int,4),
                    new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                     new SqlParameter("@DepartureAirportCode",Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[i]["Source"])),
                     new SqlParameter("@ArrivalAirportCode",Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[i]["Destination"])),
                     new SqlParameter("@FlightNumber",Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[i]["FlightNo"])),
                     new SqlParameter("@OperatingAirlineCode ",Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[i]["CarrierCode"])),
                    new SqlParameter("@pnrnumber",Convert.ToString(Air_Line.Tables[0].Rows[0]["AirlinePNR"])),
                    //new SqlParameter("@Confirmation_Id",Convert.ToString(Air_Line.Tables[0].Rows[0]["AirlinePNR"])),                                  
                    new SqlParameter("@Confirmation_Id",Convert.ToString(Session["Transid_Return"])),
                //--------------------------------FlightSegmentOneWay Table parameter End------------------------------------------------------//
 
              };

                    paramFlightSegmentOneWay[0].Direction = ParameterDirection.Output;
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_FlightSegmentOneWay_Update", paramFlightSegmentOneWay);
                    ResultFlightSegmentOneWayStatus = Convert.ToString(paramFlightSegmentOneWay[0].Value);
                    //---------------Edit By Vk---------------------------
                    ViewState["pnr_no_R"] = Convert.ToString(Air_Line.Tables[0].Rows[0]["AirlinePNR"]);
                    ViewState["confirmation_id_R"] = Convert.ToString(Session["Transid_Return"]);
                    ViewState["DepartureAirportCode"] = Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[0]["Source"]);
                    ViewState["ArrivalAirportCode"] = Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[dsUpdateFlightSegmentOneWay.Rows.Count - 1]["Destination"]);
                    ViewState["Departdate"] = Convert.ToString(dsUpdateFlightSegmentOneWay.Rows[0]["DepartureDateTime"]);
                    string Depart_date_time = Convert.ToString(ViewState["Departdate"]);
                    string[] Depart_dat = Depart_date_time.Split(' ');
                    ViewState["Depart_date"] = Convert.ToString(Depart_dat[0]);

                    //-------------------------------------------

                }

                if (ResultFlightSegmentOneWayStatus == "1")
                {
                     Adult_And_Adult_Ticket_Info_Insert();
                }
                else if (ResultFlightSegmentOneWayStatus == "0")
                {
                
                }
            }

        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "FlightSegmentOneWay_Update__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }

    }
    #endregion

    #region Insert Adult and Adult_Ticket_Info table according to GetBookingSatusResponse result

    public void Adult_And_Adult_Ticket_Info_Insert()
    {
        string flightnoSel = null, origin_Sel = null, destin_Sel = null;

        try
        {
            origin_Sel = Convert.ToString(ViewState["DepartureAirportCode"]);
            destin_Sel = Convert.ToString(ViewState["ArrivalAirportCode"]);
            #region Get Adult personaldetails

            SqlParameter[] paramadultdetails = new SqlParameter[]
            {
               new SqlParameter("@ResultAdultDetails_Output",SqlDbType.Int,4),
               new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
               new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                 new SqlParameter("@FlightType","DOM"),
            };

            paramadultdetails[0].Direction = ParameterDirection.Output;
            DataSet DsAdultdetails = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_GetAdultDetails", paramadultdetails);
            string ResultAdultDetailsStatus = Convert.ToString(paramadultdetails[0].Value);

            if (ResultAdultDetailsStatus == "1")
            {
                #region Insert Adult and AdultTicketInfo Details
                string ResultAdult_AdultTicketInfo_Status = null, Flight_type = null;
                int adultpassid = 0;
                int Pss_ID = 0;
                string JourneyType = "";
                int stops = 0;

                if (Convert.ToString(Session["Trip"]) == "One")
                {
                    Flight_type = "OneWay";

                }
                else if (Convert.ToString(Session["Trip"]) == "Round")
                {
                    Flight_type = "RoundTrip";

                }

                    DataSet dsUpdateAdult_AdultTicketInfo = new DataSet();
                    dsUpdateAdult_AdultTicketInfo = (DataSet)Session["Booking_AirLine"];
                    string nameReference = string.Empty;
                    string eticketno;
                    string flightuid = "0";
                    string givenName;
                    string surName;
                    string Passuid = "0";
                    DataTable dtdepartflighdetails = new DataTable();
                    dtdepartflighdetails = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Depart"];
                    for (int i = 0; i < dtdepartflighdetails.Rows.Count; i++)
                    {
                        origin_Sel = Convert.ToString(dtdepartflighdetails.Rows[i]["Source"]);
                        destin_Sel = Convert.ToString(dtdepartflighdetails.Rows[i]["Destination"]);
                        flightnoSel = Convert.ToString(dtdepartflighdetails.Rows[i]["FlightNo"]);
                        eticketno = Convert.ToString(dsUpdateAdult_AdultTicketInfo.Tables[0].Rows[0]["AirlinePNR"]);
                        foreach (DataRow dr in DsAdultdetails.Tables[0].Rows)
                        {
                            nameReference = Convert.ToString(dr["Adulttitle"]);
                            givenName = Convert.ToString(dr["AdultFirstName"]);
                            surName = Convert.ToString(dr["AdultLastName"]);
                            adultpassid = Convert.ToInt32(dr["AdultPass_Id"]);
                            Pss_ID = Convert.ToInt32(dr["Pss_ID"]);
                            JourneyType = Convert.ToString(dr["JourneyType"]);
                            stops = Convert.ToInt32(dr["StopQuantity"]);
                           SqlParameter[] paramAdult_AdultTicketInfo = new SqlParameter[]
                           {
           

                    //--------------------------------- ADULT and Adult_Ticket_Info Table parameter Start------------------------------------------------------//

                          new SqlParameter("@ResultAdult_AdultTicketInfo_Output",SqlDbType.Int,4),
                          new SqlParameter("@AdultPass_Id",Convert.ToInt32(adultpassid)),
                          new SqlParameter("@Pss_ID",Convert.ToInt32(Pss_ID)),
                          new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                          new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                          new SqlParameter("@nameReference",nameReference),
                          new SqlParameter("@eticketno",eticketno),
                          new SqlParameter("@flightuid",flightuid),
                          new SqlParameter("@Passuid",Passuid),
                          new SqlParameter("@Flight_type",Flight_type),
                          new SqlParameter("@JourneyType",JourneyType),
                          new SqlParameter("@Connecting",Convert.ToInt32(stops)),
                          new SqlParameter("@Origin",Convert.ToString(origin_Sel)),
                          new SqlParameter("@Destination",Convert.ToString(destin_Sel)),
                          new SqlParameter("@FlightNumber",Convert.ToString(flightnoSel)),
                          new SqlParameter("@Status",Convert.ToString(ViewState["requestedPNR_Status"])),         
                   //--------------------------------ADULT  and Adult_Ticket_Info Table parameter End------------------------------------------------------//
                          };
                        paramAdult_AdultTicketInfo[0].Direction = ParameterDirection.Output;
                        SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Adult_AdultTicketInfo_Insert", paramAdult_AdultTicketInfo);
                        ResultAdult_AdultTicketInfo_Status = Convert.ToString(paramAdult_AdultTicketInfo[0].Value);
                    }
                    }//new comment
                    if (Flight_type == "RoundTrip")
                    {
                       Adult_And_Adult_Ticket_Info_InsertReturn();
                    }

                if (ResultAdult_AdultTicketInfo_Status == "1")
                {
                    if (Convert.ToInt32(Session["Children"]) > 0)
                    {
                        Child_And_Child_Ticket_Info_Insert();
                    }
                    if (Convert.ToInt32(Session["Infants"]) > 0)
                    {
                        Infant_And_Infant_Ticket_Info_Insert();
                    }

                    msg = "Congratulations! Your ticket is Successfully booked via PNR Number " + Convert.ToString(ViewState["pnr_no"]) + ", From " + Convert.ToString(ViewState["DepartureAirportCode"]) + "to " + Convert.ToString(ViewState["ArrivalAirportCode"]) + ", DOJ: " + Convert.ToString(ViewState["Depart_date"]) + ". Thanks for Using OMS Travels.";

                }
                else if (ResultAdult_AdultTicketInfo_Status == "0")
                {
                  
                }

                #endregion

            }
            else if (ResultAdultDetailsStatus == "0")
            {
              
            }


            #endregion

        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "Adult_And_Adult_Ticket_Info_Insert__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }
    }

    public void Adult_And_Adult_Ticket_Info_InsertReturn()
    {
        string flightnoSel = null, origin_Sel = null, destin_Sel = null;

        try
        {
            origin_Sel = Convert.ToString(ViewState["DepartureAirportCode"]);
            destin_Sel = Convert.ToString(ViewState["ArrivalAirportCode"]);
            SqlParameter[] paramadultdetails = new SqlParameter[]
            {
               new SqlParameter("@ResultAdultDetails_Output",SqlDbType.Int,4),
               new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
               new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                 new SqlParameter("@FlightType","DOM"),
            };
            paramadultdetails[0].Direction = ParameterDirection.Output;
            DataSet DsAdultdetails = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_GetAdultDetails", paramadultdetails);
            string ResultAdultDetailsStatus = Convert.ToString(paramadultdetails[0].Value);
            if (ResultAdultDetailsStatus == "1")
            {
                #region Insert Adult and AdultTicketInfo Details
                string ResultAdult_AdultTicketInfo_Status = null, Flight_type = null;
                int adultpassid = 0;
                int Pss_ID = 0;
                string JourneyType = "";
                int stops = 0;

                if (Convert.ToString(Session["Trip"]) == "One")
                {
                    Flight_type = "OneWay";

                }
                else if (Convert.ToString(Session["Trip"]) == "Round")
                {
                    Flight_type = "RoundTrip";

                }

               

                DataSet dsUpdateAdult_AdultTicketInfo = new DataSet();
                dsUpdateAdult_AdultTicketInfo = (DataSet)Session["Booking_AirLine_Return"];
               
                string nameReference = string.Empty;
                string eticketno;
                string flightuid = "0";
                string givenName;
                string surName;
                string Passuid = "0";
                DataTable dtdepartflighdetails = new DataTable();
                dtdepartflighdetails = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Return"];
                for (int i = 0; i < dtdepartflighdetails.Rows.Count; i++)
                {



                    origin_Sel = Convert.ToString(dtdepartflighdetails.Rows[i]["Source"]);
                    destin_Sel = Convert.ToString(dtdepartflighdetails.Rows[i]["Destination"]);

                    flightnoSel = Convert.ToString(dtdepartflighdetails.Rows[i]["FlightNo"]);


                    eticketno = Convert.ToString(dsUpdateAdult_AdultTicketInfo.Tables[0].Rows[0]["AirlinePNR"]);

                    foreach (DataRow dr in DsAdultdetails.Tables[0].Rows)
                    {
                       
                        nameReference = Convert.ToString(dr["Adulttitle"]);
                        givenName = Convert.ToString(dr["AdultFirstName"]);
                        surName = Convert.ToString(dr["AdultLastName"]);
                        adultpassid = Convert.ToInt32(dr["AdultPass_Id"]);
                        Pss_ID = Convert.ToInt32(dr["Pss_ID"]);
                        JourneyType = Convert.ToString(dr["JourneyType"]);
                        stops = Convert.ToInt32(dr["StopQuantity"]);
                       

                    //}
                    SqlParameter[] paramAdult_AdultTicketInfo = new SqlParameter[]
                   {
           

            //--------------------------------- ADULT and Adult_Ticket_Info Table parameter Start------------------------------------------------------//

                  new SqlParameter("@ResultAdult_AdultTicketInfo_Output",SqlDbType.Int,4),
                  new SqlParameter("@AdultPass_Id",Convert.ToInt32(adultpassid)),
                  new SqlParameter("@Pss_ID",Convert.ToInt32(Pss_ID)),
                  new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                  new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                  new SqlParameter("@nameReference",nameReference),
                  new SqlParameter("@eticketno",eticketno),
                  new SqlParameter("@flightuid",flightuid),
                  new SqlParameter("@Passuid",Passuid),
                  new SqlParameter("@Flight_type",Flight_type),
                  new SqlParameter("@JourneyType",JourneyType),
                  new SqlParameter("@Connecting",Convert.ToInt32(stops)),
                  new SqlParameter("@Origin",Convert.ToString(origin_Sel)),
                  new SqlParameter("@Destination",Convert.ToString(destin_Sel)),
                  new SqlParameter("@FlightNumber",Convert.ToString(flightnoSel)),
                  new SqlParameter("@Status",Convert.ToString(ViewState["requestedPNR_Status"])),         
           //--------------------------------ADULT  and Adult_Ticket_Info Table parameter End------------------------------------------------------//
                  };

                    paramAdult_AdultTicketInfo[0].Direction = ParameterDirection.Output;

                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Adult_AdultTicketInfo_Insert", paramAdult_AdultTicketInfo);
                    ResultAdult_AdultTicketInfo_Status = Convert.ToString(paramAdult_AdultTicketInfo[0].Value);
                }
               }//new comment
                #endregion
            }
        } 
        catch (Exception ex)
        {

        }
    }
               
          
    #endregion


    #region Insert Child and Child_Ticket_Info table according to GetBookingSatusResponse result

    public void Child_And_Child_Ticket_Info_Insert()
    {
        string flightnoSel = null, origin_Sel = null, destin_Sel = null;

        try
        {
            #region Get Child personaldetails

            SqlParameter[] paramChilddetails = new SqlParameter[]
            {
                 new SqlParameter("@ResultChildDetails_Output",SqlDbType.Int,4),
                new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"]))
            };


            paramChilddetails[0].Direction = ParameterDirection.Output;
            DataSet DsChilddetails = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_GetChildDetails", paramChilddetails);
            string ResultChildDetailsStatus = Convert.ToString(paramChilddetails[0].Value);

            if (ResultChildDetailsStatus == "1")
            {
                #region Insert Child and ChildTicketInfo Details
                string ResultChild_ChildTicketInfo_Status = null, Flight_type = null;
                int childpassid = 0;
                int Pss_ID = 0;
                string JourneyType = "";
                int stops = 0;
              
                if (Convert.ToString(Session["Trip"]) == "One")
                {
                    Flight_type = "OneWay";

                }
                else if (Convert.ToString(Session["Trip"]) == "Round")
                {
                    Flight_type = "RoundTrip";

                }


              
                 DataSet dsUpdateChild_ChildTicketInfo = new DataSet();
                    dsUpdateChild_ChildTicketInfo = (DataSet)Session["Booking_AirLine"];
                           
                  string nameReference = string.Empty;
                    string eticketno;
                    string flightuid = "0";
                    string givenName;
                    string surName;
                    string Passuid = "0";
                   DataTable dtdepartflighdetails = new DataTable();
                    dtdepartflighdetails = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Depart"];
                    for (int i = 0; i < dtdepartflighdetails.Rows.Count; i++)
                    {



                        origin_Sel = Convert.ToString(dtdepartflighdetails.Rows[i]["Source"]);
                        destin_Sel = Convert.ToString(dtdepartflighdetails.Rows[i]["Destination"]);

                        flightnoSel = Convert.ToString(dtdepartflighdetails.Rows[i]["FlightNo"]);


                        eticketno = Convert.ToString(dsUpdateChild_ChildTicketInfo.Tables[0].Rows[0]["AirlinePNR"]);



                        foreach (DataRow dr in DsChilddetails.Tables[0].Rows)
                        {
                           
                                nameReference = Convert.ToString(dr["Childtitle"]);
                                givenName = Convert.ToString(dr["ChildFirstName"]);
                                surName = Convert.ToString(dr["ChildLastName"]);
                                childpassid = Convert.ToInt32(dr["ChildPass_Id"]);
                                Pss_ID = Convert.ToInt32(dr["Pss_ID"]);
                                JourneyType = Convert.ToString(dr["JourneyType"]);
                                stops = Convert.ToInt32(dr["StopQuantity"]);
                        
                       // }
                        SqlParameter[] paramChild_ChildTicketInfo = new SqlParameter[]
                   {
           

            //--------------------------------- Child and Child_Ticket_Info Table parameter Start------------------------------------------------------//

                  new SqlParameter("@ResultChild_ChildTicketInfo_Output",SqlDbType.Int,4),
                  new SqlParameter("@ChildPass_Id",Convert.ToInt32(childpassid)),
                  new SqlParameter("@Pss_ID",Convert.ToInt32(Pss_ID)),
                  new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                  new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                  new SqlParameter("@nameReference",nameReference),
                 new SqlParameter("@eticketno",eticketno),
                 new SqlParameter("@flightuid",flightuid),
                  new SqlParameter("@Passuid",Passuid),
                  new SqlParameter("@Flight_type",Flight_type),
                  new SqlParameter("@JourneyType",JourneyType),
                  new SqlParameter("@Connecting",Convert.ToInt32(stops)),
                   new SqlParameter("@Origin",Convert.ToString(origin_Sel)),
                    new SqlParameter("@Destination",Convert.ToString(destin_Sel)),
                     new SqlParameter("@FlightNumber",Convert.ToString(flightnoSel)),
                  new SqlParameter("@Status",Convert.ToString(ViewState["requestedPNR_Status"])),         
           //--------------------------------Child  and Child_Ticket_Info Table parameter End------------------------------------------------------//
                  };

                        paramChild_ChildTicketInfo[0].Direction = ParameterDirection.Output;

                        SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_ChildTicketInfo_Insert", paramChild_ChildTicketInfo);
                        ResultChild_ChildTicketInfo_Status = Convert.ToString(paramChild_ChildTicketInfo[0].Value);
                    }
                   }//new comment
                    if (Flight_type == "RoundTrip")
                    {
                       Child_And_Child_Ticket_Info_InsertReturn();

                    }

                if (ResultChild_ChildTicketInfo_Status == "1")
                {


                }
                else if (ResultChild_ChildTicketInfo_Status == "0")
                {
                  
                }


                #endregion

            }
            else if (ResultChildDetailsStatus == "0")
            {
             
            }


            #endregion
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "Child_And_Child_Ticket_Info_Insert__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }
    }
    public void Child_And_Child_Ticket_Info_InsertReturn()
    {
        string flightnoSel = null, origin_Sel = null, destin_Sel = null;

        try
        {
            #region Get Child personaldetails

            SqlParameter[] paramChilddetails = new SqlParameter[]
            {
                new SqlParameter("@ResultChildDetails_Output",SqlDbType.Int,4),
                new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
              
            };


            paramChilddetails[0].Direction = ParameterDirection.Output;
            DataSet DsChilddetails = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_GetChildDetails", paramChilddetails);
            string ResultChildDetailsStatus = Convert.ToString(paramChilddetails[0].Value);

            if (ResultChildDetailsStatus == "1")
            {
                #region Insert Child and ChildTicketInfo Details
                string ResultChild_ChildTicketInfo_Status = null, Flight_type = null;
                int childpassid = 0;
                int Pss_ID = 0;
                string JourneyType = "";
                int stops = 0;
               
                if (Convert.ToString(Session["Trip"]) == "One")
                {
                    Flight_type = "OneWay";

                }
                else if (Convert.ToString(Session["Trip"]) == "Round")
                {
                    Flight_type = "RoundTrip";

                }


                DataSet dsUpdateChild_ChildTicketInfo = new DataSet();
                dsUpdateChild_ChildTicketInfo = (DataSet)Session["Booking_AirLine_Return"];

                string nameReference = string.Empty;
                string eticketno;
                string flightuid = "0";
                string givenName;
                string surName;
                string Passuid = "0";
                DataTable dtdepartflighdetails = new DataTable();
                dtdepartflighdetails = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Return"];
                for (int i = 0; i < dtdepartflighdetails.Rows.Count; i++)
                {



                    origin_Sel = Convert.ToString(dtdepartflighdetails.Rows[i]["Source"]);
                    destin_Sel = Convert.ToString(dtdepartflighdetails.Rows[i]["Destination"]);

                    flightnoSel = Convert.ToString(dtdepartflighdetails.Rows[i]["FlightNo"]);


                    eticketno = Convert.ToString(dsUpdateChild_ChildTicketInfo.Tables[0].Rows[0]["AirlinePNR"]);



                    foreach (DataRow dr in DsChilddetails.Tables[0].Rows)
                    {
                        nameReference = Convert.ToString(dr["Childtitle"]);
                        givenName = Convert.ToString(dr["ChildFirstName"]);
                        surName = Convert.ToString(dr["ChildLastName"]);
                        childpassid = Convert.ToInt32(dr["ChildPass_Id"]);
                        Pss_ID = Convert.ToInt32(dr["Pss_ID"]);
                        JourneyType = Convert.ToString(dr["JourneyType"]);
                        stops = Convert.ToInt32(dr["StopQuantity"]);
                 

                   // }
                    SqlParameter[] paramChild_ChildTicketInfo = new SqlParameter[]
                   {
           

            //--------------------------------- Child and Child_Ticket_Info Table parameter Start------------------------------------------------------//

                  new SqlParameter("@ResultChild_ChildTicketInfo_Output",SqlDbType.Int,4),
                  new SqlParameter("@ChildPass_Id",Convert.ToInt32(childpassid)),
                  new SqlParameter("@Pss_ID",Convert.ToInt32(Pss_ID)),
                  new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                  new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                  new SqlParameter("@nameReference",nameReference),
                 new SqlParameter("@eticketno",eticketno),
                 new SqlParameter("@flightuid",flightuid),
                  new SqlParameter("@Passuid",Passuid),
                  new SqlParameter("@Flight_type",Flight_type),
                  new SqlParameter("@JourneyType",JourneyType),
                  new SqlParameter("@Connecting",Convert.ToInt32(stops)),
                   new SqlParameter("@Origin",Convert.ToString(origin_Sel)),
                    new SqlParameter("@Destination",Convert.ToString(destin_Sel)),
                     new SqlParameter("@FlightNumber",Convert.ToString(flightnoSel)),
                  new SqlParameter("@Status",Convert.ToString(ViewState["requestedPNR_Status"])),         
           //--------------------------------Child  and Child_Ticket_Info Table parameter End------------------------------------------------------//
                  };

                    paramChild_ChildTicketInfo[0].Direction = ParameterDirection.Output;

                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_ChildTicketInfo_Insert", paramChild_ChildTicketInfo);
                    ResultChild_ChildTicketInfo_Status = Convert.ToString(paramChild_ChildTicketInfo[0].Value);
                }
                }//new comment

                if (ResultChild_ChildTicketInfo_Status == "1")
                {


                }
                else if (ResultChild_ChildTicketInfo_Status == "0")
                {
               
                }


                #endregion

            }
            else if (ResultChildDetailsStatus == "0")
            {
               
            }


            #endregion
        }
        catch (Exception ex)
        {

        }
    }


    #endregion

    #region Insert Infant and Infant_Ticket_Info table according to GetBookingSatusResponse result

    public void Infant_And_Infant_Ticket_Info_Insert()
    {
        string flightnoSel = null, origin_Sel = null, destin_Sel = null;
      
        try
        {

            #region Get Infant personaldetails

            SqlParameter[] paramInfantdetails = new SqlParameter[]
            {
                new SqlParameter("@ResultInfantDetails_Output",SqlDbType.Int,4),
                new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
              
             
            };


            paramInfantdetails[0].Direction = ParameterDirection.Output;
            DataSet DsInfantdetails = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_GetInfantDetails", paramInfantdetails);
            string ResultInfantDetailsStatus = Convert.ToString(paramInfantdetails[0].Value);

            if (ResultInfantDetailsStatus == "1")
            {
                #region Insert Infant and InfantTicketInfo Details
                string ResultInfant_InfantTicketInfo_Status = null, Flight_type = null;
                int Infantpassid = 0;
                int Pss_ID = 0;
                string JourneyType = "";
                int stops = 0;
              

                if (Convert.ToString(Session["Trip"]) == "One")
                {
                    Flight_type = "OneWay";

                }
                else if (Convert.ToString(Session["Trip"]) == "Round")
                {
                    Flight_type = "RoundTrip";

                }

              

                DataSet dsUpdateChild_AdultTicketInfo = new DataSet();
                dsUpdateChild_AdultTicketInfo = (DataSet)Session["Booking_AirLine"];
        
                 string nameReference = string.Empty;
                    string eticketno;
                    string flightuid = "0";
                    string givenName;
                    string surName;
                    string Passuid = "0";
                    DataTable dtdepartflighdetails = new DataTable();
                    dtdepartflighdetails = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Depart"];
                    for (int i = 0; i < dtdepartflighdetails.Rows.Count; i++)
                    {



                        origin_Sel = Convert.ToString(dtdepartflighdetails.Rows[i]["Source"]);
                        destin_Sel = Convert.ToString(dtdepartflighdetails.Rows[i]["Destination"]);

                        flightnoSel = Convert.ToString(dtdepartflighdetails.Rows[i]["FlightNo"]);


                        eticketno = Convert.ToString(dsUpdateChild_AdultTicketInfo.Tables[0].Rows[0]["AirlinePNR"]);

                        foreach (DataRow dr in DsInfantdetails.Tables[0].Rows)
                        {
                            nameReference = Convert.ToString(dr["Infanttitle"]);
                            givenName = Convert.ToString(dr["InfantFirstName"]);
                            surName = Convert.ToString(dr["InfantLastName"]);
                            Infantpassid = Convert.ToInt32(dr["InfantPass_Id"]);
                            Pss_ID = Convert.ToInt32(dr["Pss_ID"]);
                            JourneyType = Convert.ToString(dr["JourneyType"]);
                            stops = Convert.ToInt32(dr["StopQuantity"]);
                      

                        //}

                        SqlParameter[] paramInfant_InfantTicketInfo = new SqlParameter[]
                   {
           

            //--------------------------------- Infant and Infant_Ticket_Info Table parameter Start------------------------------------------------------//

                  new SqlParameter("@ResultInfant_InfantTicketInfo_Output",SqlDbType.Int,4),
                  new SqlParameter("@InfantPass_Id",Convert.ToInt32(Infantpassid)),
                  new SqlParameter("@Pss_ID",Convert.ToInt32(Pss_ID)),
                  new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                  new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                  new SqlParameter("@nameReference",nameReference),
                  new SqlParameter("@eticketno",eticketno),
                  new SqlParameter("@flightuid",flightuid),
                  new SqlParameter("@Passuid",Passuid),
                  new SqlParameter("@Flight_type",Flight_type),
                  new SqlParameter("@JourneyType",JourneyType),
                  new SqlParameter("@Connecting",Convert.ToInt32(stops)),
                  new SqlParameter("@Origin",Convert.ToString(origin_Sel)),
                  new SqlParameter("@Destination",Convert.ToString(destin_Sel)),
                  new SqlParameter("@FlightNumber",Convert.ToString(flightnoSel)),
                  new SqlParameter("@Status",Convert.ToString(ViewState["requestedPNR_Status"])),         
           //--------------------------------Infant  and Infant_Ticket_Info Table parameter End------------------------------------------------------//
                  };

                        paramInfant_InfantTicketInfo[0].Direction = ParameterDirection.Output;

                        SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_InfantTicketInfo_Insert", paramInfant_InfantTicketInfo);
                        ResultInfant_InfantTicketInfo_Status = Convert.ToString(paramInfant_InfantTicketInfo[0].Value);
                    } }//new comment
                    if (Flight_type == "RoundTrip")
                    {
                        Infant_Ticket_Info_InsertReturn();

                    }

                if (ResultInfant_InfantTicketInfo_Status == "1")
                {


                }
                else if (ResultInfant_InfantTicketInfo_Status == "0")
                {
            
                }


                #endregion

            }
            else if (ResultInfantDetailsStatus == "0")
            {
            
            }


            #endregion


        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "Infant_And_Infant_Ticket_Info_Insert__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }
    }

    public void Infant_Ticket_Info_InsertReturn()
    {
         string flightnoSel = null, origin_Sel = null, destin_Sel = null;
   
        try
        {

            #region Get Infant personaldetails

            SqlParameter[] paramInfantdetails = new SqlParameter[]
            {
                new SqlParameter("@ResultInfantDetails_Output",SqlDbType.Int,4),
                new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
              
             
            };


            paramInfantdetails[0].Direction = ParameterDirection.Output;
            DataSet DsInfantdetails = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_GetInfantDetails", paramInfantdetails);
            string ResultInfantDetailsStatus = Convert.ToString(paramInfantdetails[0].Value);

            if (ResultInfantDetailsStatus == "1")
            {
                #region Insert Infant and InfantTicketInfo Details
                string ResultInfant_InfantTicketInfo_Status = null, Flight_type = null;
                int Infantpassid = 0;
                int Pss_ID = 0;
                string JourneyType = "";
                int stops = 0;
             
                if (Convert.ToString(Session["Trip"]) == "One")
                {
                    Flight_type = "OneWay";

                }
                else if (Convert.ToString(Session["Trip"]) == "Round")
                {
                    Flight_type = "RoundTrip";

                }

           
                DataSet dsUpdateChild_AdultTicketInfo = new DataSet();
                dsUpdateChild_AdultTicketInfo = (DataSet)Session["Booking_AirLine_Return"];
               
                string nameReference = string.Empty;
                string eticketno;
                string flightuid = "0";
                string givenName;
                string surName;
                string Passuid = "0";
                DataTable dtdepartflighdetails = new DataTable();
                dtdepartflighdetails = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Return"];
                for (int i = 0; i < dtdepartflighdetails.Rows.Count; i++)
                {



                    origin_Sel = Convert.ToString(dtdepartflighdetails.Rows[i]["Source"]);
                    destin_Sel = Convert.ToString(dtdepartflighdetails.Rows[i]["Destination"]);

                    flightnoSel = Convert.ToString(dtdepartflighdetails.Rows[i]["FlightNo"]);


                    eticketno = Convert.ToString(dsUpdateChild_AdultTicketInfo.Tables[0].Rows[0]["AirlinePNR"]);

                    foreach (DataRow dr in DsInfantdetails.Tables[0].Rows)
                    {
                      
                        nameReference = Convert.ToString(dr["Infanttitle"]);
                        givenName = Convert.ToString(dr["InfantFirstName"]);
                        surName = Convert.ToString(dr["InfantLastName"]);
                        Infantpassid = Convert.ToInt32(dr["InfantPass_Id"]);
                        Pss_ID = Convert.ToInt32(dr["Pss_ID"]);
                        JourneyType = Convert.ToString(dr["JourneyType"]);
                        stops = Convert.ToInt32(dr["StopQuantity"]);
                      

                   // }

                  
                    SqlParameter[] paramInfant_InfantTicketInfo = new SqlParameter[]
                   {
           

            //--------------------------------- Infant and Infant_Ticket_Info Table parameter Start------------------------------------------------------//

                  new SqlParameter("@ResultInfant_InfantTicketInfo_Output",SqlDbType.Int,4),
                  new SqlParameter("@InfantPass_Id",Convert.ToInt32(Infantpassid)),
                  new SqlParameter("@Pss_ID",Convert.ToInt32(Pss_ID)),
                  new SqlParameter("@Booking_St_Id",Convert.ToInt32(Session["Booking_St_Id"])),
                  new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                  new SqlParameter("@nameReference",nameReference),
                  new SqlParameter("@eticketno",eticketno),
                  new SqlParameter("@flightuid",flightuid),
                  new SqlParameter("@Passuid",Passuid),
                  new SqlParameter("@Flight_type",Flight_type),
                  new SqlParameter("@JourneyType",JourneyType),
                  new SqlParameter("@Connecting",Convert.ToInt32(stops)),
                  new SqlParameter("@Origin",Convert.ToString(origin_Sel)),
                  new SqlParameter("@Destination",Convert.ToString(destin_Sel)),
                  new SqlParameter("@FlightNumber",Convert.ToString(flightnoSel)),
                  new SqlParameter("@Status",Convert.ToString(ViewState["requestedPNR_Status"])),         
           //--------------------------------Infant  and Infant_Ticket_Info Table parameter End------------------------------------------------------//
                  };

                    paramInfant_InfantTicketInfo[0].Direction = ParameterDirection.Output;

                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_Air_InfantTicketInfo_Insert", paramInfant_InfantTicketInfo);
                    ResultInfant_InfantTicketInfo_Status = Convert.ToString(paramInfant_InfantTicketInfo[0].Value);
                }
              } //new comment
                #endregion
            }
                #endregion
        }
        catch (Exception ex)
        {

        }
    }
    #endregion

void GetFlightDetails()
    {
        try
        {
            if (Convert.ToString(Session["Trip"]) == "One")
            {
                lbl_payment_basefare.Text = Session["Currency"].ToString() + " " + Math.Round(Convert.ToDouble(Session["Basefare"]) * Convert.ToDouble(Session["convertor"])).ToString("f0");
                lbl_payment_servicetax.Text = Session["Currency"].ToString() + " " + Math.Round(Convert.ToDouble(Session["ServiceTax"]) * Convert.ToDouble(Session["convertor"])).ToString("f0");
                lbl_payment_air.Text = Session["Currency"].ToString() + " " + Math.Round(Convert.ToDouble(Session["AirportTax"]) * Convert.ToDouble(Session["convertor"])).ToString("f0");
                lbl_payment_txn_charge.Text = Session["Currency"].ToString() + " " + Math.Round(Convert.ToDouble(Session["TxnCharge"]) * Convert.ToDouble(Session["convertor"])).ToString("f0");
                double ticketprice = Convert.ToDouble(Session["Dom_Ticket_Price"]);
                double misc =
                   Convert.ToDouble(Session["Dom_AgentComm"]) +
                   Convert.ToDouble(Session["Dom_CompanyComm"]);

                lbl_payment_booking_misc.Text = Session["Currency"].ToString() + " " + Math.Round(misc * Convert.ToDouble(Session["convertor"])).ToString();
                double totaldiscount = Convert.ToDouble(Session["BookingDiscount"]);
                lbl_payment_booking_discount.Text = Session["Currency"].ToString() + " " + Math.Round(totaldiscount * Convert.ToDouble(Session["convertor"])).ToString();
                lbl_payment_totalfare.Text = Session["Currency"].ToString() + " " + Math.Round((ticketprice + misc) * Convert.ToDouble(Session["convertor"])).ToString();
                lbl_price.Text = Session["Currency"].ToString() + " " + Math.Round((ticketprice + misc) * Convert.ToDouble(Session["convertor"])).ToString();
                lbl_bankingmethod.Text = Convert.ToString(Session["BankName"]);
            }
            if (Convert.ToString(Session["Trip"]) == "Round")
            {
                lbl_payment_basefare.Text = Session["Currency"].ToString() + " " + Math.Round(Convert.ToDouble(Session["TotalBasefare"]) * Convert.ToDouble(Session["convertor"])).ToString("f0");
                lbl_payment_servicetax.Text = Session["Currency"].ToString() + " " + Math.Round(Convert.ToDouble(Session["TotalServiceTax"]) * Convert.ToDouble(Session["convertor"])).ToString("f0");
                lbl_payment_air.Text = Session["Currency"].ToString() + " " + Math.Round(Convert.ToDouble(Session["TotalAirportTax"]) * Convert.ToDouble(Session["convertor"])).ToString("f0");
                lbl_payment_txn_charge.Text = Session["Currency"].ToString() + " " + Math.Round(Convert.ToDouble(Session["TotalTxnCharge"]) * Convert.ToDouble(Session["convertor"])).ToString("f0");
                double ticketprice = Convert.ToDouble(Session["Dom_Ticket_Price"]);
                double misc =
                   Convert.ToDouble(Session["Dom_AgentComm"]) +
                   Convert.ToDouble(Session["Dom_CompanyComm"]);

                lbl_payment_booking_misc.Text = Session["Currency"].ToString() + " " + Math.Round(misc * Convert.ToDouble(Session["convertor"])).ToString();
                double totaldiscount = Convert.ToDouble(Session["TotalBookingDiscount"]);
                lbl_payment_booking_discount.Text = Session["Currency"].ToString() + " " + Math.Round(totaldiscount * Convert.ToDouble(Session["convertor"])).ToString(); 
                lbl_payment_totalfare.Text =  Session["Currency"].ToString() + " " + Math.Round((ticketprice + misc)* Convert.ToDouble(Session["convertor"])).ToString();
                lbl_price.Text = Session["Currency"].ToString() + " " + Math.Round((ticketprice + misc) * Convert.ToDouble(Session["convertor"])).ToString(); 
                lbl_bankingmethod.Text = Convert.ToString(Session["BankName"]);
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "GetFlightDetails__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/IndexDom.aspx?s=exception");
        }
    }
    
   
    void fillinformations()
    {
        try
        {
            GetUserContactInfo();
            GetFlightDetails();
            lbl_tripid.Text = Convert.ToString(Session["partnerRefId"]); lbl_source_airportname.Text = Convert.ToString(Session["DestinationFrom"]);
            lbl_destination_airportname.Text = Convert.ToString(Session["DestinationTo"]);
            lbl_date.Text = Convert.ToString(Session["departime"]);
            Get_selected_Depart_flight_route_information_and_Generate_runtime_table();
            lbl_adults.Text = Convert.ToString(Session["Adults"]);
            lbl_child.Text = Convert.ToString(Session["Children"]);
            lbl_infant.Text = Convert.ToString(Session["Infants"]);
            lbl_bankingmethod.Text = Convert.ToString(Session["BankName"]);
            lbl_farerule.Text = Convert.ToString(Session["FareRule"]);
            if (Convert.ToString(Session["Trip"]) == "One")
            {
                div_round.Visible = false;
            }
            else if (Convert.ToString(Session["Trip"]) == "Round")
            {
                div_round.Visible = true;
                lbl_farerule_round.Text = Convert.ToString(Session["FareRule_Return"]);
                lbl_source_airportname_forround.Text = Convert.ToString(Session["DestinationTo"]);
                lbl_destination_airportname_forround.Text = Convert.ToString(Session["DestinationTo"]);
                lbl_date_round.Text = Convert.ToString(Session["departtime_return"]);
                Get_selected_Depart_flight_route_information_and_Generate_runtime_table_retrun();

            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "fillinformations__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
        }

        //_______________


    }
    public void Get_selected_Depart_flight_route_information_and_Generate_runtime_table_retrun()
    {
        try
        {
            DataSet dsODxml_FlightSegment_Return = new DataSet();
            dsODxml_FlightSegment_Return = (DataSet)Session["Booking_Segment_Return"];
            if (dsODxml_FlightSegment_Return.Tables[0].Rows.Count != 0)
            {
                string dynTable = "";
                Session["Stop_quantity_Return"] = dsODxml_FlightSegment_Return.Tables[0].Rows.Count;
                dynTable = "  <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" class=\"transation\">";
                dynTable += "<tr>  <th width=\"10%\">   Airline</th><th width=\"15%\">Flight# </th><th width=\"30%\"> Leaves</th>";
                dynTable += " <th width=\"30%\"> Arrives</th>   <th width=\"8%\">    Duration     </th>  <th width=\"7%\">Class </th>  </tr>";
                //inner loop to generate columns
                for (int tRows = 0; tRows < dsODxml_FlightSegment_Return.Tables[0].Rows.Count; tRows++)
                {

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


                    dynTable += "<tr valign=\"top\"> <td><img  src=\""+imageAirLineUrl+"\"</img></td>";
                    dynTable += " <td>" + (airlinename).ToString() + "<br />" + (dsODxml_FlightSegment_Return.Tables[0].Rows[tRows]["CarrierAirLineCode"]) + "-" + (dsODxml_FlightSegment_Return.Tables[0].Rows[tRows]["FlightNumber"]) + "</td>   ";
                    dynTable += "<td align=\"left\">" + Convert.ToString(dsODxml_FlightSegment_Return.Tables[0].Rows[tRows]["Departuredatetime"]).Substring(11, 5) + "," + Convert.ToString(dsODxml_FlightSegment_Return.Tables[0].Rows[tRows]["Departuredatetime"]).Substring(0, 11) + "<br />" + (dsODxml_FlightSegment_Return.Tables[0].Rows[tRows]["Origin"]) + "(" + (dsODxml_FlightSegment_Return.Tables[0].Rows[tRows]["Origin"]) + ")<br />   </td>";
                    dynTable += "<td>" + Convert.ToString(dsODxml_FlightSegment_Return.Tables[0].Rows[tRows]["Arrivaldatetime"]).Substring(11, 5) + "," + (Convert.ToString(dsODxml_FlightSegment_Return.Tables[0].Rows[tRows]["Arrivaldatetime"])).Substring(0, 11) + "<br />" + (dsODxml_FlightSegment_Return.Tables[0].Rows[tRows]["Destination"]) + "(" + (dsODxml_FlightSegment_Return.Tables[0].Rows[tRows]["Destination"]) + ")<br />     </td>";
                  //dynTable += "<td>" + obj_airsupport.CalculateDuration(Convert.ToString(dsODxml_FlightSegment_Return.Tables["FlightSegment"].Rows[tRows]["DepartureDateTime"]), Convert.ToString(dsODxml_FlightSegment_Return.Tables["FlightSegment"].Rows[tRows]["ArrivalDateTime"])) + "</td>";
                    dynTable += "<td>Duration</td>";
                    dynTable += "<td>" + Convert.ToString(dsODxml_FlightSegment_Return.Tables[0].Rows[tRows]["ClassCode"]) + "</td>";
                    dynTable += "</tr>";

                }
                dynTable += "</table>";
                LiteralFlight_info_Return.Text = dynTable;
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "Get_selected_Depart_flight_route_information_and_Generate_runtime_table_retrun__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
        }
    } 
    public void Get_selected_Depart_flight_route_information_and_Generate_runtime_table()
    {
        try
        {
            DataSet dsODxml_FlightSegment_OneWay_Depart;
            dsODxml_FlightSegment_OneWay_Depart = new DataSet();
            dsODxml_FlightSegment_OneWay_Depart = (DataSet)Session["Booking_Segment"];
            if (dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows.Count != 0)
            {
                string dynTable = "";
                Session["Stop_quantity"] = dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows.Count;
                dynTable = "  <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"border-top: 1px solid #c3c3c3;\"     class=\"transation\">";
                dynTable += "<tr>   <th width=\"10%\">  Airline  </th>  <th width=\"15%\">   Flight#  </th> <th width=\"30%\">Leaves</th><th width=\"30%\">Arrives</th><th width=\"8%\">Duration</th><th width=\"7%\">Class</th></tr>";
                //inner loop to generate columns
                for (int tRows = 0; tRows < dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows.Count; tRows++)
                {
                    string OperatingAirlineCode = Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows[tRows]["CarrierAirLineCode"]);
                    string imageAirLineUrl = "";
                    string airlinename = "";
                    DataSet ds = obj_airsupport.GetAirImageDetails();
                    var imageurl = from ImgurlDetail in ds.Tables["AirLineImageUrlDetail"].AsEnumerable()
                                   where ImgurlDetail.Field<string>("AirlineCode") == Convert.ToString(OperatingAirlineCode).Trim()
                                   select new { airlineimgeurl = ImgurlDetail["filename"].ToString(), airlinename = ImgurlDetail["AirlineName"].ToString() };
                    if (imageurl.Count() > 0)
                    {
                        imageAirLineUrl = "../AirLineImage/" + imageurl.AsEnumerable().ElementAt(0).airlineimgeurl;
                        airlinename = imageurl.AsEnumerable().ElementAt(0).airlinename;
                    }

                    dynTable += "<tr valign=\"top\"> <td><img  src=\"" + imageAirLineUrl + "\"</img></td>";
                    dynTable += " <td align=\"left\">" + (airlinename).ToString() + "<br />" + (dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows[tRows]["CarrierAirLineCode"]) + "-" + (dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows[tRows]["FlightNumber"]) + "</td>   ";

                    dynTable += "<td align=\"left\">" + Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows[tRows]["Departuredatetime"]).Substring(11, 5) + "," + Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows[tRows]["Departuredatetime"]).Substring(0, 11) + "<br />" + (dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows[tRows]["Origin"]) + "(" + (dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows[tRows]["Origin"]) + ")<br />   </td>";
                    dynTable += "<td>" + Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows[tRows]["Arrivaldatetime"]).Substring(11, 5) + "," + (Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows[tRows]["Arrivaldatetime"])).Substring(0, 11) + "<br />" + (dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows[tRows]["Destination"]) + "(" + (dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows[tRows]["Destination"]) + ")<br />     </td>";
                    //dynTable += "<td>" + obj_airsupport.CalculateDuration(Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Tables["FlightSegment"].Rows[tRows]["DepartureDateTime"]), Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Tables["FlightSegment"].Rows[tRows]["ArrivalDateTime"])) + "</td>";
                    dynTable += "<td>Duration</td>";
                    dynTable += "<td>" + Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Tables[0].Rows[tRows]["ClassCode"]) + "</td>";
                    dynTable += "</tr>";

                }
                dynTable += "</table>";
                Literal_FlightInformation.Text = dynTable;
            }

        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "Ticket Booking", "Get_selected_Depart_flight_route_information_and_Generate_runtime_table__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
        }
    }
    


    protected void btnprint_Click(object sender, EventArgs e)
    {
        Session.Remove("partnerrefidtransaction");       
        Session["partnerrefidtransaction"] = ViewState["partnerRefId"];
        Response.Redirect("../Transaction/Ticket_H.aspx");
    }
    protected void btncancel_Click(object sender, EventArgs e)
    {
        Session.Remove("partnerrefidtransaction");      
        Session["partnerrefidtransaction"] = ViewState["partnerRefId"];
        Response.Redirect("../Transaction/Cancel.aspx");
    }
    protected void btnretry_Click(object sender, EventArgs e)
    {
        Session.Remove("partnerrefidtrip");

        Session["partnerrefidtrip"] = Session["partnerRefId"];
        Response.Redirect("../Transaction/Transaction.aspx");
    }
    public void Create_Table_From_Booking_Response_Depart(string request)
    {
        string passs = string.Empty;
        DataSet ds = new DataSet();
        DataSet ds1 = new DataSet();
        string tic = string.Empty;
        XmlDocument xdoc = new XmlDocument();
        xdoc.LoadXml("<Root>" + request + "</Root>");
        XmlNodeList xnode2 = xdoc.ChildNodes;
        foreach (XmlNode node9 in xnode2)
        {
            XmlNodeList xnode9 = node9.ChildNodes;

            foreach (XmlNode node3 in xnode9)
            {
                if (node3.Name == "TicketDetails")
                {
                    XmlNodeList xnode3 = node3.ChildNodes;
                    foreach (XmlNode node4 in xnode3)
                    {

                        if (node4.Name == "AirLineDetails")
                        {
                            string tic1 = "<AirlineDetails>" + node4.InnerXml + "</AirlineDetails>";
                            ds.ReadXml(new StringReader(tic1));
                            Session["Booking_AirLine"] = ds;

                        }
                        if (node4.Name == "HermesPNR")
                        {
                            Session["Transid"] = node4.InnerText;
                        }
                      
                        if (node4.Name == "PassengerDetails")
                        {
                            XmlNodeList xnode4 = node4.ChildNodes;
                            foreach (XmlNode node5 in xnode4)
                            {
                                if (node5.Name == "Item")
                                {
                                    passs = passs + "<Item>";
                                    XmlNodeList xnode5 = node5.ChildNodes;
                                    foreach (XmlNode node6 in xnode5)
                                    {
                                        if (node6.Name == "TicketNo")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "TransmissionControlNo")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "TYPE")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "Title")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "FirstName")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "Lastname")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "Age")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "IdentityProofId")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "IdentityProofNumber")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "SegmentDetails")
                                        {
                                            tic = tic + node6.InnerXml;
                                        }
                                    }
                                }
                                passs = passs + "</Item>";
                            }

                        }
                    }
                }
            }
        }
        ds1.ReadXml(new StringReader("<Root>" + tic + "</Root>"));
        DataTable abcd = (from abcde in ds1.Tables[0].AsEnumerable()
                          where abcde.Field<int>("Item_Id") == 0
                          select abcde).CopyToDataTable();
        DataSet ds2 = new DataSet();
        ds2.Tables.Add(abcd);
        Session["Booking_Segment"] = ds2;
        DataSet ds_final = new DataSet();
        ds_final.ReadXml(new StringReader("<Pass>" + passs + "</Pass>"));
        ViewState["passdetail"] = ds_final;
    }

    public void Create_Table_From_Booking_Response_Return(string request)
    {
        string passs = string.Empty;
        DataSet ds = new DataSet();
        DataSet ds1 = new DataSet();
        string tic = string.Empty;
        XmlDocument xdoc = new XmlDocument();
        xdoc.LoadXml("<Root>" + request + "</Root>");
        XmlNodeList xnode2 = xdoc.ChildNodes;
        foreach (XmlNode node9 in xnode2)
        {
            XmlNodeList xnode9 = node9.ChildNodes;

            foreach (XmlNode node3 in xnode9)
            {
                if (node3.Name == "TicketDetails")
                {
                    XmlNodeList xnode3 = node3.ChildNodes;
                    foreach (XmlNode node4 in xnode3)
                    {
                        if (node4.Name == "AirLineDetails")
                        {
                            string tic1 = "<AirlineDetails>" + node4.InnerXml + "</AirlineDetails>";
                            ds.ReadXml(new StringReader(tic1));
                            Session["Booking_AirLine_Return"] = ds;

                        }
                        if (node4.Name == "HermesPNR")
                        {
                            Session["Transid_Return"] = node4.InnerText;
                        }
                      
                        if (node4.Name == "PassengerDetails")
                        {
                            XmlNodeList xnode4 = node4.ChildNodes;
                            foreach (XmlNode node5 in xnode4)
                            {
                                if (node5.Name == "Item")
                                {
                                    passs = passs + "<Item>";
                                    XmlNodeList xnode5 = node5.ChildNodes;
                                    foreach (XmlNode node6 in xnode5)
                                    {
                                        if (node6.Name == "TicketNo")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "TransmissionControlNo")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "TYPE")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "Title")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "FirstName")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "Lastname")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "Age")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "IdentityProofId")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "IdentityProofNumber")
                                        {
                                            passs = passs + node6.OuterXml;

                                        }
                                        if (node6.Name == "SegmentDetails")
                                        {
                                            tic = tic + node6.InnerXml;
                                        }
                                    }
                                }
                                passs = passs + "</Item>";
                            }

                        }
                    }
                }
            }
        }
        ds1.ReadXml(new StringReader("<Root>" + tic + "</Root>"));
        DataTable abcd = (from abcde in ds1.Tables[0].AsEnumerable()
                          where abcde.Field<int>("Item_Id") == 0
                          select abcde).CopyToDataTable();
        DataSet ds2 = new DataSet();
        ds2.Tables.Add(abcd);
        Session["Booking_Segment_Return"] = ds2;
        DataSet ds_final = new DataSet();
        ds_final.ReadXml(new StringReader("<Pass>" + passs + "</Pass>"));
        ViewState["passdetail_Return"] = ds_final;
    }


    public void RefundAmountWithFailedStatus()
    {
        Booking_Information_Update();
        B2B objb2b = new B2B();
        objb2b.Credit_Agent_Amount_Insertin_ATT(Session["WhitelabelId"].ToString(), Convert.ToString(Session["agid"]), Convert.ToString(ViewState["partnerRefId"]), "");
       // Session["agent_amount"] = Convert.ToDecimal(objb2b.CheckAgentBalance(Convert.ToString(Session["agid"]), Convert.ToString(Session["HURL"])));  //get the latest amount   
          
    }

}
