using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web;
using System.Web.UI.HtmlControls;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                              Started Date  : 12-Aug-2007
* Module          : Entrance Master                                        Last Modified : 20-Aug-2007
* Programmer      : 
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_Entrance : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    EntranceEventData objEntrance = new EntranceEventData();
    LeaveEventData objLeave = new LeaveEventData();
    DataSet ds_Checkuser = new DataSet();
    cls_Common objcommon = new cls_Common();
    string strScript = string.Empty, source_Language, gstrUserGroupName = string.Empty;
    int EmployeeID = 0;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        grv_Entrance.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        if (!Page.IsPostBack)
        {
            base.CheckPages(15);
            objcommon.menu("Device", "15");
        }
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        EmployeeID = Convert.ToInt32(Session["EmpAutoID"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        LoadStrings(ci);
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        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();
        if (Session["UserGroupName"] != null)
        {
            gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        }
        if (gstrUserGroupName != "SuperAdmin")
        {
            btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = false;
        }
        btn_add.Focus();
    }
    #endregion
    #region ButtonEvents
    protected void btn_add_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_EntranceAdd.aspx");
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            objEntrance.deleteEntrances("TemporaryDelete", hdnSelectRow.Value, EmployeeID);
            base.MessageWithRedirect(rm.GetString("Alert_Entrancedeletedsuccessfully", ci), "TA_UI_Master_Entrance.aspx");
        }
        else
        {
            strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("DeletionRecordAlert", ci) + "')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("DelAlert1", strScript);
            return;
        }
    }
    protected void btn_Restore_Click(object sender, EventArgs e)
    {
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            string[] ChkBoxIDs;
            ChkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
            for (int i = 0; i < ChkBoxIDs.Length; i++)
            {
                int count = objEntrance.CheckRestoreEntrance(Convert.ToInt32(ChkBoxIDs[i]));
                if (count > 0)
                {
                    base.Message(rm.GetString("Message_Cannot_Restore", ci));
                    hdnSelectRow.Value = "";
                    return;
                }
            }
            objEntrance.deleteEntrances("Restore", hdnSelectRow.Value, EmployeeID);
            base.MessageWithRedirect(rm.GetString("Alert_Entrancerestoredsuccessfully", ci), "TA_UI_Master_Entrance.aspx");
        }
        else
        {
            strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("DeletionRecordAlert", ci) + "')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("DelAlert1", strScript);
            return;
        }
    }
    protected void btn_PermanentDelete_Click(object sender, EventArgs e)
    {
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            objEntrance.deleteEntrances("PermanentDelete", hdnSelectRow.Value, EmployeeID);
            base.MessageWithRedirect(rm.GetString("Alert_Entrancedeletedsuccessfully", ci), "TA_UI_Master_Entrance.aspx");
        }
        else
        {
            strScript = "";
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('" + rm.GetString("DeletionRecordAlert", ci) + "')";
            strScript = strScript + "</script>";
            Page.RegisterStartupScript("DelAlert1", strScript);
            return;
        }
    }
    #endregion
    #region UserDefinedFunctions
    private string CheckDelete()
    {
        string ChkBoxIDs = string.Empty;
        return (ChkBoxIDs);
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_EntranceMaster.Text = rm.GetString("Masters_Entrance_EntranceMaster", ci);
        btn_add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        btn_Delete.Text = rm.GetString("btn_Delete", ci);
        btn_Restore.Text = rm.GetString("btn_Restore", ci);
        btn_PermanentDelete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        grv_Entrance.Columns[2].Caption = rm.GetString("EntranceMaster_Entrance_Name", ci);
        grv_Entrance.Columns[3].Caption = rm.GetString("EntranceMaster_Entrance_Desc", ci);
        lblDataview.Text = rm.GetString("lblDataView", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(15, Convert.ToInt32(Session["userGroup_Id"]), "");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            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;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
            {
                this.btn_Delete.Visible = false;
                this.btn_PermanentDelete.Visible = true;
                this.btn_Restore.Visible = false;
                this.grv_Entrance.Columns[0].Visible = true;
                this.grv_Entrance.Columns[6].Visible = true;
            }
            else
            {
                this.btn_Delete.Visible = false;
                this.btn_PermanentDelete.Visible = false;
                this.btn_Restore.Visible = false;
                this.grv_Entrance.Columns[0].Visible = false;
                this.grv_Entrance.Columns[6].Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
            {
                this.grv_Entrance.Columns[5].Visible = true;
            }
            else
            {
                this.grv_Entrance.Columns[5].Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) == 1)
            {
                this.grv_Entrance.Columns[4].Visible = true;
            }
            else
            {
                this.grv_Entrance.Columns[4].Visible = false;
            }
        }
        else
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    #endregion
    #region GridviewEvents
    /// <summary>
    /// Handles the RowDataBound event of the grv_Entrance control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param>
    protected void grv_Entrance_HtmlRowCreated(object sender, 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;
            Label DeletedRecord = (Label)grv_Entrance.FindRowCellTemplateControl(e.VisibleIndex, null, "lblIsDeleted");
            HtmlInputCheckBox deleteChkBxItem = (HtmlInputCheckBox)grv_Entrance.FindRowCellTemplateControl(e.VisibleIndex, null, "chkSelect");
            LinkButton LnkbtnDelete = (LinkButton)grv_Entrance.FindRowCellTemplateControl(e.VisibleIndex, null, "btnDelete");
            if (deleteChkBxItem != null)
            {
                if (deleteChkBxItem.Disabled == false)
                {
                    LnkbtnDelete.Enabled = true;
                }
                else
                {
                    LnkbtnDelete.Enabled = false;
                    LnkbtnDelete.OnClientClick = null;
                }
            }
            if (DeletedRecord != null)
            {
                if (DeletedRecord.Text == "True")
                {
                    DeletedRecord.Text = rm.GetString("Grid_True", ci);
                    if (hdnDeletedData.Value == string.Empty)
                    {
                        hdnDeletedData.Value = Convert.ToString(e.GetValue("Entrance_Id"));
                    }
                    else
                    {
                        if (hdnDeletedData.Value.Contains(Convert.ToString(e.GetValue("Entrance_Id"))) == false)
                        {
                            hdnDeletedData.Value = hdnDeletedData.Value + "," + Convert.ToString(e.GetValue("Entrance_Id"));
                        }
                    }
                }
                else if (DeletedRecord.Text == "False")
                {
                    DeletedRecord.Text = rm.GetString("Grid_False", ci);
                }
            }
        }
    }
    #endregion
    protected void EditLinkButton_Click(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        int intEntranceID = Convert.ToInt32(btn.CommandName);
        Response.Redirect("TA_UI_Master_EntranceModify.aspx?Entrance_Id=" + intEntranceID);
    }
    protected void btn_delete_Click_1(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        int intEntranceID = Convert.ToInt32(btn.CommandName);
        int count = objEntrance.CheckEntrance_Delete(intEntranceID);
        if (count > 0)
        {
            base.Message(rm.GetString("Masters_Entrance_Cannot_Delete", ci));
            return;
        }
        objEntrance.deleteEntrances("PermanentDelete", Convert.ToString(intEntranceID), EmployeeID);
        base.MessageWithRedirect(rm.GetString("Alert_Entrancedeletedsuccessfully", ci), "TA_UI_Master_Entrance.aspx");
    }
}