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.Data.SqlTypes;
using System.Net.Mail;

public partial class Domestic_step4new : System.Web.UI.Page
{
    string Clientid, Clientpassword, Clienttype;
    string adultinfo = "";
    string childinfo = "";
    string infantinfo = "";
    int flag = 0;
    string sys_IP;
    int currentyear;
    Literal Literal_FlightInformation = new Literal();
    Literal LiteralFlight_info_Return = new Literal();
    string sourceoneway = string.Empty;
    string desoneway = string.Empty;
    string sourceround = string.Empty;
    string desround = string.Empty;
   // Air_transaction_Cal ATC = new Air_transaction_Cal();
    AirEpointSupport obj_AirEpointSupport;
    protected void Page_Load(object sender, EventArgs e)
    {
        obj_AirEpointSupport = new AirEpointSupport();
        try
        { 
            sys_IP = Request.UserHostAddress;
            if (Session["BookinRequest_OriginDestinationOption_OneWay_Depart"] == null || Session["DestinationFrom"] == null)
            {
                Response.Redirect("../User/Index.aspx?s=timeout", false);
            }
           if (!IsPostBack)
            {
                   decimal Total=0;
                decimal dectable =0;
                 if (Convert.ToString(Session["Trip"]) == "One")
                {
                Total   =  Convert.ToDecimal(Session["Dom_Ticket_Price"]);
                dectable = Convert.ToDecimal(Session["Dom_Ticket_detect"]);
                }
                 else if (Convert.ToString(Session["Trip"]) == "Round")
                 {
                     Total = Convert.ToDecimal(Session["Dom_Ticket_Price"]);
                     dectable = Convert.ToDecimal(Session["Dom_Ticket_detect"]);
                 }

                 lbl_TotTicketAmt.Text = Math.Round(Convert.ToDouble(Total) * Convert.ToDouble(Session["convertor"])).ToString();          
                lbl_deductableamt.Text = Math.Round(Convert.ToDouble(dectable)* Convert.ToDouble(Session["convertor"])).ToString();
                lbl_Agentearning.Text = Math.Round(Convert.ToDouble(Total - dectable) * Convert.ToDouble(Session["convertor"])).ToString();
                B2B objb2b = new B2B();
                decimal AgentAmount = Convert.ToDecimal(objb2b.CheckAgentBalance(Convert.ToString(Session["agid"]),Convert.ToString(Session["HURL"])));  //get the latest amount
                Session["agent_amount"] = AgentAmount;
                    if (AgentAmount >= dectable)
                    {
                        lbl_current_balance.Text = Math.Round(Convert.ToDouble(Convert.ToString(Session["agent_amount"])) * Convert.ToDouble(Session["convertor"])).ToString();
                        lbl_rest_balance.Text = Math.Round(Convert.ToDouble(Convert.ToString(Convert.ToDecimal(Session["agent_amount"]) - dectable)) * Convert.ToDouble(Session["convertor"])).ToString();
                        Session["deducted_amount"] = dectable.ToString();
                    }
                    else
                    {
                        Response.Redirect("../User/Index.aspx?s=pay", false);
                    }
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "pageLoad__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
        }
    }

    protected void btn_submit_Click(object sender, EventArgs e)
    {
        try
        {
            if (ChackBox1.Checked)
            {
                B2B objb2b = new B2B();
                bool paymentstatus = false;
                if (Convert.ToString(Session["Trip"]) == "One")
                {
                    
                }
                else if (Convert.ToString(Session["Trip"]) == "Round")
                {
                   
                }
               // Convert.ToString(Session["agid"]), Convert.ToDecimal(Session["Dom_Ticket_Price"]), Convert.ToDecimal(Session["Dom_Ticket_detect"]), Convert.ToDecimal(Session["Dom_AgentComm"]), Convert.ToString(Session["partnerRefId"]), Convert.ToString(Session["distributor"]), Request.UserHostAddress, "Dom H Flight Booking", Convert.ToString(Session["HURL"]
                int status = objb2b.InsertTransactionWithPendingStatus(Session["WhitelabelId"].ToString(), Request.UserHostAddress, Convert.ToString(Session["partnerRefId"]), Convert.ToString(Session["agid"]),  "60","0", Convert.ToDecimal(Session["Dom_Ticket_detect"]), "GI Flihgt", Session["PortalName"].ToString(), "Dom Flight Booking");
                if(status==1)
                {
                    paymentstatus = true;
                }
             
                else
                 {
                    paymentstatus = false;
                 }
                if (paymentstatus)
                {
                    Session["agent_amount"] = Convert.ToDecimal(objb2b.CheckAgentBalance(Convert.ToString(Session["agid"]), Convert.ToString(Session["HURL"])));  //get the latest amount  
                    int adultcount = Convert.ToInt32(Session["Adults"]);
                    int childcount = Convert.ToInt32(Session["Children"]);
                    int infantcount = Convert.ToInt32(Session["Infants"]);
                    currentyear = Convert.ToInt32(DateTime.Now.ToString("yyyy"));
                    #region Adultcustomerinf0
                    if (adultcount > 0)
                    {
                        for (int i = 0; i < adultcount; i++)
                        {
                            adultinfo = adultinfo + "<CustomerInfo><givenName>" + Convert.ToString(Session["Adult" + i + "FirstName"]) + "</givenName><surName>" + Convert.ToString(Session["Adult" + i + "LastName"]) + "</surName><nameReference>" + Convert.ToString(Session["Adult" + i + "Title"]) + "</nameReference><psgrtype>adt</psgrtype></CustomerInfo>";

                        }
                        ViewState["AdultsInformation"] = "<AdultsInformation>" + adultinfo + "</AdultsInformation>";
                    }
                    #endregion
                    #region Childcustomerinf0

                    if (childcount > 0)
                    {
                        for (int i = 0; i < childcount; i++)
                        {
                            childinfo = childinfo + "<CustomerInfo><givenName>" + Convert.ToString(Session["Child" + i + "FirstName"]) + "</givenName><surName>" + Convert.ToString(Session["Child" + i + "LastName"]) + "</surName><nameReference>" + Convert.ToString(Session["Child" + i + "Title"]) + "</nameReference><dob>" + Convert.ToString(Session["Child" + i + "DOB"]) + "</dob><age>" + Convert.ToString(Session["Child" + i + "DOB"]) + "</age><psgrtype>chd</psgrtype></CustomerInfo>";
                        }
                        ViewState["ChildrenInformation"] = "<ChildrenInformation>" + childinfo + "</ChildrenInformation>";
                    }

                    #endregion
                    #region Infantcustomerinf0

                    if (infantcount > 0)
                    {
                        for (int i = 0; i < infantcount; i++)
                        {
                            string[] stdate = Session["Infant" + i + "DOB"].ToString().Split('/');
                            string fdate = stdate[1] + "-" + stdate[0] + "-" + stdate[2];
                            int infantage = currentyear - Convert.ToInt32(stdate[2]);
                            //string infantdate = DateTime.Parse(Session["Infant" + i + "DOB"].ToString()).ToString("dd-MM-yyyy");
                            infantinfo = infantinfo + "<CustomerInfo><givenName>" + Convert.ToString(Session["Infant" + i + "FirstName"]) + "</givenName><surName>" + Convert.ToString(Session["Infant" + i + "LastName"]) + "</surName><nameReference>" + Convert.ToString(Session["Infant" + i + "Title"]) + "</nameReference><dob>" + fdate + "</dob><age>" + infantage + "</age><psgrtype>inf</psgrtype></CustomerInfo>";
                        }
                        ViewState["InfantsInformation"] = "<InfantsInformation>" + infantinfo + "</InfantsInformation>";
                    }

                    #endregion
                    #region Insert Data in Database
                    InsertBookingStaus();
                    #region technical problem condition
                    if (Convert.ToString(Session["Trip"]) == "One")
                    {
                        if (flag == 0)
                        {
                            InsertBooking_Cancellation_Info_Table();
                        }
                    }
                    else if (Convert.ToString(Session["Trip"]) == "Round")
                    {
                        if (flag == 0)
                        {
                            InsertBooking_Cancellation_Info_Table_For_RoundTrip();
                        }
                    }
                    #endregion
                    #endregion
                }
                else
                {
                    Response.Redirect("../User/Index.aspx?s=pay", false);
                }
            }
            else if (!ChackBox1.Checked)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertBox", "alert('Please accept terms and conditions');", true);
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "btn_submit_Click__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
        }
    }


    #region Insert All Information in Database

    #region Insert procedure for Booking Status Table

    public void InsertBookingStaus()
    {
       
        try
        {
            string travelmode = null;
            if (Convert.ToString(Session["Trip"]) == "One")
            {
                travelmode = "OneWay";
            }
            else if (Convert.ToString(Session["Trip"]) == "Round")
            {
                travelmode = "RoundTrip";
            }
            SqlParameter[] paramBookingStatus = new SqlParameter[]
               {          
                 new SqlParameter("@ResultBstatusOutput",SqlDbType.Int,4),
                 new SqlParameter("@Booking_St_Id_Output",SqlDbType.BigInt),
                 new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                 new SqlParameter("@Agent_id",Convert.ToString(Session["agid"])),
                 new SqlParameter("@Travel_mode",Convert.ToString(travelmode)), 
              };
            paramBookingStatus[0].Direction = ParameterDirection.Output;
            paramBookingStatus[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_BookingStatus_Insert", paramBookingStatus);
            string ResultBookingstatus = Convert.ToString(paramBookingStatus[0].Value);
            ViewState["Booking_St_Id"] = Convert.ToInt32(paramBookingStatus[1].Value);
            Session["Booking_St_Id"] = Convert.ToString(ViewState["Booking_St_Id"]);
            if (ResultBookingstatus == "1")
            {
                InsertBookingInformation();
            }
            else if (ResultBookingstatus == "0")
            {
            
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertBookingStaus__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }
    }

    #endregion

    # region Insert procedure for Booking Information Table
    public void InsertBookingInformation()
    {
        try
        {
            SqlParameter[] paramBookingInformation = new SqlParameter[]
               {
                   new SqlParameter("@ResultBookingInformationOutput",SqlDbType.Int,4),
                   new SqlParameter("@Booking_St_id", Convert.ToInt32(ViewState["Booking_St_Id"])),
                   new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                   new SqlParameter("@Title",Convert.ToString(Session["Contact_Title"])),
                   new SqlParameter("@First_name",Convert.ToString(Session["Contact_FirstName"])),
                   new SqlParameter("@last_name",Convert.ToString(Session["Contact_lastName"])),
                   new SqlParameter("@Address",Convert.ToString(Session["Contact_Address"])),
                   new SqlParameter("@state",Convert.ToString(Session["Contact_State"])),
                   new SqlParameter("@city",Convert.ToString(Session["Contact_City"])),
                   new SqlParameter("@country",Convert.ToString(Session["Contact_Country"])),
                   new SqlParameter("@pin_code",Convert.ToString(Session["Contact_PinCode"])),
                   new SqlParameter("@mobile_no",Convert.ToString(Session["Contact_PhoneNo"])),
                   new SqlParameter("@mobile_otherno",Convert.ToString(Session["Contact_AnotheMobNo"])),
                   new SqlParameter("@Psngr_mobile",Convert.ToString(Session["RequiredMainMobile"])),
                   new SqlParameter("@Psngr_email",Convert.ToString(Session["RequiredMainEmailid"])),
                   new SqlParameter("@Status","Pending"),
              };

            paramBookingInformation[0].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_BookingInformation_Insert", paramBookingInformation);
            string ResultBookingInformationStatus = Convert.ToString(paramBookingInformation[0].Value);
            if (ResultBookingInformationStatus == "1")
            {
                InsertOriginDestinationOptionOneWay();
            }
            else if (ResultBookingInformationStatus == "0")
            {
          
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertBookingInformation__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }
    }
    #endregion

    # region Insert procedure for OriginDestinationOptionOneWay_Depart Table

    public void InsertOriginDestinationOptionOneWay()
    {
     
        try
        {
            DataTable dsOriginDestinationOneWayDepartxml = new DataTable();
            dsOriginDestinationOneWayDepartxml = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Depart"];
            decimal TDiscount = Convert.ToDecimal(0);
            AirEpointSupport ob = new AirEpointSupport();
            if (dsOriginDestinationOneWayDepartxml.Rows.Count != 0)
            {
                SqlParameter[] paramOriginDestinationOptionOneWay_Depart = new SqlParameter[]
                    {                
                             new SqlParameter("@ResultOrginDStatusOutput",SqlDbType.Int,4),
                             new SqlParameter("@OriginDestinationOption_Id_Return_Output",SqlDbType.BigInt),
                             new SqlParameter("@Booking_St_Id",Convert.ToInt32(ViewState["Booking_St_Id"])),
                             new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                             new SqlParameter("@Origin", Convert.ToString(Session["DestinationFrom"])),
                             new SqlParameter("@Destination",Convert.ToString(Session["DestinationTo"])),
                             new SqlParameter("@DepartDate", Convert.ToDateTime(Session["DepartureDate"])),
                             new SqlParameter("@ReturnDate",Convert.ToDateTime(Session["ReturnDate"])),
                             new SqlParameter("@AdultPax",Convert.ToInt32(Session["Adults"])),
                             new SqlParameter("@ChildPax",Convert.ToInt32(Session["Children"])),
                             new SqlParameter("@InfantPax",Convert.ToInt32(Session["Infants"])),
                             new SqlParameter("@Preferredclass",Convert.ToString(Session["Class"])),
                             new SqlParameter("@Traveling_Mode",Convert.ToString(Session["Trip"])),
                             new SqlParameter("@PreferredAirline",Convert.ToString(dsOriginDestinationOneWayDepartxml.Rows[0]["CarrierCode"])),
                             new SqlParameter("@ActualBaseFare",Convert.ToDecimal(dsOriginDestinationOneWayDepartxml.Rows[0]["BasicAmount"])),
                             new SqlParameter("@Tax",Convert.ToDecimal(dsOriginDestinationOneWayDepartxml.Rows[0]["GrossAmount"])-Convert.ToDecimal(dsOriginDestinationOneWayDepartxml.Rows[0]["BasicAmount"])),
                             new SqlParameter("@STax",Convert.ToDecimal(0)),
                             new SqlParameter("@SCharge",Convert.ToDecimal(0)),
                             new SqlParameter("@TDiscount",TDiscount),  
                             new SqlParameter("@ArzooBaseFare",Convert.ToDecimal(0)),
                             new SqlParameter("@TPartnerCommission",Convert.ToDecimal(dsOriginDestinationOneWayDepartxml.Rows[0]["Commission"])),
                             new SqlParameter("@TCharge",Convert.ToDecimal(0)),
                             new SqlParameter("@TMarkup",Convert.ToDecimal(0)),
                             new SqlParameter("@TSdiscount",Convert.ToDecimal(0)),  
                             new SqlParameter("@phoneNumber",Convert.ToString(Session["RequiredMainMobile"])),
                             new SqlParameter("@email",Convert.ToString(Session["RequiredMainEmailid"])),
                             new SqlParameter("@Status","Pending"),
                              new SqlParameter("@JourneyType","Depart"),  
                             new SqlParameter("@phoneLocationType","FP"),
                             new SqlParameter("@phoneTechType","FP"),
                             new SqlParameter("@areaCityCode","FP"),
                             new SqlParameter("@countryCode","FP"),
                      };
                paramOriginDestinationOptionOneWay_Depart[0].Direction = ParameterDirection.Output;
                paramOriginDestinationOptionOneWay_Depart[1].Direction = ParameterDirection.Output;
                SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_OriginDestinationOption_ReturnData_Insert", paramOriginDestinationOptionOneWay_Depart);
                string ResultOriginDOneWayDepart_status = Convert.ToString(paramOriginDestinationOptionOneWay_Depart[0].Value);
                ViewState["OriginDestinationOptn_Id"] = Convert.ToInt32(paramOriginDestinationOptionOneWay_Depart[1].Value);
                if (ResultOriginDOneWayDepart_status == "1")
                {
                    if (Convert.ToString(Session["Trip"]) == "One")
                    {
                        InsertFlightSegmentOneway_Depart();
                    }
                    else if (Convert.ToString(Session["Trip"]) == "Round")
                    {
                        InsertOriginDestinationOption_Return();
                    }
                }
                else if (ResultOriginDOneWayDepart_status == "0")
                {
                   
                }
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertOriginDestinationOptionOneWay__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }
    }

    #endregion

    # region Insert procedure for OriginDestinationOption_Return Data

    public void InsertOriginDestinationOption_Return()
    {
       
        try
        {
            DataTable dsOriginDestination_Return = new DataTable();
            dsOriginDestination_Return = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Return"];
            decimal TDiscount = Convert.ToDecimal(0);
            AirEpointSupport ob = new AirEpointSupport();
            if (dsOriginDestination_Return.Rows.Count != 0)
            {
                SqlParameter[] paramOriginDestinationOption_Return = new SqlParameter[]
                    {                
                             new SqlParameter("@ResultOrginDStatusOutput",SqlDbType.Int,4),
                             new SqlParameter("@OriginDestinationOption_Id_Return_Output",SqlDbType.BigInt),
                             new SqlParameter("@Booking_St_Id",Convert.ToInt32(ViewState["Booking_St_Id"])),
                             new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                             new SqlParameter("@Origin", Convert.ToString(Session["DestinationTo"])),
                             new SqlParameter("@Destination",Convert.ToString(Session["DestinationFrom"])),
                             new SqlParameter("@DepartDate", Convert.ToDateTime(Session["ReturnDate"])),
                             new SqlParameter("@ReturnDate",Convert.ToDateTime(Session["ReturnDate"])),
                             new SqlParameter("@AdultPax",Convert.ToInt32(Session["Adults"])),
                             new SqlParameter("@ChildPax",Convert.ToInt32(Session["Children"])),
                             new SqlParameter("@InfantPax",Convert.ToInt32(Session["Infants"])),
                             new SqlParameter("@Preferredclass",Convert.ToString(Session["Class"])),
                             new SqlParameter("@Traveling_Mode",Convert.ToString(Session["Trip"])),
                             new SqlParameter("@PreferredAirline",Convert.ToString(dsOriginDestination_Return.Rows[0]["CarrierCode"])),
                             new SqlParameter("@ActualBaseFare",Convert.ToDecimal(dsOriginDestination_Return.Rows[0]["BasicAmount"])),
                             new SqlParameter("@Tax",Convert.ToDecimal(dsOriginDestination_Return.Rows[0]["GrossAmount"])-Convert.ToDecimal(dsOriginDestination_Return.Rows[0]["BasicAmount"])),
                             new SqlParameter("@STax",Convert.ToDecimal(0)),
                             new SqlParameter("@SCharge",Convert.ToDecimal(0)),
                             new SqlParameter("@TDiscount",TDiscount),  
                             new SqlParameter("@ArzooBaseFare",Convert.ToDecimal(0)),
                             new SqlParameter("@TPartnerCommission",Convert.ToDecimal(dsOriginDestination_Return.Rows[0]["Commission"])),
                             new SqlParameter("@TCharge",Convert.ToDecimal(0)),
                             new SqlParameter("@TMarkup",Convert.ToDecimal(0)),
                             new SqlParameter("@TSdiscount",Convert.ToDecimal(0)),  
                             new SqlParameter("@phoneNumber",Convert.ToString(Session["RequiredMainMobile"])),
                             new SqlParameter("@email",Convert.ToString(Session["RequiredMainEmailid"])),
                             new SqlParameter("@Status","Pending"),
                              new SqlParameter("@JourneyType","Return"), 
                             new SqlParameter("@phoneLocationType","FP"),
                             new SqlParameter("@phoneTechType","FP"),
                             new SqlParameter("@areaCityCode","FP"),
                             new SqlParameter("@countryCode","FP"),
                      };
                paramOriginDestinationOption_Return[0].Direction = ParameterDirection.Output;
                paramOriginDestinationOption_Return[1].Direction = ParameterDirection.Output;
                SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_OriginDestinationOption_ReturnData_Insert", paramOriginDestinationOption_Return);
                string ResultOriginDOneWayReturn_status = Convert.ToString(paramOriginDestinationOption_Return[0].Value);
                ViewState["OriginDestinationOptn_Id_Return"] = Convert.ToInt32(paramOriginDestinationOption_Return[1].Value);
                if (ResultOriginDOneWayReturn_status == "1")
                {
                    InsertFlightSegmentOneway_Depart();
                }
                else if (ResultOriginDOneWayReturn_status == "0")
                {
                   
                }
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertOriginDestinationOption_Return__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }
    }

    #endregion

    # region Insert procedure for FlightSegmentOneWay(Depart) Table

    public void InsertFlightSegmentOneway_Depart()
    {
        try
        {
            string ResultFlightSegmentOneWay_Depart_status = null;
            decimal Childfare, infantfare, TA_Child, TA_Infant, Com_Child, Com_Infant, Tax_Child, Tax_Infant;
            DataTable dsODxml_ForFlightSegment_OneWay_Depart = new DataTable();
            dsODxml_ForFlightSegment_OneWay_Depart = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Depart"];
            DataSet FareDetails = new DataSet();
            FareDetails = (DataSet)Session["Tax_Details"];
            if (dsODxml_ForFlightSegment_OneWay_Depart.Rows.Count != 0)
            {
                for (int i = 0; i < dsODxml_ForFlightSegment_OneWay_Depart.Rows.Count; i++)
                {
                    #region Get Childfare and InfantFare
                    if (Convert.ToInt32(Session["Children"]) > 0)
                    {
                        if (FareDetails.Tables["Child"].Rows[0]["TransactionAmount"].ToString() == "")
                            TA_Child = 0;
                        else TA_Child = Convert.ToDecimal(FareDetails.Tables["Child"].Rows[0]["TransactionAmount"]);
                        Com_Child = Convert.ToDecimal(FareDetails.Tables["Child"].Rows[0]["Commission"]);
                        Tax_Child = Convert.ToDecimal(FareDetails.Tables["Child"].Rows[0]["GrossAmount"]) - Convert.ToDecimal(FareDetails.Tables["Child"].Rows[0]["BasicAmt"]);
                        Childfare = Convert.ToDecimal(FareDetails.Tables["Child"].Rows[0]["GrossAmount"]) + Convert.ToDecimal(TA_Child) + Convert.ToDecimal(FareDetails.Tables["Child"].Rows[0]["ServiceAmount"]);
                    }
                    else
                    {
                        Childfare = 0;
                        TA_Child = 0;
                        Com_Child = 0;
                        Tax_Child = 0;
                    }

                    if (Convert.ToInt32(Session["Infants"]) > 0)
                    {
                        if (FareDetails.Tables["Infant"].Rows[0]["TransactionAmount"].ToString() == "")
                            TA_Infant = 0;
                        else TA_Infant = Convert.ToDecimal(FareDetails.Tables["Infant"].Rows[0]["TransactionAmount"]);
                        Com_Infant = Convert.ToDecimal(FareDetails.Tables["Infant"].Rows[0]["Commission"]);
                        infantfare = Convert.ToDecimal(FareDetails.Tables["Infant"].Rows[0]["GrossAmount"]) + Convert.ToDecimal(TA_Infant) + Convert.ToDecimal(FareDetails.Tables["Infant"].Rows[0]["ServiceAmount"]);
                        Tax_Infant = Convert.ToDecimal(FareDetails.Tables["Infant"].Rows[0]["GrossAmount"]) - Convert.ToDecimal(FareDetails.Tables["Infant"].Rows[0]["BasicAmt"]);
                    }
                    else
                    {
                        infantfare = 0;
                        TA_Infant = 0;
                        Com_Infant = 0;
                        Tax_Infant = 0;
                    }
                    #endregion
                    //-------Edit BY VK
                    string farebasiscode = Convert.ToString(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["FareBasis"]);
                    //------
                    SqlParameter[] paramForFlightSegment_OneWay_Depart = new SqlParameter[]
                    {   
                             new SqlParameter("@ResultFlightSegmentOneWay_Depart_Output",SqlDbType.Int,4),
                             new SqlParameter("@OriginDestinationOption_Id",Convert.ToInt32(ViewState["OriginDestinationOptn_Id"])),
                             new SqlParameter("@Booking_St_Id",Convert.ToInt32(ViewState["Booking_St_Id"])),
                             new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                             // ------------------------------------------DataSet(dsODxml_ForFlightSegment_OneWay_Depart) FlightSegment Table Parameter Start-------------------------------------------------------------------------------------- //
                             new SqlParameter("@AirEquipType", Convert.ToString(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["AirCraftType"])),
                             new SqlParameter("@DepartureAirportCode",Convert.ToString(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["Source"])),
                             new SqlParameter("@DepartureDateTime", dateConvert(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["DepartureDateTime"].ToString())),
                             new SqlParameter("@ArrivalAirportCode",Convert.ToString(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["Destination"])),
                             new SqlParameter("@ArrivalDateTime",dateConvert(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["ArrivalDateTime"].ToString())),
                             new SqlParameter("@FlightNumber",Convert.ToString(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["FlightNo"])),
                             new SqlParameter("@OperatingAirlineCode",Convert.ToString(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["CarrierCode"])),
                             new SqlParameter("@OperatingAirlineFlightNumber",Convert.ToString(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["FlightId"])),
                             new SqlParameter("@RPH","0"),
                             new SqlParameter("@StopQuantity",Convert.ToInt32(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["NumberofStops"])),
                             new SqlParameter("@airLineName",Convert.ToString(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["CarrierCode"])),
                             new SqlParameter("@airportTax",Convert.ToDecimal(Session["AirportTax"])),
                             new SqlParameter("@imageFileName",Convert.ToString(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["CarrierCode"])),
                             new SqlParameter("@Discount",Convert.ToDecimal(0)),
                             new SqlParameter("@MarketingAirlineCode","FP"),
                             new SqlParameter("@MealCode","FP"),
                             new SqlParameter("@SmokingAllowed","FP"),
                             new SqlParameter("@Ticket","FP"),
                             new SqlParameter("@serviceTax","FP"),
                             new SqlParameter("@serviceTaxFormula","FP"),
                             new SqlParameter("@viaFlight",""),
                             new SqlParameter("@BookingClassAvail","FP"),
                             new SqlParameter("@airportTaxChild",Convert.ToString(Tax_Child)),
                             new SqlParameter("@airportTaxInfant",Convert.ToString(Tax_Infant)),
                             new SqlParameter("@adultTaxBreakup",""),
                             new SqlParameter("@childTaxBreakup",""),
                             new SqlParameter("@infantTaxBreakup",""),
                             new SqlParameter("@octax",""),
                             new SqlParameter("@JourneyType","Depart"),
                             new SqlParameter("@Availability",""),
                             new SqlParameter("@ResBookDesigCode",""),
                             new SqlParameter("@adultFare",Convert.ToDecimal(Session["Adultfare"])),  
                             new SqlParameter("@Childfare",Convert.ToDecimal(Childfare)),
                             new SqlParameter("@infantfare",Convert.ToDecimal(infantfare)),                         
                             new SqlParameter("@bookingclass",Convert.ToString(dsODxml_ForFlightSegment_OneWay_Depart.Rows[i]["ClassCode"])),
                             new SqlParameter("@classType",Convert.ToString(Session["Class"])),                                                                        
                             new SqlParameter("@farebasiscode",Convert.ToString(farebasiscode)),
                             new SqlParameter("@Rules",""),
                             new SqlParameter("@adultArzooFare",Convert.ToDecimal(0)),
                             new SqlParameter("@childArzooFare",Convert.ToDecimal(0)),
                             new SqlParameter("@infantArzooFare",Convert.ToDecimal(0)),
                             new SqlParameter("@adultCommission",Convert.ToDecimal(FareDetails.Tables["Adult"].Rows[0]["Commission"])),  
                             new SqlParameter("@childCommission",Com_Child),
                             new SqlParameter("@commissionOnTCharge",Convert.ToDecimal(0)),
                      };
                    paramForFlightSegment_OneWay_Depart[0].Direction = ParameterDirection.Output;
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_FlightSegmentOneWayDepart_Insert", paramForFlightSegment_OneWay_Depart);
                    ResultFlightSegmentOneWay_Depart_status = Convert.ToString(paramForFlightSegment_OneWay_Depart[0].Value);
                }
                if (ResultFlightSegmentOneWay_Depart_status == "1")
                {
                    if (Convert.ToString(Session["Trip"]) == "One")
                    {
                        InsertPassenger();
                    }
                    else if (Convert.ToString(Session["Trip"]) == "Round")
                    {
                        InsertFlightSegment_Return();
                    }
                }
                else if (ResultFlightSegmentOneWay_Depart_status == "0")
                {
                    //  lblerrormsg.Text = "Flight Segment One Way Depart records not saved successfully";
                }
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertFlightSegmentOneway_Depart__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }

    }
    #endregion

    # region Insert procedure for FlightSegmentOneWay(Return) Data

    public void InsertFlightSegment_Return()
    {

        try
        {
            string ResultFlightSegment_Return_status = null;
            decimal Childfare, infantfare, TA_Child, TA_Infant, Com_Child, Com_Infant, Tax_Child, Tax_Infant;
            DataTable dsODxml_ForFlightSegment_Return = new DataTable();
            dsODxml_ForFlightSegment_Return = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Return"];
            DataSet FareDetails = new DataSet();
            FareDetails = (DataSet)Session["Tex_Details_Return"];
            if (dsODxml_ForFlightSegment_Return.Rows.Count != 0)
            {
                for (int i = 0; i < dsODxml_ForFlightSegment_Return.Rows.Count; i++)
                {
                    #region Get Childfare and InfantFare
                    if (Convert.ToInt32(Session["Children"]) > 0)
                    {
                        if (FareDetails.Tables["Child"].Rows[0]["TransactionAmount"].ToString() == "")
                            TA_Child = 0;
                        else TA_Child = Convert.ToDecimal(FareDetails.Tables["Child"].Rows[0]["TransactionAmount"]);
                        Com_Child = Convert.ToDecimal(FareDetails.Tables["Child"].Rows[0]["Commission"]);
                        Tax_Child = Convert.ToDecimal(FareDetails.Tables["Child"].Rows[0]["GrossAmount"]) - Convert.ToDecimal(FareDetails.Tables["Child"].Rows[0]["BasicAmt"]);
                        Childfare = Convert.ToDecimal(FareDetails.Tables["Child"].Rows[0]["GrossAmount"]) + Convert.ToDecimal(TA_Child) + Convert.ToDecimal(FareDetails.Tables["Child"].Rows[0]["ServiceAmount"]);
                    }
                    else
                    {
                        Childfare = 0;
                        TA_Child = 0;
                        Com_Child = 0;
                        Tax_Child = 0;
                    }

                    if (Convert.ToInt32(Session["Infants"]) > 0)
                    {
                        if (FareDetails.Tables["Infant"].Rows[0]["TransactionAmount"].ToString() == "")
                            TA_Infant = 0;
                        else TA_Infant = Convert.ToDecimal(FareDetails.Tables["Infant"].Rows[0]["TransactionAmount"]);
                        Com_Infant = Convert.ToDecimal(FareDetails.Tables["Infant"].Rows[0]["Commission"]);
                        infantfare = Convert.ToDecimal(FareDetails.Tables["Infant"].Rows[0]["GrossAmount"]) + Convert.ToDecimal(TA_Infant) + Convert.ToDecimal(FareDetails.Tables["Infant"].Rows[0]["ServiceAmount"]);
                        Tax_Infant = Convert.ToDecimal(FareDetails.Tables["Infant"].Rows[0]["GrossAmount"]) - Convert.ToDecimal(FareDetails.Tables["Infant"].Rows[0]["BasicAmt"]);
                    }
                    else
                    {
                        infantfare = 0;
                        TA_Infant = 0;
                        Com_Infant = 0;
                        Tax_Infant = 0;
                    }
                    #endregion

                    //---------edit vk
                    string farebasiscode = Convert.ToString(dsODxml_ForFlightSegment_Return.Rows[i]["FareBasis"]);

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

                    SqlParameter[] paramForFlightSegment_Return = new SqlParameter[]
                    {       
                           new SqlParameter("@ResultFlightSegmentReturn_Output",SqlDbType.Int,4),
                             new SqlParameter("@OriginDestinationOption_Id",Convert.ToInt32(ViewState["OriginDestinationOptn_Id_Return"])),
                             new SqlParameter("@Booking_St_Id",Convert.ToInt32(ViewState["Booking_St_Id"])),
                             new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                             // ------------------------------------------DataSet(dsODxml_ForFlightSegment_OneWay_Depart) FlightSegment Table Parameter Start-------------------------------------------------------------------------------------- //

                             new SqlParameter("@AirEquipType", Convert.ToString(dsODxml_ForFlightSegment_Return.Rows[i]["AirCraftType"])),
                             new SqlParameter("@DepartureAirportCode",Convert.ToString(dsODxml_ForFlightSegment_Return.Rows[i]["Source"])),
                             new SqlParameter("@DepartureDateTime", dateConvert(dsODxml_ForFlightSegment_Return.Rows[i]["DepartureDateTime"].ToString())),
                             new SqlParameter("@ArrivalAirportCode",Convert.ToString(dsODxml_ForFlightSegment_Return.Rows[i]["Destination"])),
                             new SqlParameter("@ArrivalDateTime",dateConvert(dsODxml_ForFlightSegment_Return.Rows[i]["ArrivalDateTime"].ToString())),
                             new SqlParameter("@FlightNumber",Convert.ToString(dsODxml_ForFlightSegment_Return.Rows[i]["FlightNo"])),
                             new SqlParameter("@OperatingAirlineCode",Convert.ToString(dsODxml_ForFlightSegment_Return.Rows[i]["CarrierCode"])),
                             new SqlParameter("@OperatingAirlineFlightNumber",Convert.ToString(dsODxml_ForFlightSegment_Return.Rows[i]["FlightId"])),
                             new SqlParameter("@RPH","0"),
                             new SqlParameter("@StopQuantity",Convert.ToInt32(dsODxml_ForFlightSegment_Return.Rows[i]["NumberofStops"])),
                             new SqlParameter("@airLineName",Convert.ToString(dsODxml_ForFlightSegment_Return.Rows[i]["CarrierCode"])),
                             new SqlParameter("@airportTax",Convert.ToDecimal(Session["AirportTax_Return"])),
                             new SqlParameter("@imageFileName",Convert.ToString(dsODxml_ForFlightSegment_Return.Rows[i]["CarrierCode"])),
                             new SqlParameter("@Discount",Convert.ToDecimal(0)),
                             new SqlParameter("@MarketingAirlineCode","FP"),
                             new SqlParameter("@MealCode","FP"),
                             new SqlParameter("@SmokingAllowed","FP"),
                             new SqlParameter("@Ticket","FP"),
                             new SqlParameter("@serviceTax","FP"),
                             new SqlParameter("@serviceTaxFormula","FP"),
                             new SqlParameter("@viaFlight",""),
                             new SqlParameter("@BookingClassAvail","FP"),
                             new SqlParameter("@airportTaxChild",Convert.ToString(Tax_Child)),
                             new SqlParameter("@airportTaxInfant",Convert.ToString(Tax_Infant)),
                             new SqlParameter("@adultTaxBreakup",""),
                             new SqlParameter("@childTaxBreakup",""),
                             new SqlParameter("@infantTaxBreakup",""),
                             new SqlParameter("@octax",""),
                             new SqlParameter("@JourneyType","Return"),
                             new SqlParameter("@Availability",""),
                             new SqlParameter("@ResBookDesigCode",""),
                             new SqlParameter("@adultFare",Convert.ToDecimal(Session["AdultfareReturn"])),  
                             new SqlParameter("@Childfare",Convert.ToDecimal(Childfare)),
                             new SqlParameter("@infantfare",Convert.ToDecimal(infantfare)),                         
                             new SqlParameter("@bookingclass",Convert.ToString(dsODxml_ForFlightSegment_Return.Rows[i]["ClassCode"])),
                             new SqlParameter("@classType",Convert.ToString(Session["Class"])),                                                                        
                             new SqlParameter("@farebasiscode",Convert.ToString(farebasiscode)),
                             new SqlParameter("@Rules",""),
                             new SqlParameter("@adultArzooFare",Convert.ToDecimal(0)),
                             new SqlParameter("@childArzooFare",Convert.ToDecimal(0)),
                             new SqlParameter("@infantArzooFare",Convert.ToDecimal(0)),
                             new SqlParameter("@adultCommission",Convert.ToDecimal(FareDetails.Tables["Adult"].Rows[0]["Commission"])),  
                             new SqlParameter("@childCommission",Com_Child),
                             new SqlParameter("@commissionOnTCharge",Convert.ToDecimal(0)),
                      };


                    paramForFlightSegment_Return[0].Direction = ParameterDirection.Output;
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_FlightSegmentReturn_Insert", paramForFlightSegment_Return);
                    ResultFlightSegment_Return_status = Convert.ToString(paramForFlightSegment_Return[0].Value);
                }
                if (ResultFlightSegment_Return_status == "1")
                {
                    InsertPassenger();
                }
                else if (ResultFlightSegment_Return_status == "0")
                {
                    //     lblerrormsg.Text = "Flight Segment Return records not saved successfully";
                }
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertFlightSegment_Return__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }
    }
    #endregion

    # region Insert procedure for Passenger Table
    public void InsertPassenger()
    {  
        try
        {
            SqlParameter[] paramPassenger = new SqlParameter[]
               {
                    new SqlParameter("@ResulPassengerOutput",SqlDbType.Int,4),
                    new SqlParameter("@Pss_ID_Output",SqlDbType.BigInt),
                    new SqlParameter("@OriginDestinationOption_Id",Convert.ToInt32(ViewState["OriginDestinationOptn_Id"])),
                    new SqlParameter("@Booking_St_Id",Convert.ToInt32(ViewState["Booking_St_Id"])),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                    new SqlParameter("@JourneyType","Depart"),
              };
            paramPassenger[0].Direction = ParameterDirection.Output;
            paramPassenger[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_Passenger_Insert", paramPassenger);
            string ResultPassengerStatus = Convert.ToString(paramPassenger[0].Value);
            ViewState["Pss_ID"] = Convert.ToInt32(paramPassenger[1].Value);
            string pss_id = Convert.ToString(ViewState["Pss_ID"]);
            Session["Pss_ID"] = Convert.ToUInt32(ViewState["Pss_ID"]);
            if (ResultPassengerStatus == "1")
            {
                if (Convert.ToString(Session["Trip"]) == "One")
                {
                    InsertAdultPassenger();
                }
                else if (Convert.ToString(Session["Trip"]) == "Round")
                {
                    InsertPassenger_ReturnFlight();
                }
            }
            else if (ResultPassengerStatus == "0")
            {
                //   lblerrormsg.Text = "Passenger Records not saved successfully";
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertPassenger__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }
    }

    #endregion

    # region Insert procedure for Passenger Table For Return flight
    public void InsertPassenger_ReturnFlight()
    {
        
        try
        {
            SqlParameter[] paramPassenger_Return = new SqlParameter[]
               {
                    new SqlParameter("@ResulPassengerOutput",SqlDbType.Int,4),
                    new SqlParameter("@Pss_ID_Output",SqlDbType.BigInt),
                    new SqlParameter("@OriginDestinationOption_Id",Convert.ToInt32(ViewState["OriginDestinationOptn_Id_Return"])),
                    new SqlParameter("@Booking_St_Id",Convert.ToInt32(ViewState["Booking_St_Id"])),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                    new SqlParameter("@JourneyType","Return"),
              };
            paramPassenger_Return[0].Direction = ParameterDirection.Output;
            paramPassenger_Return[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_Passenger_Insert", paramPassenger_Return);
            string ResultPassenger_Return_Status = Convert.ToString(paramPassenger_Return[0].Value);
            ViewState["Pss_ID_Return"] = Convert.ToInt32(paramPassenger_Return[1].Value);
            string pss_id_retrun = Convert.ToString(ViewState["Pss_ID_Return"]);
            Session["Pss_ID_Return"] = Convert.ToUInt32(ViewState["Pss_ID_Return"]);
            if (ResultPassenger_Return_Status == "1")
            {
                InsertAdultPassenger();
            }
            else if (ResultPassenger_Return_Status == "0")
            {
                //lblerrormsg.Text = "Passenger Return flight Records not saved successfully";
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertPassenger_ReturnFlight__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }
    }

    #endregion

    # region Insert procedure for Adult Passenger For Depart flight
    public void InsertAdultPassenger()
    {

        try
        {
            SqlDateTime AdultDOB;
            SqlDateTime AdultDOBnull;
            AdultDOBnull = SqlDateTime.Null;
            string tripdepartmodeStatus = null, tripreturnmodeStatus = null, ResultAdultStatus = null;
            string AdultsInformation = Convert.ToString(ViewState["AdultsInformation"]);
            DataSet dsAdultsInformation = new DataSet();
            dsAdultsInformation.ReadXml(new StringReader(AdultsInformation));
            if (dsAdultsInformation.Tables["CustomerInfo"].Rows.Count != 0)
            {
                for (int i = 0; i < dsAdultsInformation.Tables["CustomerInfo"].Rows.Count; i++)
                {
                    if (Convert.ToString(Session["Trip"]) == "One")
                    {
                        tripdepartmodeStatus = "Pending";
                        tripreturnmodeStatus = "Not Applicable";
                    }
                    else if (Convert.ToString(Session["Trip"]) == "Round")
                    {
                        tripdepartmodeStatus = "Pending";
                        tripreturnmodeStatus = "Pending";
                    }
                    if (i == 0)
                    { 
                        AdultDOB = AdultDOBnull;
                    }
                    else
                    {
                        AdultDOB = AdultDOBnull;
                    }
                    string pass = Convert.ToString(ViewState["Pss_ID"]);
                    SqlParameter[] paramAdult = new SqlParameter[]
               {       
                    new SqlParameter("@ResulAdultPassengerOutput",SqlDbType.Int,4),
                    new SqlParameter("@AdultPass_Id_Output",SqlDbType.BigInt),
                    new SqlParameter("@Pss_ID",Convert.ToInt32(ViewState["Pss_ID"])),
                    new SqlParameter("@Booking_St_Id",Convert.ToInt32(ViewState["Booking_St_Id"])),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                    new SqlParameter("@AdultTitle",Convert.ToString(dsAdultsInformation.Tables["CustomerInfo"].Rows[i]["nameReference"])),
                    new SqlParameter("@AdultFirstName",Convert.ToString(dsAdultsInformation.Tables["CustomerInfo"].Rows[i]["givenName"])),
                    new SqlParameter("@AdultLastName",Convert.ToString(dsAdultsInformation.Tables["CustomerInfo"].Rows[i]["surName"])),
                    new SqlParameter("@AdultDepartStatus",Convert.ToString(tripdepartmodeStatus)),
                    new SqlParameter("@AdultReturnStatus",Convert.ToString(tripreturnmodeStatus)),
                    new SqlParameter("@DOB",AdultDOB),
                    new SqlParameter("@JourneyType","Depart"),
              };
                    paramAdult[0].Direction = ParameterDirection.Output;
                    paramAdult[1].Direction = ParameterDirection.Output;
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_AdultPassenger_Insert", paramAdult);
                    ResultAdultStatus = Convert.ToString(paramAdult[0].Value);
                    ViewState["AdultPass_Id"] = Convert.ToString(paramAdult[1].Value);
                }

                if (ResultAdultStatus == "1")
                {
                    if (Convert.ToString(Session["Trip"]) == "One")
                    {
                        if (Convert.ToInt32(Session["Children"]) > 0)
                        {
                            InsertChildPassenger();
                        }
                        if (Convert.ToInt32(Session["Infants"]) > 0)
                        {
                            InsertInfantPassenger();
                        }

                    }

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

                }
                else if (ResultAdultStatus == "0")
                {
                    //     lblerrormsg.Text = "Adult Passenger Records not saved successfully";
                }
            }
        }
        catch (Exception ex)
        {

            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertAdultPassenger__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }

    }

    #endregion

    # region Insert procedure for Adult Passenger For Return flight
    public void InsertAdultPassenger_ReturnFlight()
    {
     
        try
        {
            SqlDateTime AdultDOB;
            SqlDateTime AdultDOBnull;
            AdultDOBnull = SqlDateTime.Null;
            string tripdepartmodeStatus = null, tripreturnmodeStatus = null, ResultAdultRetrunStatus = null;

            string AdultsInformation = Convert.ToString(ViewState["AdultsInformation"]);
            DataSet dsAdultsInformation_Return = new DataSet();
            dsAdultsInformation_Return.ReadXml(new StringReader(AdultsInformation));

            if (dsAdultsInformation_Return.Tables["CustomerInfo"].Rows.Count != 0)
            {
                for (int i = 0; i < dsAdultsInformation_Return.Tables["CustomerInfo"].Rows.Count; i++)
                {
                    if (Convert.ToString(Session["Trip"]) == "One")
                    {
                        tripdepartmodeStatus = "Pending";
                        tripreturnmodeStatus = "Not Applicable";
                    }
                    else if (Convert.ToString(Session["Trip"]) == "Round")
                    {
                        tripdepartmodeStatus = "Pending";
                        tripreturnmodeStatus = "Pending";
                    }                
                    AdultDOB = AdultDOBnull;
                    SqlParameter[] paramAdult_Return = new SqlParameter[]
               {
                           
                    new SqlParameter("@ResulAdultPassengerOutput",SqlDbType.Int,4),
                    new SqlParameter("@AdultPass_Id_Output",SqlDbType.BigInt),
                    new SqlParameter("@Pss_ID",Convert.ToInt32(ViewState["Pss_ID_Return"])),
                    new SqlParameter("@Booking_St_Id",Convert.ToInt32(ViewState["Booking_St_Id"])),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                    new SqlParameter("@AdultTitle",Convert.ToString(dsAdultsInformation_Return.Tables["CustomerInfo"].Rows[i]["nameReference"])),
                    new SqlParameter("@AdultFirstName",Convert.ToString(dsAdultsInformation_Return.Tables["CustomerInfo"].Rows[i]["givenName"])),
                    new SqlParameter("@AdultLastName",Convert.ToString(dsAdultsInformation_Return.Tables["CustomerInfo"].Rows[i]["surName"])),
                    new SqlParameter("@AdultDepartStatus",Convert.ToString(tripdepartmodeStatus)),
                    new SqlParameter("@AdultReturnStatus",Convert.ToString(tripreturnmodeStatus)),
                    new SqlParameter("@DOB",AdultDOB),
                     new SqlParameter("@JourneyType","Return"),
              };
                    paramAdult_Return[0].Direction = ParameterDirection.Output;
                    paramAdult_Return[1].Direction = ParameterDirection.Output;
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_AdultPassenger_Insert", paramAdult_Return);
                    ResultAdultRetrunStatus = Convert.ToString(paramAdult_Return[0].Value);
                    ViewState["AdultPass_Id_Return"] = Convert.ToString(paramAdult_Return[1].Value);

                }

                if (ResultAdultRetrunStatus == "1")
                {
                    if (Convert.ToInt32(Session["Children"]) > 0)
                    {

                        InsertChildPassenger();
                    }
                    if (Convert.ToInt32(Session["Infants"]) > 0)
                    {

                        InsertInfantPassenger();
                    }



                }
                else if (ResultAdultRetrunStatus == "0")
                {
                    //   lblerrormsg.Text = "Adult Passenger Return Flight Records not saved successfully";
                }
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertAdultPassenger_ReturnFlight__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }

    }

    #endregion

    # region Insert procedure for Child Passenger of Depart flight
    public void InsertChildPassenger()
    {
       
        try
        {
            string tripdepartmodeStatus = null, tripreturnmodeStatus = null, ResultChildStatus = null;

            string ChildrenInformation = Convert.ToString(ViewState["ChildrenInformation"]);
            DataSet dsChildrenInformation = new DataSet();
            dsChildrenInformation.ReadXml(new StringReader(ChildrenInformation));

            if (dsChildrenInformation.Tables["CustomerInfo"].Rows.Count != 0)
            {

                for (int i = 0; i < dsChildrenInformation.Tables["CustomerInfo"].Rows.Count; i++)
                {

                    if (Convert.ToString(Session["Trip"]) == "One")
                    {
                        tripdepartmodeStatus = "Pending";
                        tripreturnmodeStatus = "Not Applicable";
                    }
                    else if (Convert.ToString(Session["Trip"]) == "Round")
                    {

                        tripdepartmodeStatus = "Pending";
                        tripreturnmodeStatus = "Pending";
                    }


                    SqlParameter[] paramChild = new SqlParameter[]
               {
                           
                    new SqlParameter("@ResultChildPassengerOutput",SqlDbType.Int,4),
                    new SqlParameter("@ChildPass_Id_Output",SqlDbType.BigInt),
                    new SqlParameter("@Pss_ID",Convert.ToInt32(ViewState["Pss_ID"])),
                    new SqlParameter("@Booking_St_Id",Convert.ToInt32(ViewState["Booking_St_Id"])),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                    new SqlParameter("@ChildTitle",Convert.ToString(dsChildrenInformation.Tables["CustomerInfo"].Rows[i]["nameReference"])),
                    new SqlParameter("@ChildFirstName",Convert.ToString(dsChildrenInformation.Tables["CustomerInfo"].Rows[i]["givenName"])),
                    new SqlParameter("@ChildLastName",Convert.ToString(dsChildrenInformation.Tables["CustomerInfo"].Rows[i]["surName"])),
                    new SqlParameter("@DOB",Convert.ToDateTime(System.DateTime.Now.ToString())),
                    new SqlParameter("@Age",Convert.ToInt32(dsChildrenInformation.Tables["CustomerInfo"].Rows[i]["age"])),
                    new SqlParameter("@ChildDepartStatus",Convert.ToString(tripdepartmodeStatus)),
                    new SqlParameter("@ChildReturnStatus",Convert.ToString(tripreturnmodeStatus)),
                     new SqlParameter("@JourneyType","Depart"),
              };

                    paramChild[0].Direction = ParameterDirection.Output;
                    paramChild[1].Direction = ParameterDirection.Output;
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_ChildPassenger_Insert", paramChild);
                    ResultChildStatus = Convert.ToString(paramChild[0].Value);
                    ViewState["ChildPass_Id"] = Convert.ToString(paramChild[1].Value);

                }
                if (ResultChildStatus == "1")
                {

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


                }
                else if (ResultChildStatus == "0")
                {
                    //     lblerrormsg.Text = "Child Passenger Records not saved successfully";
                }

            }
        }
        catch (Exception ex)
        {

            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertChildPassenger__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }

    }



    #endregion

    # region Insert procedure for Child Passenger Return flight
    public void InsertChildPassenger_ReturnFlight()
    {
        
        try
        {
            string tripdepartmodeStatus = null, tripreturnmodeStatus = null, ResultChild_ReturnStatus = null;

            string ChildrenInformation = Convert.ToString(ViewState["ChildrenInformation"]);
            DataSet dsChildrenInformation_Return = new DataSet();
            dsChildrenInformation_Return.ReadXml(new StringReader(ChildrenInformation));

            if (dsChildrenInformation_Return.Tables["CustomerInfo"].Rows.Count != 0)
            {
                for (int i = 0; i < dsChildrenInformation_Return.Tables["CustomerInfo"].Rows.Count; i++)
                {
                    if (Convert.ToString(Session["Trip"]) == "One")
                    {
                        tripdepartmodeStatus = "Pending";
                        tripreturnmodeStatus = "Not Applicable";
                    }
                    else if (Convert.ToString(Session["Trip"]) == "Round")
                    {
                        tripdepartmodeStatus = "Pending";
                        tripreturnmodeStatus = "Pending";
                    }
                    SqlParameter[] paramChild = new SqlParameter[]
               {
                           
                    new SqlParameter("@ResultChildPassengerOutput",SqlDbType.Int,4),
                    new SqlParameter("@ChildPass_Id_Output",SqlDbType.BigInt),
                    new SqlParameter("@Pss_ID",Convert.ToInt32(ViewState["Pss_ID_Return"])),
                    new SqlParameter("@Booking_St_Id",Convert.ToInt32(ViewState["Booking_St_Id"])),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                    new SqlParameter("@ChildTitle",Convert.ToString(dsChildrenInformation_Return.Tables["CustomerInfo"].Rows[i]["nameReference"])),
                    new SqlParameter("@ChildFirstName",Convert.ToString(dsChildrenInformation_Return.Tables["CustomerInfo"].Rows[i]["givenName"])),
                    new SqlParameter("@ChildLastName",Convert.ToString(dsChildrenInformation_Return.Tables["CustomerInfo"].Rows[i]["surName"])),
                    new SqlParameter("@DOB",Convert.ToDateTime(System.DateTime.Now.ToString())),
                    new SqlParameter("@Age",Convert.ToInt32(dsChildrenInformation_Return.Tables["CustomerInfo"].Rows[i]["age"])),
                    new SqlParameter("@ChildDepartStatus",Convert.ToString(tripdepartmodeStatus)),
                    new SqlParameter("@ChildReturnStatus",Convert.ToString(tripreturnmodeStatus)),
                     new SqlParameter("@JourneyType","Return"),
              };

                    paramChild[0].Direction = ParameterDirection.Output;
                    paramChild[1].Direction = ParameterDirection.Output;
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_ChildPassenger_Insert", paramChild);
                    ResultChild_ReturnStatus = Convert.ToString(paramChild[0].Value);
                    ViewState["ChildPass_Id_Return"] = Convert.ToString(paramChild[1].Value);

                }
                if (ResultChild_ReturnStatus == "1")
                {
                }
                else if (ResultChild_ReturnStatus == "0")
                {
                    //   lblerrormsg.Text = "Child Passenger Return Flight Records not saved successfully";
                }

            }
        }
        catch (Exception ex)
        {

            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertChildPassenger_ReturnFlight__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }

    }



    #endregion

    # region Insert procedure for Infant Passenger Depart Flight
    public void InsertInfantPassenger()
    {

        try
        {
            string tripdepartmodeStatus = null, tripreturnmodeStatus = null, ResultInfantStatus = null;
            string InfantInformation = Convert.ToString(ViewState["InfantsInformation"]);
            DataSet dsInfantInformation = new DataSet();
            dsInfantInformation.ReadXml(new StringReader(InfantInformation));
            if (dsInfantInformation.Tables["CustomerInfo"].Rows.Count != 0)
            {
                for (int i = 0; i < dsInfantInformation.Tables["CustomerInfo"].Rows.Count; i++)
                {
                    if (Convert.ToString(Session["Trip"]) == "One")
                    {
                        tripdepartmodeStatus = "Pending";
                        tripreturnmodeStatus = "Not Applicable";
                    }
                    else if (Convert.ToString(Session["Trip"]) == "Round")
                    {
                        tripdepartmodeStatus = "Pending";
                        tripreturnmodeStatus = "Pending";
                    }
                    SqlParameter[] paramInfant = new SqlParameter[]
               {        
                    new SqlParameter("@ResultInfantPassengerOutput",SqlDbType.Int,4),
                    new SqlParameter("@InfantPass_id_Output",SqlDbType.BigInt),
                    new SqlParameter("@Pss_ID",Convert.ToInt32(ViewState["Pss_ID"])),
                    new SqlParameter("@Booking_St_Id",Convert.ToInt32(ViewState["Booking_St_Id"])),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                    new SqlParameter("@InfantTitle",Convert.ToString(dsInfantInformation.Tables["CustomerInfo"].Rows[i]["nameReference"])),
                    new SqlParameter("@InfantFirstName",Convert.ToString(dsInfantInformation.Tables["CustomerInfo"].Rows[i]["givenName"])),
                    new SqlParameter("@InfantLastName",Convert.ToString(dsInfantInformation.Tables["CustomerInfo"].Rows[i]["surName"])),
                    new SqlParameter("@DOB",Convert.ToDateTime(System.DateTime.Now.ToString())),
                    new SqlParameter("@Age",Convert.ToInt32(2)),
                    new SqlParameter("@InfantDepartStatus",Convert.ToString(tripdepartmodeStatus)),
                    new SqlParameter("@InfantReturnStatus",Convert.ToString(tripreturnmodeStatus)),
                    new SqlParameter("@JourneyType","Depart"),
              };
                    paramInfant[0].Direction = ParameterDirection.Output;
                    paramInfant[1].Direction = ParameterDirection.Output;
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_InfantPassenger_Insert", paramInfant);
                    ResultInfantStatus = Convert.ToString(paramInfant[0].Value);
                    ViewState["InfantPass_id"] = Convert.ToString(paramInfant[1].Value);
                }
                if (ResultInfantStatus == "1")
                {
                    if (Convert.ToString(Session["Trip"]) == "One")
                    {
                    }
                    else if (Convert.ToString(Session["Trip"]) == "Round")
                    {
                        InsertInfantPassenger_Return();
                    }

                }
                else if (ResultInfantStatus == "0")
                {
                    //  lblerrormsg.Text = "Infant Passenger Records not saved successfully";
                }
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertInfantPassenger__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;
        }

    }

    #endregion

    # region Insert procedure for Infant Passenger Return Flight
    public void InsertInfantPassenger_Return()
    {

        try
        {
            string tripdepartmodeStatus = null, tripreturnmodeStatus = null, ResultInfant_ReturnStatus = null;

            string InfantInformation = Convert.ToString(ViewState["InfantsInformation"]);
            DataSet dsInfantInformation_Return = new DataSet();
            dsInfantInformation_Return.ReadXml(new StringReader(InfantInformation));

            if (dsInfantInformation_Return.Tables["CustomerInfo"].Rows.Count != 0)
            {

                for (int i = 0; i < dsInfantInformation_Return.Tables["CustomerInfo"].Rows.Count; i++)
                {

                    if (Convert.ToString(Session["Trip"]) == "One")
                    {
                        tripdepartmodeStatus = "Pending";
                        tripreturnmodeStatus = "Not Applicable";
                    }
                    else if (Convert.ToString(Session["Trip"]) == "Round")
                    {
                        tripdepartmodeStatus = "Pending";
                        tripreturnmodeStatus = "Pending";
                    }


                    SqlParameter[] paramInfant_Return = new SqlParameter[]
               {
                           
                    new SqlParameter("@ResultInfantPassengerOutput",SqlDbType.Int,4),
                    new SqlParameter("@InfantPass_id_Output",SqlDbType.BigInt),
                    new SqlParameter("@Pss_ID",Convert.ToInt32(ViewState["Pss_ID_Return"])),
                    new SqlParameter("@Booking_St_Id",Convert.ToInt32(ViewState["Booking_St_Id"])),
                    new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                    new SqlParameter("@InfantTitle",Convert.ToString(dsInfantInformation_Return.Tables["CustomerInfo"].Rows[i]["nameReference"])),
                    new SqlParameter("@InfantFirstName",Convert.ToString(dsInfantInformation_Return.Tables["CustomerInfo"].Rows[i]["givenName"])),
                    new SqlParameter("@InfantLastName",Convert.ToString(dsInfantInformation_Return.Tables["CustomerInfo"].Rows[i]["surName"])),
                    new SqlParameter("@DOB",Convert.ToDateTime(System.DateTime.Now.ToString())),
                    new SqlParameter("@Age",Convert.ToInt32(2)),
                    new SqlParameter("@InfantDepartStatus",Convert.ToString(tripdepartmodeStatus)),
                    new SqlParameter("@InfantReturnStatus",Convert.ToString(tripreturnmodeStatus)),
                    new SqlParameter("@JourneyType","Return"),
              };

                    paramInfant_Return[0].Direction = ParameterDirection.Output;
                    paramInfant_Return[1].Direction = ParameterDirection.Output;
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_InfantPassenger_Insert", paramInfant_Return);
                    ResultInfant_ReturnStatus = Convert.ToString(paramInfant_Return[0].Value);
                    ViewState["InfantPass_id_Return"] = Convert.ToString(paramInfant_Return[1].Value);

                }
                if (ResultInfant_ReturnStatus == "1")
                {
                }
                else if (ResultInfant_ReturnStatus == "0")
                {
                    //   lblerrormsg.Text = "Infant Passenger Return Flight Records not saved successfully";
                }


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


    }

    #endregion

    # region Insert procedure for Booking_Can_Tran Information Table---Insert transaction_details - Only For Oneway

    public void InsertBooking_Cancellation_Info_Table()
    {
       
        try
        {

            DataTable dsODxml_For_Booking_Can_AgtTran_OneWay = new DataTable();
            dsODxml_For_Booking_Can_AgtTran_OneWay = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Depart"];

            decimal farewithoutdiscount = Convert.ToDecimal(Session["Dom_Ticket_Price"]);

            decimal TDiscount = Convert.ToDecimal(0);
            AirEpointSupport obj_temp = new AirEpointSupport();
            SqlParameter[] param_Transaction = new SqlParameter[] 
            {
                            new SqlParameter("@ResultBooking_Canltion_Output",SqlDbType.Int,4),
                            new SqlParameter("@User_ID",Convert.ToString(Session["agid"])),
                            new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                            new SqlParameter("@ServicePrefix ","DOMBOOKING"),
                            new SqlParameter("@TicketBooking_status","Pending"),
                            new SqlParameter("@IpAddress",sys_IP),
                            new SqlParameter("@Remark","Payment Request Domestic Air Booking"),                          
                            new SqlParameter("@PaymentMethod",""),                        
                            new SqlParameter("@Ticket_Price",Convert.ToDecimal(Session["Dom_Ticket_Price"])),
                             new SqlParameter("@PG_Charge",Convert.ToDecimal( 0)),
                             new SqlParameter("@Service_Tax",Convert.ToDecimal(0)),
                              new SqlParameter("@Other_Tax",Convert.ToDecimal(Session["Dom_CompanyComm"]) + Convert.ToDecimal(Session["Dom_AgentComm"])),
                               new SqlParameter("@PG_Requested_Amt ",Convert.ToDecimal( 0)),
                               new SqlParameter("@TotalPayble_Amt",Convert.ToDecimal(Session["Dom_Ticket_detect"]) ),
                               new SqlParameter("@Bank_name", ""),
                               new SqlParameter("@Wallet_Deduction_Amt",Convert.ToDecimal( 0)),
                               new SqlParameter("@Credit_Debit","Debit"),
                            new SqlParameter("@Booking_St_id", Convert.ToInt32(ViewState["Booking_St_Id"])),
                             new SqlParameter("@NoofPassanger", Convert.ToInt32(Session["Total_Passenger"])),                            
                            new SqlParameter("@ActualBaseFare",Convert.ToDecimal(Session["Basefare"])),
                            new SqlParameter("@AirPortTax",Convert.ToDecimal(Session["AirportTax"])),
                            new SqlParameter("@STax",Convert.ToDecimal(Session["ServiceTax"])),
                            new SqlParameter("@Scharge",Convert.ToDecimal(Session["TxnCharge"])),
                            new SqlParameter("@TDiscount",TDiscount),
                                new SqlParameter("@TMarkup",Convert.ToInt32(0)),
                            new SqlParameter("@TPartnerCommission",Convert.ToDecimal(0)),
                            new SqlParameter("@TSdiscount",Convert.ToDecimal(0)),
                                 new SqlParameter("@ocTax",Convert.ToDecimal(0)),
                                 new SqlParameter("@TCharge", Convert.ToInt32(0)),
                                 new SqlParameter("@Fare_With_out_Discount",farewithoutdiscount),
                             new SqlParameter("@TotalDiscount",Convert.ToDecimal( Session["BookingDiscount"])), 
                                  new SqlParameter("@AirLine_Markup",Convert.ToDecimal(0)), 
                            new SqlParameter("@AirLine_Markup_value",Convert.ToDecimal(0)),
                            new SqlParameter("@JournyType","OneWay"),
                            new SqlParameter("@FlightType  ","DOM"),
                            new SqlParameter("@Transaction_Status","Pending"),
            };
            param_Transaction[0].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_Insert_Transaction_Details", param_Transaction);
            param_Transaction[0].Value = "1";

            if (Convert.ToInt32(param_Transaction[0].Value) == 1)
            {
                
                    XmlONe();
               

            }
            else if (Convert.ToInt16(param_Transaction[0].Value) == 0)
            {
                //  lblerrormsg.Text = "Booking and Cancellation Information records not saved successfully";
            }


        }
        catch (Exception ex)
        {

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

        }

    }


    #endregion

    # region Insert procedure for Booking_Can_Tran Information Table---Insert  transaction_details
    public void InsertBooking_Cancellation_Info_Table_For_RoundTrip()
    {
        
        try
        {
          
            DataTable dsODxml_For_Booking_Can_AgtTran_OneWay = new DataTable();
            dsODxml_For_Booking_Can_AgtTran_OneWay = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Depart"];
            DataTable dsODxml_For_Booking_Can_AgtTran_return = new DataTable();
            dsODxml_For_Booking_Can_AgtTran_return = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Return"];
            decimal farewithoutdiscount = Convert.ToDecimal(Session["Dom_Ticket_Price"]);
            decimal TDiscount = Convert.ToDecimal(0);
            AirEpointSupport obj_temp = new AirEpointSupport();
            SqlParameter[] param_Transaction = new SqlParameter[] 
            {
                new SqlParameter("@ResultBooking_Canltion_Output",SqlDbType.Int,4),
                            new SqlParameter("@User_ID",Convert.ToString(Session["agid"])),
                            new SqlParameter("@partnerRefId",Convert.ToString(Session["partnerRefId"])),
                            new SqlParameter("@ServicePrefix ","DOMBOOKING"),
                            new SqlParameter("@TicketBooking_status","Pending"),
                            new SqlParameter("@IpAddress",sys_IP),
                            new SqlParameter("@Remark","Payment Request Domestic Air Booking"),                          
                            new SqlParameter("@PaymentMethod",""),                        
                            new SqlParameter("@Ticket_Price",Convert.ToDecimal(Session["Dom_Ticket_Price"])),
                             new SqlParameter("@PG_Charge",Convert.ToDecimal(0)),
                             new SqlParameter("@Service_Tax",Convert.ToDecimal(0)),
                              new SqlParameter("@Other_Tax",Convert.ToDecimal(Session["Dom_CompanyComm"]) + Convert.ToDecimal(Session["Dom_AgentComm"])),
                               new SqlParameter("@PG_Requested_Amt ",Convert.ToDecimal(0)),
                               new SqlParameter("@TotalPayble_Amt",Convert.ToDecimal(Session["Dom_Ticket_detect"]) ),
                               new SqlParameter("@Bank_name", ""),
                               new SqlParameter("@Wallet_Deduction_Amt",Convert.ToDecimal(0)),
                               new SqlParameter("@Credit_Debit","Debit"),
                            new SqlParameter("@Booking_St_id", Convert.ToInt32(ViewState["Booking_St_Id"])),
                             new SqlParameter("@NoofPassanger", Convert.ToInt32(Session["Total_Passenger"])),                            
                            new SqlParameter("@ActualBaseFare",Convert.ToDecimal(Session["TotalBasefare"])),
                            new SqlParameter("@AirPortTax",Convert.ToDecimal(Session["TotalAirportTax"])),
                            new SqlParameter("@STax",Convert.ToDecimal(Session["TotalServiceTax"])),
                            new SqlParameter("@Scharge",Convert.ToDecimal(Session["TotalTxnCharge"])),
                            new SqlParameter("@TDiscount",TDiscount),
                                new SqlParameter("@TMarkup",Convert.ToInt32(0)),
                            new SqlParameter("@TPartnerCommission",Convert.ToDecimal(0)),
                            new SqlParameter("@TSdiscount",Convert.ToDecimal(0)),
                                 new SqlParameter("@ocTax",Convert.ToDecimal(0)),
                                 new SqlParameter("@TCharge", Convert.ToInt32(0)),
                                 new SqlParameter("@Fare_With_out_Discount",farewithoutdiscount),
                             new SqlParameter("@TotalDiscount",Convert.ToDecimal(Session["TotalBookingDiscount"])), 
                                  new SqlParameter("@AirLine_Markup",Convert.ToDecimal(0)), 
                            new SqlParameter("@AirLine_Markup_value",Convert.ToDecimal(0)),
                            new SqlParameter("@JournyType","Round"),
                            new SqlParameter("@FlightType  ","DOM"),
                            new SqlParameter("@Transaction_Status","Pending"),
            };
            param_Transaction[0].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Air_Insert_Transaction_Details", param_Transaction);
            string ResultBooking_Canceltion_Info_Round_Status = Convert.ToString(param_Transaction[0].Value);
            if (ResultBooking_Canceltion_Info_Round_Status == "1")
            {
              
                    XmlONe();
              

            }
            else if (ResultBooking_Canceltion_Info_Round_Status == "0")
            {
                //   lblerrormsg.Text = "Booking and Cancellation Information of Round Trip records not saved successfully";
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport obj = new AirEpointSupport();
            obj.WriteToLog(ex.Message, "step4", "InsertBooking_Cancellation_Info_Table_For_RoundTrip__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
            flag++;

        }

    }

    #endregion

    public string EncodeStringToBase64(string toEncode)
    {

        byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
        string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
        return returnValue;
    }

    #endregion
    #region For Gentrate Xml One Ways
    public void XmlONe()
    {
        try
        {

            Session["PaymentStatus"] = "Y";
            Response.Redirect("ticket_booking.aspx", false);

        }

        catch (Exception ex)
        {

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

        }

    }
    #endregion

    public void Get_selected_Depart_flight_route_information_and_Generate_runtime_table()
    {
        try
        {
            #region Get selected Depart flight route information and Generate runtime table
            DataTable dsODxml_FlightSegment_OneWay_Depart = new DataTable();
            dsODxml_FlightSegment_OneWay_Depart = (DataTable)Session["BookinRequest_OriginDestinationOption_OneWay_Depart"];
            if (dsODxml_FlightSegment_OneWay_Depart.Rows.Count != 0)
            {
                string dynTable = "";
                Session["Stop_quantity"] = dsODxml_FlightSegment_OneWay_Depart.Rows.Count;

                dynTable = " <table cellpadding=\"0\"cellspacing=\"0\" border=\"0\" width=\"100%\" style=\"border-top: 1px solid #c3c3c3\">";
                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>";
                string duration;

                for (int tRows = 0; tRows < dsODxml_FlightSegment_OneWay_Depart.Rows.Count; tRows++)
                {

                    dynTable += "<tr valign=\"top\"> <td><img  src=\"" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["CarrierCode"]).ToString() + "\"</img></td>";
                    dynTable += " <td>" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["CarrierCode"]).ToString() + "<br />" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["CarrierCode"]) + "-" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["FlightNo"]) + "</td>   ";
                    dynTable += "<td>" + Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["DepartureDateTime"]).Substring(11, 5) + "," + (Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["DepartureDateTime"]).Substring(0, 10)) + "<br />" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["Source"]) + "(" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["Source"]) + ")<br />      </td>";
                    dynTable += "<td>" + Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["ArrivalDateTime"]).Substring(11, 5) + "," + (Convert.ToString(dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["ArrivalDateTime"]).Substring(0, 10)) + "<br />" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["Destination"]) + "(" + (dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["Destination"]) + ")<br />   </td>";
                    AirEpointSupport obj_airsupport = new AirEpointSupport();
                    duration = dsODxml_FlightSegment_OneWay_Depart.Rows[tRows]["Duration"].ToString();
                    dynTable += "<td> " + duration + "</td>";
                    dynTable += "<td>E</td>";
                    dynTable += "</tr>";
                }
                dynTable += "</table>";

                Session["dynTable"] = dynTable;

                Literal_FlightInformation.Text = dynTable;
            }
            #endregion
        }
        catch (Exception ex)
        {
            obj_AirEpointSupport = new AirEpointSupport();
            obj_AirEpointSupport.WriteToLog(ex.Message, "step1", "Get_selected_Depart_flight_route_information_and_Generate_runtime_table__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
        }
    }

//    private void Writemail()
//    {
       
//        try
//        {
//            string html;
//            html = @"<html xmlns='http://www.w3.org/1999/xhtml'>
//<head>
//    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />    
//    <link href='http://www.airepoint.com/css/css_5.css' rel='stylesheet' type='text/css' />
//    <style type='text/css'>
//        .txt11
//        {
//            font-family: 'Trebuchet MS';
//            font-size: 12px;
//            color: #000000;
//            text-decoration: none;
//        }";
//            html = html + @"@charset 'utf-8';
//.css_5 {
//	background-color: #0C6;
//}
//body {
//	margin-top: 0px;
//	margin-right: auto;
//	margin-bottom: 0px;
//	margin-left: auto;
//    font-family:'Trebuchet MS';
//    font-size:11px;
//}
//
//table{border-collapse:collapse}
//.col1,.col5,.col9{background:white}
//.col2,.col6,.col10{background:white}
//.col3,.col7{background:white}
//.col4,.col8{background:white}
//td,th{border:1px solid #000;padding:5px;font-family:'Trebuchet MS';}
//.txt1{
//	font-family:'Trebuchet MS';
//	font-size:12px;
//	color:#000000;
//	text-decoration:none;
//	text-align: justify;
//}
//.txt2{font-family:'Trebuchet MS'; font-size:12px; color:#000000; text-decoration:none; font-weight:bold}
//.txt3{font-family:'Trebuchet MS'; font-size:13px; color:#000000; text-decoration:none; font-weight:bold}
//.txt4{font-family'Trebuchet MS'; font-size:11px; color:#000000; text-decoration:none; }
//#air_logo_3 {
//	height: 117px;
//	width: 230px;
//	float: left;
//}
//#right_33 {
//	float: right;
//	height: 70px;
//	width: 210px;
//	padding-top: 30px;
//	padding-right: 0px;
//	padding-bottom: 0px;
//	padding-left: 0px;
//}
//
//    </style>
//<script type='text/javascript'>
//windows.print();
//</script>
//</head>
//<body>
//<div class='txt2'>Dear Partner,<br /><br />
//
//Your booking is being processed and a confirmed 'Electronic Air Ticket' will be generated within an hour. Please click on “Find Ticket Status” to get your ticket from your agent panel. Please carry a print out of the confirmed E-Ticket along with a valid photo ID Card to the airline check-in counter. 
//Following are the details of your booking.<br /></div><div style=' border:1px;'><strong>Transaction Id :</strong>" + Session["Transid"] + @"</div><br/>
//    <form id='form1' runat='server'>
//    <table width='900' border='0' align='center' cellpadding='0' cellspacing='0' runat='server' id='ticket'>
//       <tr><td colspan='2' valign='middle'>
//                            <span class='txt2' style='padding-right: 5px'>" + sourceoneway + @"
//                                -&gt;" + desoneway + @"</span>
//                        </td></tr> 
//        
//       
//        <tr>
//            <td colspan='2' align='center' valign='middle'>
//                <span class='txt3' style='padding-bottom: 10px'>Flight Details</span>
//            </td>
//        </tr>
//        <tr>
//            <td colspan='2' align='center' class='txt2'> " + Literal_FlightInformation.Text + @"
//            </td>
//        </tr>
//        <tr>
//            <td colspan='2' align='center' valign='middle' class='txt3'>
//                Passenger Details
//            </td>
//        </tr>
//        <tr>
//            <td colspan='2'>
//                <table width='900' border='0' cellpadding='0' cellspacing='0' class='txt2' 
//                    id='tblpassinfo'>
//                    <tr>
//                        <td align='center' valign='middle'>
//                            Sr. No.
//                        </td>
//                        <td align='center' valign='middle'>
//                            Passenger Name(s)
//                        </td>
//                        <td align='center' valign='middle'>
//                            Type
//                        </td>
//                        <td align='center' valign='middle'>
//                            Age
//                        </td>
//                        <td align='center' valign='middle'>
//                            E-ticket No.
//                        </td>
//                    </tr>";
//            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_get_pass_info_w@r10ck", new SqlParameter[] { new SqlParameter("@partnerrefid", Convert.ToString(Session["partnerRefId"])) });


//            for (int i = 1; i <= ds.Tables[0].Rows.Count; i++)
//            {

//                html += @"   <tr>
//                        <td align='center' valign='middle' class='txt2'>" + i.ToString() + @"
//                           
//                        </td>
//                        <td align='center' valign='middle' class='txt2'>" +
//                                    ds.Tables[0].Rows[i - 1]["Title"].ToString() + " " + ds.Tables[0].Rows[i - 1]["FirstName"].ToString() + " " + ds.Tables[0].Rows[i - 1]["LastName"].ToString() + @"
//                        </td>
//                        <td align='center' valign='middle' class='txt2'>" +
//                                   ds.Tables[0].Rows[i - 1]["type"].ToString() + @"
//                        </td>
//                        <td align='center' valign='middle' class='txt2'>";
//                if (ds.Tables[0].Rows[i - 1]["type"].ToString() == "ADULT")
//                {
//                    html += "--";
//                }
//                else
//                {
//                    html += ds.Tables[0].Rows[i - 1]["Age"].ToString();
//                }

//                html += @"
//                        </td>
//                        <td align='center' valign='middle'>-</td>
//                    </tr>";
//            }
//            html = html + @"</table>
//            </td>
//        </tr>
//
//    </table>
//    <br />
//    <br />
//   <div class='txt2'>Note: Airlines may change their prices any minute. This fare is not guaranteed until the Airline PNR is generated. Generation of a Transaction ID (TID) is the confirmation of booking request and payment received by us, and under no circumstances, is it equivalent to our final purchase price of respective Air ticket. 
//<br /><br />
//There might be situations, where the fare displayed may increase by the time purchase is made with the respective Airline. In this event, we will revert to you with the new fare or alternate options regarding your flight booking.
//<br /><br />
//Regards<br />
//Flight Booking Support
//</div>
//    </form>
//</body>
//</html>
//";

//            MailMessage mail = new MailMessage();
//            mail.To.Add(Convert.ToString(Session["email_id"]));
//            mail.To.Add("alok.s@commsoft.in");
//            mail.From = new MailAddress("noreply@eservices.net.in");
//            mail.IsBodyHtml = true;
//            if (Convert.ToString(Session["Trip"]) == "Round")
//            {
//                mail.Subject = "Your Flight Booking(Round) :" + sourceround + "-" + desround + "-" + Session["fagid"];
//                mail.Body = Writemailreturn();
//                var b = Attachment.CreateAttachmentFromString(Writemailreturn(), "Return Ticket.html");
//                mail.Attachments.Add(b);
//            }
//            else
//            {
//                mail.Subject = "Your Flight Booking :" + sourceoneway + "-" + desoneway + "-" + Session["fagid"];
//                mail.Body = html;
//                var a = Attachment.CreateAttachmentFromString(html, "Ticket.html");
//                mail.Attachments.Add(a);
//            }

//            SmtpClient SmtpMail = new SmtpClient();
//            {

//                SmtpMail.Host = "mail.eservices.net.in";
//                SmtpMail.Port = 25;
//                SmtpMail.EnableSsl = false;
//                SmtpMail.UseDefaultCredentials = true;
//                SmtpMail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
//                SmtpMail.Credentials = new System.Net.NetworkCredential("noreply@eservices.net.in", "admin@yahoo.123");
//                SmtpMail.Send(mail);
//            }
//        }

//        catch (Exception ex)
//        {
//            AirEpointSupport obj = new AirEpointSupport();
//            obj.WriteToLog(ex.Message, "TicketMail", "Write PDF__" + Convert.ToString(ViewState["partnerRefId"]));
//        }
//    }

//    private string Writemailreturn()
//    {
//        SqlHelper acs = new SqlHelper();
//        acs.Get_DB(Convert.ToString(Session["HURL"]));
//        try
//        {
//            string html;
//            html = @"<html xmlns='http://www.w3.org/1999/xhtml'>
//<head>
//    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />    
//    <link href='http://www.airepoint.com/css/css_5.css' rel='stylesheet' type='text/css' />
//    <style type='text/css'>
//        .txt11
//        {
//            font-family: 'Trebuchet MS';
//            font-size: 12px;
//            color: #000000;
//            text-decoration: none;
//        }";
//            html = html + @"@charset 'utf-8';
//.css_5 {
//	background-color: #0C6;
//}
//body {
//	margin-top: 0px;
//	margin-right: auto;
//	margin-bottom: 0px;
//	margin-left: auto;
//    font-family:'Trebuchet MS';
//    font-size:11px;
//}
//
//table{border-collapse:collapse}
//.col1,.col5,.col9{background:white}
//.col2,.col6,.col10{background:white}
//.col3,.col7{background:white}
//.col4,.col8{background:white}
//td,th{border:1px solid #000;padding:5px}
//.txt1{
//	font-family:'Trebuchet MS';
//	font-size:12px;
//	color:#000000;
//	text-decoration:none;
//	text-align: justify;
//}
//.txt2{font-family:'Trebuchet MS'; font-size:12px; color:#000000; text-decoration:none; font-weight:bold}
//.txt3{font-family:'Trebuchet MS'; font-size:14px; color:#000000; text-decoration:none; font-weight:bold}
//.txt4{font-family'Trebuchet MS'; font-size:11px; color:#000000; text-decoration:none; }
//#air_logo_3 {
//	height: 117px;
//	width: 230px;
//	float: left;
//}
//#right_33 {
//	float: right;
//	height: 70px;
//	width: 210px;
//	padding-top: 30px;
//	padding-right: 0px;
//	padding-bottom: 0px;
//	padding-left: 0px;
//}
//
//    </style>
//<script type='text/javascript'>
//windows.print();
//</script>
//</head>
//<body>
//<div class='txt2'>Dear Partner,<br /><br />
//
//Your booking is being processed and a confirmed 'Electronic Air Ticket' will be generated within an hour. Please click on “Find Ticket Status” to get your ticket from your agent panel. Please carry a print out of the confirmed E-Ticket along with a valid photo ID Card to the airline check-in counter. 
//Following are the details of your booking.<br /></div><div style=' border:1px;'><strong>Transaction Id :</strong>" + Session["Transid"] + @"</div><br/>
//    <form id='form1' runat='server'>
//    <table width='900' border='0' align='center' cellpadding='0' cellspacing='0' runat='server' id='ticket'>
//       <tr><td colspan='2' valign='middle'>
//                            <span class='txt2' style='padding-right: 5px'>" + sourceround + @"
//                                -&gt;" + desround + @"</span>
//                        </td></tr> 
//        
//       
//        <tr>
//            <td colspan='2' align='center' valign='middle'>
//                <span class='txt3' style='padding-bottom: 10px'>Flight Details</span>
//            </td>
//        </tr>
//        <tr>
//            <td colspan='2' align='center' class='txt2'> " + LiteralFlight_info_Return.Text + @"
//            </td>
//        </tr>
//        <tr>
//            <td colspan='2' align='center' valign='middle' class='txt3'>
//                Passenger Details
//            </td>
//        </tr>
//        <tr>
//            <td colspan='2'>
//                <table width='900' border='0' cellpadding='0' cellspacing='0' class='txt2' 
//                    id='tblpassinfo'>
//                    <tr>
//                        <td align='center' valign='middle' class='txt2'>
//                            Sr. No.
//                        </td>
//                        <td align='center' valign='middle' class='txt2'>
//                            Passenger Name(s)
//                        </td>
//                        <td align='center' valign='middle' class='txt2'>
//                            Type
//                        </td>
//                        <td align='center' valign='middle' class='txt2'>
//                            Age
//                        </td>
//                        <td align='center' valign='middle' class='txt2'>
//                            E-ticket No.
//                        </td>
//                    </tr>";
//            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_get_pass_info_w@r10ck", new SqlParameter[] { new SqlParameter("@partnerrefid", Convert.ToString(Session["partnerRefId"])) });


//            for (int i = 1; i <= ds.Tables[1].Rows.Count; i++)
//            {

//                html += @"   <tr>
//                        <td align='center' valign='middle' class='txt2'>" + i.ToString() + @"
//                           
//                        </td>
//                        <td align='center' valign='middle' class='txt2'>" +
//                                    ds.Tables[1].Rows[i - 1]["Title"].ToString() + " " + ds.Tables[1].Rows[i - 1]["FirstName"].ToString() + " " + ds.Tables[1].Rows[i - 1]["LastName"].ToString() + @"
//                        </td>
//                        <td align='center' valign='middle' class='txt2'>" +
//                                   ds.Tables[1].Rows[i - 1]["type"].ToString() + @"
//                        </td>
//                        <td align='center' valign='middle' class='txt2'>";
//                if (ds.Tables[1].Rows[i - 1]["type"].ToString() == "ADULT")
//                {
//                    html += "--";
//                }
//                else
//                {
//                    html += ds.Tables[1].Rows[i - 1]["Age"].ToString();
//                }

//                html += @"
//                        </td>
//                        <td align='center' valign='middle' class='txt2'>-</td>
//                    </tr>";
//            }
//            html = html + @"</table>
//            </td>
//        </tr>
//
//    </table>
//    <br />
//    <br />
//   <div class='txt2'>Note: Airlines may change their prices any minute. This fare is not guaranteed until the Airline PNR is generated. Generation of a Transaction ID (TID) is the confirmation of booking request and payment received by us, and under no circumstances, is it equivalent to our final purchase price of respective Air ticket. 
//<br /><br />
//There might be situations, where the fare displayed may increase by the time purchase is made with the respective Airline. In this event, we will revert to you with the new fare or alternate options regarding your flight booking.
//<br /><br />
//Regards<br />
//Flight Booking Support
//</div>
//    </form>
//</body>
//</html>
//";
//            return html;
//        }

//        catch (Exception ex)
//        {
//            return ex.ToString();
//        }
//    }


    public DateTime dateConvert(string req)
    {
        string[] d = req.Split(' ');
        string a = d[1];
        string[] b = d[0].Split('/');
        string strNewww = b[2] + "-" + b[1] + "-" + b[0] + " " + d[1];
        DateTime DepartureDateTime = Convert.ToDateTime(strNewww);
        return DepartureDateTime;
    }
}
