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          : 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_groupView : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objcommon = new cls_Common();
    string strSetAlert;
    int dashboard = 0;
    string source_Language;
    #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
        grdViewUserGroup.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        if (!Page.IsPostBack)
        {
            objcommon.menu("Previlege", "21");
            LoadStrings(ci);
            site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "','" + rm.GetString("Alert_AreyousuretoDelete", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
            CheckUserRights();
        }
        grdViewUserGroup.DataSourceID = ObjectDataSource1.ID;
    }

    private void CheckUserRights()
    {
        Cls_CheckUser chck = new Cls_CheckUser();
        DataSet ds = chck.checkRights(21, Convert.ToInt32(Session["userGroup_Id"]), " ");
        if (ds.Tables[0].Rows.Count > 0)
        {
            if (ds.Tables[0].Rows[0]["addPrv"] != DBNull.Value && Convert.ToInt32(ds.Tables[0].Rows[0]["addPrv"]) == 1)
            {
                this.btn_add.Visible = true;
            }
            else
            {
                this.btn_add.Visible = false;
            }
        }
        else
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    #endregion
    #region UserDefinedFunctions
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_HeaderUserGroups.Text = rm.GetString("Menu_Masters_UserGroups", ci);
        btn_add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        grdViewUserGroup.Columns[0].Caption = rm.GetString("AddGroups_GroupName", ci);
        //grdViewUserGroup.Columns[0].HeaderText = rm.GetString("AddGroups_GroupName", ci);
        lbl_GroupName.Text = rm.GetString("AddGroups_GroupName", ci);
        btn_Search.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Search", ci);
        btn_Clear.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Clear", ci);
        lblFilter.Text = rm.GetString("lblFilter", ci);
    }
    private void FillGrid_Search()
    {
        string strGroupName = txt_GroupName.Text.Trim();
        txt_GroupName.Text = strGroupName;
        if (strGroupName == string.Empty)
        {
            base.Message(rm.GetString("Alert_Pleasetypethegroupnametosearch", ci));
            //grdViewUserGroup.Columns.Clear();
            txt_GroupName.Focus();
        }
        else
        {
            grdViewUserGroup.DataSourceID = ObjectDataSource1.ID;
        }
    }
    public void GetEmptyText(object sender, EventArgs e)
    {
        Label lblNoRecords = (Label)sender;
        lblNoRecords.Text = rm.GetString("Alert_Norecordsfound", ci);
    }
    #endregion
    #region ButtonEvents
    protected void btn_Clear_Click(object sender, EventArgs e)
    {
        //Restores the Default view of the grid
        txt_GroupName.Text = string.Empty;
        grdViewUserGroup.DataSourceID = ObjectDataSource1.ID;
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        //fill gridview based on search details given in textbox
        FillGrid_Search();
    }
    protected void btn_add_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_groupAdd.aspx?sid=" + Session.SessionID);
    }
    #endregion
    #region GridviewEvents



    protected void grdViewUserGroup_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
        if (e.RowType == DevExpress.Web.GridViewRowType.Data)
        {
            source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
            rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
            ci = Thread.CurrentThread.CurrentCulture;
            dashboard = objcommon.CheckPageExistsInLicense(179);
            Label lbldashboard = (Label)grdViewUserGroup.FindRowCellTemplateControl(e.VisibleIndex, null, "lblDashboard");
            Label lblslash = (Label)grdViewUserGroup.FindRowCellTemplateControl(e.VisibleIndex, null, "lblslash");
            if (dashboard == 0)
            {
                if (lbldashboard != null)
                    lbldashboard.Visible = false;
                if (lblslash != null)
                    lblslash.Visible = false;
            }
            int gid = Convert.ToInt32(e.GetValue("groupId"));
            userRightsEventData delUserGrp = new userRightsEventData();
            DataSet ds = new DataSet();
            ds = delUserGrp.CheckUserGroupForDel(gid, "C");
            Label lbl = (Label)grdViewUserGroup.FindRowCellTemplateControl(e.VisibleIndex, null, "lblDele");
            Label lblSep = (Label)grdViewUserGroup.FindRowCellTemplateControl(e.VisibleIndex, null, "lblSep");
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["recCount"] != DBNull.Value)
                {
                    if (Convert.ToInt16(ds.Tables[0].Rows[0]["recCount"]) > 0)
                    {
                        if (lbl != null)
                            lbl.Visible = false;
                        if (lblSep != null)
                            lblSep.Visible = false;
                    }
                    else if (lblSep != null)
                    {
                        lblSep.Text = "/";
                    }
                }
            }
            Label lblEditLevel = (Label)grdViewUserGroup.FindRowCellTemplateControl(e.VisibleIndex, null, "lblEditLevel");
            if (lblEditLevel != null)
            {
                lblEditLevel.Text = rm.GetString("LevelWiseRights", ci);
                lblEditLevel.ToolTip = rm.GetString("lblEditLevelwiseRights", ci);
            }
            Label lblHId = (Label)grdViewUserGroup.FindRowCellTemplateControl(e.VisibleIndex, null, "lblHId");
            if (lblHId != null)
            {
                lblHId.ToolTip = rm.GetString("lblEditgrouprights", ci);
            }
            Label lblEdit = (Label)grdViewUserGroup.FindRowCellTemplateControl(e.VisibleIndex, null, "lblEdit");
            if (lblEdit != null)
            {
                lblEdit.Text = rm.GetString("ModuleRights", ci);
                lblEdit.ToolTip = rm.GetString("ModuleRightsTooltip", ci);
            }
            Label lblDashboard = (Label)grdViewUserGroup.FindRowCellTemplateControl(e.VisibleIndex, null, "lblDashboard");
            if (lblDashboard != null)
            {
                lblDashboard.Text = rm.GetString("DashboardRights", ci);
                lblDashboard.ToolTip = rm.GetString("DashboardRightsTooltip", ci);
            }
            Label lblAssignedText = (Label)grdViewUserGroup.FindRowCellTemplateControl(e.VisibleIndex, null, "lblAssignedText");
            if (lblAssignedText != null)
            {
                lblAssignedText.Text = rm.GetString("AssignedTo", ci);
                lblAssignedText.ToolTip = rm.GetString("AssignedToTooltip", ci);
            }
            Label lblDele = (Label)grdViewUserGroup.FindRowCellTemplateControl(e.VisibleIndex, null, "lblDele");
            if (lblDele != null)
            {
                lblDele.Text = rm.GetString("btn_Delete", ci);
                lblDele.ToolTip = rm.GetString("DeleteUsergroupTooltip", ci);
            }
            if (lblslash != null)
                lblslash.ToolTip = rm.GetString("lblEditgrouprights", ci);
            if (lblSep != null)
                lblSep.ToolTip = rm.GetString("lblEditgrouprights", ci);
        }
    }
    #endregion
}