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          : Level Settings                              Last Modified : 14-Aug-2007
* Programmer      : Senthil Kumar NP
* BackUp          :
****************************************************************************************************************************/
public partial class Organization_Settings_Organization_levelAdd : Base.BasePage
{
    #region Global Variable Declration
    ResourceManager objResourceManager;
    CultureInfo objCultureInfo;
    cls_Common objcommon = new cls_Common();
    #endregion
    #region Page load
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        // lblErr.Visible = false;
        string strSourceLanguage;
        strSourceLanguage = Convert.ToString(Session["Session_ActiveLanguage"]);
        objResourceManager = new ResourceManager(strSourceLanguage, System.Reflection.Assembly.Load("App_GlobalResources"));
        objCultureInfo = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(objCultureInfo);
        if (!IsPostBack)
        {
            objcommon.menu("OrgSettings", "47");
            txtLevelName.Focus();
            btnAdd.OnClientClick = "if(Page_ClientValidate()) return confirm('" + objResourceManager.GetString("Alert_AreyousuretoAddChildLevel", objCultureInfo) + "');return false;";
        }
    }
    #endregion
    #region Button Add click
    protected void butAdd_Click(object sender, EventArgs e)
    {
        int intParentLevelID = Convert.ToInt16(Session["levelid"]);
        if (intParentLevelID == 0)
        {
            intParentLevelID = 0;
        }
        levelsEventData lvInsert = new levelsEventData();
        DataSet dsLvInsert = new DataSet();
        dsLvInsert = lvInsert.insertNewLevel(this.txtLevelName.Text.Trim().Replace("'", "''"), intParentLevelID, Convert.ToString(Session["EmpAutoID"]));
        if (dsLvInsert.Tables[0].Rows.Count > 0)
        {
            if (dsLvInsert.Tables[0].Rows[0]["recCount"] != DBNull.Value)
            {
                if (Convert.ToInt16(dsLvInsert.Tables[0].Rows[0]["recCount"]) > 0)
                {
                    //lblErr.Visible = true;
                }
                else
                {
                    Session["levelid"] = null;
                    string str = "alert('" + objResourceManager.GetString("Alert_Level_Settings_Saved_Successfully", objCultureInfo) + "');location.replace('Organization_levels.aspx?sid=" + Session.SessionID + "');";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
                }
            }
        }
    }
    #endregion
    #region Load String from Resourcfile
    private void LoadStrings(CultureInfo ci)
    {
        //lblHeader.Text = objResourceManager.GetString("UserGroups_LevelSettings", ci);
        lblHeader.Text = objResourceManager.GetString("Org_Level_Settings", ci);
        lblLeavelName.Text = objResourceManager.GetString("LevelDetails_LevelName", ci);
        lbl_Man.Text = objResourceManager.GetString("IndicatesMandatoryFields", ci);
        RequiredFieldValidator1.ErrorMessage = objResourceManager.GetString("Req_Levelname", ci);
        btnAdd.Text = "&nbsp;&nbsp;" + objResourceManager.GetString("btn_Add_Child_Level", ci);
        //lblErr.Text = objResourceManager.GetString("Alert_Levelnamealreadyexits", ci);
        btnCancel.Text = "&nbsp;&nbsp;" + objResourceManager.GetString("btn_Back", ci);
        lblFilter.Text = objResourceManager.GetString("lblFilter", ci);
    }
    #endregion
    #region Cancel button click
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Organization_levels.aspx");
    }
    #endregion
}
