using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Configuration;
using MySql.Data.MySqlClient;
using MySql.Data;
using CLS_BL;
using CLS_DL;
using CLS_PL;
namespace SUNWEB
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        //TestT44
       
        BL_ErrorLog ObjLog = new BL_ErrorLog();
        BL_SELECT ObjSel = new BL_SELECT();
        BLCompany ObjBL = new BLCompany();
        PLCOMMON ObjPL = new PLCOMMON();
        BL_USER ObjUserBL = new BL_USER(); //This Object for All User and Page Related fuctions included 
        PLCUSTOMER ObjCustPL = new PLCUSTOMER();
        Int32 K = 0;
        Int32 L = 0;
        string ConStr = ConfigurationManager.ConnectionStrings["ConMysql"].ConnectionString;
        string Curr_Date = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        MYSQLDB ObjMain = new MYSQLDB();
        DataTable DT = new DataTable();
        DataTable Dt2 = new DataTable();
        DataTable DtEnduer = new DataTable();
        string UserId = string.Empty;
        string RoldPwd = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Session["UserName"] == null)
            {
                Response.Redirect("Login.aspx");
            }

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {


            if (txtNewPassword.Text.ToString().Trim() == txtRepeatPassword.Text.ToString().Trim())
            {
                UserId = Session["UserId"].ToString();
                RoldPwd = ObjMain.ExecuteScalar("select Password from portaldb.usermaster where userid=" + UserId + " ");
                if (RoldPwd == txtOldPassword.Text.ToString().Trim())
                {

                   K = ObjMain.ExecuteNonQuery("Update portaldb.usermaster set Password='" + txtNewPassword.Text.ToString().Trim() + "'  where userid=" + UserId + " ");


                  //  UserId = ObjMain.ExecuteScalar("select Userid from portaldb.Usermaster where UserName='" + Session["UserName"].ToString() + "' and Password='" + Session["Password"].ToString() + "' ");
                    UPTActiveUserid(UserId);

                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' Password Updated Successfuly  !  ');location.href='Login.aspx'", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert(' OldPasword is wrong !  ');", true);
                }



            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "err_msg", "alert('Pasword Mismatch ');", true);
            }




        }



        public void UPTActiveUserid(string UserId)
        {
            string ActiveVal = "0";
            L = ObjMain.ExecuteNonQuery("Update portaldb.Usermaster set  Active=" + ActiveVal + ", UPTTIME='" + Curr_Date + "' where   Userid=" + UserId + " ");

        }





    }
}