using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                   Started Date  : 12-Aug-2007
* Module          : Reset Password                              Last Modified : 14-Aug-2007
* Programmer      : Janakaraj.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class System_Settings_System_ResetPassword : Base.BasePage
{
    #region VariableDeclaration
    ResetPwd obj_ResetPwd = new ResetPwd();
    ManualEntryEventData objManualEntryEventData = new ManualEntryEventData();
    Email_Triggering objEmail = new Email_Triggering();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    string strSetAlert;
    string EmployeeCode = "";
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objcommon = new cls_Common();
    int Count = 0;
    int isTriggered = 0;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            txt_EmployeeId.Focus();
            objcommon.menu("Previlege", "55");
        }
        //get the culture info to set the language
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        btn_Reset1.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_AreyousuretoReset", ci) + "');return false;";
        //Call to a function to implement the UserRights
        UserRights();
        if (!Page.IsPostBack)
        {
            EmployeeCode = obj_ResetPwd.GetEmployeeCode();
            txt_EmployeeId.Text = EmployeeCode;
            ViewState["EmployeeCode"] = EmployeeCode;
            obj_ResetPwd.Delete_EmployeeDetails();
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
        }
    }
    #endregion
    #region ButtonEvents
    protected void btn_Reset1_Click(object sender, EventArgs e)
    {
        string EmpCode = txt_EmployeeId.Text;
        string strScript = "";
        DataSet ds_EmpName = new DataSet();
        ds_EmpName = objManualEntryEventData.SelectEmpName(Convert.ToInt32(Session["EmpAutoId"]), EmpCode, Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["GradeLevel"]), "", Convert.ToInt32(Session["parentLevelId"]), "");
        if (ds_EmpName != null)
        {
            if (ds_EmpName.Tables[0].Rows.Count == 0)
            {
                strScript = strScript + "<script language='javascript'>";
                strScript = strScript + "alert('" + rm.GetString("Alert_InvalidEmployeeCode", ci) + "')";
                strScript = strScript + "</script>";
                Page.RegisterStartupScript("Alert", strScript);
                txt_EmployeeId.Text = "";
                txt_EmployeeId.Focus();
                return;
            }
            ds_EmpName.Dispose();
        }
        Count = obj_ResetPwd.ResetPassword(EmpCode, "QL5OWbmiorXf+5GMDoaz1w==");
        strScript = strScript + "<script language='javascript'>";
        if (Count == 0)
        {
            strScript = strScript + "alert('" + rm.GetString("Alert_EmployeeIdnotfound", ci) + "')";
        }
        else
        {
            isTriggered = objEmail.PassingEmpDetailsAndModuleForEmailTriggering("ResetPassword", EmpCode);
            if (isTriggered == 0 || isTriggered == -1)
            {
                strScript = strScript + "alert('" + rm.GetString("ReqField_PwdChanged", ci) + "')";
            }
            else if (isTriggered == 1)
            {
                strScript = strScript + "alert('" + rm.GetString("ReqField_PwdChanged_Employee", ci) + "')";
            }
            else if (isTriggered == 2)
            {
                strScript = strScript + "alert('" + rm.GetString("ReqField_PwdChanged_MailServer", ci) + "')";
            }
        }
        strScript = strScript + "</script>";
        txt_EmployeeId.Text = "";
        txt_EmployeeId.Focus();
        //Dispaly alert messsage.
        Page.RegisterStartupScript("Alert", strScript);
    }
    #endregion
    #region UserDefinedFunctions
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_EmpId.Text = rm.GetString("email_EmployeeId", ci);
        lbl_Header.Text = rm.GetString("SystemSettings_ResetPassword_ResetPassword", ci);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("ReqField_EmpIds", ci);
        //btn_Search.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Search", ci);
        btn_Search.Text = "";
        btn_Reset1.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Reset", ci);
        lblMandatory.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lblResetPassword.Text = rm.GetString("SystemSettings_ResetPassword_ResetPassword", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(55, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("SystemLandingPage.aspx");
        }
    }
    #endregion
}