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

public partial class User_booking : System.Web.UI.Page
{
    string TicketStatus;
    string ResultBkngInfStatus;
    string Clientid, Clientpassword, Clienttype, IntClientID, IntClientPassword, IntClientType, IntBookingStatus;
    protected void Page_Load(object sender, EventArgs e)
    {
 
        //Session["agid"] = "1304";
        try
        {
            if (!IsPostBack)
            {
             
                DataSet CompletedTrips = new DataSet();
                string status= string.Empty;
                string pnrSt = string.Empty;
				        int totPass,incan; 
                //CompletedTrips = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_get_completed_trips_lavi", new SqlParameter[] { new SqlParameter("@UserID", Convert.ToString(Session["agid"])) });
                //CompletedTrips = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2Bflight_get_All_Booking_trips_W@r10ck", new SqlParameter[] { new SqlParameter("@UserID", Convert.ToString(Session["agid"])) });
               CompletedTrips = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_get_Booking_trips_alok", new SqlParameter[] { new SqlParameter("@UserID", Convert.ToString(Session["agid"])) });
               //CompletedTrips = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_get_Booking_trips_alok_Ticket_Price", new SqlParameter[] { new SqlParameter("@UserID", Convert.ToString(Session["agid"])) });
                
                if (CompletedTrips.Tables.Count > 0)
                { 
                    gridview_completed_trip.DataSource = CompletedTrips.Tables[0];
                    gridview_completed_trip.DataBind();
                    for (int i = 0; i < CompletedTrips.Tables[0].Rows.Count; i++)
                    {
                        status= Convert.ToString( CompletedTrips.Tables[0].Rows[i]["Status"]);
                        pnrSt = Convert.ToString(CompletedTrips.Tables[0].Rows[i]["Confirmationid"]);
						 totPass = Convert.ToInt32(CompletedTrips.Tables[0].Rows[i]["totalnoofpass"]);
                        incan = Convert.ToInt32(CompletedTrips.Tables[0].Rows[i]["incancel"]);
                        Label lblstatus = (Label)gridview_completed_trip.Rows[i].FindControl("lbl_status_upcoming");
                        Button btnstatus = (Button)gridview_completed_trip.Rows[i].FindControl("btnpending");
                        LinkButton linkP = (LinkButton)gridview_completed_trip.Rows[i].FindControl("linkprint");
                        LinkButton linkC = (LinkButton)gridview_completed_trip.Rows[i].FindControl("linkcancel");                   
                        if (status == "Pending")
                        {
                            lblstatus.Visible = false;
                            btnstatus.Visible = true;
                        }
                        else if (status == "SUCCESS")
                        {
                            lblstatus.Text = "Success";
                        }
                        else
                        {
                            lblstatus.Visible = true;
                            btnstatus.Visible = false;
                        }
                        if (pnrSt == "" || status=="Refunded")
                        {
                             if (totPass > incan)
                            {
                                linkP.Enabled = true;
                                linkC.Enabled = true;
                            }
                            else
                            {
                                linkP.Enabled = false;
                                linkC.Enabled = false;
                            }
                        }
                    }
                }


                //btnflight.Style.Add("background", "#c02d3d");
                //btnflight.Style.Add("box-shadow", "0 0 3px #333");
                //btnflight.Style.Add("color", "white");
            }

           
        }

        catch (Exception ex)
        {
            AirEpointSupport ob = new AirEpointSupport();
            ob.WriteToLog(ex.Message, "AllCompletedTrips", "page_load__" + Convert.ToString(Session["agid"]));
            Response.Redirect("../User/index.aspx?s=exception");
        }

    }
    protected void btnFltsbtn_Click(object sender, EventArgs e)
    {
        DataSet CompletedTrips = new DataSet();
        string status = string.Empty;
        string pnrSt = string.Empty;
        //CompletedTrips = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_get_completed_trips_lavi", new SqlParameter[] { new SqlParameter("@UserID", Convert.ToString(Session["agid"])) });
       // CompletedTrips = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2Bflight_get_All_Booking_trips_W@r10ck_New", new SqlParameter[] { new SqlParameter("@UserID", Convert.ToString(Session["agid"])), new SqlParameter("@fromdate", Convert.ToString(txtFlightfrom.Text.Trim())), new SqlParameter("@todate", Convert.ToString(txtFlightto.Text.Trim())) });
        CompletedTrips = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "B2B_get_Booking_trips_alok_new", new SqlParameter[] { new SqlParameter("@UserID", Convert.ToString(Session["agid"])), new SqlParameter("@fromdate", Convert.ToString(txtFlightfrom.Text.Trim())), new SqlParameter("@todate", Convert.ToString(txtFlightto.Text.Trim())) });
        if (CompletedTrips.Tables.Count > 0)
        {
            gridview_completed_trip.DataSource = CompletedTrips.Tables[0];
            gridview_completed_trip.DataBind();

            for (int i = 0; i < CompletedTrips.Tables[0].Rows.Count; i++)
            {
                status = Convert.ToString(CompletedTrips.Tables[0].Rows[i]["Status"]);
                pnrSt = Convert.ToString(CompletedTrips.Tables[0].Rows[i]["Confirmationid"]);
                Label lblstatus = (Label)gridview_completed_trip.Rows[i].FindControl("lbl_status_upcoming");
                Button btnstatus = (Button)gridview_completed_trip.Rows[i].FindControl("btnpending");
                LinkButton linkP = (LinkButton)gridview_completed_trip.Rows[i].FindControl("linkprint");
                LinkButton linkC = (LinkButton)gridview_completed_trip.Rows[i].FindControl("linkcancel");
                if (status == "Pending")
                {
                    lblstatus.Visible = false;
                    btnstatus.Visible = true;
                }
                else if (status == "SUCCESS")
                {
                    lblstatus.Text = "Success";
                }
                else
                {
                    lblstatus.Visible = true;
                    btnstatus.Visible = false;
                }
                if (pnrSt == "" || status == "Refunded")
                {
                    linkP.Enabled = false;
                    linkC.Enabled = false;
                }
            }
        }


    }
   
   
    protected void gridview_completed_trip_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            string partnerrefid = Convert.ToString(e.CommandArgument);
            
            if (e.CommandName == "print")
            {
                AirEpointSupport obj_airsupport = new AirEpointSupport();
                string FlightType = obj_airsupport.getFlightType(partnerrefid,Convert.ToString(Session["HURL"]));
                string API_Provider = obj_airsupport.getAPIProvider(partnerrefid, Convert.ToString(Session["HURL"]));
                Session["partnerrefidtransaction"] = partnerrefid;
                if (FlightType == "DOM")
                {                  
                        Response.Redirect("../Transaction/Ticket_H.aspx", false);                  
                }
                else if (FlightType == "INAIR")
                {                  
                        Response.Redirect("../Transaction/InternationalTicket_H.aspx", false);                 
                }
            }
            if (e.CommandName == "cancelreq")
            {
                AirEpointSupport obj_airsupport = new AirEpointSupport();
                string FlightType = obj_airsupport.getFlightType(partnerrefid, Convert.ToString(Session["HURL"]));
                Session["partnerrefidtransaction"] = partnerrefid;
                 string API_Provider = obj_airsupport.getAPIProvider(partnerrefid, Convert.ToString(Session["HURL"]));
                 if (FlightType == "DOM")
                {
                   
                        Response.Redirect("../Transaction/Cancel_H.aspx", false);
                  
                }
                else if (FlightType == "INAIR")
                {
                  
                        Response.Redirect("../Transaction/InternationalCancel_H.aspx", false);
                   
                }
                //Page.ClientScript.RegisterStartupScript(this.GetType(), "aks", "window.open('policy.aspx','Lavi','height=300, width = 450')", true);

            }
            if (e.CommandName == "findstatus")
            {
                AirEpointSupport obj_airsupport = new AirEpointSupport();
                string FlightType = obj_airsupport.getFlightType(partnerrefid, Convert.ToString(Session["HURL"]));
                Session["partnerrefidtransaction"] = partnerrefid;
               // GetEticket_Status();
                Response.Redirect("Fltbookingdetails.aspx");
            }
        }
        catch (Exception ex)
        {
            AirEpointSupport ob = new AirEpointSupport();
            ob.WriteToLog(ex.Message, "AllUpcomingTrips", "gridview_upcoming_trip_RowCommand__" + Convert.ToString(Session["user_id"]));
            Response.Redirect("../User/index.aspx?s=exception");
        }
    }

   


    public override void VerifyRenderingInServerForm(Control control)
    {
        /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
           server control at run time. */
    }
   
}