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 ChangePassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["LOGINID"] == null && Session["USERNAME"] == null)
            {
                Response.Redirect("../login.aspx");
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }
    
    protected void rbtnSubmit_Click(object sender, EventArgs e)
    {
        if (txt_Curt_Pwd.Text !="" && txt_newpwd.Text != "" && txt_conf_pwd.Text != "")
        {
            if (txt_newpwd.Text == txt_conf_pwd.Text)
            {
                try
                {
                    SqlParameter[] param = new SqlParameter[] 
                    {
                        new SqlParameter("@status", SqlDbType.Int, 4),
                        new SqlParameter("@LOGINID",Session["LOGINID"].ToString()),
                        new SqlParameter("@CurrentPwd", txt_Curt_Pwd.Text.Trim()),
                        new SqlParameter("@NEWPWD",txt_conf_pwd.Text.Trim()),
                    };
                    param[0].Direction = ParameterDirection.Output;
                    SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "udp_changepasswordPartner_TEST", param);
                    string Result = Convert.ToString(param[0].Value);
                    if (Result == "1")
                    {
                        lblMessage.Text = "Password Changed Successfully!!.";
                        lblMessage.ForeColor = Color.Blue;
                        CommonFunction.ClearControlValues(tblChangePwd);
                    }
                    else if (Result == "0")
                    {
                        lblMessage.Text = "Current Password is wrong. Please fill corrected password.";
                        lblMessage.ForeColor = Color.Red;
                    }
                }
                catch (Exception ex)
                {
                  //  Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OhCrap", String.Format("alert('There is some technical problem. Please try again');"), true);
                    throw (ex);
                }
            }
            else
            {
                lblMessage.Text = "New password and Confirm Password not matched";
                lblMessage.ForeColor = Color.Red;
            }
        }
    }
}
