using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Resources;
using System.Globalization;
using System.Threading;

public partial class Organization_Settings_Organization_CCMailGroup : Base.BasePage
{

    ResourceManager rm;

    ShiftEvenData objShift = new ShiftEvenData();
    cls_Common objClassCommon = new cls_Common();
    CCGroupEventData_Angler objCcGroup = new CCGroupEventData_Angler();

    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    string gstrUserGroupName = string.Empty;
    protected override void Page_Load(object sender, EventArgs e)
    {

        // Session Checking
        base.Page_Load(sender, e);

        // Get the culture info to set the language
        if (!Page.IsPostBack)
        {
            //base.CheckPages(115);
        }

        CultureInfo ci;

        string source_Language;
        source_Language = Session["Session_ActiveLanguage"].ToString();
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);

        gstrUserGroupName = Session["UserGroupName"].ToString();
        txtSearch.Focus();

        if (!IsPostBack)
        {
            objClassCommon.menu("LeaveSettings", "240");
        }

        //Set UserRights
        //UserRights();
    }


    // Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        //lbl_Header.Text = rm.GetString("OrganisationSettings_ApprovalSettings", ci);
    }
   
    public void UserRights()
    {
        try
        {
            ds_Checkuser = objCheckUser.checkRights(115, Convert.ToInt32(Session["userGroup_Id"]), "");

            if (ds_Checkuser.Tables[0].Rows.Count > 0)
            {
                if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) == 0)
                {
                    Response.Redirect("OrganizationLandingPage.aspx");
                }

                if (ds_Checkuser.Tables[0].Rows[0]["addPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["addPrv"]) == 1)
                {
                    this.btn_Add.Visible = true;
                }
                else
                {
                    this.btn_Add.Visible = false;
                }
            }
            else
            {
                Response.Redirect("OrganizationLandingPage.aspx");
            }
        }
        catch
        {
            //
        }
    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        Response.Redirect("Organization_CCMailGroupAdd.aspx");
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        string ChkBoxIDs = string.Empty;
        ChkBoxIDs = CheckDelete();
        if (ChkBoxIDs != string.Empty)
        {
            objCcGroup.delete_CCGroupsInChildTables(ChkBoxIDs, "A");
            string str = "alert('Deleted Successfully')";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
        gvCcGroup.DataBind();
    }
    protected void btn_Clear_Click(object sender, EventArgs e)
    {
        ddlSearchOption.SelectedValue = "0";
        txtSearch.Text = string.Empty;
        gvCcGroup.DataBind();
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        txtSearch.Text = txtSearch.Text.Trim();
        gvCcGroup.DataBind();
    }

    private string CheckDelete()
    {
        string ChkBoxIDs = "";
        try
        {
            foreach (GridViewRow i in gvCcGroup.Rows)
            {
                CheckBox deleteChkBxItem = (CheckBox)i.FindControl("chkSelect");

                if (deleteChkBxItem.Checked)
                {
                    if (ChkBoxIDs == "")
                    {
                        ChkBoxIDs = ((Label)i.FindControl("lblCCGroupId")).Text.ToString();
                    }
                    else
                    {
                        // Concatenate DataGrid item with comma for SQL Delete
                        ChkBoxIDs = ChkBoxIDs + "," + ((Label)i.FindControl("lblCCGroupId")).Text.ToString();
                    }
                }
            }
        }
        catch
        {
            //
        }
        return ChkBoxIDs;
    }
    protected void btn_Back_Click(object sender, EventArgs e)
    {
        Response.Redirect("Organization_LeaveSettings.aspx");
    }
}
