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_CityModify : Base.BasePage
{
    #region VaribleDeclaration
    ResourceManager rm;
    CultureInfo ci;
    int CID;
    int EmpID;
    GenericEventdata objgeneric = new GenericEventdata();
    EmployeeEventData objEmployee = new EmployeeEventData();
    MultiLingualEventData objMultiLingualEventData = new MultiLingualEventData();
    DataSet dsEmployeeLingual = new DataSet();
    string source_Language;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    cls_Common objcommon = new cls_Common();
    string strSetAlert;
    #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
        dsEmployeeLingual = objMultiLingualEventData.GetEmployeeLingual(EmpID);
        if (dsEmployeeLingual.Tables[0].Rows.Count > 0)
        {
            source_Language = "Resources." + dsEmployeeLingual.Tables[0].Rows[0]["Resource_File_Name"].ToString();
            rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
            ci = Thread.CurrentThread.CurrentCulture;
            LoadStrings(ci);
        }
        else
        {
            source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
            rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
            ci = Thread.CurrentThread.CurrentCulture;
            LoadStrings(ci);
        }
        //Set UserRights
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        UserRights();
        CID = Convert.ToInt32(Request.QueryString["ID"]);
        ddl_Country.Focus();
        if (!IsPostBack)
        {
            DataSet ds = new DataSet();
            string userGroupName = string.Empty;
            userGroupName = Convert.ToString(Session["UserGroupName"]);
            ds = objgeneric.Getcity(CID, userGroupName);
            fillcountry();
            ddl_Country.SelectedValue = ds.Tables[0].Rows[0]["countryID"].ToString();
            fillstate(Convert.ToInt32(ddl_Country.SelectedValue));
            ddl_State.SelectedValue = ds.Tables[0].Rows[0]["stateID"].ToString();
            hdf_state.Value = ds.Tables[0].Rows[0]["stateID"].ToString();
            txt_CityName.Text = ds.Tables[0].Rows[0]["city"].ToString();
            ds.Dispose();
            btn_add.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_ConfirmSave") + "');return false;";
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "Alert_LookUp('" + rm.GetString("Alert_Errorretrievingdatafromlookup", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
            objcommon.menu("EmployeeMaster", "227");
        }
    }
    #endregion
    #region ButtonEvents
    protected void btn_add_Click(object sender, EventArgs e)
    {
        int state = Convert.ToInt32(hdf_state.Value);
        string city = txt_CityName.Text.Trim().Replace("'", "''");
        int CityCount = objgeneric.CheckStateCityInsertUpdate("M", CID, city, state, 3);
        if (CityCount > 0)
        {
            base.Message(rm.GetString("Masters_Generic_City_Already_Declared", ci));
        }
        else
        {
            objgeneric.Updatecity(CID, city, state, EmpID);
            string str = "alert('" + rm.GetString("Alert_Citymodifiedsuccessfully", ci) + "');location.replace('TA_UI_Master_CityList.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_CityList.aspx");
    }
    #endregion
    #region UserDefinedFunctions
    //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);
        }
    }
    //fill state ddl
    private void fillstate(int country)
    {
        DataSet ds = new DataSet();
        ds = objEmployee.SelectStates(country);
        if (ds.Tables[0].Rows.Count > 0)
        {
            ddl_State.DataSource = ds;
            ddl_State.DataTextField = "Title";
            ddl_State.DataValueField = "ID";
            ddl_State.DataBind();
        }
        ds.Dispose();
        foreach (ListItem item in ddl_State.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_CityName.Text = rm.GetString("City_Name", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("Validator_State_CountryName", ci);
        RequiredFieldValidator2.ErrorMessage = rm.GetString("Validator_City_State", ci);
        RequiredFieldValidator3.ErrorMessage = rm.GetString("Validator_City_City", ci);
        lbl_HeaderCity.Text = rm.GetString("Masters_Generic_City", ci);
        btn_add.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);
        ddl_State.Items[0].Text = rm.GetString("Select", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(227, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    #endregion
}