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 : 16-Aug-2007
* Programmer      : Arun Vinoth.T
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_CountryModify : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    cls_Common objcommon = new cls_Common();
    string strSetAlert;
    int CID;
    int EmpID;
    GenericEventdata objgeneric = new GenericEventdata();
    #endregion
    #region PageLoad
    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();
        CID = Convert.ToInt32(Request.QueryString["ID"]);
        txt_CountryName.Focus();
        btn_save.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_ConfirmSave", ci) + "');return false;"; ;
        if (!IsPostBack)
        {
            DataSet ds = new DataSet();
            string userGroupName = string.Empty;
            userGroupName = Convert.ToString(Session["UserGroupName"]);
            ds = objgeneric.Getcountry(CID, userGroupName);
            txt_CountryName.Text = ds.Tables[0].Rows[0]["country"].ToString();
            ds.Dispose();
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
            objcommon.menu("EmployeeMaster", "225");
        }
    }
    #endregion
    #region ButtonEvents
    protected void btn_save_Click(object sender, EventArgs e)
    {
        string country = txt_CountryName.Text.Trim().Replace("'", "''");
        int CountryCount = objgeneric.CheckCountryInsertUpdate("M", CID, country);
        if (CountryCount > 0)
        {
            base.Message(rm.GetString("Masters_Generic_Country_Already_Declared", ci));
        }
        else
        {
            objgeneric.Updatecountry(CID, country, EmpID);
            //Todo: Karthikeyan URL Changed
            string str = "alert('" + rm.GetString("Alert_Countrymodifiedsuccessfully", ci) + "');location.replace('TA_UI_Master_CountryList.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        //Response.Redirect("TA_UI_Master_CountryView.aspx?ID=" + Request.QueryString["ID"]);
        Response.Redirect("TA_UI_Master_CountryList.aspx");
    }
    #endregion
    #region UserDefinedFunctions
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_CountryName.Text = rm.GetString("Country_Name", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        RequiredFieldValidator3.ErrorMessage = rm.GetString("Validator_Country_Country", ci);
        lbl_HeaderCountry.Text = rm.GetString("Masters_Generic_Country", ci);
        btn_save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(225, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    #endregion
}