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

public partial class TrainService_Login : System.Web.UI.Page
{
    string WebsiteUrl;
    string bookPageTitle, bookKeywords, description, sno;
    protected void Page_Load(object sender, EventArgs e)
    {

        try
        {



            WebsiteUrl = HttpContext.Current.Request.Url.ToString();
            Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetNoStore();
            GetWhitelabelDetails();
            Category_Name();
            if (!IsPostBack)
            {
                //Session.Abandon();
                //Session.Clear();
                getmessage();
            }
        }
        catch (Exception ex)
        {
            throw (ex);

        }
    }

    protected void btn_submit_Click(object sender, EventArgs e)
    {
        try
        {


            login();
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }

    public void login()
    {
        if (txt_uname.Text != "" && txt_pwd.Text != "")
        {
            try
            {
                SqlParameter[] check_login_details = new SqlParameter[]
                {
                    new SqlParameter("@DomailName","http://venusrecharge.in"), 
                    new SqlParameter("@User_details",txt_uname.Text.Trim()),
                    new SqlParameter("@Password",txt_pwd.Text.Trim()),
                    new SqlParameter("@ErrorResult",SqlDbType.Int),
                };
                check_login_details[3].Direction = ParameterDirection.Output;
                DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_CHECK_USERLOGIN_DETAILS_New_WithOutUserType", check_login_details);
                int loginvariable = Convert.ToInt32(check_login_details[3].Value);
                if (loginvariable == 1)
                {
                    if (ds.Tables[0].Rows.Count != 0 & loginvariable == 1)
                    {
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            Session["LOGINID"] = dr[0].ToString();
                            Session["USERTYPE"] = dr[3].ToString();
                            Session["EMAILID"] = dr[2].ToString();
                            Session["MobileNo"] = dr[4].ToString();
                            Session["USERNAME"] = txt_uname.Text.Trim();
                            Session["PASSWORD"] = txt_pwd.Text.Trim();
                            //Session["DMRStatus"] = dr["DMRStatus"].ToString();
                            //Session["FlightStatus"] = dr["FLAGFLIGHT"].ToString();
                            Session["agency_name"] = dr["CORPORATENAME"].ToString();
                            if (Session["USERTYPE"].Equals("Agent"))
                            {
                                Response.Redirect("PaymentPage.aspx", false);
                            }
                            
                        }
                    }
                    else
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('You have entered invalid login details, please login with correct details.!');"), true);
                    }
                }
                if (loginvariable == 2)
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Your account has been deactivate. Please contact Helpdesk');"), true);
                }
                if (loginvariable == 3)
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('You are not authorize user for this portal. Please contact Helpdesk');"), true);
                }
            }
            catch (Exception ex)
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('You have entered invalid login details, please login with correct details.!');"), true);
                //throw (ex);
            }
        }
    }

    public void getmessage()
    {
        try
        {
            SqlParameter[] getmess = new SqlParameter[] { };
            SqlDataReader Dr = SqlHelper.ExecuteReader(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_ShowActiveMessage", getmess);

            if (Dr.Read())
            {
                lblmessage.Visible = true;
                lblheading.Text = Convert.ToString(Dr["msgHeading"]);
                lblmessage.Text = Convert.ToString(Dr["AddContent"]);
            }
            else
            {
                lblmessage.Visible = false;
            }
            Dr.Dispose();
        }
        catch (Exception ex)
        {
            lblerror.Text = "There is some technical error, Please try after some time";
            lblerror.ForeColor = Color.Red;
        }
    }

    private void GetWhitelabelDetails()
    {
        try
        {
            SqlParameter[] check_DomainName = new SqlParameter[]
            {
                new SqlParameter("@DomainName","http://venusrecharge.in")
            };
            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)
                {
                    Session["headerlogoimage"] = dr[0].ToString();
                    Session["helpdeskmobileno"] = dr[1].ToString();
                    Session["helpdeskemailid"] = dr[2].ToString();
                    Session["copyright"] = dr[3].ToString();
                    Session["HelpDeskMobileNoAlter"] = dr[4].ToString();
                    Session["WhitelabelId"] = dr[5].ToString();
                    Session["CompanyName"] = dr[6].ToString();
                    Session["PortalName"] = dr[7].ToString();
                    Session["agentimage"] = "~/images/logo.png";
                }
            }
            lblimage.Text = Session["headerlogoimage"].ToString();
        }
        catch (Exception ex)
        {

        }
    }

    private void Category_Name()
    {
        SqlParameter[] param_subscription = new SqlParameter[]
        {
            new SqlParameter("@domainname","http://venusrecharge.in"),
        };
        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 = "http://venusrecharge.in/" + bookPageTitle;
        Page.Title = bookPageTitle.ToString();
    }
}