using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;

public partial class Agent_FlightNew : System.Web.UI.Page
{
    string usertype, Ipaddress;
    string bookPageTitle, bookKeywords, description, sno, Permission;

    
       

   
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["LOGINID"] == null && Session["USERTYPE"] == null)
            {
                Response.Redirect("../login.aspx");
            }
            GetWLDetails();
            DataTable dsInfo = GetDsCorporatedetails(Convert.ToString(Session["LOGINID"]), Convert.ToString(Session["USERTYPE"]));
            if (dsInfo.Rows.Count > 0)
            {
                
                Session["copyright"] = Convert.ToString(dsInfo.Rows[0]["Copyright"]);
                Session["helpdeskmobileno"] = Convert.ToString(dsInfo.Rows[0]["HelpDeskMobileNo"]);
                Session["helpdeskemailid"] = Convert.ToString(dsInfo.Rows[0]["HelpDeskEmailId"]);
                Session["HelpDeskMobileNoAlter"] = "";
                imglogo.ImageUrl = "../images/" + Convert.ToString(dsInfo.Rows[0]["LogoImage"]);
            }
            else
            {
                imglogo.ImageUrl = "../images/logo.png";
            }
            lblCopyRight.Text = Session["copyright"].ToString();
            lblMobileNo.Text = Session["helpdeskmobileno"].ToString();
            lblMobileNoAlt.Text = Session["HelpDeskMobileNoAlter"].ToString();
            lblEmailIdSupport.Text = Session["helpdeskemailid"].ToString();
            
            Category_Name();
            if (!IsPostBack)
            {
                userdetails();
                getmessage();
                FlightCredaintial();
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
   //public void FlightCredaintial()
    //{
      //  Session["fusername"] = "venus_utility";// 
      //  Session["password"] = "dmVudXNfdXRpbGl0eUAxMjM=";//"venus_utility@123";// 
       // Session["token"] = "eyJjaXR5IjogIkRFTEhJIiwiYWRkcmVzcyI6ICJVZHlvZyBWaWhhciIsInRpbWVzdGFtcCI6ICIyMDE4LTEwLTE1IDEyOjM1OjAwIn0 =";
    //}

    public void FlightCredaintial()
    {
        //Session["username"] = "venus_utility";// "testingaccount";
        //Session["password"] = "venus_utility@123";// "dGVzdGluZzEyMw ==";
        //Session["token"] = "eyJjaXR5IjogIkRFTEhJIiwiYWRkcmVzcyI6ICJVZHlvZyBWaWhhciIsInRpbWVzdGFtcCI6ICIyMDE4LTEwLTE1IDEyOjM1OjAwIn0 =";
        Session["fusername"] = "pwvenusutilitytravel";
        Session["password"] = "SmYkbC1RdEFLXTFKUmpP";
        Session["token"]=GenerateToken("Jharkhand");
    }

    public string GenerateToken(string City)
    {
        string timestamp1 = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        string json = new JavaScriptSerializer().Serialize(new
            {
                timestamp = timestamp1,
                address = City,
                city = City
        });
        byte[] byt = System.Text.Encoding.UTF8.GetBytes(json);

        return Convert.ToBase64String(byt);
    }
    public void userdetails()
    {
        try
        {
            lblUserType.Text = Session["USERTYPE"].ToString();
            SqlParameter[] get_user_details = new SqlParameter[]
            {
                new SqlParameter("@LOGINID",Session["LOGINID"].ToString())
            };

            SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_USERDETAILS", get_user_details);
            if (dr.Read())
            {
                lblAgentid.Text = Convert.ToString(dr["USERNAME"]);
                lblbalance.Text = Convert.ToString(dr["balance"]);
                lbl_title.Text = Convert.ToString(dr["title"]);
                lbl_FirstName.Text = Convert.ToString(dr["firstname"]);
                lbl_LastName.Text = Convert.ToString(dr["LASTNAME"]);
                lblUserType.Text = Convert.ToString(dr["USERTYPE"]);
                Session["agid"] = Session["USERNAME"].ToString();// Session["LOGINID"].ToString();
                Session["fagid"] = Convert.ToString(dr["USERNAME"]);
                Session["agent_amount"] = Convert.ToString(dr["balance"]);
                Session["agency_name"] = Convert.ToString(dr["title"]) + " " + Convert.ToString(dr["firstname"]) + " " + Convert.ToString(dr["LASTNAME"]);
            }
            dr.Close();
        }
        catch (Exception ex)
        {
            //string st = ex.Message;
            throw (ex);
        }
    }
    public void getmessage()
    {
        try
        {
            SqlParameter[] get_user_details = new SqlParameter[]
            {
                new SqlParameter("@LOGINID",Session["WhitelabelId"].ToString())
            };
            SqlDataReader Dr = SqlHelper.ExecuteReader(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_GETWHITELABELNOTIC", get_user_details);
            if (Dr.Read())
            {
                lblmessage.Visible = true;
                lblheading.Text = Convert.ToString(Dr["msgHeading"]);
                lblmessage.Text = Convert.ToString(Dr["AddContent"]);
            }
            else
            {
                lblmessage.Visible = false;
            }
            Dr.Close();
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
    private void Category_Name()
    {
        SqlParameter[] param_subscription = new SqlParameter[]
        {
            //new SqlParameter("@domainname",ConfigurationManager.AppSettings["WebsiteUrl"]),
        };

        DataSet objDs = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.Text, "select AgentPanelTitle from WhiteLebelCorporateDetail where courentlevel=" + Convert.ToInt32(Session["WhitelabelId"].ToString()) + "", null);
        if (objDs.Tables[0].Rows.Count != 0)
        {
            foreach (DataRow dr in objDs.Tables[0].Rows)
            {
                
                bookPageTitle += dr["AgentPanelTitle"].ToString() + "/";
                string abcd = bookPageTitle;
            }

            HtmlMeta myMetaKeyWords = new HtmlMeta();
            myMetaKeyWords.Name = description;
            string category = lbltest.Text.Trim();
            string categoryname = category;
            myMetaKeyWords.Content = sno;
            Page.Header.Controls.Add(myMetaKeyWords);
        }
        getPageTitle();
    }
    private void getPageTitle()
    {
        bookPageTitle = ConfigurationManager.AppSettings["WebsiteUrl"] + " / " + bookPageTitle;
        Page.Title = bookPageTitle.ToString();
        Session["comp_name"] = bookPageTitle.ToString();
    }
    public DataTable GetDsCorporatedetails(string LoginId, string UserType)
    {
        SqlParameter[] check_DomainName = new SqlParameter[]
          {
                new SqlParameter("@LoginID",LoginId),
                new SqlParameter("@Type",UserType)
          };

        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "usp_GetDsCorporateDetails", check_DomainName);
        return ds.Tables[0];

    }
    protected void linklogout_Click(object sender, EventArgs e)
    {
        SqlParameter[] parampartnerregistration = new SqlParameter[]
        {
            new SqlParameter("@LOGINID",Session["LOGINID"].ToString()),
        };
        SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_CHANGESTATUS", parampartnerregistration);
        Session.Abandon();
        Session.Clear();
        Response.Redirect("../login.aspx");
    }
    private void GetWLDetails()
    {
        try
        {
            SqlParameter[] check_DomainName = new SqlParameter[]
            {
                new SqlParameter("@DomainName",ConfigurationManager.AppSettings["WebsiteUrl"])
            };

            DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "usp_GetWhiteLabelDetails", check_DomainName);
            if (ds.Tables[0].Rows.Count != 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    lblimage.Text = dr[0].ToString();
                    Session["copy"] = Convert.ToString(dr["copyright"]);
                    Session["comp_name"] = Convert.ToString(dr["CompanyName"]);
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}