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.Collections.Generic;
using System.Xml;
using System.IO;


public partial class Domestic_RoundTripResult : System.Web.UI.Page
{
    public string DepartDate_range;

    DataSet ds = new DataSet();
    Hermes obj_Hermes;
    string Clientid, Clientpassword, Clienttype;
    string intClienttype, intClientid, intClientpassword, IntAvalability;
    string prfredairlines;
    int TotalPassenger = 0;
    static int radiobuttonindex;

    long minimumfare = 0;
    long maximumfare = 0;
    long minimumfare_return = 0;
    long maximumfare_return = 0;
    AirEpointSupport obj_AirEpointSupport;


    protected void Page_Load(object sender, EventArgs e)
    {
        obj_AirEpointSupport = new AirEpointSupport();
        try
        {


            if (!IsPostBack)
            {

                ds = obj_AirEpointSupport.GetAirPortDetails();
                AirPortList = ds.Tables[0];
                txt_departdate.Text = DateTime.Now.AddDays(0).ToString("dd-MMM-yyyy");
                txt_arrivaldate.Text = DateTime.Now.AddDays(1).ToString("dd-MMM-yyyy");
                HiddenField_Roundtrip.Value = "True";
                B2B objbeb = new B2B();
                decimal CompanyComm_Perc = objbeb.Domestic_GetCompanyCommission_Perc(Convert.ToString(Session["agid"]), Convert.ToString(Session["HURL"]));
                decimal AgentComm_Perc = objbeb.Domestic_GetAgentCommission_Perc(Convert.ToString(Session["agid"]), Convert.ToString(Session["HURL"]));
               // ViewState["AgentComm_Perc"] = "80";
               // ViewState["CompanyComm_Perc"] = "20";
                Fill_Initial();
                GetResults();
                if (Convert.ToString(ViewState["ErrorTag"]) != "")
                {

                    Session["Errortag"] = Convert.ToString(ViewState["ErrorTag"]);

                }
                else
                {




                    if (Session["myResult"] != null)
                    {



                        lbl_dayofweek.Text = Convert.ToDateTime(Convert.ToString(Session["DepartureDate"])).ToString("ddd");
                        lbl_day_Selectedflight.Text = Convert.ToDateTime(Convert.ToString(Session["DepartureDate"])).ToString("ddd");

                        lbl_day_Selectedflight_return.Text = Convert.ToDateTime(Convert.ToString(Session["ReturnDate"])).ToString("ddd");
                        lbl_date_Selectedflight_return.Text = Convert.ToDateTime(Convert.ToString(Session["ReturnDate"])).ToString("dd-MMM-yyyy");

                        lbl_date.Text = Convert.ToDateTime(Convert.ToString(Session["DepartureDate"])).ToString("dd-MMM-yyyy");
                        lbl_date_Selectedflight.Text = Convert.ToDateTime(Convert.ToString(Session["DepartureDate"])).ToString("dd-MMM-yyyy");
                        lbl_adults.Text = Convert.ToString(Session["Adults"]);
                        lbl_child.Text = Convert.ToString(Session["Children"]);
                        lbl_infant.Text = Convert.ToString(Session["Infants"]);
                        lbl_source.Text = Convert.ToString(Session["DestinationFrom"]);
                        lbl_destination.Text = Convert.ToString(Session["DestinationTo"]);
                        lbl_from.Text = Convert.ToString(Session["DestinationFromvalue"]);
                        lbl_to.Text = Convert.ToString(Session["DestinationToValue"]);
                        TotalPassenger = Convert.ToInt32(Session["Adults"]) + Convert.ToInt32(Session["Children"]) + Convert.ToInt32(Session["Infants"]);

                        Session["Total_Passenger"] = Convert.ToInt32(lbl_adults.Text) + Convert.ToInt32(lbl_child.Text) + Convert.ToInt32(lbl_infant.Text);

                        #region Retrun Trip data fill
                        lbl_source_round.Text = Convert.ToString(Session["DestinationFrom"]);
                        lbl_destination_round.Text = Convert.ToString(Session["DestinationTo"]);

                        #endregion


                    }


                    // GetData();
                    lbl_filter_maxprice.Text = maximumfare.ToString();
                    lbl_filter_minprice.Text = minimumfare.ToString();
                    lbl_filter_minprice_slider.Text = minimumfare.ToString();
                    lbl_filter_maxprice_slider.Text = maximumfare.ToString();
                    lbl_filter_maxprice_return.Text = maximumfare_return.ToString();
                    lbl_filter_minprice_return.Text = minimumfare_return.ToString();
                    lbl_filter_minprice_slider_return.Text = minimumfare_return.ToString();
                    lbl_filter_maxprice_slider_return.Text = maximumfare_return.ToString();
                    #region Fill modify search flight div according to previous session search



                    #endregion

                }

            }

            txt_departdate.Attributes.Add("readonly", "readonly");

            txt_arrivaldate.Attributes.Add("readonly", "readonly");
            #region Depart  Date Validation
            // Depart Date VALIDATION
            DateTime DepartMaxDate = new DateTime();
            DepartMaxDate = DateTime.Now.AddYears(10);

            DateTime DepartMinimumDate = new DateTime();
            DepartMinimumDate = DateTime.Now;


            string DepartMinYear = DepartMinimumDate.ToString("yyyy");
            string DepartMinMonth = DepartMinimumDate.ToString("MM");
            string DepartMinDay = DepartMinimumDate.ToString("dd");


            string DepartMaxYear = DepartMaxDate.ToString("yyyy");
            string DepartMaxMonth = DepartMaxDate.ToString("MM");
            string DepartMaxDay = DepartMaxDate.ToString("dd");
            DepartDate_range = "[[" + DepartMinYear + "," + DepartMinMonth + "," + DepartMinDay + "],[" + DepartMaxYear + "," + DepartMaxMonth + "," + DepartMaxDay + "]]";


            #endregion
        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "RoundTripResult", "Page_Load__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=timeout");
        }
    }


    protected void DataListOne_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

                Label lblFareDetails = (Label)e.Item.FindControl("lblFareDetails");
                Label LabelTotalFare = (Label)e.Item.FindControl("LabelTotalFare");
                Label LabelTotalFare1 = (Label)e.Item.FindControl("LabelTotalFare1");
                Label Labeldiscount = (Label)e.Item.FindControl("Labeldiscount");
                // Label LabelRule = (Label)e.Item.FindControl("LabelRule");
                Label LabelMisc = (Label)e.Item.FindControl("lbl_mics");
                Label lbl_netfare = (Label)e.Item.FindControl("lbl_netfare");
                Label lbl_agentearning = (Label)e.Item.FindControl("lbl_agentearning");

                Label label_ner_age_comm = (Label)e.Item.FindControl("label_ner_age_comm");


                Image imageAirLineUrl = new Image();
                imageAirLineUrl = (Image)e.Item.FindControl("ImageFlight");
                Label LabelAirllinename = (Label)e.Item.FindControl("LabelAirllinename");
                Label Labelairlinecode = (Label)e.Item.FindControl("LabelAirlinecode");
                string airlinecode = Labelairlinecode.Text;

                DataSet ds = obj_AirEpointSupport.GetAirImageDetails();
                var imageurl = from ImgurlDetail in ds.Tables["AirLineImageUrlDetail"].AsEnumerable()
                               where ImgurlDetail.Field<string>("AirlineCode") == Convert.ToString(airlinecode).Trim()
                               select new
                               {
                                   airlineimgeurl = ImgurlDetail["filename"].ToString(),
                                   airlinename = ImgurlDetail["AirlineName"].ToString()
                               };
                if (imageurl.Count() > 0)
                {
                    imageAirLineUrl.ImageUrl = "../AirLineImage/" + imageurl.AsEnumerable().ElementAt(0).airlineimgeurl;
                    LabelAirllinename.Text = imageurl.AsEnumerable().ElementAt(0).airlinename;
                }
                else
                {
                    imageAirLineUrl.ImageUrl = "../AirLineImage/blank.jpg";

                }


                HiddenField HiddenField_SelectedFlght_totalFare = (HiddenField)e.Item.FindControl("HiddenField_SelectedFlght_totalFare");


                decimal AgentComm_Perc = Convert.ToDecimal(ViewState["AgentComm_Perc"]);
                decimal CompanyComm_Perc = Convert.ToDecimal(ViewState["CompanyComm_Perc"]);



                decimal[] fares = DomesticPrice_Agent(Convert.ToDecimal((e.Item.DataItem as System.Data.DataRowView).Row["BasicAmount"]), Convert.ToDecimal((e.Item.DataItem as System.Data.DataRowView).Row["GrossAmount"]), Convert.ToDecimal(0), Convert.ToDecimal((e.Item.DataItem as System.Data.DataRowView).Row["Commission"]), Convert.ToDecimal(0));
                //decimal[] fares = ;
                decimal markup = Convert.ToDecimal(Session["agentMarkup"]);
                decimal all_markup = Convert.ToDecimal(Session["allMarkup"]);

                decimal ticketfare = fares[5] + markup + all_markup;
                decimal CompanyComm = Math.Round((fares[4] * CompanyComm_Perc) / 100);
                decimal AgentComm = Math.Round((fares[4] * AgentComm_Perc) / 100);

                lbl_netfare.Text = Math.Round((ticketfare - (AgentComm + markup)) * Convert.ToDecimal(Session["convertor"])).ToString();
                lbl_agentearning.Text = Math.Round((AgentComm + markup) * Convert.ToDecimal(Session["convertor"])).ToString();


                LabelTotalFare.Text = Math.Round((ticketfare) * Convert.ToDecimal(Session["convertor"])).ToString();
                label_ner_age_comm.Text = Math.Round((ticketfare) * Convert.ToDecimal(Session["convertor"])).ToString();
                LabelTotalFare1.Text = Math.Round((ticketfare) * Convert.ToDecimal(Session["convertor"])).ToString();
                LabelMisc.Text = Math.Round((markup+all_markup) * Convert.ToDecimal(Session["convertor"])).ToString();
                Labeldiscount.Text = Math.Round((fares[3]) * Convert.ToDecimal(Session["convertor"])).ToString();

                //string rule = "";
                // LabelRule.Text = rule;


                //  ((Label)(e.Item.FindControl("LabelFlght_Refund_noRefund"))).Text = "Refundable";




                int rownumber = e.Item.ItemIndex;
                Label LabelflghtSegmentsID = (Label)e.Item.FindControl("LabelflghtSegmentsID");
                if (rownumber > 0)
                {
                    string previousrowitem = (DataListOne.Items[e.Item.ItemIndex - 1].FindControl("LabelflghtSegmentsID") as Label).Text;


                    string currentrowitem = (e.Item.FindControl("LabelflghtSegmentsID") as Label).Text;

                    if (previousrowitem == currentrowitem)
                    {



                        RadioButton rbtndatalist = (RadioButton)e.Item.FindControl("RBtn");
                        rbtndatalist.Style.Add("display", "none");
                        TableRow trseperatorline = (TableRow)e.Item.FindControl("trseperatorline");
                        trseperatorline.Style.Add("display", "none");

                        ((Label)(e.Item.FindControl("LabelTotalFare"))).ForeColor = System.Drawing.Color.White;
                        ((Label)(e.Item.FindControl("lblFareDetails"))).ForeColor = System.Drawing.Color.White;
                        ((Label)(e.Item.FindControl("LabelTotalFare"))).Text = "";
                        ((Label)(e.Item.FindControl("lblFareDetails"))).Text = "";

                        ((Label)(e.Item.FindControl("lbl_Spacer"))).Visible = true;

                    }
                }






                ////Lavi
                long fareslider = Convert.ToInt64(LabelTotalFare.Text);

                if (e.Item.ItemIndex == 0)
                {
                    minimumfare = fareslider;
                    maximumfare = fareslider;
                }
                if (fareslider < minimumfare)
                {
                    minimumfare = fareslider;
                }
                if (fareslider > maximumfare)
                {
                    maximumfare = fareslider;
                }


            }
        }
        catch (Exception ex)
        {

        }
    }

    protected void DataListOne_ItemCommand(object source, DataListCommandEventArgs e)
    {

        try
        {
            if (e.CommandName == "Rule")
            {
                string output = (string)e.CommandArgument;
                // string[] a = output.Split(',');
                string Air_ID = Convert.ToString(((Label)DataListOne.Items[Convert.ToInt32(output)].FindControl("LabelAirlinecode")).Text);
                string Fly_ID = Convert.ToString(((Label)DataListOne.Items[Convert.ToInt32(output)].FindControl("Label1")).Text);
                string Cls_ID = Convert.ToString(((Label)DataListOne.Items[Convert.ToInt32(output)].FindControl("lblairlineclass")).Text);
                string requ = @"<FareRequest>
<UserTrackId>" + Convert.ToString(Session["UserT_ID"]) + @"</UserTrackId>
<AirlineId>" + Air_ID + @"</AirlineId >
<FlightId>" + Fly_ID + @"</FlightId>
<ClassCode>" + Cls_ID + @"</ClassCode>
</FareRequest>";
                Hermes heman = new Hermes();
                string ase = heman.Dom_Fare_Rule(requ);

                string rule = string.Empty;
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(ase);
                XmlNodeList xNodeList = doc.SelectNodes("FareResponse");
                foreach (XmlNode Node in xNodeList)
                {
                    XmlNodeList xNodeList1 = Node.ChildNodes;
                    foreach (XmlNode xnode in xNodeList1)
                    {

                        if (xnode.Name == "Status")
                        {
                            if (xnode.InnerText == "1")
                            {
                                rule = xnode.NextSibling.InnerText;
                            }
                            else
                            {
                                rule = "No Rule is Available.";
                            }
                        }
                    }
                }


                string response = rule.Replace(".", "<br><br>");
                litl_Rule.Text = rule;
                // using System.Web.UI.HtmlControls;

                ContentPlaceHolder myPlaceHolder = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
                HtmlControl myControl = (HtmlControl)myPlaceHolder.FindControl("contioner_pop");



                // HtmlGenericControl div = ((HtmlGenericControl)Page.FindControl("#ctl00_ContentPlaceHolder1_contioner_pop"));
                //  HtmlGenericControl div = new HtmlGenericControl("#ctl00_ContentPlaceHolder1_contioner_pop");
                myControl.Style.Add("display", "block");
                // Control test=Page.FindControl("#ctl00_ContentPlaceHolder1_contioner_pop");


            }
        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "RoundTripResult", "myrepeater_ItemCommand__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/IndexDom.aspx?s=exception");
        }
    }
    protected void RBtn_CheckedChanged(object sender, EventArgs e)
    {
        try
        {
            RadioButton RBtn = (RadioButton)sender;

            Session["RadioButtonSenderEvent"] = RBtn;
            ViewState["OneWayRouteSelect"] = "True";
        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "RoundTripResult", "RBtn_CheckedChanged__" + Convert.ToString(Session["partnerRefId"]));
            //Response.Redirect("../User/Index.aspx?s=exception");
        }
    }

    #region GET THE RESULT FROM AIR API
    private void GetResults()
    {

        try
        {
            Session.Remove("childnode");
            if (Convert.ToString(Session["Response"]) != "")
            {

                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(Session["myResult"].ToString());

                XmlNodeList xNodeList = xDoc.SelectNodes("AvailabilityResponse");
                foreach (XmlNode xNode in xNodeList)
                {
                    XmlNodeList innerNodeList = xNode.ChildNodes;
                    foreach (XmlNode xNodeInner in innerNodeList)
                    {
                        if (xNodeInner.Name == "AvailFlightDetails")
                        {
                            if (xNodeInner.NextSibling != null)
                            {


                                ViewState["TotalSearchResult"] = xNodeInner.InnerXml;
                                ds = new DataSet();
                                string st1 = "<root>" + xNodeInner.InnerXml + "</root>";
                                ds.ReadXml(new StringReader(st1));


                                DataTable flightSegment = ds.Tables["SegFlightDetails"];
                                Session["fs"] = flightSegment;
                                DataTable adult_price = (from abc in ds.Tables["Item"].AsEnumerable()
                                                         where abc.Field<string>("Pax") == "ADT"
                                                         select abc).CopyToDataTable();


                                //// For Adult only

                                DataTable newTable = new DataTable();
                                newTable.Columns.Add(new DataColumn("FlightId", typeof(string)));
                                newTable.Columns.Add(new DataColumn("CarrierCode", typeof(string)));
                                newTable.Columns.Add(new DataColumn("FlightNo", typeof(string)));
                                newTable.Columns.Add(new DataColumn("AirCraftType", typeof(string)));
                                newTable.Columns.Add(new DataColumn("Source", typeof(string)));
                                newTable.Columns.Add(new DataColumn("Destination", typeof(string)));
                                newTable.Columns.Add(new DataColumn("DepartureDateTime", typeof(string)));
                                newTable.Columns.Add(new DataColumn("ArrivalDateTime", typeof(string)));
                                newTable.Columns.Add(new DataColumn("Duration", typeof(string)));
                                newTable.Columns.Add(new DataColumn("NumberofStops", typeof(string)));
                                newTable.Columns.Add(new DataColumn("SegFlightDetails_Id", typeof(int)));
                                newTable.Columns.Add(new DataColumn("AvailFlightItem_Id", typeof(int)));
                                newTable.Columns.Add(new DataColumn("PaxFareDetails_Id", typeof(int)));
                                newTable.Columns.Add(new DataColumn("BasicAmount", typeof(double)));
                                newTable.Columns.Add(new DataColumn("GrossAmount", typeof(double)));
                                newTable.Columns.Add(new DataColumn("FareBasis", typeof(string)));
                                newTable.Columns.Add(new DataColumn("FuelSurcharge", typeof(double)));
                                newTable.Columns.Add(new DataColumn("Commission", typeof(double)));
                                newTable.Columns.Add(new DataColumn("Pax", typeof(string)));
                                newTable.Columns.Add(new DataColumn("ClassCode", typeof(string)));
                                DataRow Table_Row;
                                for (int i = 0; i < ds.Tables["SegFlightDetails"].Rows.Count; i++)
                                {
                                    var dttt = (from table2 in ds.Tables["PaxFareDetails"].AsEnumerable()
                                                where table2.Field<int>("SegFlightDetails_Id") == i
                                                select table2).Take(1).ToArray();
                                    ////  dttt[0].ItemArray[3].ToString();
                                    //DataTable adult_price = (from abc in ds.Tables["Item"].AsEnumerable()
                                    //                         where abc.Field<string>("Pax") == "ADT" && abc.Field<int>("PaxFareDetails_Id") == Convert.ToInt32(dttt[0].ItemArray[3])
                                    //                         select abc).CopyToDataTable();
                                    int j = Convert.ToInt32(dttt[0].ItemArray[3]);
                                    double GA = 0;
                                    double BA = 0;
                                    double FS = 0;
                                    double Com = 0;
                                    string Farebasis = string.Empty;
                                    if (adult_price.Rows[j]["GrossAmount"] == null || Convert.ToString(adult_price.Rows[j]["GrossAmount"]) == "" || Convert.ToString(adult_price.Rows[j]["GrossAmount"]) == "0")
                                    {
                                        for (int a = 1; a <= 3; a++)
                                        {
                                            if (Convert.ToString(adult_price.Rows[j + a]["GrossAmount"]) != "" && Convert.ToString(adult_price.Rows[j + a]["GrossAmount"]) != "0")
                                            {
                                                GA = Convert.ToDouble(adult_price.Rows[j + a]["GrossAmount"]);
                                                BA = Convert.ToDouble(adult_price.Rows[j + a]["BasicAmount"]);
                                                FS = Convert.ToDouble(adult_price.Rows[j + a]["FuelSurcharge"]);
                                                Com = Convert.ToDouble(adult_price.Rows[j + a]["Commission"]);
                                                Farebasis = Convert.ToString(adult_price.Rows[j + a]["FareBasis"]);
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        GA = Convert.ToDouble(adult_price.Rows[j]["GrossAmount"]);
                                        BA = Convert.ToDouble(adult_price.Rows[j]["BasicAmount"]);
                                        FS = Convert.ToDouble(adult_price.Rows[j]["FuelSurcharge"]);
                                        Com = Convert.ToDouble(adult_price.Rows[j]["Commission"]);
                                        Farebasis = Convert.ToString(adult_price.Rows[j]["FareBasis"]);
                                    }
                                    string noStop = string.Empty;
                                    if (ds.Tables["SegFlightDetails"].Rows[i]["NumberofStops"].ToString() == "")
                                    {
                                        noStop = "0";
                                    }
                                    else
                                    {
                                        noStop = ds.Tables["SegFlightDetails"].Rows[i]["NumberofStops"].ToString();
                                    }


                                    newTable.Rows.Add(ds.Tables["SegFlightDetails"].Rows[i]["FlightId"].ToString(), ds.Tables["SegFlightDetails"].Rows[i]["CarrierCode"],
                                        Convert.ToString(ds.Tables["SegFlightDetails"].Rows[i]["FlightNo"]), ds.Tables["SegFlightDetails"].Rows[i]["AirCraftType"],
                                        ds.Tables["SegFlightDetails"].Rows[i]["Source"], ds.Tables["SegFlightDetails"].Rows[i]["Destination"],
                                        ds.Tables["SegFlightDetails"].Rows[i]["DepartureDateTime"], ds.Tables["SegFlightDetails"].Rows[i]["ArrivalDateTime"],
                                        ds.Tables["SegFlightDetails"].Rows[i]["Duration"], noStop,
                                        ds.Tables["SegFlightDetails"].Rows[i]["SegFlightDetails_Id"], ds.Tables["SegFlightDetails"].Rows[i]["AvailFlightItem_Id"],
                                         dttt[0].ItemArray[3].ToString(), BA, GA, Farebasis, FS, Com, Convert.ToString(adult_price.Rows[0]["Pax"]), Convert.ToString(dttt[0].ItemArray[0]));
                                    //ds.Tables["PaxFareDetails"].Rows[i]["PaxFareDetails_Id"], BA, GA, Farebasis, FS, Com, Convert.ToString(adult_price.Rows[j]["Pax"]), Convert.ToString(ds.Tables["PaxFareDetails"].Rows[i]["ClassCode"]));


                                }
                                Session["newTable_Depart"] = newTable;

                                //  DataTable flightdetails = newTable;
                                DataRow row2 = null;
                                var AirLinesName1 = (from Airline in newTable.AsEnumerable()
                                                     select new { Aircode = Airline["CarrierCode"] }).Distinct();

                                DataTable dataTable2 = new DataTable();
                                // dataTable2 = (DataTable)Session["dataTable2"];
                                dataTable2.Columns.Add("AirlineCode", typeof(string));
                                dataTable2.Columns.Add("AirLineName", typeof(string));
                                foreach (var rowObj in AirLinesName1.ToList())
                                {
                                    DataSet ds2 = new DataSet();
                                    ds2 = obj_AirEpointSupport.GetAirLineDetails();
                                    var AirName = from Airline2 in ds2.Tables["AirLine"].AsEnumerable()
                                                  where Airline2.Field<string>("AirLineCode") == rowObj.Aircode.ToString()
                                                  select new
                                                  {
                                                      Airlinename = Airline2["AirLineName"]
                                                  };
                                    row2 = dataTable2.NewRow();
                                    string airlinenamefinal;
                                    if (AirName.AsEnumerable().Count() <= 0)
                                    {
                                        airlinenamefinal = "";
                                    }
                                    else airlinenamefinal = AirName.AsEnumerable().ElementAt(0).Airlinename.ToString();
                                    dataTable2.Rows.Add(rowObj.Aircode, airlinenamefinal);
                                }

                                CheckBoxList_Airlines.DataSource = dataTable2;
                                CheckBoxList_Airlines.DataValueField = "AirLineCode";
                                CheckBoxList_Airlines.DataTextField = "AirLineName";
                                CheckBoxList_Airlines.DataBind();

                                foreach (ListItem item in CheckBoxList_Airlines.Items)
                                {
                                    item.Selected = true;
                                    int thisIndex = CheckBoxList_Airlines.Items.IndexOf(item);
                                    if (thisIndex == -1)
                                    {
                                        item.Attributes.Add("Style", "Display:none;");
                                    }
                                    item.Attributes.Add("onClick", "hideRows('" + item.Value + "',this);");

                                }

                                DataTable new_depart_sort = (from new_sort in newTable.AsEnumerable()
                                                             orderby new_sort["GrossAmount"] ascending
                                                             select new_sort).CopyToDataTable();
                                DataListOne.DataSource = new_depart_sort;
                                DataListOne.DataBind();





                            }
                            else
                            {


                                ViewState["TotalSearchResult"] = xNodeInner.InnerXml;
                                ds = new DataSet();
                                string st1 = "<root>" + xNodeInner.InnerXml + "</root>";
                                ds.ReadXml(new StringReader(st1));


                                DataTable flightSegment = ds.Tables["SegFlightDetails"];
                                Session["fs"] = flightSegment;
                                DataTable adult_price = (from abc in ds.Tables["Item"].AsEnumerable()
                                                         where abc.Field<string>("Pax") == "ADT"
                                                         select abc).CopyToDataTable();


                                //// For Adult only

                                DataTable newTable = new DataTable();
                                newTable.Columns.Add(new DataColumn("FlightId", typeof(string)));
                                newTable.Columns.Add(new DataColumn("CarrierCode", typeof(string)));
                                newTable.Columns.Add(new DataColumn("FlightNo", typeof(string)));
                                newTable.Columns.Add(new DataColumn("AirCraftType", typeof(string)));
                                newTable.Columns.Add(new DataColumn("Source", typeof(string)));
                                newTable.Columns.Add(new DataColumn("Destination", typeof(string)));
                                newTable.Columns.Add(new DataColumn("DepartureDateTime", typeof(string)));
                                newTable.Columns.Add(new DataColumn("ArrivalDateTime", typeof(string)));
                                newTable.Columns.Add(new DataColumn("Duration", typeof(string)));
                                newTable.Columns.Add(new DataColumn("NumberofStops", typeof(string)));
                                newTable.Columns.Add(new DataColumn("SegFlightDetails_Id", typeof(int)));
                                newTable.Columns.Add(new DataColumn("AvailFlightItem_Id", typeof(int)));
                                newTable.Columns.Add(new DataColumn("PaxFareDetails_Id", typeof(int)));
                                newTable.Columns.Add(new DataColumn("BasicAmount", typeof(double)));
                                newTable.Columns.Add(new DataColumn("GrossAmount", typeof(double)));
                                newTable.Columns.Add(new DataColumn("FareBasis", typeof(string)));
                                newTable.Columns.Add(new DataColumn("FuelSurcharge", typeof(double)));
                                newTable.Columns.Add(new DataColumn("Commission", typeof(double)));
                                newTable.Columns.Add(new DataColumn("Pax", typeof(string)));
                                newTable.Columns.Add(new DataColumn("ClassCode", typeof(string)));
                                DataRow Table_Row;
                                for (int i = 0; i < ds.Tables["SegFlightDetails"].Rows.Count; i++)
                                {
                                    var dttt = (from table2 in ds.Tables["PaxFareDetails"].AsEnumerable()
                                                where table2.Field<int>("SegFlightDetails_Id") == i
                                                select table2).Take(1).ToArray();
                                    ////  dttt[0].ItemArray[3].ToString();
                                    //DataTable adult_price = (from abc in ds.Tables["Item"].AsEnumerable()
                                    //                         where abc.Field<string>("Pax") == "ADT" && abc.Field<int>("PaxFareDetails_Id") == Convert.ToInt32(dttt[0].ItemArray[3])
                                    //                         select abc).CopyToDataTable();
                                    int j = Convert.ToInt32(dttt[0].ItemArray[3]);
                                    double GA = 0;
                                    double BA = 0;
                                    double FS = 0;
                                    double Com = 0;
                                    string Farebasis = string.Empty;
                                    if (adult_price.Rows[j]["GrossAmount"] == null || Convert.ToString(adult_price.Rows[j]["GrossAmount"]) == "" || Convert.ToString(adult_price.Rows[j]["GrossAmount"]) == "0")
                                    {
                                        for (int a = 1; a <= 3; a++)
                                        {
                                            if (Convert.ToString(adult_price.Rows[j + a]["GrossAmount"]) != "" && Convert.ToString(adult_price.Rows[j + a]["GrossAmount"]) != "0")
                                            {
                                                GA = Convert.ToDouble(adult_price.Rows[j + a]["GrossAmount"]);
                                                BA = Convert.ToDouble(adult_price.Rows[j + a]["BasicAmount"]);
                                                FS = Convert.ToDouble(adult_price.Rows[j + a]["FuelSurcharge"]);
                                                Com = Convert.ToDouble(adult_price.Rows[j + a]["Commission"]);
                                                Farebasis = Convert.ToString(adult_price.Rows[j + a]["FareBasis"]);
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        GA = Convert.ToDouble(adult_price.Rows[j]["GrossAmount"]);
                                        BA = Convert.ToDouble(adult_price.Rows[j]["BasicAmount"]);
                                        FS = Convert.ToDouble(adult_price.Rows[j]["FuelSurcharge"]);
                                        Com = Convert.ToDouble(adult_price.Rows[j]["Commission"]);
                                        Farebasis = Convert.ToString(adult_price.Rows[j]["FareBasis"]);
                                    }
                                    string noStop = string.Empty;
                                    if (ds.Tables["SegFlightDetails"].Rows[i]["NumberofStops"].ToString() == "")
                                    {
                                        noStop = "0";
                                    }
                                    else
                                    {
                                        noStop = ds.Tables["SegFlightDetails"].Rows[i]["NumberofStops"].ToString();
                                    }


                                    newTable.Rows.Add(ds.Tables["SegFlightDetails"].Rows[i]["FlightId"].ToString(), ds.Tables["SegFlightDetails"].Rows[i]["CarrierCode"],
                                        Convert.ToString(ds.Tables["SegFlightDetails"].Rows[i]["FlightNo"]), ds.Tables["SegFlightDetails"].Rows[i]["AirCraftType"],
                                        ds.Tables["SegFlightDetails"].Rows[i]["Source"], ds.Tables["SegFlightDetails"].Rows[i]["Destination"],
                                        ds.Tables["SegFlightDetails"].Rows[i]["DepartureDateTime"], ds.Tables["SegFlightDetails"].Rows[i]["ArrivalDateTime"],
                                        ds.Tables["SegFlightDetails"].Rows[i]["Duration"], noStop,
                                        ds.Tables["SegFlightDetails"].Rows[i]["SegFlightDetails_Id"], ds.Tables["SegFlightDetails"].Rows[i]["AvailFlightItem_Id"],
                                         dttt[0].ItemArray[3].ToString(), BA, GA, Farebasis, FS, Com, Convert.ToString(adult_price.Rows[0]["Pax"]), Convert.ToString(dttt[0].ItemArray[0]));
                                    //ds.Tables["PaxFareDetails"].Rows[i]["PaxFareDetails_Id"], BA, GA, Farebasis, FS, Com, Convert.ToString(adult_price.Rows[j]["Pax"]), Convert.ToString(ds.Tables["PaxFareDetails"].Rows[i]["ClassCode"]));





                                }
                                Session["newTable_Return"] = newTable;

                                DataRow row2 = null;
                                var AirLinesName1 = (from Airline in newTable.AsEnumerable()
                                                     select new { Aircode = Airline["CarrierCode"] }).Distinct();

                                DataTable dataTable2 = new DataTable();
                                // dataTable2 = (DataTable)Session["dataTable2"];
                                dataTable2.Columns.Add("AirlineCode", typeof(string));
                                dataTable2.Columns.Add("AirLineName", typeof(string));
                                foreach (var rowObj in AirLinesName1.ToList())
                                {
                                    DataSet ds2 = new DataSet();
                                    ds2 = obj_AirEpointSupport.GetAirLineDetails();
                                    var AirName = from Airline2 in ds2.Tables["AirLine"].AsEnumerable()
                                                  where Airline2.Field<string>("AirLineCode") == rowObj.Aircode.ToString()
                                                  select new
                                                  {
                                                      Airlinename = Airline2["AirLineName"]
                                                  };
                                    row2 = dataTable2.NewRow();
                                    string airlinenamefinal;
                                    if (AirName.AsEnumerable().Count() <= 0)
                                    {
                                        airlinenamefinal = "";
                                    }
                                    else airlinenamefinal = AirName.AsEnumerable().ElementAt(0).Airlinename.ToString();
                                    dataTable2.Rows.Add(rowObj.Aircode, airlinenamefinal);
                                }

                                CheckBoxList_Airlines_return.DataSource = dataTable2;
                                CheckBoxList_Airlines_return.DataValueField = "AirLineCode";
                                CheckBoxList_Airlines_return.DataTextField = "AirLineName";
                                CheckBoxList_Airlines_return.DataBind();

                                foreach (ListItem item in CheckBoxList_Airlines_return.Items)
                                {
                                    item.Selected = true;
                                    int thisIndex = CheckBoxList_Airlines_return.Items.IndexOf(item);
                                    if (thisIndex == -1)
                                    {
                                        item.Attributes.Add("Style", "Display:none;");
                                    }
                                    item.Attributes.Add("onClick", "hideRows('" + item.Value + "',this);");

                                }

                                DataTable new_return_sort = (from new_sort in newTable.AsEnumerable()
                                                             orderby new_sort["GrossAmount"] ascending
                                                             select new_sort).CopyToDataTable();

                                DataListRound.DataSource = new_return_sort;
                                DataListRound.DataBind();
                            }

                        }
                    }
                }
            }
        }

        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "OneWayResult", "GetData__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=timeout");
        }


    }
    #endregion
    protected void DataListRound_ItemDataBound(object sender, DataListItemEventArgs e)
    {


        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                lbl_cur.Text = Session["Currency"].ToString();
                Label lblFareDetails = (Label)e.Item.FindControl("lblFareDetails");
                Label LabelTotalFare = (Label)e.Item.FindControl("LabelTotalFare");
                Label LabelTotalFare1 = (Label)e.Item.FindControl("LabelTotalFare1");
                Label Labeldiscount = (Label)e.Item.FindControl("Labeldiscount");
                // Label LabelRule = (Label)e.Item.FindControl("LabelRule");
                Label LabelMics = (Label)e.Item.FindControl("lbl_mics_return");
                Label lbl_netfare = (Label)e.Item.FindControl("lbl_netfare");
                Label lbl_agentearning = (Label)e.Item.FindControl("lbl_agentearning");
                Label LabelAgentCommission = (Label)e.Item.FindControl("LabelAgentCommission");
                Label LabelCompanyCommission = (Label)e.Item.FindControl("LabelCompanyCommission");
                Label label_ner_age_comm = (Label)e.Item.FindControl("label_ner_age_comm");

                Label LabelArzooNetFare = (Label)e.Item.FindControl("LabelArzooNetFare");
                Image imageAirLineUrl = new Image();
                imageAirLineUrl = (Image)e.Item.FindControl("ImageFlight");
                Label LabelAirllinename = (Label)e.Item.FindControl("LabelAirllinename");
                Label Labelairlinecode = (Label)e.Item.FindControl("LabelAirlinecode");
                string airlinecode = Labelairlinecode.Text;

                DataSet ds = obj_AirEpointSupport.GetAirImageDetails();
                var imageurl = from ImgurlDetail in ds.Tables["AirLineImageUrlDetail"].AsEnumerable()
                               where ImgurlDetail.Field<string>("AirlineCode") == Convert.ToString(airlinecode).Trim()
                               select new
                               {
                                   airlineimgeurl = ImgurlDetail["filename"].ToString(),
                                   airlinename = ImgurlDetail["AirlineName"].ToString()
                               };
                if (imageurl.Count() > 0)
                {
                    imageAirLineUrl.ImageUrl = "../AirLineImage/" + imageurl.AsEnumerable().ElementAt(0).airlineimgeurl;
                    LabelAirllinename.Text = imageurl.AsEnumerable().ElementAt(0).airlinename;
                }
                else
                {
                    imageAirLineUrl.ImageUrl = "../AirLineImage/blank.jpg";

                }
                decimal AgentComm_Perc = Convert.ToDecimal(ViewState["AgentComm_Perc"]);
                decimal CompanyComm_Perc = Convert.ToDecimal(ViewState["CompanyComm_Perc"]);

                decimal[] fares = DomesticPrice_Agent(Convert.ToDecimal((e.Item.DataItem as System.Data.DataRowView).Row["BasicAmount"]), Convert.ToDecimal((e.Item.DataItem as System.Data.DataRowView).Row["GrossAmount"]), Convert.ToDecimal(0), Convert.ToDecimal((e.Item.DataItem as System.Data.DataRowView).Row["Commission"]), Convert.ToDecimal(0));
                decimal mark_up = Convert.ToDecimal(Session["agentMarkup"]);
                decimal all_markup = Convert.ToDecimal(Session["allMarkup"]);
                decimal ticketfare = fares[5] + mark_up + all_markup;
                decimal CompanyComm = Math.Round((fares[4] * CompanyComm_Perc) / 100);
                decimal AgentComm = Math.Round((fares[4] * AgentComm_Perc) / 100);

                lbl_netfare.Text = Math.Round((ticketfare - (AgentComm + mark_up)) * Convert.ToDecimal(Session["convertor"])).ToString();
                lbl_agentearning.Text = Math.Round((AgentComm + mark_up) * Convert.ToDecimal(Session["convertor"])).ToString();

                LabelTotalFare.Text = Math.Round((ticketfare) * Convert.ToDecimal(Session["convertor"])).ToString();
                LabelTotalFare1.Text = Math.Round((ticketfare) * Convert.ToDecimal(Session["convertor"])).ToString();
                label_ner_age_comm.Text = Math.Round((ticketfare) * Convert.ToDecimal(Session["convertor"])).ToString();
                LabelMics.Text = Math.Round((mark_up+all_markup) * Convert.ToDecimal(Session["convertor"])).ToString();
                Labeldiscount.Text = Math.Round((fares[3]) * Convert.ToDecimal(Session["convertor"])).ToString();


                //  string rule = "";
                //LabelRule.Text = rule;


                //((Label)(e.Item.FindControl("LabelFlght_Refund_noRefund"))).Text = "Refundable";



                int rownumber = e.Item.ItemIndex;
                Label LabelflghtSegmentsID = (Label)e.Item.FindControl("LabelflghtSegmentsID");
                if (rownumber > 0)
                {
                    string previousrowitem = (DataListRound.Items[e.Item.ItemIndex - 1].FindControl("LabelflghtSegmentsID") as Label).Text;


                    string currentrowitem = (e.Item.FindControl("LabelflghtSegmentsID") as Label).Text;

                    if (previousrowitem == currentrowitem)
                    {
                        RadioButton rbtndatalist = (RadioButton)e.Item.FindControl("RBtnRound");
                        rbtndatalist.Style.Add("display", "none");
                        TableRow trseperatorline = (TableRow)e.Item.FindControl("trseperatorline");
                        trseperatorline.Style.Add("display", "none");
                        ((Label)(e.Item.FindControl("LabelTotalFare"))).ForeColor = System.Drawing.Color.White;
                        ((Label)(e.Item.FindControl("lblFareDetails"))).ForeColor = System.Drawing.Color.White;
                        ((Label)(e.Item.FindControl("LabelTotalFare"))).Text = "";
                        ((Label)(e.Item.FindControl("lblFareDetails"))).Text = "";
                        ((Label)(e.Item.FindControl("lbl_Spacer"))).Visible = true;
                    }
                }
                ////Lavi
                long fareslider_return = Convert.ToInt64(LabelTotalFare.Text);
                if (e.Item.ItemIndex == 0)
                {
                    minimumfare_return = fareslider_return;
                    maximumfare_return = fareslider_return;
                }
                if (fareslider_return < minimumfare_return)
                {
                    minimumfare_return = fareslider_return;
                }
                if (fareslider_return > maximumfare_return)
                {
                    maximumfare_return = fareslider_return;
                }


            }
        }
        catch (Exception ex)
        {
            //     obj_AirEpointSupport.WriteToLog(ex.Message, "RoundTripResult", "DataListRound_ItemDataBound__" + Convert.ToString(Session["partnerRefId"]));
            //Response.Redirect("../User/Index.aspx?s=exception");
        }

    }

    protected void DataListRound_ItemCommand(object source, DataListCommandEventArgs e)
    {

        try
        {
            if (e.CommandName == "Rule")
            {
                string output = (string)e.CommandArgument;
                // string[] a = output.Split(',');
                string Air_ID = Convert.ToString(((Label)DataListRound.Items[Convert.ToInt32(output)].FindControl("LabelAirlinecode")).Text);
                string Fly_ID = Convert.ToString(((Label)DataListRound.Items[Convert.ToInt32(output)].FindControl("Label1")).Text);
                string Cls_ID = Convert.ToString(((Label)DataListRound.Items[Convert.ToInt32(output)].FindControl("lblairlineclass")).Text);
                string requ = @"<FareRequest>
<UserTrackId>" + Convert.ToString(Session["UserT_ID"]) + @"</UserTrackId>
<AirlineId>" + Air_ID + @"</AirlineId >
<FlightId>" + Fly_ID + @"</FlightId>
<ClassCode>" + Cls_ID + @"</ClassCode>
</FareRequest>";
                Hermes heman = new Hermes();
                string ase = heman.Dom_Fare_Rule(requ);

                string rule = string.Empty;
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(ase);
                XmlNodeList xNodeList = doc.SelectNodes("FareResponse");
                foreach (XmlNode Node in xNodeList)
                {
                    XmlNodeList xNodeList1 = Node.ChildNodes;
                    foreach (XmlNode xnode in xNodeList1)
                    {

                        if (xnode.Name == "Status")
                        {
                            if (xnode.InnerText == "1")
                            {
                                rule = xnode.NextSibling.InnerText;
                            }
                            else
                            {
                                rule = "No Rule is Available.";
                            }
                        }
                    }
                }
                litl_Rule.Text = rule;

                // using System.Web.UI.HtmlControls;

                ContentPlaceHolder myPlaceHolder = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
                HtmlControl myControl = (HtmlControl)myPlaceHolder.FindControl("contioner_pop");



                // HtmlGenericControl div = ((HtmlGenericControl)Page.FindControl("#ctl00_ContentPlaceHolder1_contioner_pop"));
                //  HtmlGenericControl div = new HtmlGenericControl("#ctl00_ContentPlaceHolder1_contioner_pop");
                myControl.Style.Add("display", "block");
                // Control test=Page.FindControl("#ctl00_ContentPlaceHolder1_contioner_pop");


            }
        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "RoundTripResult", "myrepeater_ItemCommand__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/IndexDom.aspx?s=exception");
        }
    }
    protected void RBtnRound_CheckedChanged(object sender, EventArgs e)
    {
        try
        {
            if (Convert.ToString(ViewState["OneWayRouteSelect"]) != "")
            {
                RadioButton RBtnRound = (RadioButton)sender;
                Session["RadioButton_Round_SenderEvent"] = RBtnRound;
                ViewState["Return_RouteSelect"] = "True";
            }
        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "RoundTripResult", "RBtnRound_CheckedChanged__" + Convert.ToString(Session["partnerRefId"]));
            //Response.Redirect("../User/Index.aspx?s=exception");
        }
    }
    public void RemoveSession_OneWay()
    {
        Session.Remove("AirportTax");
        Session.Remove("Basefare");
        Session.Remove("ServiceTax");
        Session.Remove("TxnCharge");
        Session.Remove("BookingDiscount");
        Session.Remove("Dom_Ticket_Price");
        //Session.Remove("Dom_AgentComm");
        //Session.Remove("Dom_CompanyComm");
        //_________ 

    }
    public void RemoveSession_Return()
    {
        Session.Remove("AirportTax_Return");
        Session.Remove("Basefare_Return");
        Session.Remove("ServiceTax_Return");
        Session.Remove("TxnCharge_Return");
        Session.Remove("BookingDiscount_Return");
        Session.Remove("Dom_AgentComm_Return");
        Session.Remove("Dom_CompanyComm_Return");
        Session.Remove("Dom_Ticket_Price_Return");


    }
    public void Get_SelectedFlight__Departs_details()
    {
        try
        {
            DataSet ds_alldata;
            RadioButton RBtn = (RadioButton)Session["RadioButtonSenderEvent"];
            Session.Remove("RadioButtonSenderEvent");
            int index = Convert.ToInt32(RBtn.Text);
            DataListItem item = (DataListItem)DataListOne.Items[index];
            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
            {
                RemoveSession_OneWay();
                int adultfare = 0;
                int childfare = 0;
                int infantfare = 0;
                string StrClientID = null;
                StrClientID = RBtn.ClientID;
                RBtn = (RadioButton)item.FindControl("RBtn");
                if (StrClientID == RBtn.ClientID)
                {

                    ViewState["flightSegmentsid"] = ((Label)item.FindControl("LabelflghtSegmentsID")).Text;
                    int ItemId = Convert.ToInt32(ViewState["flightSegmentsid"]);
                    DataTable dtDepart = (DataTable)Session["newTable_Depart"];
                    var onwordresult = from OnwordTable in dtDepart.AsEnumerable()
                                       where OnwordTable.Field<int>("AvailFlightItem_Id") == ItemId
                                       select OnwordTable;
                    DataTable dt = new DataTable();
                    dt = onwordresult.CopyToDataTable();
                    Session["SelectedDepartFlight"] = dt;
                }
            }
        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "RoundTripResult", "Get_SelectedFlight__Departs_details__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
        }
    }
    public void Get_SelectedFlight_Return_details()
    {
        try
        {

            DataSet ds_alldata_round;
            RadioButton RBtnRound = (RadioButton)Session["RadioButton_Round_SenderEvent"];
            Session.Remove("RadioButton_Round_SenderEvent");
            int index = Convert.ToInt32(RBtnRound.Text);
            DataListItem item = (DataListItem)DataListRound.Items[index];
            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
            {
                RemoveSession_Return();
                int adultfare_round = 0;
                int childfare_round = 0;
                int infantfare_round = 0;
                string StrClientID = null;
                StrClientID = RBtnRound.ClientID;
                RBtnRound = (RadioButton)item.FindControl("RBtnRound");
                if (StrClientID == RBtnRound.ClientID)
                {
                    if (Convert.ToString(ViewState["OneWayRouteSelect"]) != "")
                    {
                        ViewState["flightSegmentsid_Return"] = ((Label)item.FindControl("LabelflghtSegmentsID")).Text;
                        int ItemId_return = Convert.ToInt32(ViewState["flightSegmentsid_Return"]);
                        DataTable dtReturn = (DataTable)Session["newTable_Return"];
                        var returnresult = from OnwordTable in dtReturn.AsEnumerable()
                                           where OnwordTable.Field<int>("AvailFlightItem_Id") == ItemId_return
                                           select OnwordTable;
                        DataTable dt_R = new DataTable();
                        dt_R = returnresult.CopyToDataTable();
                        Session["SelectedReturnFlight"] = dt_R;
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alertBox", "alert('Please first select the departure ');", true);
                        RBtnRound.Checked = false;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "RoundTripResult", "Get_SelectedFlight_Return_details__" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
        }

    }

    public static DataTable AirPortList;

    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
    {
        prefixText = AirEpointSupport.ToUpperFirstLetter(prefixText);
        var RESULT = (from table1 in AirPortList.AsEnumerable()
                      where table1.Field<string>("CityName").Contains(prefixText) || table1.Field<string>("CityCode").Contains(prefixText) || table1.Field<string>("Counrty").Contains(prefixText) || table1.Field<string>("AirPortDec").Contains(prefixText) ||
                     table1.Field<string>("CityName").Contains(prefixText.ToUpper()) || table1.Field<string>("CityCode").Contains(prefixText.ToUpper()) || table1.Field<string>("Counrty").Contains(prefixText.ToUpper()) || table1.Field<string>("AirPortDec").Contains(prefixText.ToUpper())
                      select table1).Distinct();
        DataTable dt = new DataTable();
        dt = RESULT.CopyToDataTable();
        DataSet _ds = new DataSet();
        _ds.Tables.Add(dt);
        List<string> CompletionSet = new List<string>();
        foreach (DataRow rdr in _ds.Tables[0].Rows)
        {
            string daaa = rdr["CityName"].ToString().ToUpper() + "," + rdr["AirPortDec"].ToString().ToUpper() + " (" + rdr["CityCode"].ToString().ToUpper() + ")";
            CompletionSet.Add(daaa.ToString());
        }
        return CompletionSet.ToArray();
    }
    protected void btn_submit_Click(object sender, EventArgs e)
    {
        try
        {
            bool validation = true;
            string msg = "";
            if (RadioButtonround.Checked && Convert.ToDateTime(txt_arrivaldate.Text) < Convert.ToDateTime(txt_departdate.Text))
            {
                validation = false;
                msg = "Return date can not less than departure date.";
            }
            if (txt_from.Text.Trim() == "" || txt_from.Text == "Enter Origin City or Airport Name")
            {
                validation = false;
                msg = "Please enter origin city.";
            }
            if (txt_to.Text.Trim() == "" || txt_to.Text == "Enter Destination City or Airport Name")
            {
                validation = false;
                msg = "Please enter destination city.";
            }
            if (validation)
            {
                #region Submit Form

                int x = obj_AirEpointSupport.CheckSearchFlight(txt_from.Text, txt_to.Text);
                if (x == 1)
                {
                    // Checklist();

                    if (true)
                    {
                        Session["From_Source"] = txt_from.Text;
                        Session["To_Source"] = txt_to.Text;
                        string DestinationFromValue = obj_AirEpointSupport.FindAirPortCode(txt_from.Text).Replace(")", "");
                        string DestinationToValue = obj_AirEpointSupport.FindAirPortCode(txt_to.Text).Replace(")", "");
                        Session["sourc"] = DestinationFromValue;
                        Session["Dest"] = DestinationToValue;
                        string DestinationFrom = obj_AirEpointSupport.FindAirPortCityName(txt_from.Text);
                        string DestinationTo = obj_AirEpointSupport.FindAirPortCityName(txt_to.Text);
                        string trip;
                        if (RadioButtononeway.Checked)
                        {
                            trip = "One";
                            Session["ReturnDate"] = Convert.ToDateTime(txt_departdate.Text).ToString("yyyy-MMM-dd");

                            Session["ReturnDate1"] = Convert.ToDateTime(txt_departdate.Text).ToString("dd-MMM-yyyy");

                        }
                        else if (RadioButtonround.Checked)
                        {
                            trip = "Round";

                            Session["ReturnDate"] = Convert.ToDateTime(txt_arrivaldate.Text).ToString("yyyy-MMM-dd");

                            Session["ReturnDate1"] = Convert.ToDateTime(txt_arrivaldate.Text).ToString("dd-MMM-yyyy");
                        }
                        else
                        {
                            trip = "SplFare";
                        }

                        Session["Trip"] = trip;
                        Session["DestinationFrom"] = DestinationFrom.ToString();
                        Session["DestinationFromValue"] = DestinationFrom;
                        Session["DestinationTo"] = DestinationTo;
                        Session["DestinationToValue"] = DestinationTo;
                        Session["DepartureDate"] = Convert.ToDateTime(txt_departdate.Text).ToString("yyyy-MMM-dd");
                        Session["DepartureDate1"] = Convert.ToDateTime(txt_departdate.Text).ToString("dd-MMM-yyyy");
                        Session["Adults"] = ddl_adult.SelectedItem.Value.ToString();
                        Session["Children"] = ddl_child.SelectedItem.Value.ToString();
                        Session["Infants"] = ddl_infant.SelectedItem.Value.ToString();
                        Session["Class"] = ddl_class.SelectedItem.Value.ToString();
                        TotalPassenger = Convert.ToInt32(ddl_adult.SelectedItem.Value) + Convert.ToInt32(ddl_child.SelectedItem.Value);
                        Session.Remove("partnerRefId");

                        Random r = new Random();

                        Session["partnerRefId"] = obj_AirEpointSupport.Generate_TID();
                        string sss = Convert.ToString(Session["partnerRefId"]);
                        #region  Domestic Search
                        if (obj_AirEpointSupport.CheckSourceDestination(txt_from.Text, txt_to.Text) == "DOM")
                        {




                            #region Regular Domestic

                            #region Domestic

                            if (Convert.ToString(ViewState["flighttypelavi"]) != "DOM")
                            {
                                ViewState["selectedairlines"] = "";
                            }
                            Session["DestinationFrom"] = DestinationFrom;
                            Session["DestinationFromValue"] = DestinationFromValue;
                            Session["DestinationTo"] = DestinationTo;
                            Session["DestinationToValue"] = DestinationToValue;
                            Session["FlightType"] = "DOM";
                            #region Domestic Oneway
                            if (Convert.ToString(Session["Trip"]) == "One")
                            {
                                if (TotalPassenger <= 9)
                                {
                                    //  ViewState["selectedairlines"] = "AI,G8,IC,6E,9W,S2,IT,9H,I7,SG,IX";
                                    txt_arrivaldate.Text = DateTime.Parse(txt_departdate.Text).ToString("MM/dd/yyyy");
                                    string request_Avail = @"<AvailabilityReq><BookingType>O</BookingType><JryDetails><Item><Origin>" + DestinationFromValue + @"</Origin><Destination>" + DestinationToValue + @"</Destination>
<TravelDate>" + txt_arrivaldate.Text + @"</TravelDate></Item></JryDetails><ClassType>Economy</ClassType>
<Airlinecodes></Airlinecodes><Adults>" + ddl_adult.SelectedItem.Value.ToString() + @"</Adults><Childs>" + ddl_child.SelectedItem.Value.ToString() + @"</Childs>
<Infants>" + ddl_infant.SelectedItem.Value.ToString() + @"</Infants>
<ResidentofIndia>1</ResidentofIndia><DirectAccess>0</DirectAccess><TransFeeFlag>1</TransFeeFlag></AvailabilityReq>";
                                    Hermes obj_hermes = new Hermes();
                                    DataSet ds = new DataSet();
                                    string response_avail = obj_hermes.AirAvailability(request_Avail);
                                    Session["myResult"] = response_avail;
                                    ds.ReadXml(new StringReader(response_avail));
                                    Session["Response"] = ds;



                                    Response.Redirect("../Domestic/OneWayResult.aspx", false);
                                }
                                else
                                {
                                    Page.RegisterStartupScript("XXX", "<script> alert('Sum of Adult and child passenger travelling not more than 9')</script>");
                                }
                            }
                            #endregion
                            #region Domestic Round
                            else if (Convert.ToString(Session["Trip"]) == "Round")
                            {
                                if (TotalPassenger <= 9)
                                {

                                    txt_departdate.Text = DateTime.Parse(txt_departdate.Text).ToString("MM/dd/yyyy");
                                    txt_arrivaldate.Text = DateTime.Parse(txt_arrivaldate.Text).ToString("MM/dd/yyyy");

                                    string request_Avail = @"<AvailabilityReq><BookingType>R</BookingType><JryDetails><Item><Origin>" + DestinationFromValue + @"</Origin><Destination>" + DestinationToValue + @"</Destination>
<TravelDate>" + txt_departdate.Text + @"</TravelDate></Item><Item><Origin>" + DestinationToValue + @"</Origin><Destination>" + DestinationFromValue + @"</Destination>
<TravelDate>" + txt_arrivaldate.Text + @"</TravelDate></Item></JryDetails><ClassType>Economy</ClassType>
<Airlinecodes></Airlinecodes><Adults>" + ddl_adult.SelectedItem.Value.ToString() + @"</Adults><Childs>" + ddl_child.SelectedItem.Value.ToString() + @"</Childs>
<Infants>" + ddl_infant.SelectedItem.Value.ToString() + @"</Infants>
<ResidentofIndia>1</ResidentofIndia><DirectAccess>0</DirectAccess><TransFeeFlag>1</TransFeeFlag></AvailabilityReq>";
                                    Hermes obj_hermes = new Hermes();
                                    DataSet ds = new DataSet();
                                    string response_avail = obj_hermes.AirAvailability(request_Avail);

                                    Session["myResult"] = response_avail;
                                    ds.ReadXml(new StringReader(response_avail));
                                    Session["Response"] = ds;

                                    Response.Redirect("../Domestic/RoundTripResult.aspx", false);
                                }
                                else
                                {
                                    Page.RegisterStartupScript("XXX", "<script> alert('Sum of Adult and child passenger travelling not more than 9')</script>");
                                }
                            }
                            #endregion
                            #endregion

                            #endregion



                        }
                        #endregion


                        #region International Search
                        else if (obj_AirEpointSupport.CheckSourceDestination(txt_from.Text, txt_to.Text) == "INAIR" || obj_AirEpointSupport.CheckSourceDestination(txt_from.Text, txt_to.Text) == "SETO")
                        {
                            //if (obj_AirEpointSupport.GetActiveVendorForService("International") == "Arzoo")
                            //{

                            Session["FlightType"] = "INAIR";
                            if (Convert.ToString(ViewState["flighttypelavi"]) != "INAIR")
                            {
                                ViewState["selectedairlines"] = "";
                            }
                            #region INTERNATIONAL One Way
                            if (Convert.ToString(Session["Trip"]) == "One")
                            {


                                if (TotalPassenger <= 9)
                                {

                                    txt_arrivaldate.Text = DateTime.Parse(txt_departdate.Text).AddDays(2).ToString("MM/dd/yyyy");
                                    string Request = "<AvailabilityReq><BookingType>O</BookingType><Details><Item><Source>" + DestinationFromValue + "</Source><Destination>" + DestinationToValue + "</Destination><Date>" + DateTime.Parse(txt_departdate.Text).ToString("MM/dd/yyyy") + "</Date></Item></Details><ClassTypeId>Economy</ClassTypeId><AIRLINES /><Adult>" + Convert.ToInt16(ddl_adult.SelectedItem.Value.ToString()) + "</Adult><Child>" + Convert.ToInt16(ddl_child.SelectedItem.Value.ToString()) + "</Child><Infant>" + Convert.ToInt16(ddl_infant.SelectedItem.Value.ToString()) + "</Infant><ResidentofIndia>1</ResidentofIndia><AirlineCode></AirlineCode><DirectAccess>0</DirectAccess></AvailabilityReq>";
                                    Session.Remove("Response");
                                    obj_AirEpointSupport.WriteXmlLog(Request, "International_Request");
                                    obj_Hermes = new Hermes();
                                  //  string Response_result = obj_Hermes.Inter_AirAvailability(Request);
                                    string Response_result = "";
                                    obj_AirEpointSupport.WriteXmlLog(Response_result, "International_Response");
                                    Session["Response"] = Response_result;
                                    Response.Redirect("../International/OneWayInternational.aspx", false);
                                }

                                else
                                {
                                    Page.RegisterStartupScript("XXX", "<script> alert('Sum of Adult and child passenger travelling not more than 9')</script>");
                                }

                            }
                            #endregion

                            #region INTERNATIONAL RoundTrip
                            else if (Convert.ToString(Session["Trip"]) == "Round")
                            {
                                if (DateTime.Parse(txt_arrivaldate.Text) < DateTime.Parse(txt_departdate.Text))
                                {


                                    Page.RegisterStartupScript("XXX", "<script> alert('Return Date Cannot be less than Depart Date')</script>");


                                    if (TotalPassenger > 9)
                                    {
                                        Page.RegisterStartupScript("XXX", "<script> alert('Sum of Adult and child passenger travelling not more than 9')</script>");
                                    }
                                }
                                else
                                {
                                    if (TotalPassenger <= 9)
                                    {

                                        string Request = "<AvailabilityReq><BookingType>R</BookingType><Details><Item><Source>" + DestinationFromValue + "</Source><Destination>" + DestinationToValue + "</Destination><Date>" + DateTime.Parse(txt_departdate.Text).ToString("MM/dd/yyyy") + "</Date></Item><Item><Source>" + DestinationToValue + "</Source><Destination>" + DestinationFromValue + "</Destination><Date>" + DateTime.Parse(txt_arrivaldate.Text).ToString("MM/dd/yyyy") + "</Date></Item></Details><ClassTypeId>Economy</ClassTypeId><AIRLINES /><Adult>" + Convert.ToInt16(ddl_adult.SelectedItem.Value.ToString()) + "</Adult><Child>" + Convert.ToInt16(ddl_child.SelectedItem.Value.ToString()) + "</Child><Infant>" + Convert.ToInt16(ddl_infant.SelectedItem.Value.ToString()) + "</Infant><ResidentofIndia>1</ResidentofIndia><AirlineCode></AirlineCode><DirectAccess>0</DirectAccess></AvailabilityReq>";

                                        Session.Remove("Response");
                                        obj_Hermes = new Hermes();
                                        //string Response_result = obj_Hermes.Inter_AirAvailability(Request);
                                        string Response_result = "";
                                        Session["Response"] = Response_result;
                                        Response.Redirect("../international/RoundTripResultInternational.aspx", false);



                                    }

                                    else
                                    {
                                        Page.RegisterStartupScript("XXX", "<script> alert('Sum of Adult and child passenger travelling not more than 9')</script>");
                                    }

                                }
                            }
                            #endregion

                        }
                        #endregion

                    }
                    else
                    {
                        Page.RegisterStartupScript("XXX", "<script> alert('Source and Destination names do not exist.')</script>");
                    }

                }
                else if (x == 0)
                {
                    Page.RegisterStartupScript("XXX", "<script> alert('Source and Destination names do not exist.')</script>");
                }
                #endregion
            }
            else
            {
                RegisterClientScriptBlock("alert", "<script>alert('" + msg + "');</script>");
            }


        }

        catch (Exception ex)
        {
            obj_AirEpointSupport.WriteToLog(ex.Message, "OneWayResult", "btn_submit_modify search__" + Convert.ToString(Session["partnerRefId"]));

            RegisterClientScriptBlock("alert", "<script>alert('Please correct input validations');</script>");
        }
    }
    public DataSet Tax_Deatils(string Tax_Request)
    {
        Hermes objhermes = new Hermes();
        DataSet ds_taxdetail = new DataSet();
        ds_taxdetail = objhermes.AirTaxDetails(Tax_Request);
        return ds_taxdetail;
    }
    public decimal[] DomesticPrice(decimal ActualBaseFare, decimal Gross, decimal STax, decimal TDiscount, decimal TCharge)
    {
        decimal Tax = Gross - ActualBaseFare;
        decimal[] fares = new decimal[6];
        fares[0] = ActualBaseFare;
        fares[1] = Tax;
        fares[2] = STax;
        fares[3] = TCharge;
        fares[4] = TDiscount;
        decimal totalfare = (fares[0] + fares[1] + fares[2] + fares[3]);
        fares[5] = totalfare;
        return fares;
    }

    private void Fill_Initial()
    {


        if (Convert.ToString(Session["Trip"]) == "One")
        {
            RadioButtononeway.Checked = true;
            RadioButtonround.Checked = false;
            RadioButtonspecial.Checked = false;
        }
        else if (Convert.ToString(Session["Trip"]) == "Round")
        {
            RadioButtononeway.Checked = false;
            RadioButtonround.Checked = true;
            RadioButtonspecial.Checked = false;
        }
        else if (Convert.ToString(Session["Trip"]) == "SplFare")
        {
            RadioButtononeway.Checked = false;
            RadioButtonround.Checked = false;
            RadioButtonspecial.Checked = true;
        }
        ddl_adult.SelectedValue = Convert.ToString(Session["Adults"]);
        ddl_child.SelectedValue = Convert.ToString(Session["Children"]);
        ddl_infant.SelectedValue = Convert.ToString(Session["Infants"]);
        ddl_class.SelectedValue = Convert.ToString(Session["Class"]);
        txt_departdate.Text = Convert.ToDateTime(Session["DepartureDate"]).ToString("dd-MMM-yyyy");
        txt_arrivaldate.Text = Convert.ToDateTime(Session["ReturnDate"]).ToString("dd-MMM-yyyy");
    }
    public string CalculateTotal(object UnitPrice)
    {
        double Total = double.Parse(UnitPrice.ToString()) * Convert.ToDouble(Session["convertor"]);
        return Math.Round(Total).ToString("f2");
    }
    protected void linkbuttonprefferd_Click(object sender, EventArgs e)
    {
        int x = obj_AirEpointSupport.CheckSearchFlight(txt_from.Text, txt_to.Text);
        if (x == 1)
        {
            if (obj_AirEpointSupport.CheckSourceDestination(txt_from.Text, txt_to.Text) == "INAIR" || obj_AirEpointSupport.CheckSourceDestination(txt_from.Text, txt_to.Text) == "SETO")
            {
                DataSet ds1 = new DataSet();
                ds1 = obj_AirEpointSupport.GetAirLineDetails();
                var AirLinesName1 = from Airline in ds1.Tables["AirLine"].AsEnumerable()
                                    where Airline.Field<string>("Type") == "INAIR"
                                    select Airline;
                DataTable dt1 = AirLinesName1.CopyToDataTable();
                CheckBoxList_Airlines.DataSource = dt1;
                CheckBoxList_Airlines.DataValueField = "AirLineCode";
                CheckBoxList_Airlines.DataTextField = "AirLineName";
                CheckBoxList_Airlines.Width = 800;
                CheckBoxList_Airlines.RepeatColumns = 5;
                CheckBoxList_Airlines.DataBind();
                //  uniquename3.Visible = true;
                lblmsg.Visible = false;
                //  uniquename3.Visible = true;
                modalpopup1.Show();
                CheckBoxList_Airlines.Visible = true;
                ViewState["flighttypelavi"] = "INAIR";
            }
            else
            {
                DataSet ds1 = new DataSet();
                ds1 = obj_AirEpointSupport.GetAirLineDetails();
                var AirLinesName1 = from Airline in ds1.Tables["AirLine"].AsEnumerable()
                                    where Airline.Field<string>("Type") == "DOM"
                                    select Airline;
                DataTable dt1 = AirLinesName1.CopyToDataTable();
                CheckBoxList_Airlines.DataSource = dt1;
                CheckBoxList_Airlines.DataValueField = "AirLineCode";
                CheckBoxList_Airlines.DataTextField = "AirLineName";
                CheckBoxList_Airlines.Width = 400;
                CheckBoxList_Airlines.RepeatColumns = 3;
                CheckBoxList_Airlines.DataBind();
                //   uniquename3.Visible = true;
                modalpopup1.Show();
                lblmsg.Visible = false;
                CheckBoxList_Airlines.Visible = true;
                ViewState["flighttypelavi"] = "DOM";
            }
        }
        else
        {
            //     uniquename3.Visible = true;
            modalpopup1.Show();
            lblmsg.Visible = true;
            CheckBoxList_Airlines.Visible = false;
            ViewState["flighttypelavi"] = "";
        }
    }
    private void Checklist()
    {
        try
        {

            CheckBoxList list = CheckBoxList_Airlines;

            int count = 0;
            foreach (ListItem item in list.Items)
            {
                if (item.Selected)
                {
                    prfredairlines += item.Value + ",";
                    count += 1;
                }
            }
            if (count == 0)
            {
                foreach (ListItem item in list.Items)
                {

                    prfredairlines += item.Value + ",";


                }

            }
            ViewState["selectedairlines"] = prfredairlines.Remove(prfredairlines.Length - 1, 1);
        }
        catch (Exception ex)
        {
          //  Air_transaction_Cal.writeToLogFile("BookingProcess_DomesticInterNational.aspx-Checklist()" + ex.Message.ToString(), Server.MapPath("~/Air_InternaltionalExceptionList"));
            ViewState["selectedairlines"] = "";
        }
    }
    protected void btn_book_Click(object sender, EventArgs e)
    {
        try
        {
            if (Convert.ToString(ViewState["OneWayRouteSelect"]) != "" && Convert.ToString(ViewState["Return_RouteSelect"]) != "")
            {



                Get_SelectedFlight__Departs_details();
                Get_SelectedFlight_Return_details();
                DataSet ds_alldata = new DataSet();
                ds_alldata.ReadXml(new StringReader(Convert.ToString(Session["myResult"])));
                DataTable dtdepart = (DataTable)Session["SelectedDepartFlight"];
                Session["BookinRequest_OriginDestinationOption_OneWay_Depart"] = dtdepart;
                DataTable dtReturn = (DataTable)Session["SelectedReturnFlight"];
                Session["BookinRequest_OriginDestinationOption_OneWay_Return"] = dtReturn;

                string Tax_Request = @"<TAXREQUEST>
<UserTrackId>" + ds_alldata.Tables["AvailabilityResponse"].Rows[0][0].ToString() + @"</UserTrackId>
<AirlineId>" + dtdepart.Rows[0]["CarrierCode"].ToString() + @"</AirlineId>
<FlightDetails>";
                for (int i = 0; i < dtdepart.Rows.Count; i++)
                {
                    Tax_Request = Tax_Request + @"<Item>
<FlightId>" + dtdepart.Rows[i]["FlightId"].ToString() + @"</FlightId>
<ClassCode>" + dtdepart.Rows[i]["ClassCode"].ToString() + @"</ClassCode>
<AirlineId>" + dtdepart.Rows[i]["CarrierCode"].ToString() + @"</AirlineId>
<EticketFlag>1</EticketFlag>
<BasicAmount>" + dtdepart.Rows[i]["BasicAmount"] + @"</BasicAmount>
</Item>";
                }
                //                for (int i = 0; i < dtdepart.Rows.Count; i++)
                //                {
                //                    Tax_Request = Tax_Request + @"<Item>
                //<FlightId>" + dtdepart.Rows[i]["FlightId"].ToString() + @"</FlightId>";
                //                    var cs_id = (from csid in ds_alldata.Tables["PaxFareDetails"].AsEnumerable()
                //                                 where csid.Field<int>("SegFlightDetails_Id") == Convert.ToInt32(dtdepart.Rows[i]["SegFlightDetails_Id"])
                //                                 select csid).ToArray();
                //                    Tax_Request = Tax_Request + @"<ClassCode>" + cs_id[0].ItemArray[0].ToString() + @"</ClassCode>";

                //                    Tax_Request = Tax_Request + @"<AirlineId>" + dtdepart.Rows[i]["CarrierCode"].ToString() + @"</AirlineId>
                //<EticketFlag>1</EticketFlag>
                //<BasicAmount>" + dtdepart.Rows[i]["GrossAmount"].ToString() + @"</BasicAmount>
                //</Item>";
                //                }
                Tax_Request = Tax_Request + @"</FlightDetails>
<TransFeeFlag>0</TransFeeFlag>
</TAXREQUEST>";

                Session["Tax_Details"] = Tax_Deatils(Tax_Request);

                DataSet ds_taxdetail_Depart = new DataSet();
                ds_taxdetail_Depart = (DataSet)Session["Tax_Details"];

                Session["FareRule"] = "FareRule";
                decimal adultfare = 0;
                decimal childfare = 0;
                decimal infantfare = 0;
                decimal adultbase = 0;
                decimal childbase = 0;
                decimal infantbase = 0;
                decimal adultservice = 0;
                decimal childservice = 0;
                decimal infantservice = 0;
                decimal adultComm = 0;
                decimal childComm = 0;
                decimal infantComm = 0;
                decimal totalfare, totalbase, totalser, totalcomm;


                adultfare = adultfare + (Convert.ToDecimal(ds_taxdetail_Depart.Tables["Adult"].Rows[0]["GrossAmount"]) * Convert.ToDecimal(Session["Adults"]));
                adultbase = adultbase + (Convert.ToDecimal(ds_taxdetail_Depart.Tables["Adult"].Rows[0]["BasicAmt"]) * Convert.ToDecimal(Session["Adults"]));
                adultservice = adultservice + (Convert.ToDecimal(ds_taxdetail_Depart.Tables["Adult"].Rows[0]["ServiceAmount"]) * Convert.ToDecimal(Session["Adults"]));
                if (ds_taxdetail_Depart.Tables["Adult"].Rows[0]["Commission"].ToString() == "")
                    adultComm = adultComm + 0;
                else
                    adultComm = adultComm + (Convert.ToDecimal(ds_taxdetail_Depart.Tables["Adult"].Rows[0]["Commission"]) * Convert.ToDecimal(Session["Adults"]));
                Session["Adultfare"] = adultfare;
                if (Convert.ToInt32(Session["Children"]) > 0)
                {

                    childfare = childfare + (Convert.ToDecimal(ds_taxdetail_Depart.Tables["Child"].Rows[0]["GrossAmount"]) * Convert.ToDecimal(Session["Children"]));
                    childbase = childbase + (Convert.ToDecimal(ds_taxdetail_Depart.Tables["Child"].Rows[0]["BasicAmt"]) * Convert.ToDecimal(Session["Children"]));
                    childservice = childservice + (Convert.ToDecimal(ds_taxdetail_Depart.Tables["Child"].Rows[0]["ServiceAmount"]) * Convert.ToDecimal(Session["Children"]));
                    if (ds_taxdetail_Depart.Tables["Child"].Rows[0]["Commission"].ToString() == "")
                        childComm = childComm + 0;
                    else
                        childComm = childComm + (Convert.ToDecimal(ds_taxdetail_Depart.Tables["Child"].Rows[0]["Commission"]) * Convert.ToDecimal(Session["Children"]));
                    Session["Childfare"] = childfare;
                }
                if (Convert.ToInt32(Session["Infants"]) > 0)
                {

                    infantfare = infantfare + (Convert.ToDecimal(ds_taxdetail_Depart.Tables["Infant"].Rows[0]["GrossAmount"]) * Convert.ToDecimal(Session["Infants"]));
                    infantbase = infantbase + (Convert.ToDecimal(ds_taxdetail_Depart.Tables["Infant"].Rows[0]["BasicAmt"]) * Convert.ToDecimal(Session["Infants"]));
                    infantservice = infantservice + (Convert.ToDecimal(ds_taxdetail_Depart.Tables["Infant"].Rows[0]["ServiceAmount"]) * Convert.ToDecimal(Session["Infants"]));
                    if (ds_taxdetail_Depart.Tables["Infant"].Rows[0]["Commission"].ToString() == "")
                        infantComm = infantComm + 0;
                    else
                        infantComm = infantComm + (Convert.ToDecimal(ds_taxdetail_Depart.Tables["Infant"].Rows[0]["Commission"]) * Convert.ToDecimal(Session["Infants"]));
                    Session["Infantfare"] = infantfare;
                }




                totalfare = adultfare + childfare + infantfare;
                totalbase = adultbase + childbase + infantbase;
                totalser = adultservice + childservice + infantservice;
                totalcomm = adultComm + childComm + infantComm;

                decimal[] ongoingfares = DomesticPrice(totalbase, totalfare, totalser, totalcomm, 0);

                //decimal[] fares = obj_AirEpointSupport.DomesticPrice(Convert.ToDecimal(dsbookingdetails.Tables["ChargeableFares"].Rows[0]["ActualBaseFare"]), Convert.ToDecimal(dsbookingdetails.Tables["ChargeableFares"].Rows[0]["Tax"]), Convert.ToDecimal(dsbookingdetails.Tables["ChargeableFares"].Rows[0]["STax"]), Convert.ToDecimal(dsbookingdetails.Tables["ChargeableFares"].Rows[0]["TDiscount"]), Convert.ToDecimal(dsbookingdetails.Tables["NonChargeableFares"].Rows[0]["TCharge"]));

                decimal mark_up = Convert.ToDecimal(Session["agentMarkup"]);
                decimal all_markup = Convert.ToDecimal(Session["allMarkup"]);
                Session["AirportTax"] = ongoingfares[1];
                Session["Basefare_depart"] = ongoingfares[0];
                Session["ServiceTax_depart"] = ongoingfares[2];
                Session["TxnCharge_depart"] = ongoingfares[3];
                Session["BookingDiscount_depart"] = ongoingfares[3];
                decimal Comm_Depart = ongoingfares[4];
                B2B objbeb = new B2B();
               // decimal CompanyComm_Perc = objbeb.Domestic_GetCompanyCommission_Perc(Convert.ToInt32(Session["agid"]), Convert.ToString(Session["HURL"]));
               // decimal AgentComm_Perc = objbeb.Domestic_GetAgentCommission_Perc(Convert.ToInt32(Session["agid"]), Convert.ToString(Session["HURL"]));
                decimal CompanyComm_Perc = 20;
                decimal AgentComm_Perc = 80;

                decimal price = ongoingfares[5];
                Session["totalPrice_onGoing"] = price;

                Tax_Request = string.Empty;
                decimal adultfare_ret = 0;
                decimal childfare_ret = 0;
                decimal infantfare_ret = 0;
                decimal adultbase_ret = 0;
                decimal childbase_ret = 0;
                decimal infantbase_ret = 0;
                decimal adultservice_ret = 0;
                decimal childservice_ret = 0;
                decimal infantservice_ret = 0;
                decimal adultcomm_ret = 0;
                decimal childcomm_ret = 0;
                decimal infantcomm_ret = 0;

                decimal totalfare_ret, totalbase_ret, totalser_ret, totalcom_ret;

                Tax_Request = @"<TAXREQUEST>
               <UserTrackId>" + ds_alldata.Tables["AvailabilityResponse"].Rows[0][0].ToString() + @"</UserTrackId>
               <AirlineId>" + dtReturn.Rows[0]["CarrierCode"].ToString() + @"</AirlineId>
               <FlightDetails>";
                for (int i = 0; i < dtReturn.Rows.Count; i++)
                {
                    Tax_Request = Tax_Request + @"<Item>
                               <FlightId>" + dtReturn.Rows[i]["FlightId"].ToString() + @"</FlightId>
                               <ClassCode>" + dtReturn.Rows[i]["ClassCode"].ToString() + @"</ClassCode>
                               <AirlineId>" + dtReturn.Rows[i]["CarrierCode"].ToString() + @"</AirlineId>
                               <EticketFlag>1</EticketFlag>
                               <BasicAmount>" + dtReturn.Rows[i]["BasicAmount"] + @"</BasicAmount>
                               </Item>";
                }
                //               { for (int i = 0; i < dtReturn.Rows.Count; i++)

                //                    Tax_Request = Tax_Request + @"<Item>
                //<FlightId>" + dtReturn.Rows[i]["FlightId"].ToString() + @"</FlightId>";
                //                    var cs_idret = (from csidret in ds_alldata.Tables["PaxFareDetails"].AsEnumerable()
                //                                 where csidret.Field<int>("SegFlightDetails_Id") == Convert.ToInt32(dtReturn.Rows[i]["SegFlightDetails_Id"])
                //                                 select csidret).ToArray();
                //                    Tax_Request = Tax_Request + @"<ClassCode>" + cs_idret[0].ItemArray[0].ToString() + @"</ClassCode>";

                //                    Tax_Request = Tax_Request + @"<AirlineId>" + dtReturn.Rows[i]["CarrierCode"].ToString() + @"</AirlineId>
                //<EticketFlag>1</EticketFlag>
                //<BasicAmount>" + dtReturn.Rows[i]["GrossAmount"].ToString() + @"</BasicAmount>
                //</Item>";
                //                }
                Tax_Request = Tax_Request + @"</FlightDetails>
               <TransFeeFlag>0</TransFeeFlag>
               </TAXREQUEST>";

                Session["Tex_Details_Return"] = Tax_Deatils(Tax_Request);
                DataSet ds_taxdetail_Return = (DataSet)Session["Tex_Details_Return"];

                adultfare_ret = adultfare_ret + (Convert.ToDecimal(ds_taxdetail_Return.Tables["Adult"].Rows[0]["GrossAmount"]) * Convert.ToDecimal(Session["Adults"]));
                adultbase_ret = adultbase_ret + (Convert.ToDecimal(ds_taxdetail_Return.Tables["Adult"].Rows[0]["BasicAmt"]) * Convert.ToDecimal(Session["Adults"]));
                adultservice_ret = adultservice_ret + (Convert.ToDecimal(ds_taxdetail_Return.Tables["Adult"].Rows[0]["ServiceAmount"]) * Convert.ToDecimal(Session["Adults"]));
                if (ds_taxdetail_Return.Tables["Adult"].Rows[0]["Commission"].ToString() == "")
                    adultcomm_ret = adultcomm_ret + 0;
                else
                    adultcomm_ret = adultcomm_ret + (Convert.ToDecimal(ds_taxdetail_Return.Tables["Adult"].Rows[0]["Commission"]) * Convert.ToDecimal(Session["Adults"]));
                Session["AdultfareReturn"] = adultfare_ret;
                if (Convert.ToInt32(Session["Children"]) > 0)
                {

                    childfare_ret = childfare_ret + (Convert.ToDecimal(ds_taxdetail_Return.Tables["Child"].Rows[0]["GrossAmount"]) * Convert.ToDecimal(Session["Children"]));
                    childbase_ret = childbase_ret + (Convert.ToDecimal(ds_taxdetail_Return.Tables["Child"].Rows[0]["BasicAmt"]) * Convert.ToDecimal(Session["Children"]));
                    childservice_ret = childservice_ret + (Convert.ToDecimal(ds_taxdetail_Return.Tables["Child"].Rows[0]["ServiceAmount"]) * Convert.ToDecimal(Session["Children"]));
                    if (ds_taxdetail_Return.Tables["Child"].Rows[0]["Commission"].ToString() == "")
                        childcomm_ret = childcomm_ret + 0;
                    else
                        childcomm_ret = childcomm_ret + (Convert.ToDecimal(ds_taxdetail_Return.Tables["Child"].Rows[0]["Commission"]) * Convert.ToDecimal(Session["Children"]));
                    Session["ChildfareReturn"] = childfare_ret;
                }
                if (Convert.ToInt32(Session["Infants"]) > 0)
                {

                    infantfare_ret = infantfare_ret + (Convert.ToDecimal(ds_taxdetail_Return.Tables["Infant"].Rows[0]["GrossAmount"]) * Convert.ToDecimal(Session["Infants"]));
                    infantbase_ret = infantbase_ret + (Convert.ToDecimal(ds_taxdetail_Return.Tables["Infant"].Rows[0]["BasicAmt"]) * Convert.ToDecimal(Session["Infants"]));
                    infantservice_ret = infantservice_ret + (Convert.ToDecimal(ds_taxdetail_Return.Tables["Infant"].Rows[0]["ServiceAmount"]) * Convert.ToDecimal(Session["Infants"]));
                    if (ds_taxdetail_Return.Tables["Infant"].Rows[0]["Commission"].ToString() == "")
                        infantcomm_ret = infantcomm_ret + 0;
                    else
                        infantcomm_ret = infantcomm_ret + (Convert.ToDecimal(ds_taxdetail_Return.Tables["Infant"].Rows[0]["Commission"]) * Convert.ToDecimal(Session["Infants"]));
                    Session["InfantfareReturn"] = infantfare_ret;
                }




                totalfare_ret = adultfare_ret + childfare_ret + infantfare_ret;
                totalbase_ret = adultbase_ret + childbase_ret + infantbase_ret;
                totalser_ret = adultservice_ret + childservice_ret + infantservice_ret;
                totalcom_ret = adultcomm_ret + childcomm_ret + infantcomm_ret;

                decimal[] returnfares_ret = DomesticPrice(totalbase_ret, totalfare_ret, totalser_ret, totalcom_ret, 0);

                //decimal[] fares = obj_AirEpointSupport.DomesticPrice(Convert.ToDecimal(dsbookingdetails.Tables["ChargeableFares"].Rows[0]["ActualBaseFare"]), Convert.ToDecimal(dsbookingdetails.Tables["ChargeableFares"].Rows[0]["Tax"]), Convert.ToDecimal(dsbookingdetails.Tables["ChargeableFares"].Rows[0]["STax"]), Convert.ToDecimal(dsbookingdetails.Tables["ChargeableFares"].Rows[0]["TDiscount"]), Convert.ToDecimal(dsbookingdetails.Tables["NonChargeableFares"].Rows[0]["TCharge"]));

                mark_up = Convert.ToDecimal(Session["agentMarkup"]);
                Session["AirportTax_Return"] = returnfares_ret[1];
                Session["Basefare_Return"] = returnfares_ret[0];
                Session["ServiceTax_Return"] = returnfares_ret[2];
                Session["TxnCharge_Return"] = returnfares_ret[3];
                Session["BookingDiscount_Return"] = returnfares_ret[3];
                decimal Comm_Return = ongoingfares[4];
                decimal priceround = returnfares_ret[5];
                Session["totalPrice_Return"] = priceround;
                Session["TotalAirportTax"] = Math.Ceiling(ongoingfares[1] + returnfares_ret[1]);
                Session["TotalBasefare"] = Math.Ceiling(ongoingfares[0] + returnfares_ret[0]);
                Session["TotalServiceTax"] = Math.Ceiling(ongoingfares[2] + returnfares_ret[2]);
                Session["TotalTxnCharge"] = Math.Ceiling(ongoingfares[3] + returnfares_ret[3]);
                Session["TotalBookingDiscount"] = Math.Ceiling(ongoingfares[3] + returnfares_ret[3]);
                decimal total_Com = Comm_Depart + Comm_Return;

                decimal TOTAL_AMOUNT = ongoingfares[5] + returnfares_ret[5];
                Session["totalPrice"] = TOTAL_AMOUNT;
                decimal CompanyComm = Math.Round(((total_Com) * CompanyComm_Perc) / 100);
                decimal AgentComm = Math.Round(((total_Com) * AgentComm_Perc) / 100);
                Session["Dom_Ticket_Price"] = ongoingfares[5] + returnfares_ret[5] + (mark_up + all_markup) * 2;

                Session["Dom_Ticket_detect"] = ongoingfares[5] + returnfares_ret[5] - (AgentComm)+all_markup*2;
                Session["Dom_AgentComm"] = AgentComm + mark_up*2;
                Session["Dom_CompanyComm"] = CompanyComm+all_markup*2;
                //RemoveSession();










                Response.Redirect("step3.aspx", false);


            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertBox", "alert('Please select both the departure and return route');", true);
            }

        }

        catch (Exception ex)
        {

            obj_AirEpointSupport.WriteToLog(ex.Message, "RoundTripResult", "btn_book_Click __" + Convert.ToString(Session["partnerRefId"]));
            Response.Redirect("../User/Index.aspx?s=exception");
        }
    }
    public decimal[] DomesticPrice_Agent(decimal ActualBaseFare, decimal Gross, decimal STax, decimal TDiscount, decimal TCharge)
    {
        decimal[] fares = new decimal[6];
        fares[0] = ActualBaseFare;
        fares[1] = 0;
        fares[2] = 0;
        fares[3] = 0;
        fares[4] = TDiscount;
        decimal totalfare = (fares[0] + fares[1] + fares[2] + fares[3]) - fares[4];
        fares[5] = Gross;
        return fares;
    }
}

