using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                         Started Date  : 12-Aug-2007
* Module          : Shift Master                                      Last Modified : 21-Aug-2007
* Programmer      : Janakaraj.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_ShiftView : Base.BasePage
{
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    cls_Common objCommon = new cls_Common();
    DataSet ds_Checkuser = new DataSet();
    ShiftEvenData obj_Shift = new ShiftEvenData();
    int ShiftId, auEmpId;
    string gstrUserGroupName = string.Empty;
    int payrollConfig = 0;
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        //get the culture info to set the language   
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        LoadStrings(ci);
        auEmpId = Convert.ToInt32(Session["EmpAutoID"].ToString());
        //Set UserRights
        UserRights();
        loadcss();
        ShiftId = Convert.ToInt16(Request.QueryString["ShiftId"]);
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        if (gstrUserGroupName == "SuperAdmin")
        {
            btn_Restore.Visible = true;
            btn_PermanentDelete.Visible = true;
        }
        else
        {
            btn_Restore.Visible = false;
            btn_PermanentDelete.Visible = false;
            lblDeleted.Visible = false;
            lblDeletedData.Visible = false;
        }
        int count = obj_Shift.CheckShift_Delete(ShiftId);
        if (count > 0)
        {
            //btn_Modify.Enabled = false;
            btn_Delete.Enabled = false;
            btn_PermanentDelete.Enabled = false;
            btn_Restore.Enabled = false;
        }
        if (!Page.IsPostBack)
        {
            GetShiftDetails();
            btn_Modify.Focus();
            btn_Modify.Style.Add("outline", "none");
            btn_Delete.OnClientClick = "return confirm('" + rm.GetString("Alert_ConfirmDelete", ci) + "')";
            btn_Restore.OnClientClick = "return confirm('" + rm.GetString("Alert_Areyousuretorestore", ci) + "')";
            btn_PermanentDelete.OnClientClick = "return confirm('" + rm.GetString("Alert_AreyouwantDeleteRecordPermanently", ci) + "')";
            objCommon.menu("ShiftMaster", "19");
        }
        payrollConfig = objCommon.CheckPageExistsInLicense(185);
        /*Below parameter is used for Angler*/
        if (payrollConfig == 1)
        {
            lblshiftType.Style.Add("display", "none");
            lblshiftType1.Style.Add("display", "none");
        }



        divEastmanShifts.Style.Add("display", "none");
        divspOT1.Style.Add("display", "none");
        divspOT2.Style.Add("display", "none");
        #region packageIDCalling
        if (Convert.ToString(Session["packageID"]) != "")
        {
            switch (Convert.ToString(Session["packageID"]))
            {
                case "155":
                    //Eastman
                    divEastmanShifts.Style.Add("display", "");
                    break;
                case "156":
                    //iffco
                    divspOT1.Style.Add("display", "");
                    divspOT2.Style.Add("display", "");
                    break;
                default:
                    break;
            }
        }
        if (Convert.ToString(Session["packageID"]) != "")
        {
            if (Convert.ToInt32(Session["packageID"]) < 159)  //vaigai and future clients
                DIVMaxShiftworkHours.Style.Add("display", "none");
        }
        #endregion
    }
    private void GetShiftDetails()
    {
        DataSet ds_Shift = obj_Shift.SelectShiftById(ShiftId);
        if (ds_Shift.Tables[0].Rows.Count > 0)
        {
            #region Eastman
            if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["CategoryName"]) != null)
                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["CategoryName"]) != "")
                    lblempCategoryvalue.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["CategoryName"]);
            #endregion

            #region Vaighai

            if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["MaxShiftWorkHours"]) != null)
                if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["MaxShiftWorkHours"]) != "")
                    if (lblMaxShiftWorkHours != null)
                        lblMaxShiftWorkHours.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["MaxShiftWorkHours"]);

            #endregion

            lbl_OrgLevel.Text = ds_Shift.Tables[0].Rows[0]["Name"].ToString();
            lbl_ShiftName.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_Name"]);
            if (ds_Shift.Tables[0].Rows[0]["Shift_ShortName"] != null)
                lblShiftShortName.Text = ds_Shift.Tables[0].Rows[0]["Shift_ShortName"].ToString();
            else
                lblShiftShortName.Text = "";
            lbl_ShiftDescr.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_Description"]);
            if (ds_Shift.Tables[0].Rows[0]["DefaultShift"].ToString() == "False")
                lblYesNo.Text = "No";
            else
                lblYesNo.Text = "Yes";
            if (ds_Shift.Tables[0].Rows[0]["isStraightShift"].ToString() == "True")
            {
                lblStraightShiftValue.Text = rm.GetString("ShiftSetting_Yes", ci);
                div_Break.Visible = false;
                divFirstSessionAndSecond.Visible = false;
                straightShiftParameters.Style.Add("display", "");
                lblMinimumHrs.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["straightPresentTime"]);
                lblBreak.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["BreakHours"]);
            }
            DateTime time1 = new DateTime();
            DateTime time2 = new DateTime();
            DateTime time3 = new DateTime();
            DateTime time4 = new DateTime();
            DateTime time5 = new DateTime();
            DateTime time6 = new DateTime();
            DateTime time7 = new DateTime();
            DateTime time8 = new DateTime();
            DateTime time9 = new DateTime();
            DateTime time10 = new DateTime();
            DateTime time11 = new DateTime();
            DateTime time12 = new DateTime();
            if (ds_Shift.Tables[0].Rows[0]["Shift_StartTime"].ToString() != "" && ds_Shift.Tables[0].Rows[0]["Shift_EndTime"].ToString() != "")
            {
                time2 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_EndTime"].ToString());
                time1 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_StartTime"].ToString());
                lbl_ShiftTiming.Text = time1.ToString(Session["MTimeFormat"].ToString()) + " " + "TO" + " " + time2.ToString(Session["MTimeFormat"].ToString());
            }
            if (ds_Shift.Tables[0].Rows[0]["Shift_FirstHalf_StartTime"].ToString() != "" && ds_Shift.Tables[0].Rows[0]["Shift_FirstHalf_EndTime"].ToString() != "")
            {
                time9 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_FirstHalf_StartTime"].ToString());
                time10 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_FirstHalf_EndTime"].ToString());
                lblFirstHalfTimings.Text = time9.ToString(Session["MTimeFormat"].ToString()) + " " + "TO" + " " + time10.ToString(Session["MTimeFormat"].ToString());
            }
            if (ds_Shift.Tables[0].Rows[0]["Shift_SecondHalf_StartTime"].ToString() != "" && ds_Shift.Tables[0].Rows[0]["Shift_SecondHalf_EndTime"].ToString() != "")
            {
                time11 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_SecondHalf_StartTime"].ToString());
                time12 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_SecondHalf_EndTime"].ToString());
                lblSecondHalfTimings.Text = time11.ToString(Session["MTimeFormat"].ToString()) + " " + "TO" + " " + time12.ToString(Session["MTimeFormat"].ToString());
            }
            lbl_GraceShiftin.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_GraceInTime"]);
            lbl_GraceShiftout.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_GraceOutTime"]);
            if (ds_Shift.Tables[0].Rows[0]["Shift_BreakStartTime1"].ToString() != "")
            {
                time3 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_BreakStartTime1"].ToString());
                lbl_brkin1.Text = time3.ToString(Session["MTimeFormat"].ToString());
            }
            if (ds_Shift.Tables[0].Rows[0]["Shift_BreakEndTime1"].ToString() != "")
            {
                time4 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_BreakEndTime1"].ToString());
                lbl_brkout1.Text = time4.ToString(Session["MTimeFormat"].ToString());
            }
            if (ds_Shift.Tables[0].Rows[0]["Shift_BreakStartTime2"].ToString() != "")
            {
                time5 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_BreakStartTime2"].ToString());
                lbl_brkin2.Text = time5.ToString(Session["MTimeFormat"].ToString());
            }
            if (ds_Shift.Tables[0].Rows[0]["Shift_BreakEndTime2"].ToString() != "")
            {
                time6 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_BreakEndTime2"].ToString());
                lbl_brkout2.Text = time6.ToString(Session["MTimeFormat"].ToString());
            }
            if (ds_Shift.Tables[0].Rows[0]["Shift_BreakStartTime3"].ToString() != "")
            {
                time7 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_BreakStartTime3"].ToString());
                lbl_brkin3.Text = time7.ToString(Session["MTimeFormat"].ToString());
            }
            if (ds_Shift.Tables[0].Rows[0]["Shift_BreakEndTime3"].ToString() != "")
            {
                time8 = Convert.ToDateTime(ds_Shift.Tables[0].Rows[0]["Shift_BreakEndTime3"].ToString());
                lbl_brkout3.Text = time8.ToString(Session["MTimeFormat"].ToString());
            }
            if (ds_Shift.Tables[0].Rows[0]["Shift_FirstHalfWorkingHours"].ToString() != "")
            {
                lblFirstHalfWorkHrsData.Text = ds_Shift.Tables[0].Rows[0]["Shift_FirstHalfWorkingHours"].ToString();
            }
            if (ds_Shift.Tables[0].Rows[0]["Shift_SecondHalfWorkingHours"].ToString() != "")
            {
                lblSecondHalfWorkHrsData.Text = ds_Shift.Tables[0].Rows[0]["Shift_SecondHalfWorkingHours"].ToString();
            }
            if (ds_Shift.Tables[0].Rows[0]["Isdeleted"].ToString() != "")
            {
                lblDeletedData.Text = ds_Shift.Tables[0].Rows[0]["Isdeleted"].ToString();
                if (lblDeletedData.Text == "True" || lblDeletedData.Text == rm.GetString("Grid_True", ci))
                {
                    btn_Delete.Visible = false;
                }
                else if (lblDeletedData.Text == "False" || lblDeletedData.Text == rm.GetString("Grid_False", ci))
                {
                    btn_Restore.Visible = false;
                }
                if (lblDeletedData.Text == "True")
                {
                    lblDeletedData.Text = rm.GetString("Grid_True", ci);
                }
                else if (lblDeletedData.Text == "False")
                {
                    lblDeletedData.Text = rm.GetString("Grid_False", ci);
                }
            }
            if (ds_Shift.Tables[0].Rows[0]["ShiftType"] != DBNull.Value)
            {
                if (Convert.ToBoolean(ds_Shift.Tables[0].Rows[0]["ShiftType"]) == true)
                {
                    lblServiceTypeData.Text = "Free Scan";
                }
                else
                {
                    lblServiceTypeData.Text = "Function Key";
                }
            }
            if (ds_Shift.Tables[0].Rows[0]["24HrsShift"] != DBNull.Value)
            {
                if (Convert.ToBoolean(ds_Shift.Tables[0].Rows[0]["24HrsShift"]) == true)
                {
                    lbl24HrsShift_Data.Text = "Yes";
                }
                else
                {
                    lbl24HrsShift_Data.Text = "No";
                }
            }
            lbl_MinOt.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_MinTimeOT"]);
            lbl_MaxOt.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_MaxTimeOT"]);
            lbl_OtWorkingday.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_WorkingDay_OverTime"]);
            // lbl_OtHolidayday.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_Holiday_OverTime"]);
            // lbl_OtWeekoff.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_Weekoff_OverTime"]);
            lbl_TotalWorkinghrs.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["Shift_TotalWorkingHours"]);

            if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["specialOvertime_start1"]) != "" && Convert.ToString(ds_Shift.Tables[0].Rows[0]["specialOvertime_start1"]) != "00:00")
                lblspecialOvertime1value.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["specialOvertime_start1"]);
            if (Convert.ToString(ds_Shift.Tables[0].Rows[0]["specialOvertime_start2"]) != "" && Convert.ToString(ds_Shift.Tables[0].Rows[0]["specialOvertime_start2"]) != "00:00")
                lblspecialOvertimeStart2value.Text = Convert.ToString(ds_Shift.Tables[0].Rows[0]["specialOvertime_start2"]);
        }
    }
    protected void btn_Modify_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_ShiftModify.aspx?SID=" + ShiftId);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_ShiftDetails.aspx");
    }
    protected void ImageButton1_Click(object sender, EventArgs e)
    {
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        int count = obj_Shift.CheckShift_Delete(ShiftId);
        if (count > 0)
        {
            base.Message(rm.GetString("Master_Shift_Cannot_delete", ci));
            return;
        }
        obj_Shift.DeleteShiftAll(ShiftId.ToString(), "TemporaryDelete", auEmpId);
        base.MessageWithRedirect(rm.GetString("Alert_Shiftdeletedsuccessfully", ci), "TA_UI_Master_ShiftDetails.aspx");
    }
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_OrganizationLevel.Text = rm.GetString("EntranceMaster_Company", ci);
        lbl_BreakTimings1.Text = rm.GetString("ShiftTiming_BreakTimings", ci);
        lbl_EndTime1.Text = rm.GetString("OnDuty_OutTime", ci);
        lbl_EndTime2.Text = rm.GetString("OnDuty_OutTime", ci);
        lbl_EndTime3.Text = rm.GetString("OnDuty_OutTime", ci);
        lbl_ShiftTiming1.Text = rm.GetString("ShiftTiming_ShiftTimings", ci);
        lbl_FirstHalfTimings.Text = rm.GetString("ShiftTiming_FirstHalfTimings", ci);
        lbl_SecondHalfTimings.Text = rm.GetString("ShiftTiming_SecondHalfTimings", ci);
        lbl_GraceShiftIn1.Text = rm.GetString("ShiftTiming_GraceShiftIn", ci);
        lbl_GraceShiftOut1.Text = rm.GetString("ShiftTiming_GraceShiftOut", ci);
        lbl_MaximumExtraTimeforOT.Text = rm.GetString("ShiftTiming_MaximumExtraTimeForOT", ci);
        lbl_MinimumExtraTimeforOT.Text = rm.GetString("ShiftTiming_MinimumExtraTimeForOT", ci);
        lbl_OvertimeOnWorkingDays.Text = rm.GetString("ShiftTiming_OverTimeOnWorkingDays", ci);
        lbl_ShiftDescription.Text = rm.GetString("ShiftTiming_ShiftDescription", ci);
        lbl_ShiftName1.Text = rm.GetString("ShiftTiming_ShiftName", ci);
        lbl_ShiftShortName1.Text = rm.GetString("ShiftTiming_ShiftShortName", ci);
        lbl_StartTime1.Text = rm.GetString("OnDuty_InTime", ci);
        lbl_StartTime2.Text = rm.GetString("Lunch_StartTime", ci);
        lbl_StartTime3.Text = rm.GetString("OnDuty_InTime", ci);
        lbl_TotalWorkingHours.Text = rm.GetString("ShiftTiming_TotalWorkingHours", ci);
        lbl_HeaderShiftTiming.Text = rm.GetString("Masters_Shift_ShiftTiming", ci);
        btn_Modify.Text = rm.GetString("btn_Modify", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        lblDeleted.Text = rm.GetString("DeleteStatus", ci);
        btn_PermanentDelete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_PermanentDelete", ci);
        btn_Restore.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Restore", ci);
        lblFirstHalfWorkHrs.Text = rm.GetString("Masters_Shift_FirstHalfWorkHours", ci);
        lblSecondHalfWorkHrs.Text = rm.GetString("Masters_Shift_SecondHalfWorkHours", ci);
        lblDefaultShift.Text = rm.GetString("Masters_Shift_DefaultShift", ci);
        lblSeriveType.Text = rm.GetString("ShiftType", ci);
        lbl_General.Text = rm.GetString("Shift_General", ci);
        lbl24HrsShift.Text = rm.GetString("Shift_24Hrs", ci);
        lbl_ShiftTimings.Text = rm.GetString("ShiftTiming_ShiftTimings", ci);
        lbl_OverTime.Text = rm.GetString("Menu_Reports_OverTime", ci);
        lblBreakHours.Text = rm.GetString("Field_BreakHours", ci);
        lblAttendancePresentMinHrs.Text = rm.GetString("Field_MinimumHrs", ci);
        lblStraightShift.Text = rm.GetString("Field_StraightShift", ci);
        #region Eastman
        lblEmpCategory.Text = rm.GetString("lblEmpCategory", ci);
        #endregion
        #region Vaighai
        lbl_MaxShiftWorkHours.Text = rm.GetString("ShiftAdd_MaxShiftWorkHours", ci);
        #endregion
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(19, 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"]) != 1)
            {
                Response.Redirect("TA_UI_Master_ShiftDetails.aspx");
            }
            if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
            {
                this.btn_Modify.Visible = true;
            }
            else
            {
                this.btn_Modify.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 = true;
                this.btn_Restore.Visible = true;
            }
            else
            {
                this.btn_Delete.Visible = false;
                this.btn_PermanentDelete.Visible = false;
                this.btn_Restore.Visible = false;
            }
        }
        else
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }

    private void loadcss()
    {
        CultureInfo ci;
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        //if Standard Demo
        htmlShift.Attributes.Add("dir", rm.GetString("Direction", ci));
        if (source_Language == "Resources.Resource_AR")
        {
            stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            stylecustom.Href = "../dist/css/custom-rtl.css";
            stylefonts.Href = "../dist/css/fonts.css";
        }
        else
        {
            //htmlShift.Attributes.Add("dir", "rtl");
            //stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            //stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            //styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            //stylecustom.Href = "../dist/css/custom-rtl.css";
            //stylefonts.Href = "../dist/css/fonts.css";
            stylebootstrap.Href = "../bootstrap/css/bootstrap.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min.css";
            stylecustom.Href = "../dist/css/custom.css";
            stylefonts.Href = "../dist/css/fonts.css";
        }
    }
    protected void btn_PermanentDelete_Click(object sender, EventArgs e)
    {
        int count = obj_Shift.CheckShift_Delete(ShiftId);
        if (count > 0)
        {
            base.Message(rm.GetString("Master_Shift_Cannot_delete", ci));
            return;
        }
        //Calling shift permanent delete method
        obj_Shift.PermanentDeleteShiftAll(ShiftId.ToString(), "PermanentDelete", auEmpId);
        base.MessageWithRedirect(rm.GetString("Alert_Shiftdeletedsuccessfully", ci), "TA_UI_Master_ShiftDetails.aspx");
    }
    protected void btn_Restore_Click(object sender, EventArgs e)
    {
        int count = obj_Shift.CheckShift_Restore(ShiftId);
        if (count > 0)
        {
            base.Message(rm.GetString("Message_Cannot_Restore", ci));
            return;
        }
        //Calling Restore All Method
        obj_Shift.RestoreShiftAll(ShiftId.ToString(), "Restore", auEmpId);
        base.MessageWithRedirect(rm.GetString("Alert_Shiftrestoredsuccessfully", ci), "TA_UI_Master_ShiftDetails.aspx");
    }
}
