using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
/****************************************************************************************************************************
* 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_StateModify : Base.BasePage
{
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    int SID;
    int EmpID;
    GenericEventdata objgeneric = new GenericEventdata();
    cls_Common objCommon = new cls_Common();
    string strSetAlert;
    protected override void Page_Load(object sender, EventArgs e)
    {        
        //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();
        SID = Convert.ToInt32(Request.QueryString["ID"]);
        ddl_Country.Focus();
        //Todo: removed tostring option
        EmpID = Convert.ToInt32(Session["EmpAutoID"]);
        if (!IsPostBack)
        {
            DataSet ds = new DataSet();
            string userGroupName = string.Empty;
            userGroupName = Convert.ToString(Session["UserGroupName"]);
            ds = objgeneric.Getstate(SID, userGroupName);
            fillcountry();
            //Todo:Updated the convert functions
            ddl_Country.SelectedValue =Convert.ToString(ds.Tables[0].Rows[0]["countryID"]);
            txt_StateName.Text = Convert.ToString(ds.Tables[0].Rows[0]["state"]);
            ds.Dispose();
            btn_save.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", "226");
        }
    }
    protected void btn_save_Click(object sender, EventArgs e)
    {
        int country = Convert.ToInt32(ddl_Country.SelectedValue);
        string state = txt_StateName.Text.Trim().Replace("'", "''");
        int StateCount = objgeneric.CheckStateCityInsertUpdate("M", SID, state, country, 2);
        if (StateCount > 0)
        {
            //lblError.Text = rm.GetString("Masters_Generic_State_Already_Declared", ci);
            base.Message(rm.GetString("Masters_Generic_State_Already_Declared", ci));
        }
        else
        {
            objgeneric.Updatestate(SID, state, country, EmpID);
            string str = "alert('" + rm.GetString("Alert_Statemodifiedsuccessfully", ci) + "');location.replace('TA_UI_Master_StateList.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
            //Response.Redirect("TA_UI_Master_StateView.aspx?Id=" + SID);
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        //ToDo:
        //Response.Redirect("TA_UI_Master_StateView.aspx?ID=" + Request.QueryString["ID"]);
        Response.Redirect("TA_UI_Master_StateList.aspx");
    }
    //fill country dropdown
    private void fillcountry()
    {
        DataSet ds_country = new DataSet();
        string userGroupName = string.Empty;
        ds_country = objgeneric.Getcountries(userGroupName);
        if (ds_country.Tables[0].Rows.Count > 0)
        {
            ddl_Country.DataSource = ds_country;
            ddl_Country.DataTextField = "country";
            ddl_Country.DataValueField = "ID";
            ddl_Country.DataBind();
        }
        ds_country.Dispose();
        foreach (ListItem item in ddl_Country.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_CountryName.Text = rm.GetString("Country_Name", ci);
        lbl_StateName.Text = rm.GetString("State_Name", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("Validator_State_CountryName", ci);
        RequiredFieldValidator3.ErrorMessage = rm.GetString("Validator_State_StateName", ci);
        lbl_HeaderState.Text = rm.GetString("Masters_Generic_State", ci);
        btn_save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        ddl_Country.Items[0].Text = rm.GetString("Select", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(226, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
        else
        {
            //   
        }
    }
}
