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.Drawing;
using System.Net.Mail;
using System.Collections.Generic;
using System.IO;
using System.Globalization;

public partial class Domestic_Step3 : System.Web.UI.Page
{
    public string adultDOBrange;
    public string ChildDOBrange;
    public string infantDOBrange;
    public string AdultDOBrange;
    public string AdultPassportrange;
    public string ChildPassportrange;
    public string InfantPassportrange;
    AirEpointSupport obj;
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (Session["agid"].ToString() == "172354")
        //{
        //    BtnContinue.Style.Add("Display", "none");
        //}
        try
        {
            obj = new AirEpointSupport();
            if (Session["DestinationFrom"] == null)
            {
                Response.Redirect("../../User/Index.aspx?s=timeout", false);
            }
            if (!IsPostBack)
            {
                #region Adult DOB,Child DOB,Infant DOB Validation
                DateTime AdultMinimumDob = new DateTime();
                AdultMinimumDob = DateTime.Now.AddYears(-10);
                DateTime AdultMaximumDob = new DateTime();
                AdultMaximumDob = DateTime.Now.AddYears(-70);
                string AdultMinYear = AdultMinimumDob.ToString("yyyy");
                string AdultMinMonth = AdultMinimumDob.ToString("mm");
                string AdultMinDay = AdultMinimumDob.ToString("dd");
                string AdultMaxYear = AdultMaximumDob.ToString("yyyy");
                string AdultMaxMonth = AdultMaximumDob.ToString("mm");
                string AdultMaxDay = AdultMaximumDob.ToString("dd");
                AdultDOBrange = "[[" + AdultMaxYear + "," + AdultMaxMonth + "," + AdultMaxDay + "],[" + AdultMinYear + "," + AdultMinMonth + "," + AdultMinDay + "]]";
                DateTime ChildMinimumDob = new DateTime();
                ChildMinimumDob = DateTime.Now.AddYears(-2);
                DateTime ChildMaximumDob = new DateTime();
                ChildMaximumDob = DateTime.Now.AddYears(-12);
                string ChildMinYear = ChildMinimumDob.ToString("yyyy");
                string ChildMinMonth = ChildMinimumDob.ToString("MM");
                string ChildMinDay = ChildMinimumDob.ToString("dd");
                string ChildMaxYear = ChildMaximumDob.ToString("yyyy");
                string ChildMaxMonth = ChildMaximumDob.ToString("MM");
                string ChildMaxDay = ChildMaximumDob.ToString("dd");
                ChildDOBrange = "[[" + ChildMaxYear + "," + ChildMaxMonth + "," + ChildMaxDay + "],[" + ChildMinYear + "," + ChildMinMonth + "," + ChildMinDay + "]]";
                // Infant DOB VALIDATION
                DateTime InfantMinimumDob = new DateTime();
                InfantMinimumDob = DateTime.Now.AddYears(-0);
                DateTime InfantMaximumDob = new DateTime();
                InfantMaximumDob = DateTime.Now.AddYears(-2);
                string InfantMinYear = InfantMinimumDob.ToString("yyyy");
                string InfantMinMonth = InfantMinimumDob.ToString("MM");
                string InfantMinDay = InfantMinimumDob.ToString("dd");
                string InfantMaxYear = InfantMaximumDob.ToString("yyyy");
                string InfantMaxMonth = InfantMaximumDob.ToString("MM");
                string InfantMaxDay = InfantMaximumDob.ToString("dd");
                infantDOBrange = "[[" + InfantMaxYear + "," + InfantMaxMonth + "," + InfantMaxDay + "],[" + InfantMinYear + "," + InfantMinMonth + "," + InfantMinDay + "]]";
                //AdultPassport Range
                DateTime AdultMinimumPassportExpairy = new DateTime();
                AdultMinimumPassportExpairy = DateTime.Now.AddYears(-10);
                DateTime AdultMaximumPassportExpairy = new DateTime();
                AdultMaximumPassportExpairy = DateTime.Now.AddYears(-70);
                string AdultPassportMinYear = AdultMinimumDob.ToString("yyyy");
                string AdultPassportMinMonth = AdultMinimumDob.ToString("mm");
                string AdultPassportMinDay = AdultMinimumDob.ToString("dd");
                string AdultPassportMaxYear = AdultMaximumDob.ToString("yyyy");
                string AdultPassportMaxMonth = AdultMaximumDob.ToString("mm");
                string AdultPassportMaxDay = AdultMaximumDob.ToString("dd");
                AdultPassportrange = "[[" + AdultPassportMaxYear + "," + AdultPassportMaxMonth + "," + AdultPassportMaxDay + "],[" + AdultPassportMinYear + "," + AdultPassportMinMonth + "," + AdultPassportMinDay + "]]";
                //ChildPassport Range
                DateTime ChildMinimumPassportExpairy = new DateTime();
                ChildMinimumPassportExpairy = DateTime.Now.AddYears(-10);
                DateTime ChildMaximumPassportExpairy = new DateTime();
                ChildMaximumPassportExpairy = DateTime.Now.AddYears(-70);
                string ChildPassportMinYear = AdultMinimumDob.ToString("yyyy");
                string ChildPassportMinMonth = AdultMinimumDob.ToString("mm");
                string ChildPassportMinDay = AdultMinimumDob.ToString("dd");
                string ChildPassportMaxYear = AdultMaximumDob.ToString("yyyy");
                string ChildPassportMaxMonth = AdultMaximumDob.ToString("mm");
                string ChildPassportMaxDay = AdultMaximumDob.ToString("dd");
                ChildPassportrange = "[[" + ChildPassportMaxYear + "," + ChildPassportMaxMonth + "," + ChildPassportMaxDay + "],[" + ChildPassportMinYear + "," + ChildPassportMinMonth + "," + ChildPassportMinDay + "]]";
                //InfantPassport Range
                DateTime InfantMinimumPassportExpairy = new DateTime();
                InfantMinimumPassportExpairy = DateTime.Now.AddYears(-10);
                DateTime InfantMaximumPassportExpairy = new DateTime();
                InfantMaximumPassportExpairy = DateTime.Now.AddYears(-70);
                string InfantPassportMinYear = AdultMinimumDob.ToString("yyyy");
                string InfantPassportMinMonth = AdultMinimumDob.ToString("mm");
                string InfantPassportMinDay = AdultMinimumDob.ToString("dd");
                string InfantPassportMaxYear = AdultMaximumDob.ToString("yyyy");
                string InfantPassportMaxMonth = AdultMaximumDob.ToString("mm");
                string InfantPassportMaxDay = AdultMaximumDob.ToString("dd");
                InfantPassportrange = "[[" + InfantPassportMaxYear + "," + InfantPassportMaxMonth + "," + InfantPassportMaxDay + "],[" + InfantPassportMinYear + "," + InfantPassportMinMonth + "," + InfantPassportMinDay + "]]";
                #endregion
                #region code to open rows for insert details of Adults.
                if (Convert.ToString(Session["Adults"]) != "")
                {
                    int i = Convert.ToInt32(Session["Adults"].ToString());
                    if (i > 0)
                    {
                        for (int j = 0; j < i; j++)
                        {
                            tableDetails.FindControl("trAdult" + j).Visible = true;
                        }
                    }
                }
                #endregion
                #region code to open rows for insert details of Child
                if (Convert.ToString(Session["Children"]) != "")
                {
                    int k = Convert.ToInt32(Session["Children"].ToString());
                    if (k > 0)
                    {
                        cphETTSS_trchild.Visible = true;
                        for (int l = 0; l < k; l++)
                        {
                            tableDetails.FindControl("trchild" + l).Visible = true;
                        }
                    }
                }
                #endregion
                #region code to open rows for insert details of Infant.
                if (Convert.ToString(Session["Infants"]) != "")
                {
                    int m = Convert.ToInt32(Session["Infants"].ToString());
                    if (m > 0)
                    {
                        cphETTSS_trinfant.Visible = true;
                        for (int n = 0; n < m; n++)
                        {
                            tableDetails.FindControl("trInfant" + n).Visible = true;
                        }
                    }
                }
                #endregion
              //  fillagentdetails();
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport ob = new AirEpointSupport();
            ob.WriteToLog(ex.Message, "step3", "pageLoad__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../../User/Index.aspx?s=exception");
        }
    }

    protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
    {
        
        try
        {
            int intems = Convert.ToInt32(ddlState.SelectedItem.Value);
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_get_city1", new SqlParameter[] { new SqlParameter("@stateid", intems) });
            txtcity.Enabled = true;
            ddl_district.Enabled = true;
            ddl_district.DataSource = ds.Tables[0];
            ddl_district.DataValueField = "CityName";
            ddl_district.DataTextField = "CityName";
            ddl_district.DataBind();
        }
        catch (Exception ex)
        {
            AirEpointSupport ob = new AirEpointSupport();
            ob.WriteToLog(ex.Message, "step3", "ddlState_SelectedIndexChanged__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../../User/Index.aspx?s=exception");
        }
    }
    protected void BtnContinue_Click(object sender, EventArgs e)
    {
        try
        {
            bool validation = true;
            string message = "Validation Error";
            #region Adult Server Side Validations By Lavi
            if (Convert.ToString(Session["Adults"]) != "")
            {
                int i = Convert.ToInt32(Session["Adults"].ToString());
                if (i > 0)
                {
                    for (int j = 0; j < i; j++)
                    {
                        if (((TextBox)tableadult.FindControl("txtadultFirstName" + j)).Text == "" || ((TextBox)tableadult.FindControl("txtadultFirstName" + j)).Text == "First Name")
                        {
                            validation = false;
                            message = "Please Enter Adult " + (j + 1).ToString() + "First Name";
                            break;
                        }

                        if (((TextBox)tableadult.FindControl("txtadultLastName" + j)).Text == "" || ((TextBox)tableadult.FindControl("txtadultLastName" + j)).Text == "Last Name")
                        {
                            validation = false;
                            message = "Please Enter Adult " + (j + 1).ToString() + "Last Name";
                            break;
                        }

                        if (((DropDownList)tableadult.FindControl("DdlAdultTitle" + j)).SelectedItem.Value == "Title")
                        {
                            validation = false;
                            message = "Please Select Adult " + (j + 1).ToString() + "Title";
                            break;
                        }

                        if (((DropDownList)tableadult.FindControl("ddlAdultgender" + j)).SelectedItem.Value == "Gender")
                        {
                            validation = false;
                            message = "Please Select Adult " + (j + 1).ToString() + "Gender";
                            break;
                        }

                    }

                }
            }
            #endregion

            #region Child Server Side Validation By Lavi
            if (validation)
            {
                if (Convert.ToString(Session["Children"]) != "")
                {
                    int k = Convert.ToInt32(Session["Children"].ToString());
                    if (k > 0)
                    {
                        for (int l = 0; l < k; l++)
                        {
                            if (((TextBox)tablechild.FindControl("TxtChildFirstName" + l)).Text == "" || ((TextBox)tableadult.FindControl("TxtChildFirstName" + l)).Text == "First Name")
                            {
                                validation = false;
                                message = "Please Enter Child " + (l + 1).ToString() + "First Name";
                                break;
                            }

                            if (((TextBox)tablechild.FindControl("TxtChildLastName" + l)).Text == "" || ((TextBox)tableadult.FindControl("TxtChildLastName" + l)).Text == "Last Name")
                            {
                                validation = false;
                                message = "Please Enter Child " + (l + 1).ToString() + "Last Name";
                                break;
                            }

                            if (((DropDownList)tablechild.FindControl("DdlChild" + l)).SelectedItem.Value == "Title")
                            {
                                validation = false;
                                message = "Please Select Child " + (l + 1).ToString() + "Title";
                                break;
                            }
                            if (((DropDownList)tablechild.FindControl("ddlChildgender" + l)).SelectedItem.Value == "Gender")
                            {
                                validation = false;
                                message = "Please Select Child " + (l + 1).ToString() + "Gender";
                                break;
                            }

                            if (((DropDownList)tablechild.FindControl("TxtChildDOB" + l)).SelectedItem.Value == "" )
                            {
                                validation = false;
                                message = "Please Select Child " + (l + 1).ToString() + "Age";
                                break;
                            }
                        }
                    }
                }
            }
            #endregion

            #region Infant Server side validation by Lavi
            if (validation)
            {
                if (Convert.ToString(Session["Infants"]) != "")
                {
                    int m = Convert.ToInt32(Session["Infants"].ToString());
                    if (m > 0)
                    {
                        for (int n = 0; n < m; n++)
                        {
                            if (((TextBox)tableinfant.FindControl("TxtInfantFirstName" + n)).Text == "" || ((TextBox)tableinfant.FindControl("TxtInfantFirstName" + n)).Text == "First Name")
                            {
                                validation = false;
                                message = "Please Enter Infant " + (n + 1).ToString() + "First Name";
                                break;
                            }

                            if (((TextBox)tableinfant.FindControl("TxtInfantLastName" + n)).Text == "" || ((TextBox)tableinfant.FindControl("TxtInfantLastName" + n)).Text == "Last Name")
                            {
                                validation = false;
                                message = "Please Enter Infant " + (n + 1).ToString() + "Last Name";
                                break;
                            }


                            if (((DropDownList)tableinfant.FindControl("DdlInfant" + n)).SelectedItem.Value == "Title")
                            {
                                validation = false;
                                message = "Please Select Infant " + (n + 1).ToString() + "Title";
                                break;
                            }
                            if (((DropDownList)tableinfant.FindControl("ddlInfantgender" + n)).SelectedItem.Value == "Gender")
                            {
                                validation = false;
                                message = "Please Select Infant " + (n + 1).ToString() + "Gender";
                                break;
                            }

                            if (((TextBox)tableinfant.FindControl("TxtInfantDOB" + n)).Text == "DOB" || ((TextBox)tableinfant.FindControl("TxtInfantDOB" + n)).Text == "")
                            {
                                validation = false;
                                message = "Please Select Infant " + (n + 1).ToString() + "Date of Birth";
                                break;
                            }
                        }

                    }
                }
            }
            #endregion

            #region Contact Details Validations
            if (validation)
            {
                if (txt_phonenumber.Text.Trim() == "" || txt_phonenumber.Text.Trim() == "Include Area code for Landline")
                {
                    validation = false;
                    message = "Please Enter Your Phone Number";
                }
                if (txt_phonenumber.Text.Trim().Length != 10)
                {
                    validation = false;
                    message = "Phone Number is not valid";
                }
                if (txtContactPin_Zip.Text.Trim() == "" || txtContactPin_Zip.Text.Trim() == "Pin/ Zip Code")
                {
                    validation = false;
                    message = "Please Enter Your Pin/Zip Code";
                }
                if (txtContactPin_Zip.Text.Trim().Length != 6)
                {
                    validation = false;
                    message = "Pin Code is not valid";
                }
                if (ddlState.SelectedValue == "Select State")
                {
                    validation = false;
                    message = "Please Select Your State";
                }
              
                if (txtContactAddress.Text.Trim() == "" || txtContactAddress.Text.Trim() == "Enter Your Address Here")
                {
                    validation = false;
                    message = "Please Enter Your Address";
                }
                if (txtcontactFname.Text.Trim() == "" || txtContactAddress.Text.Trim() == "First name")
                {
                    validation = false;
                    message = "Please Enter Your First name in Contact Details";
                }
                if (txtcontactLname.Text.Trim() == "" || txtcontactLname.Text.Trim() == "Last name")
                {
                    validation = false;
                    message = "Please Enter Your Last name in Contact Details";
                }
                if (DdlContactTitle.SelectedValue == "Title")
                {
                    validation = false;
                    message = "Please Select Title in Contact Details";
                }
            }
            #endregion

            if (validation)
            {
                #region Cretre Dynamic Session Variabkles Lavi
                if (Convert.ToString(Session["Adults"]) != "")
                {
                    int i = Convert.ToInt32(Session["Adults"].ToString());
                    if (i > 0)
                    {
                        for (int j = 0; j < i; j++)
                        {
                            Session["Adult" + j.ToString() + "Title"] = ((DropDownList)tableadult.FindControl("DdlAdultTitle" + j)).SelectedItem.Value;
                            Session["Adult" + j.ToString() + "FirstName"] = ((TextBox)tableadult.FindControl("txtadultFirstName" + j)).Text.Trim();
                            Session["Adult" + j.ToString() + "LastName"] = ((TextBox)tableadult.FindControl("txtadultLastName" + j)).Text.Trim();
                            Session["Adult" + j.ToString() + "Gender"] = ((DropDownList)tableadult.FindControl("ddlAdultgender" + j)).Text.Trim();
                            Session["Adult" + j.ToString() + "DOB"] = DateTime.Parse(((TextBox)tableadult.FindControl("TxtAdultDOB" + j)).Text.Trim()).ToString("MM/dd/yyyy");
                        }
                    }
                }

                if (Convert.ToString(Session["Children"]) != "")
                {
                    int k = Convert.ToInt32(Session["Children"].ToString());
                    if (k > 0)
                    {
                        for (int l = 0; l < k; l++)
                        {
                            Session["Child" + l.ToString() + "Title"] = ((DropDownList)tablechild.FindControl("DdlChild" + l.ToString())).SelectedItem.Value;
                            Session["Child" + l.ToString() + "FirstName"] = ((TextBox)tablechild.FindControl("TxtChildFirstName" + l.ToString())).Text.Trim();
                            Session["Child" + l.ToString() + "LastName"] = ((TextBox)tablechild.FindControl("TxtChildLastName" + l.ToString())).Text.Trim();
                            Session["Child" + l.ToString() + "DOB"] = ((DropDownList)tablechild.FindControl("TxtChildDOB" + l.ToString())).SelectedItem.Value;
                            Session["Child" + l.ToString() + "Gender"] = ((DropDownList)tablechild.FindControl("ddlChildgender" + l.ToString())).SelectedItem.Value;
                        }
                    }
                }

                if (Convert.ToString(Session["Infants"]) != "")
                {
                    int m = Convert.ToInt32(Session["Infants"].ToString());
                    if (m > 0)
                    {
                        for (int n = 0; n < m; n++)
                        {
                            Session["Infant" + n.ToString() + "Title"] = ((DropDownList)tableinfant.FindControl("DdlInfant" + n.ToString())).SelectedItem.Value;
                            Session["Infant" + n.ToString() + "FirstName"] = ((TextBox)tableinfant.FindControl("TxtInfantFirstName" + n.ToString())).Text.Trim();
                            Session["Infant" + n.ToString() + "LastName"] = ((TextBox)tableinfant.FindControl("TxtInfantLastName" + n.ToString())).Text.Trim();
                            Session["Infant" + n.ToString() + "DOB"] = DateTime.Parse(((TextBox)tableinfant.FindControl("TxtInfantDOB" + n.ToString())).Text.Trim()).ToString("MM/dd/yyyy");
                            Session["Infant" + n.ToString() + "Gender"] = ((DropDownList)tableinfant.FindControl("ddlInfantgender" + n.ToString())).SelectedItem.Value;
                        }
                    }
                }
                #endregion
                if (txtcontactLname.Text.Trim() != "Last Name" && txtcontactLname.Text.Trim() != "")
                {
                    Session["Contact_lastName"] = ToUpperFirstLetter(txtcontactLname.Text.Trim());
                }
                else
                {

                }
                if (txtcontactFname.Text != "First Name" && txtcontactFname.Text != "")
                {
                    Session["Contact_FirstName"] = ToUpperFirstLetter(txtcontactFname.Text.Trim());
                }
                else
                {
                    validation = false;
                    message = "Please Enter Your First Name";
                }
                if (txtcity.Text.Trim() == "City" && txtcity.Text.Trim() == "")
                {
                    Session["Contact_City"] = txtcity.Text.Trim();
                }
                else
                {
                    validation = false;
                    message = "Please Enter Your City";
                }

                if (txtContactPin_Zip.Text.Trim() != "Pin/ Zip Code" && txtContactPin_Zip.Text.Trim() != "")
                {
                    Session["Contact_PinCode"] = txtContactPin_Zip.Text.Trim();
                }
                else
                {
                    validation = false;
                    message = "Please Enter Your Pin/ Zip Code";
                }
                if (txt_phonenumber.Text.Trim() != "" && txt_phonenumber.Text.Trim() != "Mobile No.")
                {
                    Session["Contact_PhoneNo"] = txt_phonenumber.Text.Trim();
                }
                else
                {
                    validation = false;
                    message = "Please Enter Your Phone No";
                }
                if (txtemail.Text.Trim() != "" && txtemail.Text.Trim() != "Email Id")
                {
                    Session["RequiredMainEmailid"] = txtemail.Text.Trim();
                }
                else
                {
                    validation = false;
                    message = "Please Enter Your Email Id";
                }
                Session["RequiredMainMobile"] = txt_phonenumber.Text.Trim();
                Session["Contact_Title"] = DdlContactTitle.SelectedItem.Value;
                Session["Contact_Address"] = txtContactAddress.Text.Trim();
                Session["Contact_State"] = ddlState.SelectedItem.Text;
                Session["Contact_Country"] = ddl_country.Text.Trim();
                Session["Booking_Request"] = Dom_Flight_Booking_Request();
                 if (IsValidXml(Convert.ToString(Session["Booking_Request"])))
                {

                    Response.Redirect("Step4.aspx", false);
                }
                else
                {
                    RegisterClientScriptBlock("alert", "<script>alert('Please do not use special character Like &,<,> in customer information.');</script>");
                }
               // Response.Redirect("Step4.aspx", false);
            }
            else
            {
                RegisterClientScriptBlock("alert", "<script>alert('" + message + "');</script>");
            }
        }
        catch (Exception ex)
        {

            AirEpointSupport ob = new AirEpointSupport();
            ob.WriteToLog(ex.Message, "step3", "bt_Continue_Cliclk__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../../User/Index.aspx?s=exception");

        }


    }
    public bool IsValidXml(string xml)
    {
        try
        {
            XDocument.Parse(xml);
            return true;
        }
        catch
        {
            return false;
        }
    }
    public string Dom_Flight_Booking_Request()
    {
        string request = string.Empty;
        char travelMode;
        DataSet ds_alldata = new DataSet();
        ds_alldata=(DataSet)Session["Response"];
        DataTable FlightSegment_OneWay_Depart = new DataTable();
        DataTable class_details = new DataTable();
        class_details = (DataTable)Session["ClassCodeNew"];
        #region ONEWAY BOOKING REQUEST

        if (Convert.ToString(Session["Trip"]) == "One")
        {
            FlightSegment_OneWay_Depart = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Depart"];
            request = @"<AIRBOOKING>
<UserTrackId>" + ds_alldata.Tables["AvailabilityResponse"].Rows[0][0].ToString() + @"</UserTrackId>
<CustomerDetails>
<PhoneNumber>" + txt_phonenumber.Text + @"</PhoneNumber>
<CustomerTitle>" + DdlContactTitle.SelectedItem.Text + @"</CustomerTitle>
<BookedByCusomter>" + txtcontactFname.Text + " " + txtcontactLname.Text + @"</BookedByCusomter>
<CustomerAddr>" + txtContactAddress.Text + @"</CustomerAddr>
<CustomerCity>" + txtcity.Text + @"</CustomerCity>
<CustomerCountryId>99</CustomerCountryId>
<CustomerEmail>venusutilityservices@gmail.com</CustomerEmail>
<PinCode>" + txtContactPin_Zip.Text + @"</PinCode>
</CustomerDetails>
<SpecialRemarks />
<SendingMail>0</SendingMail>
<SendingSMS>0</SendingSMS>
<No_of_Adults>" + Convert.ToInt32(Session["Adults"].ToString()) + @"</No_of_Adults>
<No_of_Child>" + Convert.ToInt32(Session["Children"].ToString()) + @"</No_of_Child>
<No_of_Infants>" + Convert.ToInt32(Session["Infants"].ToString()) + @"</No_of_Infants>";
            if (Convert.ToString(Session["Trip"]) == "One")
            {
                travelMode = 'O';
            }
            else travelMode = 'R';
            request = request + @"<TravelTypeId>" + travelMode + @"</TravelTypeId>
<TotalAmount>" + Convert.ToDouble(Session["totalPrice"]) + @"</TotalAmount>
<FrequentFlyer>
<item>
<NamePosition />
<FreqFlyerAirline />
<FreqFlyerNumber />
</item>
</FrequentFlyer>
<SPECIALREQUEST>
<item>
<SegmantNumber />
<item>
<NamePosition />
<SSRCode />
</item>
</item>
</SPECIALREQUEST>
<MEALREQUEST>
<item>
<SegmantNumber />
<item>
<NamePosition />
<MealCode />
</item>
</item>
</MEALREQUEST>
<Bookingdetails>
<item>
<AirLinesId>" + FlightSegment_OneWay_Depart.Rows[0]["CarrierCode"].ToString() + @"</AirLinesId>
<Payment>
<item>
<CurrencyCode>INR</CurrencyCode>
<Amount>" + Convert.ToDouble(Session["totalPrice"]) + @"</Amount>
</item>
</Payment>
<TourCode />
<PassengerDetail>";
            for (int i = 0; i < Convert.ToInt32(Session["Adults"]); i++)
            {
                request = request + @"<item>
<PassengerType>1</PassengerType>
<Title>" + Session["Adult" + i.ToString() + "Title"].ToString() + @"</Title>
<FirstName>" + Session["Adult" + i.ToString() + "FirstName"].ToString() + @"</FirstName>
<LastName>" + Session["Adult" + i.ToString() + "LastName"].ToString() + @"</LastName>
<Age/>
<IdentityProofId />
<IdentityProofNumber />
<Gender>" + Session["Adult" + i.ToString() + "Gender"].ToString() + @"</Gender>
<Segment>";
                for (int j = 0; j < FlightSegment_OneWay_Depart.Rows.Count; j++)
                {
                    request = request + @"<item>
<FlightId>" + Convert.ToInt32(FlightSegment_OneWay_Depart.Rows[j]["FlightId"]) + @"</FlightId>
<ClassCode>" + class_details.Rows[j]["ClassCode"].ToString() + @"</ClassCode>
<SpRequestId />
<FrequentFlyerId />
<FrequentFlyerNumber />
<MealsPrefId />
<SeatPrefId />
</item>";
                }
                request = request + @"</Segment>
</item>";
            }
            for (int c = 0; c < Convert.ToInt32(Session["Children"]); c++)
            {
                request = request + @"<item>
<PassengerType>2</PassengerType>
<Title>" + Session["Child" + c.ToString() + "Title"].ToString() + @"</Title>
<FirstName>" + Session["Child" + c.ToString() + "FirstName"].ToString() + @"</FirstName>
<LastName>" + Session["Child" + c.ToString() + "LastName"].ToString() + @"</LastName>
<Age>" + Session["Child" + c.ToString() + "DOB"].ToString() + @"</Age>
<IdentityProofId />
<IdentityProofNumber />
<Gender>" + Session["Child" + c.ToString() + "Gender"].ToString() + @"</Gender>
<Segment>";
                for (int j = 0; j < FlightSegment_OneWay_Depart.Rows.Count; j++)
                {
                    request = request + @"<item>
<FlightId>" + Convert.ToInt32(FlightSegment_OneWay_Depart.Rows[j]["FlightId"]) + @"</FlightId>
<ClassCode>" + class_details.Rows[j]["ClassCode"].ToString() + @"</ClassCode>
<SpRequestId />
<FrequentFlyerId />
<FrequentFlyerNumber />
<MealsPrefId />
<SeatPrefId />
</item>";
                }
                request = request + @"</Segment>
</item>";
            }
            for (int d = 0; d < Convert.ToInt32(Session["Infants"]); d++)
            {
                request = request + @"<item>
<PassengerType>3</PassengerType>
<Title>" + Session["Infant" + d.ToString() + "Title"].ToString() + @"</Title>
<FirstName>" + Session["Infant" + d.ToString() + "FirstName"].ToString() + @"</FirstName>
<LastName>" + Session["Infant" + d.ToString() + "LastName"].ToString() + @"</LastName>
<Age>" + Session["Infant" + d.ToString() + "DOB"].ToString() + @"</Age>
<IdentityProofId />
<IdentityProofNumber />
<Gender>" + Session["Infant" + d.ToString() + "Gender"].ToString() + @"</Gender>
<Segment>";
                for (int j = 0; j < FlightSegment_OneWay_Depart.Rows.Count; j++)
                {
                    request = request + @"<item>
<FlightId>" + Convert.ToInt32(FlightSegment_OneWay_Depart.Rows[j]["FlightId"]) + @"</FlightId>
<ClassCode>" + class_details.Rows[j]["ClassCode"].ToString() + @"</ClassCode>
<SpRequestId />
<FrequentFlyerId />
<FrequentFlyerNumber />
<MealsPrefId />
<SeatPrefId />
</item>";
                }
                request = request + @"</Segment>
</item>";
            }

            request = request + @"</PassengerDetail>
</item>
</Bookingdetails>
</AIRBOOKING>";
        }
        #endregion
        #region ROUNDTRIP BOOKING REQUEST
        else
        {
            FlightSegment_OneWay_Depart = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Depart"];
            DataTable FlightSegment_OneWay_Return = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Return"];
            request = @"<AIRBOOKING>
<UserTrackId>" + ds_alldata.Tables["AvailabilityResponse"].Rows[0][0].ToString() + @"</UserTrackId>
<CustomerDetails>
<PhoneNumber>" + txt_phonenumber.Text + @"</PhoneNumber>
<CustomerTitle>" + DdlContactTitle.SelectedItem.Text + @"</CustomerTitle>
<BookedByCusomter>" + txtcontactFname.Text + " " + txtcontactLname.Text + @"</BookedByCusomter>
<CustomerAddr>" + txtContactAddress.Text + @"</CustomerAddr>
<CustomerCity>" + txtcity.Text + @"</CustomerCity>
<CustomerCountryId>99</CustomerCountryId>
<CustomerEmail>venusutilityservices@gmail.com</CustomerEmail>
<PinCode>" + txtContactPin_Zip.Text + @"</PinCode>
</CustomerDetails>
<SpecialRemarks />
<SendingMail>0</SendingMail>
<SendingSMS>0</SendingSMS>
<No_of_Adults>" + Convert.ToInt32(Session["Adults"].ToString()) + @"</No_of_Adults>
<No_of_Child>" + Convert.ToInt32(Session["Children"].ToString()) + @"</No_of_Child>
<No_of_Infants>" + Convert.ToInt32(Session["Infants"].ToString()) + @"</No_of_Infants>";
            if (Convert.ToString(Session["Trip"]) == "One")
            {
                travelMode = 'O';
            }
            else travelMode = 'R';
            request = request + @"<TravelTypeId>" + travelMode + @"</TravelTypeId>
<TotalAmount>" + Convert.ToDouble(Session["totalPrice"]) + @"</TotalAmount>
<FrequentFlyer>
<item>
<NamePosition />
<FreqFlyerAirline />
<FreqFlyerNumber />
</item>
</FrequentFlyer>
<SPECIALREQUEST>
<item>
<SegmantNumber />
<item>
<NamePosition />
<SSRCode />
</item>
</item>
</SPECIALREQUEST>
<MEALREQUEST>
<item>
<SegmantNumber />
<item>
<NamePosition />
<MealCode />
</item>
</item>
</MEALREQUEST>
<Bookingdetails>
<item>
<AirLinesId>" + FlightSegment_OneWay_Depart.Rows[0]["CarrierCode"].ToString() + @"</AirLinesId>
<Payment>
<item>
<CurrencyCode>INR</CurrencyCode>
<Amount>" + Convert.ToDouble(Session["totalPrice_onGoing"]) + @"</Amount>
</item>
</Payment>
<TourCode />
<PassengerDetail>";
            for (int i = 0; i < Convert.ToInt32(Session["Adults"]); i++)
            {
                request = request + @"<item>
<PassengerType>1</PassengerType>
<Title>" + Session["Adult" + i.ToString() + "Title"].ToString() + @"</Title>
<FirstName>" + Session["Adult" + i.ToString() + "FirstName"].ToString() + @"</FirstName>
<LastName>" + Session["Adult" + i.ToString() + "LastName"].ToString() + @"</LastName>
<Age/>
<IdentityProofId />
<IdentityProofNumber />
<Gender>" + Session["Adult" + i.ToString() + "Gender"].ToString() + @"</Gender>

<Segment>";
                for (int j = 0; j < FlightSegment_OneWay_Depart.Rows.Count; j++)
                {
                    request = request + @"<item>
<FlightId>" + Convert.ToInt32(FlightSegment_OneWay_Depart.Rows[j]["FlightId"]) + @"</FlightId>
<ClassCode>" + FlightSegment_OneWay_Depart.Rows[j]["ClassCode"].ToString() + @"</ClassCode>
<SpRequestId />
<FrequentFlyerId />
<FrequentFlyerNumber />
<MealsPrefId />
<SeatPrefId />
</item>";
                }
                request = request + @"</Segment>
</item>";
            }
            for (int c = 0; c < Convert.ToInt32(Session["Children"]); c++)
            {
                request = request + @"<item>
<PassengerType>2</PassengerType>
<Title>" + Session["Child" + c.ToString() + "Title"].ToString() + @"</Title>
<FirstName>" + Session["Child" + c.ToString() + "FirstName"].ToString() + @"</FirstName>
<LastName>" + Session["Child" + c.ToString() + "LastName"].ToString() + @"</LastName>
<Age>" + Session["Child" + c.ToString() + "DOB"].ToString() + @"</Age>
<IdentityProofId />
<IdentityProofNumber />
<Gender>" + Session["Child" + c.ToString() + "Gender"].ToString() + @"</Gender>
<Segment>";
                for (int j = 0; j < FlightSegment_OneWay_Depart.Rows.Count; j++)
                {
                    request = request + @"<item>
<FlightId>" + Convert.ToInt32(FlightSegment_OneWay_Depart.Rows[j]["FlightId"]) + @"</FlightId>
<ClassCode>" + FlightSegment_OneWay_Depart.Rows[j]["ClassCode"].ToString() + @"</ClassCode>
<SpRequestId />
<FrequentFlyerId />
<FrequentFlyerNumber />
<MealsPrefId />
<SeatPrefId />
</item>";
                }
                request = request + @"</Segment>
</item>";
            }
            for (int d = 0; d < Convert.ToInt32(Session["Infants"]); d++)
            {
                request = request + @"<item>
<PassengerType>3</PassengerType>
<Title>" + Session["Infant" + d.ToString() + "Title"].ToString() + @"</Title>
<FirstName>" + Session["Infant" + d.ToString() + "FirstName"].ToString() + @"</FirstName>
<LastName>" + Session["Infant" + d.ToString() + "LastName"].ToString() + @"</LastName>
<Age>" + Session["Infant" + d.ToString() + "DOB"].ToString() + @"</Age>
<IdentityProofId />
<IdentityProofNumber />
<Gender>" + Session["Infant" + d.ToString() + "Gender"].ToString() + @"</Gender>
<Segment>";
                for (int j = 0; j < FlightSegment_OneWay_Depart.Rows.Count; j++)
                {
                    request = request + @"<item>
<FlightId>" + Convert.ToInt32(FlightSegment_OneWay_Depart.Rows[j]["FlightId"]) + @"</FlightId>
<ClassCode>" + FlightSegment_OneWay_Depart.Rows[j]["ClassCode"].ToString() + @"</ClassCode>
<SpRequestId />
<FrequentFlyerId />
<FrequentFlyerNumber />
<MealsPrefId />
<SeatPrefId />
</item>";
                }
                request = request + @"</Segment>
</item>";
            }

            request = request + @"</PassengerDetail>
</item>

<item>
<AirLinesId>" + FlightSegment_OneWay_Return.Rows[0]["CarrierCode"].ToString() + @"</AirLinesId>
<Payment>
<item>
<CurrencyCode>INR</CurrencyCode>
<Amount>" + Convert.ToDouble(Session["totalPrice_Return"]) + @"</Amount>
</item>
</Payment>
<TourCode />
<PassengerDetail>";
            for (int i = 0; i < Convert.ToInt32(Session["Adults"]); i++)
            {
                request = request + @"<item>
<PassengerType>1</PassengerType>
<Title>" + Session["Adult" + i.ToString() + "Title"].ToString() + @"</Title>
<FirstName>" + Session["Adult" + i.ToString() + "FirstName"].ToString() + @"</FirstName>
<LastName>" + Session["Adult" + i.ToString() + "LastName"].ToString() + @"</LastName>
<Age/>
<IdentityProofId />
<IdentityProofNumber />
<Gender>" + Session["Adult" + i.ToString() + "Gender"].ToString() + @"</Gender>

<Segment>";
                for (int j = 0; j < FlightSegment_OneWay_Return.Rows.Count; j++)
                {
                    request = request + @"<item>
<FlightId>" + Convert.ToInt32(FlightSegment_OneWay_Return.Rows[j]["FlightId"]) + @"</FlightId>
<ClassCode>" + FlightSegment_OneWay_Return.Rows[j]["ClassCode"].ToString() + @"</ClassCode>
<SpRequestId />
<FrequentFlyerId />
<FrequentFlyerNumber />
<MealsPrefId />
<SeatPrefId />
</item>";
                }
                request = request + @"</Segment>
</item>";
            }
            for (int c = 0; c < Convert.ToInt32(Session["Children"]); c++)
            {
                request = request + @"<item>
<PassengerType>2</PassengerType>
<Title>" + Session["Child" + c.ToString() + "Title"].ToString() + @"</Title>
<FirstName>" + Session["Child" + c.ToString() + "FirstName"].ToString() + @"</FirstName>
<LastName>" + Session["Child" + c.ToString() + "LastName"].ToString() + @"</LastName>
<Age>" + Session["Child" + c.ToString() + "DOB"].ToString() + @"</Age>
<IdentityProofId />
<IdentityProofNumber />
<Gender>" + Session["Child" + c.ToString() + "Gender"].ToString() + @"</Gender>
<Segment>";
                for (int j = 0; j < FlightSegment_OneWay_Return.Rows.Count; j++)
                {
                    request = request + @"<item>
<FlightId>" + Convert.ToInt32(FlightSegment_OneWay_Return.Rows[j]["FlightId"]) + @"</FlightId>
<ClassCode>" + FlightSegment_OneWay_Return.Rows[j]["ClassCode"].ToString() + @"</ClassCode>
<SpRequestId />
<FrequentFlyerId />
<FrequentFlyerNumber />
<MealsPrefId />
<SeatPrefId />
</item>";
                }
                request = request + @"</Segment>
</item>";
            }
            for (int d = 0; d < Convert.ToInt32(Session["Infants"]); d++)
            {
                request = request + @"<item>
<PassengerType>3</PassengerType>
<Title>" + Session["Infant" + d.ToString() + "Title"].ToString() + @"</Title>
<FirstName>" + Session["Infant" + d.ToString() + "FirstName"].ToString() + @"</FirstName>
<LastName>" + Session["Infant" + d.ToString() + "LastName"].ToString() + @"</LastName>
<Age>" + Session["Infant" + d.ToString() + "DOB"].ToString() + @"</Age>
<IdentityProofId />
<IdentityProofNumber />
<Gender>" + Session["Infant" + d.ToString() + "Gender"].ToString() + @"</Gender>
<Segment>";
                for (int j = 0; j < FlightSegment_OneWay_Return.Rows.Count; j++)
                {
                    request = request + @"<item>
<FlightId>" + Convert.ToInt32(FlightSegment_OneWay_Return.Rows[j]["FlightId"]) + @"</FlightId>
<ClassCode>" + FlightSegment_OneWay_Return.Rows[j]["ClassCode"].ToString() + @"</ClassCode>
<SpRequestId />
<FrequentFlyerId />
<FrequentFlyerNumber />
<MealsPrefId />
<SeatPrefId />
</item>";
                }
                request = request + @"</Segment>
</item>";
            }

            request = request + @"</PassengerDetail>
</item>
</Bookingdetails>
</AIRBOOKING>";

        }
        #endregion
        return request;
    }

    protected void ddl_country_SelectedIndexChanged(object sender, EventArgs e)
    {
        //bing city from here
    }
    public static string ToUpperFirstLetter(string source)
    {
        if (string.IsNullOrEmpty(source))
            return string.Empty;
        char[] letters = source.ToCharArray();
        letters[0] = char.ToUpper(letters[0]);
        return new string(letters);
    }
    protected void txtAdultPassportNo1_TextChanged(object sender, EventArgs e)
    {
       
    }

 public void fillagentdetails()
    {
        try
        {
            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "agent_auto_fill_details", new SqlParameter[] { new SqlParameter("@userId", Convert.ToString(Session["agid"])) });
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Gender"].ToString() == "Male")
                {
                    DdlContactTitle.SelectedValue = "Mr.";
                }
                else
                    DdlContactTitle.SelectedValue = "Ms.";
                txtcontactFname.Text=ds.Tables[0].Rows[0]["Agent_first_name"].ToString();
                txtcontactLname.Text = ds.Tables[0].Rows[0]["Agent_last_name"].ToString();
                txtContactAddress.Text = ds.Tables[0].Rows[0]["address1"].ToString();
                txtcity.Text = ds.Tables[0].Rows[0]["city"].ToString();
                ddl_country.Text = ds.Tables[0].Rows[0]["country"].ToString();
            }
        }
        catch(Exception ex)
        {

        }
    }
}
