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 Admin_MyProfile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["AdminEMAILID"] == null)
            {
                Response.Redirect("AdminLogin.aspx");
            }
            else
            {
                userdetails();
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }

    public void userdetails()
    {
        try
        {
            SqlParameter[] get_user_details = new SqlParameter[]
            {
                new SqlParameter("@EMAILID",Session["EMAILID"].ToString()),
            };
            SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_USERDETAILS_ADMIN", get_user_details);
            if (dr.Read())
            {
                txtName.Text = Convert.ToString(dr["NAME"]);
                txtEmailId.Text = Convert.ToString(dr["EMAILID"]);                
                txtMobileNo.Text = Convert.ToString(dr["MobileNo"]);
                ViewState["id"] = Convert.ToString(dr["id"]);
            }
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem. Please try again');"), true);
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            SqlParameter[] updateadminuserprofile = new SqlParameter[]
            {
                new SqlParameter("@Name",txtName.Text),
                new SqlParameter("@Emailid",txtEmailId.Text),
                new SqlParameter("@Mobileno", txtMobileNo.Text),
                new SqlParameter("@ID",ViewState["id"].ToString())
            };
            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_changeAdminUserDetail", updateadminuserprofile);
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('Profile update Successfully');"), true);
        }
        catch (Exception ex)
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem. Please try again');"), true);
            throw (ex);
        }
    }
    
}

