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.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Drawing;

public partial class masterpage_MasterPage : System.Web.UI.MasterPage
{
    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)
            {
                Permission = "N";
                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
            {
                Permission = "Y";
                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();
            usertype = Session["USERTYPE"].ToString();
            Category_Name();
            if (!IsPostBack)
            {
                userdetails();
                getmessage();
            }
            if (Session["USERTYPE"].Equals("Agent"))
            {
                hMynetworkWL.Visible = false;
                ulMyNetworkWL.Visible = false;
                hMynetworkMDS.Visible = false;
                ulMyNetworkMDS.Visible = false;
                hMynetworkDS.Visible = false;
                ulMyNetworkDS.Visible = false;
                hMyAccountDS.Visible = false;
                ulMyAccountDS.Visible = false;
                hMyAccountWL.Visible = false;
                ulMyAccountWL.Visible = false;
                hMyProfileWLMDS.Visible = false;
                ulMyProfileWLMDS.Visible = false;
                hSupportDeskWL.Visible = false;
                ulSupportDeskWL.Visible = false;
                lnkbtnNewDMRPay.Visible = true;
                lnkbtnNewDMRPay.NavigateUrl = "../Agent/MoneyTransferPay.aspx";
				lnkbtnNewDMRPay.Visible = false;
                link_flight.Visible = false;
               lnk_Utility.Visible = false;
                hMyAccountDiv.Visible = false;
                ulMyAccountDiv.Visible = false;

            }
            else if (Session["USERTYPE"].Equals("Distributor"))
            {
                hMynetworkWL.Visible = false;
                ulMyNetworkWL.Visible = false;
                hMynetworkMDS.Visible = false;
                ulMyNetworkMDS.Visible = false;
                hMyAccountAgent.Visible = false;
                ulMyAccountAgent.Visible = false;
                hMyAccountWL.Visible = false;
                ulMyAccountWL.Visible = false;
                hMyProfileWLMDS.Visible = false;
                ulMyProfileWLMDS.Visible = false;
                hSupportDeskWL.Visible = false;
                ulSupportDeskWL.Visible = false;
                link_dmr.Visible = false;
                hMyServices.Visible = false;
                ulMyServices.Visible = false;
                hMyAccountDiv.Visible = false;
                ulMyAccountDiv.Visible = false;
            }
            else if (Session["USERTYPE"].Equals("Master Distributor"))
            {
                hMyServices.Visible = false;
                ulMyServices.Visible = false;
                hMynetworkDS.Visible = false;
                ulMyNetworkDS.Visible = false;
                hMyAccountAgent.Visible = false;
                ulMyAccountAgent.Visible = false;
                hMyAccountDS.Visible = false;
                ulMyAccountDS.Visible = false;
                hMynetworkWL.Visible = false;
                ulMyNetworkWL.Visible = false;
                hMyProfileWLMDS.Visible = false;
                ulMyProfileWLMDS.Visible = false;
                hSupportDeskWL.Visible = false;
                ulSupportDeskWL.Visible = false;
                hMyAccountDiv.Visible = false;
                ulMyAccountDiv.Visible = false;
            }
            else if (Session["USERTYPE"].Equals("Master Admin"))
            {
                hMyServices.Visible = false;
                ulMyServices.Visible = false;
                hMynetworkDS.Visible = false;
                ulMyNetworkDS.Visible = false;
                hMyAccountAgent.Visible = false;
                ulMyAccountAgent.Visible = false;
                hMyAccountDS.Visible = false;
                ulMyAccountDS.Visible = false;
                hMyProfileAGDS.Visible = false;
                ulMyProfileAGDS.Visible = false;
                hMynetworkMDS.Visible = false;
                ulMyNetworkMDS.Visible = false;
                hSupportDeskDSAG.Visible = false;
                ulSupportDeskDSAG.Visible = false;
                hMyAccountDiv.Visible = false;
                ulMyAccountDiv.Visible = false;
            }
            else if (Session["USERTYPE"].Equals("Division"))
            {
                hMyServices.Visible = false;
                ulMyServices.Visible = false;
                hMynetworkDS.Visible = false;
                ulMyNetworkDS.Visible = false;
                hMyAccountAgent.Visible = false;
                ulMyAccountAgent.Visible = false;
                hMyAccountDS.Visible = false;
                ulMyAccountDS.Visible = false;
                hMynetworkWL.Visible = false;
                ulMyNetworkWL.Visible = false;
                hMyProfileWLMDS.Visible = false;
                ulMyProfileWLMDS.Visible = false;
                hSupportDeskWL.Visible = false;
                ulSupportDeskWL.Visible = false;
                hMynetworkMDS.Visible = false;
                ulMyNetworkMDS.Visible = false;
                hMyAccountWL.Visible = false;
                ulMyAccountWL.Visible = false;
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
    public string GetElectricityVendor()
     {
        SqlParameter[] warlock = new SqlParameter[]
        {
            new SqlParameter("@Service","DMT"),
            new SqlParameter("@WLID",Convert.ToInt64(Session["WhitelabelId"]))
        };
        DataSet ds = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "Get_VendorList", warlock);
         if (ds.Tables[0].Rows.Count > 0)
         {
             return Convert.ToString(ds.Tables[0].Rows[0][0]);
         }
         else
             return "";
     }
    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 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["helpdeskmobileno"] = dr[1].ToString();
                    //Session["helpdeskemailid"] = dr[2].ToString();
                    //Session["copyright"] = dr[3].ToString();
                    Session["copy"] = Convert.ToString(dr["copyright"]);
                    Session["comp_name"] = Convert.ToString(dr["CompanyName"]);
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    private void Category_Name()
    {
        //int subcategory_id = (int)ViewState["SCat_Id"];
        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)
            {
                //Label1.Text = dr[0].ToString();
                bookPageTitle += dr["AgentPanelTitle"].ToString() + "/";
                string abcd = bookPageTitle;
                //sno = bookKeywords += dr["Keyword"].ToString();
                //description += dr["Description"].ToString();
            }

            HtmlMeta myMetaKeyWords = new HtmlMeta();
            // myMetaKeyWords.Name = "keywords";
            myMetaKeyWords.Name = description;
            string category = lbltest.Text.Trim();
            string categoryname = category;
            myMetaKeyWords.Content = sno;
            //myMetaKeyWords.Content = dr["Book_name"].ToString() + "by" + dr["PublishedBy"].ToString() + "," + categoryname + "," + AuthorName;
            Page.Header.Controls.Add(myMetaKeyWords);
        }
        //Response.Write("<meta name=" + description + " content=" + description + ">");
        getPageTitle();
    }
    private void getPageTitle()
    {
        bookPageTitle = ConfigurationManager.AppSettings["WebsiteUrl"] + " / " + bookPageTitle;
        Page.Title = bookPageTitle.ToString();
        Session["comp_name"] = bookPageTitle.ToString();
    }
    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");
    }
    protected void lnkbtnTrain_Click(object sender, EventArgs e)
    {
         ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", " alert('Please contact to Suppot for  Activate TRAIN SEAT BOOKING Service on your Portal.'); window.open('https://www.irctc.co.in/nget/train-search');", true);
    }
     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];
        
     }
}
