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          : User Group Master                                    Last Modified : 21-Aug-2007
* Programmer      : Senthil Kumar NP
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_groupAdd : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    CultureInfo ci;
    userRightsEventData usrRights = new userRightsEventData();
    cls_Common objcommon = new cls_Common();
    int payrollConfig = 0;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, 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"]);
        if (!IsPostBack)
        {
            LoadStrings(ci);
            txt_groupName.Focus();
            btn_save.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_ConfirmSave", ci) + "');return false;";
            objcommon.menu("Previlege", "21");
        }
        /*Added New parameter(Max Days/Month)for Angler. For this we are checking whether the payroll configuration page is exists or not*/
        if (ViewState["payrollConfig"] != null)
        {
            payrollConfig = (int)ViewState["payrollConfig"];
        }
        else
        {
            payrollConfig = objcommon.CheckPageExistsInLicense(185);
        }
        /*Below parameter is used for Angler*/
        if (payrollConfig == 0)
        {
            //divReportsBasedOn.Style.Add("display", "none");
            divAllowLeavePastEntry.Style.Add("display", "none");
        }
    }
    #endregion
    #region ButtonEvents
    protected void btn_cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_groupView.aspx");
    }
    protected void rbtnIndUsers_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        if (Convert.ToString(rbtnIndUsers.SelectedValue) == "Yes")
        {
            cbSpecialRights.Text = rm.GetString("EntryforPastDays_Leave_Permission_Individual", ci);
        }
        else
        {
            cbSpecialRights.Text = rm.GetString("EntryforPastDays_Leave_Permission", ci);
        }
    }
    protected void btn_save_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        ds = usrRights.checkDuplication(this.txt_groupName.Text.Trim().Replace("'", "''"));
        int intIndividualUsers = 0;
        int intReportsBasedOn = 0;
        if (rbtnIndUsers.Items[0].Selected == true)
        {
            intIndividualUsers = 1;
        }
        int SpecialRights = 0;
        if (cbSpecialRights.Checked)
        {
            SpecialRights = 1;
        }
        if (rblReportsBasedOn.Items[1].Selected)
        {
            intReportsBasedOn = 1;
        }
        int AllowLeaveApprovalPastEntry = 0;
        if (cbAllowLeaveApprovalPastEntry.Checked)
        {
            AllowLeaveApprovalPastEntry = 1;
        }
        if (ds.Tables[0].Rows.Count > 0)
        {
            base.Message(rm.GetString("Alert_Groupnamealreadyexists", ci));
        }
        else
        {
            usrRights.insertUserGroup("I", 0, Convert.ToString(this.txt_groupName.Text.Replace("'", "''").Trim()), 0, intIndividualUsers, SpecialRights, Convert.ToString(Session["EmpAutoID"]), DateTime.Now, intReportsBasedOn, AllowLeaveApprovalPastEntry);
            string str = "alert('" + rm.GetString("Alert_SavedSuccessfully", ci) + "');location.replace('TA_UI_Master_groupView.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
    }
    #endregion
    #region UserDefinedFunctions
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_GroupName.Text = rm.GetString("AddGroups_GroupName", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        Req_LeaveType.ErrorMessage = rm.GetString("Validator_AddGroups_GroupName", ci);
        lbl_HeaderAddGroups.Text = rm.GetString("Menu_Masters_UserGroups", ci);
        btn_save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        lblIndividualUser.Text = rm.GetString("Individual_Users", ci);
        lblSpecialRights.Text = rm.GetString("Special_Rights", ci);
        //lblEnterForPastDays.Text = rm.GetString("EntryforPastDays_Leave_Permission", ci);
        rbtnIndUsers.Items[0].Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnIndUsers.Items[1].Text = rm.GetString("ShiftSetting_No", ci);
        cbSpecialRights.Text = rm.GetString("EntryforPastDays_Leave_Permission", ci);
        cbAllowLeaveApprovalPastEntry.Text = "Allow Leave Approval for past days";
    }
    #endregion
}