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          : Additional WeeklyOff Settings               Last Modified : 14-Aug-2007
* Programmer      : Janakaraj.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
 * Modified By      :   Manjula.P
 * Modified On      :   09-Oct-2013
 * Descriptions     :   Checking restore options with Group selection Mantis :  	0019292
****************************************************************************************************************************/
public partial class Organization_Settings_Organization_AddlWeekoff : Base.BasePage
{
    #region "Variable Declaration"
    AddlWeekOffEventData obj = new AddlWeekOffEventData();
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    LeaveEventData objLeave = new LeaveEventData();
    DataSet ds_Checkuser = new DataSet();
    string gstrUserGroupName = string.Empty;
    cls_Common objcommon = new cls_Common();
    int auditEmpId;
    string source_Language;
    #endregion
    #region Page Load Event
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        grv_Addl_Weekoff.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            Session["parentLevelId"] = 0;
            DataSet dsAdditonalWeeklyOff = new DataSet();
            dsAdditonalWeeklyOff = obj.Select_AddlWeekoffdetails(gstrUserGroupName, Convert.ToInt32(Session["parentLevelId"]), ddl_Day.SelectedValue, ddl_Week.SelectedValue);
            Session["WeeklyOffData"] = dsAdditonalWeeklyOff;
            grv_Addl_Weekoff.DataSourceID = ObjectDataSource1.ID;
            objcommon.menu("Others", "49");
        }
        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);
        auditEmpId = Convert.ToInt32(Session["EmpAutoID"].ToString());
        UserRights();
        if (gstrUserGroupName != "SuperAdmin")
        {
            btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = false;
        }
        btn_add.Focus();
    }
    #endregion
    #region Button Click Events
    protected void btn_add_Click(object sender, EventArgs e)
    {
        Response.Redirect("Organization_AddlWeekoff_Add.aspx");
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        if (hdnSelectRow.Value != string.Empty)
        {
            obj.TemporaryDelete_AddlWeekoff(hdnSelectRow.Value, auditEmpId);
            string str = "alert('" + rm.GetString("Alert_Deleted_Sucessfully_AdditionaWeeklyOff", ci) + "');location.replace('Organization_AddlWeekoff.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
    }
    protected void btn_Restore_Click(object sender, EventArgs e)
    {
        if (hdnSelectRow.Value != string.Empty)
        {
            string[] ChkBoxIDs;
            ChkBoxIDs = objLeave.commaStringToArray(hdnSelectRow.Value);
            for (int i = 0; i < ChkBoxIDs.Length; i++)
            {
                int count = obj.CheckRestoreAddlWeekoff(Convert.ToInt32(ChkBoxIDs[i]), "", "", "R");
                if (count > 0)
                {
                    string str = "alert('" + rm.GetString("Message_Cannot_Restore", ci) + "');";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
                    hdnSelectRow.Value = string.Empty;
                    grv_Addl_Weekoff.DataBind();
                    return;
                }
            }
            int countGroup = obj.CheckRestoreAddlWeekoffGroup(hdnSelectRow.Value);
            if (countGroup > 1)
            {
                string str = "alert('" + rm.GetString("Message_Cannot_Restore_MorethanOneActive", ci) + "');";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
                hdnSelectRow.Value = string.Empty;
                grv_Addl_Weekoff.DataBind();
                return;
            }
            obj.Restore_AddlWeekoff(hdnSelectRow.Value, auditEmpId);
        }
        Response.Redirect("Organization_AddlWeekoff.aspx");
    }
    protected void btn_PermanentDelete_Click(object sender, EventArgs e)
    {
        if (hdnSelectRow.Value != string.Empty)
        {
            obj.PermanentDelete_AddlWeekoff(hdnSelectRow.Value, auditEmpId);
            string str = "alert('" + rm.GetString("Alert_Deleted_Sucessfully_AdditionaWeeklyOff", ci) + "');location.replace('Organization_AddlWeekoff.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        try
        {
            DataSet dsAdditonalWeeklyOff = new DataSet();
            dsAdditonalWeeklyOff = obj.Select_AddlWeekoffdetails(gstrUserGroupName, Convert.ToInt32(Session["parentLevelId"]), ddl_Day.SelectedValue, ddl_Week.SelectedValue);
            Session["WeeklyOffData"] = dsAdditonalWeeklyOff;
            grv_Addl_Weekoff.DataSourceID = ObjectDataSource1.ID;
        }
        catch (Exception ex)
        {
            base.Message(ex.Message);
        }
    }
    protected void btn_Clear_Click(object sender, EventArgs e)
    {
        try
        {
            Session["parentLevelId"] = 0;
            ddl_Day.SelectedValue = "All";
            ddl_Week.SelectedValue = "All";
            Response.Redirect("Organization_AddlWeekoff.aspx");
        }
        catch (Exception ex)
        {
            base.Message(ex.Message);
        }
    }
    #endregion
    #region User Definded Functions
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("Org_Additional_Weeklyoff", ci);
        btn_add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Add", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btn_Restore.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Restore", ci);
        btn_PermanentDelete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_PermanentDelete", ci);
        grv_Addl_Weekoff.Columns[1].Caption = rm.GetString("LevelDetails_LevelName", ci);
        grv_Addl_Weekoff.Columns[2].Caption = rm.GetString("lbl_AdditionalWeekoffdayweek", ci);
        grv_Addl_Weekoff.Columns[3].Caption = rm.GetString("DeleteStatus", ci);
        lbl_selectedweek.Text = "&nbsp;&nbsp;" + rm.GetString("AdditionalWeeklyOff_WeeklyOffWeek", ci);
        //lbl_selectedweek.Text = rm.GetString("ShiftPattern_Day", ci);
        lbl_Weekof.Text = "&nbsp;&nbsp;" + rm.GetString("ShiftPattern_Day", ci);
        btn_Search.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Search", ci);
        btn_Clear.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Clear", ci);
        ddl_Day.Items[0].Text = rm.GetString("ExportData_All", ci);
        ddl_Day.Items[1].Text = rm.GetString("Sunday", ci);
        ddl_Day.Items[2].Text = rm.GetString("Monday", ci);
        ddl_Day.Items[3].Text = rm.GetString("Tuesday", ci);
        ddl_Day.Items[4].Text = rm.GetString("Wednesday", ci);
        ddl_Day.Items[5].Text = rm.GetString("Thursday", ci);
        ddl_Day.Items[6].Text = rm.GetString("Friday", ci);
        ddl_Day.Items[7].Text = rm.GetString("Saturday", ci);
        ddl_Week.Items[0].Text = rm.GetString("ExportData_All", ci);
        ddl_Week.Items[1].Text = rm.GetString("FirstWeek", ci);
        ddl_Week.Items[2].Text = rm.GetString("SecondWeek", ci);
        ddl_Week.Items[3].Text = rm.GetString("ThirdWeek", ci);
        ddl_Week.Items[4].Text = rm.GetString("FourthWeek", ci);
        ddl_Week.Items[5].Text = rm.GetString("FifthWeek", ci);
        lblFilter.Text = rm.GetString("lblFilter", ci);
    }
    public void UserRights()
    {
        try
        {
            ds_Checkuser = objCheckUser.checkRights(49, 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;
                }
                if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
                {
                    this.btn_Delete.Visible = true;
                    this.btn_PermanentDelete.Visible = false;
                    this.btn_Restore.Visible = false;
                    this.grv_Addl_Weekoff.Columns[1].Visible = true;
                }
                else
                {
                    this.btn_Delete.Visible = false;
                    this.btn_PermanentDelete.Visible = false;
                    this.btn_Restore.Visible = false;
                    this.grv_Addl_Weekoff.Columns[1].Visible = false;
                }
            }
            else
            {
                Response.Redirect("OrganizationLandingPage.aspx");
            }
        }
        catch
        {
        }
    }
    #endregion
    #region GridView Events
    protected void grv_Addl_Weekoff_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs 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)grv_Addl_Weekoff.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;
                }
            }
            Label lblWeekOffDay = (Label)grv_Addl_Weekoff.FindRowCellTemplateControl(e.VisibleIndex, null, "lblRegionname");
            if (lblWeekOffDay.Text != "")
            {
                string[] lblWeekOffDays = lblWeekOffDay.Text.Split('-');
                string DisplayWeekOffDay = string.Empty;
                string DisplayWeekOffDays = string.Empty;
                string First = lblWeekOffDays[0].ToString().Trim();
                string Second = lblWeekOffDays[1].ToString().Trim();
                switch (First)
                {
                    case "Sunday":
                        DisplayWeekOffDay = rm.GetString("Sunday", ci);
                        break;
                    case "Monday":
                        DisplayWeekOffDay = rm.GetString("Monday", ci);
                        break;
                    case "Tuesday":
                        DisplayWeekOffDay = rm.GetString("Tuesday", ci);
                        break;
                    case "Wednesday":
                        DisplayWeekOffDay = rm.GetString("Wednesday", ci);
                        break;
                    case "Thursday":
                        DisplayWeekOffDay = rm.GetString("Thursday", ci);
                        break;
                    case "Friday":
                        DisplayWeekOffDay = rm.GetString("Friday", ci);
                        break;
                    case "Saturday":
                        DisplayWeekOffDay = rm.GetString("Saturday", ci);
                        break;
                }
                switch (Second)
                {
                    case "First Week":
                        DisplayWeekOffDays = rm.GetString("FirstWeek", ci);
                        break;
                    case "Second Week":
                        DisplayWeekOffDays = rm.GetString("SecondWeek", ci);
                        break;
                    case "Third Week":
                        DisplayWeekOffDays = rm.GetString("ThirdWeek", ci);
                        break;
                    case "Fourth Week":
                        DisplayWeekOffDays = rm.GetString("FourthWeek", ci);
                        break;
                    case "Fifth Week":
                        DisplayWeekOffDays = rm.GetString("FifthWeek", ci);
                        break;
                }
                lblWeekOffDay.Text = DisplayWeekOffDay + " - " + DisplayWeekOffDays;
            }
            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("Addl_WeeklyOff_Id"));
                    }
                    else
                    {
                        if (hdnDeletedData.Value.Contains(Convert.ToString(e.GetValue("Addl_WeeklyOff_Id"))) == false)
                        {
                            hdnDeletedData.Value = hdnDeletedData.Value + "," + Convert.ToString(e.GetValue("Addl_WeeklyOff_Id"));
                        }
                    }
                }
                else if (DeletedRecord.Text == "False")
                {
                    DeletedRecord.Text = rm.GetString("Grid_False", ci);
                }
            }
        }
    }
    #endregion
}
