using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Masters_TA_UI_Master_OverTimeType : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    CultureInfo ci;
    GenericEventdata objGeneric = new GenericEventdata();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    string gstrUserGroupName = string.Empty;
    int auEmpId;
    OverTimeCodeEventData objClass = new OverTimeCodeEventData();
    LeaveEventData objLeave = new LeaveEventData();
    string strScript = string.Empty;
    cls_Common objCommon = new cls_Common();
    string source_Language;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        gv.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            objCommon.menu("Others", "100");
        }
        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);
        auEmpId = Convert.ToInt32(Session["EmpAutoID"].ToString());
        //Set UserRights
        UserRights();
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        if (gstrUserGroupName == "SuperAdmin")
        {
            btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = true;
            //gv.Columns[5].Visible = true;
        }
        else
        {
            btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = false;
            //gv.Columns[5].Visible = false;
        }
        btn_add.Focus();
    }
    #endregion
    #region ButtonEvents
    protected void btn_add_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_OverTimeTypeAdd.aspx");
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        string[] ChkBoxIDs;
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            ChkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
            for (int i = 0; i < ChkBoxIDs.Length; i++)
            {
                objClass.DeleteOtType(Convert.ToInt32(ChkBoxIDs[i]), auEmpId);
            }
            string str = "alert('" + rm.GetString("Alert_OverTimetypedeletedsuccessfully", ci) + "');location.replace('TA_UI_Master_OverTimeType.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
        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)
    {
        string[] ChkBoxIDs;
        //bool BxsChkd = false;
        OverTimeCodeEventData objClass = new OverTimeCodeEventData();
        int gid;
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            ChkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
            for (int i = 0; i < ChkBoxIDs.Length; i++)
            {
                objClass.RestoreOtType(Convert.ToInt32(ChkBoxIDs[i]), auEmpId);
            }
            string str = "alert('" + rm.GetString("Alert_OverTimetyperestoredsuccessfully", ci) + "');location.replace('TA_UI_Master_OverTimeType.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
        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)
    {
        string[] ChkBoxIDs;
        OverTimeCodeEventData objClass = new OverTimeCodeEventData();
        int gid;
        if (hdnSelectRow.Value != string.Empty && hdnSelectRow.Value != null)
        {
            ChkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
            for (int i = 0; i < ChkBoxIDs.Length; i++)
            {
                objClass.PremanentDeleteOtType(Convert.ToInt32(ChkBoxIDs[i]), auEmpId);
            }
            string str = "alert('" + rm.GetString("Alert_OverTimetypedeletedsuccessfully", ci) + "');location.replace('TA_UI_Master_OverTimeType.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
        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_Cancel_Click(object sender, EventArgs e)
    {
    }
    #endregion
    #region UserDefinedFunctions
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("OverTimeType", ci);
        btn_add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        btn_PermanentDelete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btn_Restore.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Restore", ci);
        gv.Columns[2].Caption = rm.GetString("Master_OverTimeType", ci);
        gv.Columns[3].Caption = rm.GetString("OverTimeCategory", ci);
        gv.Columns[4].Caption = rm.GetString("EntranceMaster_Company", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(100, 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_PermanentDelete.Visible = true;
                this.gv.Columns[0].Visible = true;
                this.gv.Columns[6].Visible = true;
            }
            else
            {
                this.btn_PermanentDelete.Visible = false;
                this.gv.Columns[0].Visible = false;
                this.gv.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.gv.Columns[5].Visible = true;
            }
            else
            {
                this.gv.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.gv.Columns[4].Visible = true;
            }
            else
            {
                this.gv.Columns[4].Visible = false;
            }
        }
        else
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    #endregion
    #region GridviewEvents
    protected void gv_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;
            Label DeletedRecord = (Label)gv.FindRowCellTemplateControl(e.VisibleIndex, null, "lblIsDeleted");
            if (DeletedRecord != null)
            {
                if (DeletedRecord.Text == "True")
                {
                    DeletedRecord.Text = rm.GetString("Grid_True", ci);
                    if (hdnDeletedData.Value == string.Empty)
                    {
                        hdnDeletedData.Value = e.GetValue("OtTypeID").ToString();
                    }
                    else
                    {
                        if (hdnDeletedData.Value.Contains(e.GetValue("OtTypeID").ToString()) == false)
                        {
                            hdnDeletedData.Value = hdnDeletedData.Value + "," + e.GetValue("OtTypeID").ToString();
                        }
                    }
                }
                else if (DeletedRecord.Text == "False")
                {
                    DeletedRecord.Text = rm.GetString("Grid_False", ci);
                }
            }
            Label lblOtCat = (Label)gv.FindRowCellTemplateControl(e.VisibleIndex, null, "lblOtCat");
            if (lblOtCat.Text.Trim() == "WorkingDay")
            {
                lblOtCat.Text = rm.GetString("OverTimeType_WorkingDay", ci);
            }
            else if (lblOtCat.Text.Trim() == "WeeklyOff")
            {
                lblOtCat.Text = rm.GetString("ShiftSetting_WeeklyOff", ci);
            }
            else if (lblOtCat.Text.Trim() == "Holiday")
            {
                lblOtCat.Text = rm.GetString("Masters_Holidays_Holidays", ci);
            }
        }
    }
    #endregion
    protected void EditLinkButton_Click(object sender, EventArgs e)
    {
        //ToDo: 23-11-2015
        LinkButton btn = sender as LinkButton;
        int intEntranceID = Convert.ToInt32(btn.CommandName);
        Response.Redirect("TA_UI_Master_OverTimeTypeModify.aspx?Id=" + intEntranceID);
    }
    protected void btn_delete_Click_1(object sender, EventArgs e)
    {
        //ToDo: 23-11-2015
        LinkButton btn = sender as LinkButton;
        int intOTTypeID = Convert.ToInt32(btn.CommandName);
        objClass.PremanentDeleteOtType(Convert.ToInt32(intOTTypeID), auEmpId);
        string str = "alert('" + rm.GetString("Alert_OverTimetypedeletedsuccessfully", ci) + "');location.replace('TA_UI_Master_OverTimeType.aspx');";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
    }
}
