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_GradeModify : Base.BasePage
{
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    string strSetAlert;
    cls_Common objcommon = new cls_Common();
    GenericEventdata objGeneric = new GenericEventdata();
    int GradeID;
    int EmpId;
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        EmpId = Convert.ToInt32(Session["EmpAutoID"].ToString());
        //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);
        //Set UserRights
        UserRights();
        txt_GradeName.Focus();
        GradeID = Convert.ToInt16(Request.QueryString["Id"]);
        if (!IsPostBack)
        {
            DataSet ds = new DataSet();
            string userGroupName = string.Empty;
            ds = objGeneric.Getgrade(GradeID, userGroupName);
            if (ds.Tables[0].Rows.Count > 0)
            {
                txt_GradeName.Text = ds.Tables[0].Rows[0]["Grade_Name"].ToString();
                ddl_Grade.SelectedValue = ds.Tables[0].Rows[0]["Grade_Level"].ToString();
            }
            ds.Dispose();
            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");
        }
    }
    protected void btn_add_Click(object sender, EventArgs e)
    {
        string grade = txt_GradeName.Text.Trim().Replace("'", "''");
        int level = Convert.ToInt16(ddl_Grade.SelectedValue);
        //Check Grade Name already eixsts or not
        int count = objGeneric.CheckGradeName_Updates(GradeID, grade);
        if (count > 0)
        {
            //lbl_Error.Text = rm.GetString("Masters_Generic_Grade_Already_Declared", ci);
            base.Message(rm.GetString("Masters_Generic_Grade_Already_Declared", ci));
            return;
        }
        objGeneric.UpdateGrade(GradeID, grade, level, EmpId);
        //Response.Redirect("TA_UI_Master_GradeView.aspx?ID=" + GradeID);
        string strRedirectPage = "TA_UI_Master_GradeList.aspx";
        base.MessageWithRedirect(rm.GetString("Alert_Grademodifiedsuccessfully", ci), strRedirectPage);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_GradeList.aspx");
    }
    //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"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
        else
        {
            //   
        }
    }
}
