using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                         Started Date  : 14-jun-2008
* Module          : Employee Type                                     Last Modified : 14-jun-2008
* Programmer      : Senthil Kumar NP
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_EmployeeTypeModify : Base.BasePage
{
    ResourceManager rm;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    cls_Common objcls_Common = new cls_Common();
    CultureInfo ci;
    string strSetAlert;
    DataSet ds_Checkuser = new DataSet();
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        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;
        LoadStrings(ci);
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        //Set UserRights
        UserRights();
        if (!IsPostBack)
        {
            objcls_Common.menu("EmployeeMaster", "95");
            //btn_save.OnClientClick = "if(Page_ClientValidate()) return confirm('"+ rm.GetString("Alert_ConfirmSave",ci) +"');return false;";
            if (Request.QueryString["TypeID"] != null)
            {
                int TypeID;
                TypeID = Convert.ToInt32(Request.QueryString["TypeID"]);
                TypeEventData Cat = new TypeEventData();
                DataSet ds = new DataSet();
                ds = Cat.SelectType(TypeID);
                if (ds != null)
                {
                    if (ds.Tables.Count > 0)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            if (ds.Tables[0].Rows[0]["TypeName"] != DBNull.Value)
                            {
                                txtType.Text = Convert.ToString(ds.Tables[0].Rows[0]["TypeName"]);
                                string selectScript = objcls_Common.SelectAll(txtType);
                                if (Convert.ToBoolean(ds.Tables[0].Rows[0]["IsFlexible"]))
                                {
                                    rbtnFlexibleYes.Checked = true;
                                }
                                else
                                {
                                    rbtnFlexibleNo.Checked = true;
                                }
                                RegisterStartupScript("SelectScript", selectScript);
                            }
                        }
                    }
                }
            }
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
            // focus to first control
            //txtType.Focus();
        }
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(95, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
        else
        {
            //   
        }
    }
    protected void btn_save_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["TypeID"] != null)
        {
            int TypeID;
            TypeID = Convert.ToInt32(Request.QueryString["TypeID"]);
            string TypeName = Convert.ToString(txtType.Text.Trim().Replace("'", "''"));
            bool IsFlexible = false;
            if (rbtnFlexibleYes.Checked == true)
            {
                IsFlexible = true;
            }
            DataSet ds = new DataSet();
            TypeEventData Cat = new TypeEventData();
            ds = Cat.CheckDuplicate("U", TypeName, TypeID);
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    //lblError.Text = "Employee Type Already Exists";
                    //base.Message(rm.GetString("Alert_EmployeeTypealreadyexists",ci));
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_EmployeeTypealreadyexists", ci) + "');", true);
                }
                else
                {
                    Cat.InsertUpdate("U", txtType.Text.Trim().Replace("'", "''"), Convert.ToString(Session["EmpAutoID"]), TypeID, IsFlexible);
                    //string str = "alert('"+ rm.GetString("Alert_EmployeeTypemodifiedsuccessfully",ci)+"');location.replace('TA_UI_Master_EmployeeTypelist.aspx')";
                    //Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
                    string strScript = "";
                    strScript = strScript + "<script language='javascript'>";
                    strScript = strScript + "alert('" + rm.GetString("Alert_EmployeeTypemodifiedsuccessfully", ci) + "');";
                    strScript = strScript + "location.replace('TA_UI_Master_EmployeeTypelist.aspx');";
                    strScript = strScript + "</script>";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
                }
            }
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Type.Text = rm.GetString("Master_Type", ci);
        lbl_Header.Text = rm.GetString("Master_Type", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        btn_save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        RequiredFieldValidator3.ErrorMessage = rm.GetString("Validator_EnterType", ci);
        lblFlexibleTimings.Text = rm.GetString("FlexibleTimings", ci);
        rbtnFlexibleYes.Text = rm.GetString("Yes", ci);
        rbtnFlexibleNo.Text = rm.GetString("Grid_False", ci);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_EmployeeTypelist.aspx");
    }
}
