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          : Generic Master                                    Last Modified : 21-Aug-2007
* Programmer      : Arun Vinoth.T
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_GradeAdd : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    string strSetAlert;
    GenericEventdata objGeneric = new GenericEventdata();
    cls_Common objcommon = new cls_Common();
    int EmpId;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        txt_GradeName.Focus();
        //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;
        LoadStrings(ci);
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        EmpId = Convert.ToInt32(Session["EmpAutoID"].ToString());
        if (!IsPostBack)
        {
            btn_add.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_ConfirmSave", ci) + "');return false;";
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
            objcommon.menu("EmployeeMaster", "228");
        }
        //Set UserRights
        UserRights();
    }
    #endregion
    #region ButtonEvents
    protected void btn_add_Click(object sender, EventArgs e)
    {
        string Grade = txt_GradeName.Text.Trim().Replace("'", "''");
        int Level = Convert.ToInt32(ddl_Grade.SelectedValue);
        int count = objGeneric.CheckGradeName_Insert(Grade);
        if (count > 0)
        {
            base.Message(rm.GetString("Masters_Generic_Grade_Already_Declared", ci));
            return;
        }
        objGeneric.InsertGrade(Grade, Level, EmpId);
        string str = "alert('" + rm.GetString("Alert_Gradesavedsuccessfully", ci) + "');location.replace('TA_UI_Master_GradeList.aspx');";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_GradeList.aspx");
    }
    #endregion
    #region UserDefinedFunctions
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_GradeName.Text = rm.GetString("Grade_GradeName", ci);
        lbl_GradeLevel.Text = rm.GetString("Grade_GradeLevel", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        RequiredFieldValidator2.ErrorMessage = rm.GetString("Validator_Grade_GradeName", ci);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("Validator_Grade_GradeLevel", ci);
        lbl_HeaderGrade.Text = rm.GetString("Masters_Generic_Grade", ci);
        btn_add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        ddl_Grade.Items[0].Text = rm.GetString("Select", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(228, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    #endregion
}