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          : News and Events                             Last Modified : 14-Aug-2007
* Programmer      : Senthil Kumar NP
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
****************************************************************************************************************************/
public partial class Organization_Settings_Organization_NewsView : Base.BasePage
{
    #region Global Variable Declaration
    ResourceManager rm;
    CultureInfo ci;
    NewsEventData objNews = new NewsEventData();
    string source_Language;
    string gstrUserGroupName = string.Empty;
    cls_Common objcommon = new cls_Common();
    #endregion

    #region Page Load Event
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        GridView1.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            objcommon.menu("Others", "53");
        }
        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"]);
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "RestoreAlert('" + rm.GetString("Alert_Norecordsfound", ci) + "','" + rm.GetString("Alert_Areyousuretorestore", ci) + "','" + rm.GetString("Alert_Selecteddataisnotindeletedstatus", ci) + "','" + rm.GetString("Alert_Selectdatatorestore", ci) + "','" + rm.GetString("Alert_Nodeletedrecordsavailable", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("RestoreAlert", strSetAlert);
        UserRights();
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        if (gstrUserGroupName != "SuperAdmin")
        {
            GridView1.Columns[5].Visible = false;
            btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = false;
        }
        this.btn_add.Focus();
    }
    #endregion

    #region Button Click Events
    protected void btn_add_Click(object sender, EventArgs e)
    {
        Response.Redirect("Organization_News.aspx");
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        if (hdnSelectRow.Value != string.Empty)
        {
            objNews.temporaryDeleteNews(hdnSelectRow.Value, Convert.ToString(Session["EmpAutoID"]));
        }
        string str = "alert('" + rm.GetString("Alert_NewsEvents_Deleted_Successfully", ci) + ".');location.replace('Organization_NewsView.aspx');";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
    }
    protected void btn_Restore_Click(object sender, EventArgs e)
    {
        if (hdnSelectRow.Value != string.Empty)
        {
            objNews.restoreNews(hdnSelectRow.Value, Convert.ToString(Session["EmpAutoID"]));
        }
        Response.Redirect("Organization_NewsView.aspx");
    }
    protected void btn_PermanentDelete_Click(object sender, EventArgs e)
    {
        if (hdnSelectRow.Value != string.Empty)
        {
            objNews.permanentDeleteNews(hdnSelectRow.Value, Convert.ToString(Session["EmpAutoID"]));
        }
        string str = "alert('News Events deleted successfully');location.replace('Organization_NewsView.aspx');";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
    }
    #endregion

    #region User Defined Functions
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("UserGroups_NewsEvents", ci);
        btn_add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        GridView1.Columns[5].Caption = rm.GetString("DeleteStatus", ci);
        GridView1.Columns[4].Caption = rm.GetString("Designation_DesignationDesc", ci);
        GridView1.Columns[3].Caption = rm.GetString("NewsEvents_Title", ci);
        GridView1.Columns[2].Caption = rm.GetString("OnDuty_OutDate", ci);
        GridView1.Columns[1].Caption = rm.GetString("OnDuty_InDate", ci);
        btn_Restore.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Restore", ci);
        btn_PermanentDelete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_PermanentDelete", ci);
    }
    private void UserRights()
    {
        Cls_CheckUser chck = new Cls_CheckUser();
        DataSet ds = chck.checkRights(53, 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;
            }
            if (ds.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds.Tables[0].Rows[0]["deletePrv"]) == 1)
            {
                //Todo : This Line set to visible false
                this.btn_Delete.Visible = true;
                this.GridView1.Columns[0].Visible = true;
                this.btn_PermanentDelete.Visible = false;
                this.btn_Restore.Visible = false;
            }
            else
            {
                this.btn_Delete.Visible = false;
                this.btn_PermanentDelete.Visible = false;
                this.btn_Restore.Visible = false;
                this.GridView1.Columns[0].Visible = false;
            }
        }
        else
        {
            Response.Redirect("OrganizationLandingPage.aspx");
        }
    }
    #endregion

    #region GridView Events
    protected void GridView1_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
    {
        base.Page_Load(sender, e);
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        if (e.RowType == DevExpress.Web.GridViewRowType.Data)
        {
            Label DeletedRecord = (Label)GridView1.FindRowCellTemplateControl(e.VisibleIndex, null, "lblIsDeleted");
            if (DeletedRecord != null)
            {
                if (DeletedRecord.Text == "True" || DeletedRecord.Text == rm.GetString("Grid_True", ci))
                {
                    DeletedRecord.ForeColor = System.Drawing.Color.Red;
                }
            }
            if (DeletedRecord != null)
            {
                if (DeletedRecord.Text == "True")
                {
                    DeletedRecord.Text = rm.GetString("Grid_True", ci);
                    if (hdnDeletedData.Value == string.Empty)
                    {
                        hdnDeletedData.Value = e.GetValue("NewsEvent_Id").ToString();
                    }
                    else
                    {
                        if (hdnDeletedData.Value.Contains(e.GetValue("NewsEvent_Id").ToString()) == false)
                        {
                            hdnDeletedData.Value = hdnDeletedData.Value + "," + e.GetValue("NewsEvent_Id").ToString();
                        }
                    }
                }
                else if (DeletedRecord.Text == "False")
                {
                    DeletedRecord.Text = rm.GetString("Grid_False", ci);
                }
            }
        }
    }
    #endregion
}
