using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                        Created On  : 12-Aug-2007
* Module          : Leave Policy                                     Modified On : 08-Aug-2007
* Created By      : Arun Vinoth.T
* Modified By     : 
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
****************************************************************************************************************************/
public partial class Organization_Settings_OTRoundoffModify_Remote : Base.BasePage
{
    #region Global Variable Declaration
    int CompanyID;
    ResourceManager rm;
    CultureInfo ci;
    string ConcatenateString = string.Empty;
    #endregion

    #region Page Load Event
    protected override void Page_Load(object sender, EventArgs e)
    {
        GC.Collect();
        base.Page_Load(sender, e);
        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 (Request.QueryString["CompanyID"] != null && Request.QueryString["CompanyID"] != "")
        {
            CompanyID = Convert.ToInt32(Request.QueryString["CompanyID"].ToString());
            GenerateControls();
        }
    }
    #endregion

    #region User Defined Functions
    private void GenerateControls()
    {
        Response.Clear();
        DataSet dsShiftSetting = new DataSet();
        DataSet dsOTRoundoff = new DataSet();
        dsOTRoundoff = getValue(CompanyID);
        int i = 1;
        string str_tblRoundoff = "";
        if (dsOTRoundoff != null)
        {
            DataTable dt_OTRoundoff = new DataTable();
            if (dsOTRoundoff.Tables.Count > 0)
            {
                string strRowCount = string.Empty;
                dt_OTRoundoff = dsOTRoundoff.Tables[0];
                if (dt_OTRoundoff.Rows.Count > 0)
                {
                    strRowCount = Convert.ToString(dt_OTRoundoff.Rows.Count);
                    Session["OTRowCount"] = strRowCount;
                    hdn_OTRowCount.Value = strRowCount;
                }
                else
                {
                    Session["OTRowCount"] = 0;
                }
                if (dt_OTRoundoff.Rows.Count > 0)
                {
                    str_tblRoundoff += "<div width='100%'>";
                    foreach (DataRow dr in dt_OTRoundoff.Rows)
                    {
                        string StartTime = dr["StartTime"].ToString();
                        string EndTime = dr["EndTime"].ToString();
                        string RoundedAs = dr["RoundedAs"].ToString();
                        str_tblRoundoff += "<div class='row pull-left-button' id='tbl_LeavePolicy" + i + "'>";
                        str_tblRoundoff += "<div class='col-md-3'>";
                        str_tblRoundoff += "<input type='text' value ='" + StartTime + "' ID='txt_From" + i + "' style=\"margin-bottom:15px\" Class='form-control' onpaste='return false' ondrop='return false' oncut='return false' EnableViewState='true' runat='server' MaxLength='5' onblur=\"javascript:return RoundoffValidation(this," + i + ",'" + rm.GetString("Alert_EnterStartTimeTheRangeis", ci) + "','" + rm.GetString("Alert_EntervalidStartTime", ci) + "','" + rm.GetString("Alert_GivenStartTimeshouldbegreaterthanoneminuteofpreviousEndTimePleaseverify", ci) + "','" + rm.GetString("Alert_GivenStartTimeshouldbelesserthancurrentEndTimePleaseverify", ci) + "','" + rm.GetString("Alert_EnterEndTimewhichshouldbegreaterthanStartTime", ci) + "','" + rm.GetString("Alert_EntervalidEndTimehhmm", ci) + "','" + rm.GetString("Alert_EnterEndTimewhichshouldbegreaterthanStartTimeandmaximumof", ci) + "','" + rm.GetString("Alert_EndTimeshouldbegreaterthanStartTime", ci) + "','" + rm.GetString("Alert_GivenEndTimeshouldbelesserthanoneminuteofnextStartTimePleaseverify", ci) + "','" + rm.GetString("Alert_GivenEndTimeshouldbegreaterthancurrentStartTimePleaseverify", ci) + "','" + rm.GetString("Alert_EnterRoundedAsTheRangeis", ci) + "','" + rm.GetString("Alert_EntervalidRoundedAs", ci) + "','" + rm.GetString("Alert_EnterRoundedAsTheRangeis", ci) + "');\"/>";
                        str_tblRoundoff += "</div>";
                        str_tblRoundoff += "<div class='col-md-3'>";
                        str_tblRoundoff += "<input type='text' value ='" + EndTime + "' ID='txt_To" + i + "' style=\"margin-bottom:15px\" Class='form-control' onpaste='return false' ondrop='return false' oncut='return false' EnableViewState='true' runat='server' MaxLength='5' onblur=\"javascript:return RoundoffValidation(this," + i + ",'" + rm.GetString("Alert_EnterStartTimeTheRangeis", ci) + "','" + rm.GetString("Alert_EntervalidStartTime", ci) + "','" + rm.GetString("Alert_GivenStartTimeshouldbegreaterthanoneminuteofpreviousEndTimePleaseverify", ci) + "','" + rm.GetString("Alert_GivenStartTimeshouldbelesserthancurrentEndTimePleaseverify", ci) + "','" + rm.GetString("Alert_EnterEndTimewhichshouldbegreaterthanStartTime", ci) + "','" + rm.GetString("Alert_EntervalidEndTimehhmm", ci) + "','" + rm.GetString("Alert_EnterEndTimewhichshouldbegreaterthanStartTimeandmaximumof", ci) + "','" + rm.GetString("Alert_EndTimeshouldbegreaterthanStartTime", ci) + "','" + rm.GetString("Alert_GivenEndTimeshouldbelesserthanoneminuteofnextStartTimePleaseverify", ci) + "','" + rm.GetString("Alert_GivenEndTimeshouldbegreaterthancurrentStartTimePleaseverify", ci) + "','" + rm.GetString("Alert_EnterRoundedAsTheRangeis", ci) + "','" + rm.GetString("Alert_EntervalidRoundedAs", ci) + "','" + rm.GetString("Alert_EnterRoundedAsTheRangeis", ci) + "');\"/>";
                        str_tblRoundoff += "</div>";
                        str_tblRoundoff += "<div class='col-md-3'>";
                        str_tblRoundoff += "<input type='text' value ='" + RoundedAs + "' ID='txt_RoundedAs" + i + "' style=\"margin-bottom:15px\" Class='form-control' onpaste='return false' ondrop='return false' oncut='return false' EnableViewState='true' runat='server' MaxLength='5' onblur=\"javascript:return RoundoffValidation(this," + i + ",'" + rm.GetString("Alert_EnterStartTimeTheRangeis", ci) + "','" + rm.GetString("Alert_EntervalidStartTime", ci) + "','" + rm.GetString("Alert_GivenStartTimeshouldbegreaterthanoneminuteofpreviousEndTimePleaseverify", ci) + "','" + rm.GetString("Alert_GivenStartTimeshouldbelesserthancurrentEndTimePleaseverify", ci) + "','" + rm.GetString("Alert_EnterEndTimewhichshouldbegreaterthanStartTime", ci) + "','" + rm.GetString("Alert_EntervalidEndTimehhmm", ci) + "','" + rm.GetString("Alert_EnterEndTimewhichshouldbegreaterthanStartTimeandmaximumof", ci) + "','" + rm.GetString("Alert_EndTimeshouldbegreaterthanStartTime", ci) + "','" + rm.GetString("Alert_GivenEndTimeshouldbelesserthanoneminuteofnextStartTimePleaseverify", ci) + "','" + rm.GetString("Alert_GivenEndTimeshouldbegreaterthancurrentStartTimePleaseverify", ci) + "','" + rm.GetString("Alert_EnterRoundedAsTheRangeis", ci) + "','" + rm.GetString("Alert_EntervalidRoundedAs", ci) + "','" + rm.GetString("Alert_EnterRoundedAsTheRangeis", ci) + "');\"/>";
                        str_tblRoundoff += "</div >";
                        str_tblRoundoff += "<div class='col-md-3'><button type=\"button\" style=\"margin-left:0px\" id=\"Del_Button" + i + "\" class=\"btn del-btn\" runat=\"server\" OnClick=\"javascript:return removeRowOT(" + i + ",this,'" + rm.GetString("Alert_Deleteonebyonefromlastdata", ci) + "');\"><span class=\"fa fa-trash-o\"></span> Delete</button></div></div>";
                        i++;
                    }
                    str_tblRoundoff += "</div>";
                }
            }
        }
        ConcatenateString += "$" + Convert.ToString((i - 1));
        str_tblRoundoff += ConcatenateString;
        Response.Write(str_tblRoundoff);
        Response.End();
    }
    protected DataSet getValue(int CompanyId)
    {
        ShiftSettingsEventData getShift = new ShiftSettingsEventData();
        DataSet ds = new DataSet();
        DataSet dsOTRoundoff = new DataSet();
        ds = getShift.GetShiftSettingsByComId(CompanyId);
        if (ds != null)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["maxHoursBeforeShift"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["maxHoursBeforeShift"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["maxHoursAfterShift"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["maxHoursAfterShift"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["HolidayOT"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["HolidayOT"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["WeekOffOT"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["WeekOffOT"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["FullDayAttendance"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["FullDayAttendance"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["halfdayAttendance"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["halfdayAttendance"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["DefaultMonthClosureDate"] != DBNull.Value)
                {
                    ConcatenateString += "$" + (Convert.ToDateTime(ds.Tables[0].Rows[0]["DefaultMonthClosureDate"].ToString())).ToString(Session["MDateFormat"].ToString());
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["IsFlexible"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToInt32(ds.Tables[0].Rows[0]["IsFlexible"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["FlexibleFlag"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToInt32(ds.Tables[0].Rows[0]["FlexibleFlag"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["otOption"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["otOption"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["OTRoundoffEnable"] != DBNull.Value)
                {
                    if (Convert.ToInt32(ds.Tables[0].Rows[0]["OTRoundoffEnable"]) == 1)
                    {
                        int shiftSettingId = Convert.ToInt32(ds.Tables[0].Rows[0]["ShiftSettingId"]);
                        dsOTRoundoff = getShift.GetOTRoundoffByShiftSettingId(shiftSettingId);
                    }
                    ConcatenateString += "$" + Convert.ToInt32(ds.Tables[0].Rows[0]["OTRoundoffEnable"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["WeeklyOffStartHours"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["WeeklyOffStartHours"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["IgnoreDuplicatePunch"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["IgnoreDuplicatePunch"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["PunchInterval"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["PunchInterval"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["AfterShiftTime"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["AfterShiftTime"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["BeforeShiftTime"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["BeforeShiftTime"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["DefinedWorkhrs"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["DefinedWorkhrs"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["NoOfSuccessiveDaysInYear"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["NoOfSuccessiveDaysInYear"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[1].Rows[0]["RecordCount"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[1].Rows[0]["RecordCount"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["CompensationValitityDays"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["CompensationValitityDays"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                ConcatenateString += "$$" + Convert.ToString(ds.Tables[0].Rows[0]["HalfDayCompOff"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["FullDayCompOff"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["VaildityCompOffDays"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["LateEntry"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["EarlyEntry"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["EarlyExit"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["LateExit"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["IsLunchDeduction"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["LunchDeductionHours"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["Flexi_AfterShiftTime"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["Flexi_BeforeShiftTime"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["Flexi_DefinedWorkhrs"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["MaxHoursBeforeShift_24HrsShift"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["WeeklyOffStartHours_24HrsShift"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["CumulativeWeekStartDay"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["CumulativeWeekEndDay"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["DefaultLunchHours"]);
                ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["MaxLunchHours"]);
                //Modified by Gopinath on 18Jun14 for Angler Migration added new column named as 'ExceptionHours'
                if (ds.Tables[0].Rows[0]["MaxWorkPlaceInHours"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["MaxWorkPlaceInHours"]);
                }
                if (ds.Tables[0].Rows[0]["Carry_Forward_COff_Year"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["Carry_Forward_COff_Year"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["isRequestingforCompOff"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["isRequestingforCompOff"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["FirstAndLast"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["FirstAndLast"]);
                }
                if (ds.Tables[0].Rows[0]["SpecialOverTime1"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["SpecialOverTime1"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["SpecialOverTime2"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["SpecialOverTime2"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["LATEMINSPERDAY"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["LATEMINSPERDAY"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["LATEDAYSPERMONTH"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["LATEDAYSPERMONTH"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["EarlyExitMinsPerDay"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["EarlyExitMinsPerDay"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["EarlyExitDaysPerMonth"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["EarlyExitDaysPerMonth"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }
                if (ds.Tables[0].Rows[0]["EnableAbsent"] != DBNull.Value)
                {
                    ConcatenateString += "$" + Convert.ToString(ds.Tables[0].Rows[0]["EnableAbsent"]);
                }
                else
                {
                    ConcatenateString += "$0";
                }

            }
            else
            {
                Response.Clear();
                Response.Write("Fail");
                Response.End();
            }
        }
        else
        {
            Response.Clear();
            Response.Write("Fail");
            Response.End();
        }
        return dsOTRoundoff;
        ds.Clear();
        ds.Dispose();
    }
    #endregion
}
