using System;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.Net;
using System.Net.Mail;
using System.Resources;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.DirectoryServices;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                   Started Date  : 12-Aug-2007
* Module          : Shift Settings                              Last Modified : 14-Aug-2007
* Programmer      : Senthil Kumar NP
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
****************************************************************************************************************************/
public partial class Organization_Settings_Organization_ShiftSetting : Base.BasePage
{
    #region Global Variable Declaration
    ResourceManager rm;
    CultureInfo ci;
    ShiftEvenData objShift = new ShiftEvenData();
    cls_Common objClassCommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    EmployeeEventData ObjEmployeeEventData = new EmployeeEventData();
    ShiftExchange objshift = new ShiftExchange();
    BrandingEventdata obj_Branding = new BrandingEventdata();
    DataSet ds_Checkuser = new DataSet();
    string gstrUserGroupName = string.Empty;
    string strMonthClosureDate, gstrDateFormat;
    int payrollConfig = 0;
    string strDate, strTime;
    /// <summary>
    /// Approval settings variables
    /// </summary>
    int ApprovalExists = 0, approvalPage = 0, OnDutyEntryExists = 0, manualEntryExists = 0, permissionSanctionExists = 0, leaveSanctionExists = 0, shiftPatternExists = 0, shiftRosterExists = 0, otApprovalExists = 0;
    byte[] img_Cuslogo;
    int findex;
    string str_imgType, strFileName;
    string strClassnameForLoad = string.Empty, strTxtDataForLoad = string.Empty, strPathName = string.Empty, strPreviewPath = string.Empty, strDestinationPath = string.Empty;
    string[] delim = { "\r\n" };
    string gstrHeaderBgColorCode = string.Empty;
    bool blnStyleSheetModified;
    int intCompanyId = 0;
    #endregion
    #region Page Load Event
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        if (!Page.IsPostBack)
        {
            objClassCommon.menu("Configuration", "51");
            Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
            Hidden2.Value = Convert.ToString(Session["ITimeFormat"]);
            base.CheckPages(51);
            hdf_controlID.Value = "";
        }
        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;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        string strSetAlert = "";
        strSetAlert = strSetAlert + "<script language='javascript'>";
        strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_Select_Company", ci) + "','" + rm.GetString("Alert_Enter_Before_Shift_Maximum_Hours", ci) + "','" + rm.GetString("Alert_Enter_valid_Before_Shift_Maximum_Hours", ci) + "','" + rm.GetString("Alert_Enter_Weekly_Off_Shift_Start_Hours", ci) + "','" + rm.GetString("Alert_Enter_valid_Weekly_Off_Shift_Start_Hours", ci) + "','" + rm.GetString("Alert_Enter_After_Shift_Maximum_Hours", ci) + "','" + rm.GetString("Alert_Enter_valid_After_Shift_Maximum_Hours", ci) + "','" + rm.GetString("Alert_Enter_valid_Time_Interval", ci) + "','" + rm.GetString("Alert_Enter_Time_Interval", ci) + "','" + rm.GetString("Alert_Enter_Default_Monthclosure_Date", ci) + "','" + rm.GetString("Alert_Enter_all_the_three_OT_Roundoff_values", ci) + "','" + rm.GetString("Alert_Add_the_OT_Roundoff_values_by_clicking_ADD_button", ci) + "','" + rm.GetString("Alert_Are_you_sure_to_Save", ci) + "','" + rm.GetString("Alert_Enter_Before_Shift_Max_Hours", ci) + "','"
            + rm.GetString("Alert_Enter_After_Shift_Max_Hours", ci) + "','" + rm.GetString("Alert_Enter_Shift_Break", ci) + "','" + rm.GetString("Alert_Enter_Shift_Max_Break_Hours", ci) + "','" + rm.GetString("Alert_Enter_No_of_Working_hours_Weekly", ci) + "','" + rm.GetString("Alert_Enter_No_of_Working_hours_Monthly", ci) + "','" + rm.GetString("Alert_Enter_all_the_three_OT_Roundoff_values", ci) + "','" + rm.GetString("Alert_NoDetailsfoundd", ci) + "','" + rm.GetString("Alert_Enter_HalfDayComoff", ci) + "','" + rm.GetString("Alert_Enter_FullDayComoff", ci) + "', '" + rm.GetString("Alert_Enter_ValidsDays", ci) + "','" + rm.GetString("Alert_Enter_Lunch_Deduction_Hours", ci) + "','" + rm.GetString("Alert_Enter_Valid_Lunch_Deduction_Hours", ci) + "', '" + rm.GetString("Alert_Vaild_HalfDayComoff", ci) + "', '" + rm.GetString("Alert_Enter_ValidRange_Lunch_Deduction_Hours", ci) + "','" + rm.GetString("Alert_EnterBeforeShiftMaxHrsfor24HrsShift", ci) + "','" + rm.GetString("Alert_Select_a_Company_to_Save_Approval_Settings", ci) + "','" + rm.GetString("Alert_PleaseEnterNumberofSuccessiveDays", ci) + "','" + rm.GetString("Alert_NumberofSuccessiveDaysisnotmorethan365", ci) + "','" + rm.GetString("Alert_PleaseselectGifJPEGJPGBMPFiles", ci) + "','" + rm.GetString("Alert_EnterValidEmailId", ci) + "','" + rm.GetString("Alert_EnterUserName", ci) + "','" + rm.GetString("Alert_EnterPassword", ci) + "');";
        strSetAlert = strSetAlert + "SetAlertCheckDate('" + rm.GetString("Alert_Validmonthdatefourdigit", ci) + "','" + rm.GetString("Alert_Validdatemonthfourdigit", ci) + "','" + rm.GetString("Alert_Invalidyearentry", ci) + "','" + rm.GetString("Alert_Invalidmonthentry", ci) + "','" + rm.GetString("Alert_Invaliddateentry", ci) + "','" + rm.GetString("Alert_IncorrectdateformatDDMONYYYY", ci) + "','" + rm.GetString("Alert_Entertime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "','" + rm.GetString("Alert_Invalidtimeformat1", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMM", ci) + "','" + rm.GetString("Alert_ValiddatemonthMMDDYYHHMMTT", ci) + "','" + rm.GetString("Alert_PleaseentervalidDateandTime", ci) + "','" + rm.GetString("Alert_Invalidvalueforhours", ci) + "','" + rm.GetString("Alert_Invalidvalueforminites", ci) + "');";
        strSetAlert = strSetAlert + "SetMyreferencesAlertMessages('" + rm.GetString("Alert_EnterAdminEmailId", ci) + "','" + rm.GetString("Alert_EnterIPAddressHostName", ci) + "','" + rm.GetString("Alert_EnterPortNumber", ci) + "','" + rm.GetString("Alert_ConfirmSave", ci) + "');";
        strSetAlert = strSetAlert + "</script>";
        Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        CVMonthClosureDate.ErrorMessage = "";
        // approval setting coding copied from file   
        approvalPage = objClassCommon.CheckPageExistsInLicense(228);
        //approvalPage = 0;
        if (approvalPage != 0)
        {
            liApproval.Style.Add("display", "block");
            DivCompoff.Style.Add("display", "block");
            shiftPatternExists = objClassCommon.CheckPageExistsInLicense(20);
            shiftRosterExists = objClassCommon.CheckPageExistsInLicense(69);
            otApprovalExists = objClassCommon.CheckPageExistsInLicense(97);
            leaveSanctionExists = objClassCommon.CheckPageExistsInLicense(248);
            manualEntryExists = objClassCommon.CheckPageExistsInLicense(98);
        }
        else
        {
            liApproval.Style.Add("display", "none");
            DivCompoff.Style.Add("display", "none");
        }
        if (!IsPostBack)
        {
            liGeneral.Attributes.Add("Class", "active");
            tab1.Attributes.Add("Class", "tab-pane active");
            ddlCompany.Focus();
            CompanyBinding();
            if (Convert.ToString(Session["WeekStartDay"]) == "")
            {
                ddlWeekStartDay.SelectedValue = "1";
                Session["WeekStartDay"] = "1";
            }
            else
                ddlWeekStartDay.SelectedValue = Convert.ToString(Session["WeekStartDay"]);
            if (Convert.ToString(Session["WeekEndDay"]) == "")
            {
                ddlWeekEndDay.SelectedValue = "7";
                Session["WeekEndDay"] = "7";
            }
            else
            {
                ddlWeekEndDay.SelectedValue = Convert.ToString(Session["WeekEndDay"]);
            }
            if (Convert.ToString(Session["MonthStartDay"]) == "")
            {
                ddlMonthStrDate.SelectedValue = "1";
                Session["MonthStartDay"] = "1";
            }
            else
            {
                ddlMonthStrDate.SelectedValue = Convert.ToString(Session["MonthStartDay"]);
            }
            if (Convert.ToString(Session["MonthEndDay"]) == "")
            {
                ddlMonthEndDate.SelectedValue = "31";
                Session["MonthEndDay"] = "31";
            }
            else
            {
                ddlMonthEndDate.SelectedValue = Convert.ToString(Session["MonthEndDay"]);
            }
            string strSetYearSelect = "";
            strSetYearSelect = strSetYearSelect + "<script language='javascript'>";
            strSetYearSelect = strSetYearSelect + "GetWeekCount(); GetMonthCount();";
            strSetYearSelect = strSetYearSelect + "</script>";
            Page.RegisterStartupScript("SetCounts", strSetYearSelect);
            //Approval setting Codings
            if (shiftPatternExists == 0)
                trPattern.Style.Add("display", "none");
            if (shiftRosterExists == 0)
                trRoster.Style.Add("display", "none");
            if (otApprovalExists == 0)
                trOTApproval.Style.Add("display", "none");
            if (leaveSanctionExists == 0)
            {
                trLeaveSanction.Style.Add("display", "none");
                trPermissionSanction.Style.Add("display", "none");
                trOnDutyEntry.Style.Add("display", "none");
            }
            if (manualEntryExists == 0)
                trManualEntry.Style.Add("display", "none");
            if (ApprovalExists == 0)
                trApproval.Style.Add("display", "none");
            DateandTimeFormatWhilePageLoading();
            LoadMailConfiguration();
            UserRights();
            /*Added New parameter(Max Days/Month)for Angler. For this we are checking whether the payroll configuration page is exists or not*/
            payrollConfig = objClassCommon.CheckPageExistsInLicense(185);
            /*Below parameter is used for Angler*/
            if (payrollConfig == 0)
            {
                divDefaultlunch.Style.Add("display", "none");
                lblExceptionHrs.Style.Add("display", "none");
                txtExceptionHrs.Style.Add("display", "none");
                txtExceptionHours.Text = "00:40";
                txtDefaultLunch.Text = "01:00";
                txtLunchHrs.Text = "00:10";
                lblMandat.Text = "11 No.";
                Session["payrollConfig"] = 0;
            }
            else
            {
                lblMandat.Text = "11 No.";
                Session["payrollConfig"] = 1;
            }
        }

        if (Session["Demo"] != null && Convert.ToString(Session["Demo"]) == "Express")
        {
            Compoff.Style.Add("display", "none");
            trException.Style.Add("display", "none");
            trOverTime.Style.Add("display", "none");
            trWkOff.Style.Add("display", "none");
            trHoliWkOff.Style.Add("display", "none");
            trOvertimehead.Style.Add("display", "none");
            trFullDayComoff.Style.Add("display", "none");
            trHalfDayComoff.Style.Add("display", "none");
            trOTCompOffSettings.Style.Add("display", "none");
            trOTRoundOff.Style.Add("display", "none");
            txtFullDayComoff.Text = "08:00";
            txtHalfDayComoff.Text = "04:00";
            trFlexiOverTime.Style.Add("display", "none");
            NonFlexiSettings.Style.Add("display", "none");
        }

        if (Convert.ToString(Session["packageID"]) != "")
        {
            if (Convert.ToInt32(Session["packageID"]) == 157)
            {
                DivLateMinutes2.Style.Add("display", "none");
                DivEarlyExit2.Style.Add("display", "none");
                divAbsent.Style.Add("display", "none");
            }
            else if (Convert.ToInt32(Session["packageID"]) < 159)  //vaigai and future clients can see
            {
                DivLateMinutes1.Style.Add("display", "none");
                DivLateMinutes2.Style.Add("display", "none");
                DivEarlyExit1.Style.Add("display", "none");
                DivEarlyExit2.Style.Add("display", "none");
                divAbsent.Style.Add("display", "none");
            }
        }
    }
    #endregion
    #region User Defined Functions
    private void CompanyBinding()
    {
        DataSet dsCompany = new DataSet();
        dsCompany = objShift.SelectCompany(gstrUserGroupName, Convert.ToString(Session["LevelRights"]), 0);
        if (dsCompany != null)
        {
            if (dsCompany.Tables[0].Rows.Count > 0)
            {
                BindDropDown(dsCompany, ddlCompany);
                BindDropDown(dsCompany, ddlApprovalCompany);
                BindDropDown(dsCompany, ddlCompanyOT);
            }
        }
    }
    private void BindDropDown(DataSet dsCompany, DropDownList ddl)
    {
        ddl.DataSource = dsCompany;
        ddl.DataTextField = "CompanyName";
        ddl.DataValueField = "CompanyId";
        ddl.DataBind();
        FillTitle(ddl);
    }
    private void FillTitle(DropDownList ddl)
    {
        foreach (ListItem item in ddl.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    protected void ClearValues()
    {
        this.txtBeforeShiftMax.Text = string.Empty;
        this.txtAfterShiftMax.Text = string.Empty;
        this.txtShiftBreak.Text = string.Empty;
        this.txtShiftMaxBreak.Text = string.Empty;
        this.txtWorkingHoursWeek.Text = string.Empty;
        this.txtWorkingHoursMonth.Text = string.Empty;
        this.txt_OvertmeOnholidays.Text = string.Empty;
        this.txt_OvertimeOnWeeklyOff.Text = string.Empty;
        this.txtMonthClosureDate.Text = string.Empty;
        this.txtWeekOffStartHours.Text = string.Empty;
        this.divFlexibleParameter.Visible = false;
        this.txtBeforeShiftMax_24HrsShift.Text = string.Empty;
        this.txtWeekOffStartHours_24HrsShift.Text = string.Empty;
        this.txtHalfDayComoff.Text = this.txtFullDayComoff.Text = this.txtValidsDays.Text = string.Empty;
    }
    private void LoadStrings(CultureInfo ci)
    {
        #region ApprovalTab
        #region IFFCO 
        if (Convert.ToString(Session["packageID"]) != "")
            if (Convert.ToInt16(Session["packageID"]) >= 159)
            {
                divWebclockInOut.Style.Add("display", "none");
                lblwebClockInOut.Text = rm.GetString("WebClockInOutApproval", ci);
            }
        #endregion
        lblApprovalCompany.Text = lblCompany.Text = rm.GetString("EntranceMaster_Company", ci);
        lbl_Pattern.Text = rm.GetString("OrganisationSettings_ApprovalSettings_Pattern", ci);
        lbl_Roster.Text = rm.GetString("OrganisationSettings_ApprovalSettings_Roster", ci);
        lbl_OTApproval.Text = rm.GetString("lblOVerTimeApproval", ci);
        lbl_LeaveSanction.Text = rm.GetString("OrganisationSettings_ApprovalSettings_LeaveSanction", ci);
        lbl_PermissionSanction.Text = rm.GetString("OrganisationSettings_ApprovalSettings_PermissionSanction", ci);
        lbl_ManualEntry.Text = rm.GetString("OrganisationSettings_ApprovalSettings_ManualEntry", ci);
        lbl_OnDutyEntry.Text = rm.GetString("OnDutyApproval_Header", ci);
        lblApproval.Text = rm.GetString("OrganisationSettings_ApprovalSettings_Approval", ci);
        #endregion
        chkboxFreescan.Text = rm.GetString("lbl_FreescanConsiderday", ci);
        lbl_Header.Text = rm.GetString("Menu_Org_Settings", ci);
        lblEmailSettingsConfig.Text = rm.GetString("lbl_EmailSettingConfigurations", ci);
        Label11.Text = rm.GetString("lbl_TestEmailFunctionality", ci);
        lbl_EmailIDTest.Text = rm.GetString("Alert_EnterValidEmailId", ci);
        lbl_IndicatesMandatoryFields6.Text = lbl_IndicatesMandatoryFields5.Text = lbl_IndicatesMandatoryFields4.Text = lbl_IndicatesMandatoryFields3.Text = lbl_IndicatesMandatoryFields2.Text = lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lblCompany2.Text = rm.GetString("EntranceMaster_Company", ci);
        lbl_ShiftMax.Text = rm.GetString("ShiftSetting_BeforeShiftMaxHrs", ci);
        lbl_AfterShiftmax.Text = rm.GetString("ShiftSetting_AfterShiftMaxHrs", ci);
        lbl_ShiftBreak.Text = rm.GetString("ShiftSetting_ShiftBreak", ci);
        lbl_ShitMaxbreak.Text = rm.GetString("ShiftSetting_ShiftMaxBreakHrs", ci);
        lbl_WeeklyWorkinghrs.Text = rm.GetString("ShiftSetting_NoOfWorkingHrsWeekly", ci);
        lbl_MonthlyWorkinghrs.Text = rm.GetString("ShiftSetting_NoOfWorkingHrsMonthly", ci);
        lblAfterShiftTime.Text = rm.GetString("AfterShiftTime", ci);
        lblBeforeShiftTime.Text = rm.GetString("BeforeShiftTime", ci);
        lblConsiderDefinedWorkHours.Text = rm.GetString("ConsiderDefinedWorkHours", ci);
        lblNoOfSuccessiveDays.Text = rm.GetString("NoOfSuccessiveDays", ci);
        lblAllowedlateminday.Text = rm.GetString("LateInMinutesPerDay", ci);
        lblAllowedlatedaymonth.Text = rm.GetString("LateInDaysPerMonth", ci);
        lblEarlyoutMintsPerDay.Text = rm.GetString("EarlyoutMintsPerDay", ci);
        lblEarlyoutDaysPermonth.Text = rm.GetString("EarlyoutDaysPermonth", ci);
        btnExample4.InnerText = btnExample3.InnerText = btnExample2.InnerText = btnExample1.InnerText = rm.GetString("Example", ci);
        lblEarlyoutMonthExample.InnerText = rm.GetString("EarlyoutMonthExample", ci);
        lblEarlyMintsDayExample.InnerText = rm.GetString("EarlyMintsDayExample", ci);
        lblLateInMonthExample.InnerText = rm.GetString("LateInMonthExample", ci);
        lblLateInMintsDayExample.InnerText = rm.GetString("LateInMintsDayExample", ci);
        chkEnableAbsent.Text = rm.GetString("AbsentLeaveEnable", ci);
        btnEnableAbsentExample.InnerText = rm.GetString("Example", ci);
        lblEnableAbsent.InnerText = rm.GetString("EnableAbsentExample", ci);
        lbl_OverTimeOnHolidays.Text = rm.GetString("ShiftTiming_OverTimeOnHolidays", ci);
        lbl_OverTimeOnWeeklyOff.Text = rm.GetString("ShiftTiming_OverTimeOnWeeklyOff", ci);
        lblHoliWeek.Text = rm.GetString("lblHolidayWeekOff", ci);
        lbl_MonthClosureDate.Text = rm.GetString("lbl_MonthClosureDate", ci);
        lblFullDay.Text = rm.GetString("Full_Day_Attendance", ci);
        lblHalfDay.Text = rm.GetString("Half_Day_Attendance", ci);
        lblCompensation.Text = rm.GetString("ShiftSetting_Compensation", ci);
        lblDataProcess.Text = rm.GetString("ShiftTiming_DataProcessSetting", ci);
        lblFlexibleHours.Text = rm.GetString("ShiftTiming_FlexibleShiftTimingsSetting", ci) + " (Every Valid Check-in & Check-out)";
        lblOverTimeSettings.Text = rm.GetString("ShiftTiming_OverTimeSetting", ci);
        lblOption.Text = rm.GetString("Option", ci);
        lblOTRoundOff.Text = rm.GetString("OT_Roundoff", ci);
        lblWeeklyOffStartHours.Text = rm.GetString("Weekly_Off_Config", ci);
        lblWeekOffStartHours.Text = rm.GetString("Weekly_Off_Start_Hours", ci);
        lblFlexible.Text = rm.GetString("FlexibleTimings", ci);
        lblStartTime.Text = rm.GetString("OnDuty_InTime", ci);
        lblEndTime.Text = rm.GetString("OnDuty_OutTime", ci);
        btnAdd.Text = "&nbsp;&nbsp" + rm.GetString("btn_Add", ci);
        rbFullDayNo.Text = rm.GetString("ShiftSetting_No", ci);
        rbFullDayYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnDefinedWorkHoursYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnDefinedWorkHoursNo.Text = rm.GetString("ShiftSetting_No", ci);
        rbHalfDayNo.Text = rm.GetString("ShiftSetting_No", ci);
        rbHalfDayYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnHoliday.Text = rm.GetString("Masters_Holidays_Holidays", ci);
        rbtnIndividualEmployee.Text = rm.GetString("ShiftSetting_IndividualEmployee", ci);
        rbtnNo.Text = rm.GetString("ShiftSetting_No", ci);
        rbtnOrganization.Text = rm.GetString("ShiftSetting_Organization", ci);
        rbtnOTDisable.Text = rm.GetString("SMSTemplateList_btnDisable", ci);
        rbtnOTEnable.Text = rm.GetString("SMSTemplateList_btnEnable", ci);
        rbtnWeekoff.Text = rm.GetString("ShiftSetting_WeeklyOff", ci);
        rbtnYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        Label1.Text = rm.GetString("ShiftSetting_hhmm", ci);
        Label2.Text = rm.GetString("ShiftSetting_hhmm", ci);
        Label3.Text = rm.GetString("ShiftSetting_hhmm", ci);
        rbtCompoffRequestYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtCompoffRequestNo.Text = rm.GetString("ShiftSetting_No", ci);
        lblCompoffRequest.Text = rm.GetString("lbl_CompoffRequest", ci);
        lbl_Comoffcarry.Text = rm.GetString("lbl_CarryForwardtheCompOff", ci);
        rbtnCompCarryYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnCompCarryNo.Text = rm.GetString("ShiftSetting_No", ci);
        lblTimeInterval.Text = rm.GetString("TimeInterval_ShiftSettings", ci);
        lblIgnoreDuplicatePunches.Text = rm.GetString("IgnoreDuplicatePunches_ShiftSettings", ci);
        rbtIgnoreDuplicatesYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtIgnoreDuplicatesNo.Text = rm.GetString("ShiftSetting_No", ci);
        lblRoundedAs.Text = rm.GetString("ShiftSetting_RoundedAs", ci);
        CVMonthClosureDate.ErrorMessage = rm.GetString("Custome_Month_Closure_date_should_not_be_future_date", ci);
        RngOverTimeOnHolidays.ErrorMessage = rm.GetString("RngOver_TimeOnHolidays", ci);
        RngOverTimeOnWeeklyOff.ErrorMessage = rm.GetString("RngOver_TimeOnWeeklyOff", ci);
        ddlCompany.Items[0].Text = rm.GetString("Select", ci);
        lblHalfDayComoff.Text = rm.GetString("Min_Hrs_HalfDay_Comoff", ci);
        lblFullDayComoff.Text = rm.GetString("Min_Hrs_FullDay_Comoff", ci);
        lblValidsDays.Text = rm.GetString("CompOff_Validity_Days", ci);
        lblOTCompOffSettings.Text = rm.GetString("OT_CompOff_Settings", ci);
        lblLuchDeductionSettings.Text = rm.GetString("ShiftTiming_LunchDeductionSettings", ci);
        lblisLunchDeduct.Text = rm.GetString("ShiftTiming_LunchDeductionSettingsOnWeeklyOffHoliday", ci);
        rbtnYesLunch.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnNoLunch.Text = rm.GetString("ShiftSetting_No", ci);
        lblDeductionHours.Text = rm.GetString("ShiftTiming_LunchDeductionSettings_Hours", ci);
        //Commented for bug number:0025330 by Manikandan.RR on 12-08-2014
        //if (Session["Demo"] != null && Convert.ToString(Session["Demo"]) == "Express")
        //{
        lblNonFlexiSettings.Text = rm.GetString("Non_Flexible_Over_Time_Settings", ci);
        lblFlexSettings.Text = rm.GetString("Flexible_Over_Time_Settings", ci);
        lblflexAfter.Text = rm.GetString("AfterShiftTime", ci);
        lblflexBefore.Text = rm.GetString("BeforeShiftTime", ci);
        lnkMailConfig.Text = btn_Add.Text = btnSaveShiftSetting.Text = btnSaveApprovalSet.Text = btn_Save.Text = "&nbsp;&nbsp" + rm.GetString("btn_Save", ci);
        lnkTestEmail.Text = "&nbsp;&nbsp" + rm.GetString("btn_lnkTestEmail", ci);
        lbl_ReportCon.Text = rm.GetString("lbl_EmailDateFilterCon", ci);
        lbl_ReportCon1.Text = rm.GetString("lbl_EmailDateFilterCon1", ci);
        lbl_DayCount1.Text = rm.GetString("lbl_DayCount", ci);
        lbl_DayCount2.Text = rm.GetString("lbl_DayCount", ci);
        lbl_CusLogo.Text = rm.GetString("BrandingandPersonalization_CustomerLogo", ci);
        lblCompany.Text = rm.GetString("EntranceMaster_Company", ci);
        btn_Add.Text = lnkbtnmyReferences.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        rbtnNoLeaveSanction.Text = rm.GetString("ShiftSetting_No", ci);
        rbtnNoManualEntry.Text = rm.GetString("ShiftSetting_No", ci);
        rbtnNoOnDutyEntry.Text = rm.GetString("ShiftSetting_No", ci);
        rbtnNoOTApproval.Text = rm.GetString("ShiftSetting_No", ci);
        rbtnNoApproval.Text = rm.GetString("ShiftSetting_No", ci);
        rbtnNoPattern.Text = rm.GetString("ShiftSetting_No", ci);
        rbtnNoRoster.Text = rm.GetString("ShiftSetting_No", ci);
        rbtnNoPermissionSanction.Text = rm.GetString("ShiftSetting_No", ci);
        rbtnYesLeaveSanction.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnYesManualEntry.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnYesOnDutyEntry.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnYesOTApproval.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnYesApproval.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnYesPattern.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnYesRoster.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnYesPermissionSanction.Text = rm.GetString("ShiftSetting_Yes", ci);
        ddlApprovalCompany.Items[0].Text = rm.GetString("Select", ci);
        lbl_Man.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lbl_CompanyDetails.Text = rm.GetString("Shift_CompanyDetails", ci);
        lbl_CompanyDetails1.Text = rm.GetString("Shift_CompanyDetails", ci);
        lbl_LeaveOnSuc.Text = rm.GetString("Shift_Leave_On_Successive_Year", ci);
        lbl_ShiftMax_24HrsShift.Text = rm.GetString("Shift_Max24hrs", ci);
        lblWeekOffStartHours_24HrsShift.Text = rm.GetString("Shift_WeekOffStart24Hrs", ci);
        chkboxAfterShiftTime.Text = rm.GetString("AfterShiftTime", ci);
        chkboxBeforeShiftTime.Text = rm.GetString("BeforeShiftTime", ci);
        chkflexAfter.Text = rm.GetString("AfterShiftTime", ci);
        chkflexBefore.Text = rm.GetString("BeforeShiftTime", ci);
        lbl_WeekStartDay.Text = rm.GetString("Shift_WeekStartDay", ci);
        lbl_WeekEndDay.Text = rm.GetString("Shift_WeekEndDay", ci);
        lblMonthStartDate.Text = rm.GetString("Shift_MonthStartDate", ci);
        lblMonthEndDate.Text = rm.GetString("Shift_MonthEndDate", ci);
        lbl_Branding.Text = rm.GetString("System_Branding", ci);
        lblExceptionDetails.Text = rm.GetString("Shift_ExceptionDet", ci);
        lbl_Note.Text = rm.GetString("Shift_Note", ci);
        chkboxExceptionDetails.Items[0].Text = rm.GetString("Dashboard_Late", ci);
        chkboxExceptionDetails.Items[1].Text = rm.GetString("Report_EarlyEntry", ci);
        chkboxExceptionDetails.Items[2].Text = rm.GetString("Report_Early_Exit", ci);
        chkboxExceptionDetails.Items[3].Text = rm.GetString("Report_Late_Exit", ci);
        //lbl_Language.Text = rm.GetString("SystemSettings_MultiLingual_Language", ci);
        //lbl_lingualHeader.Text = rm.GetString("SystemSettings_MultiLingualSelection", ci);
        //ddlLanguage.Items[0].Text = rm.GetString("Select", ci);
        //lbl_DateFormat.Text = rm.GetString("DateandTimeFormat_DateFormat", ci);
        //lbl_TimeFormat.Text = rm.GetString("DateandTimeFormat_TimeFormat", ci);
        lbl_HeaderDateandTimeFormat.Text = rm.GetString("Menu_SystemSettings_DateandTimeFormat", ci);
        lnkbtnmyReferences.Text = "&nbsp;&nbsp" + rm.GetString("btn_Save", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        lblUserName.Text = rm.GetString("EmployeeMaster_UserName", ci);
        lblPassword.Text = rm.GetString("Caption_Password", ci);
        lblMailId.Text = rm.GetString("Admin_Mail_Id", ci);
        lblServerIP.Text = rm.GetString("ServerIP_HostName", ci);
        lblSMTPPort.Text = rm.GetString("SMTP_Port", ci);
        lblSSLEnable.Text = rm.GetString("SSL_Enable", ci);
        lblAuthentication.Text = rm.GetString("Authentication", ci);
        rbtnAuthenticationNo.Text = rm.GetString("ShiftSetting_No", ci);
        rbtnAuthenticationYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        rbtnSSLNo.Text = rm.GetString("ShiftSetting_No", ci);
        rbtnSSLYes.Text = rm.GetString("ShiftSetting_Yes", ci);
        lblGeneralTab.Text = rm.GetString("Shift_General", ci);
        lblOTCompTab.Text = rm.GetString("Shift_OTCompOff", ci);
        lblReportConfigTab.Text = rm.GetString("Shift_ReportConfig", ci);
        lblApprovalTab.Text = rm.GetString("Shift_Approval", ci);
        lblMailTab.Text = rm.GetString("Shift_MailConfig", ci);
        lblMyPrefTab.Text = rm.GetString("Shift_MyPreferences", ci);
        lnhbtnTestDomain.Text = "&nbsp;&nbsp;" + rm.GetString("btn_VerifyConnection", ci);
        lblDomain.Text = rm.GetString("lbl_Domain_Name", ci);
        //RegVtxtMailId.ErrorMessage = rm.GetString("Alert_EnterValidEmailId", ci);
    }
    private void DateandTimeFormatWhilePageLoading()
    {
        // get date,time format from session and show the same in UI
        strDate = Convert.ToString(Session["MDateFormat"]);
        strTime = Convert.ToString(Session["MTimeFormat"]);
        rbtDomain.SelectedValue = Convert.ToString(Session["IsDomain"]);
        txt_DomainName.Text = Convert.ToString(Session["DomainName"]);
        txt_AdminUserName.Text = Convert.ToString(Session["DomainAdminUserName"]);
        string strSpt1 = "";
        if (Convert.ToString(Session["DomainAdminPassword"]) != "")
        {
            strSpt1 = Encryption.Decrypt(Convert.ToString(Session["DomainAdminPassword"]), "Domain");
            txt_AdminPassword.Attributes["value"] = strSpt1;
            txt_AdminPassword.Attributes.Add("value", strSpt1);
            txt_AdminPassword.Text = strSpt1;
        }
        else
        {
            txt_AdminPassword.Text = "";
        }
        switch (strDate)
        {
            case "dd/MM/yyyy":
                rbtnddmmyyyy.Checked = true;
                break;
            case "MM/dd/yyyy":
                rbtnmmddyyyy.Checked = true;
                break;
            case "dd-MMM-yyyy":
                rbtnddmmmyy.Checked = true;
                break;
        }
        if (strTime.Equals(rbtnhhmmsstt.Text))
        {
            rbtnhhmmsstt.Checked = true;
        }
        else
        {
            rbtnHHmmss.Checked = true;
        }
    }
    private int ConvertHoursMinsToMinutes(string inHoursMins)
    {
        int intTotalMinutes = 0, intHours = 0, intMinutes = 0;
        string[] HoursMins = inHoursMins.Split(':');
        intHours = Int16.Parse(HoursMins[0]);
        intMinutes = Int16.Parse(HoursMins[1]);
        intTotalMinutes = (intHours * 60) + intMinutes;
        return intTotalMinutes;
    }
    public void CompareTodate(object s, ServerValidateEventArgs e)
    {
        try
        {
            string strToDateTime;
            gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
            strToDateTime = objClassCommon.DateTimeConvertion((gstrDateFormat), txtMonthClosureDate.Text, "D");
            DateTime dtCurrentDate = DateTime.Parse(DateTime.Now.ToShortDateString());
            DateTime dtToDate = DateTime.Parse(strToDateTime);
            TimeSpan diff = dtToDate.Subtract(dtCurrentDate);
            int day = diff.Days;
            if (day <= 0)
                e.IsValid = true;
            else
            {
                Message(rm.GetString("Custome_Month_Closure_date_should_not_be_future_date", ci));
                e.IsValid = false;
            }
        }
        catch
        {
        }
    }
    #region Message.
    #endregion
    public void UserRights()
    {
        try
        {
            ds_Checkuser = objCheckUser.checkRights(51, 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;
                    this.btnSaveShiftSetting.Visible = true;
                    this.btnSaveApprovalSet.Visible = true;
                }
                else
                {
                    this.btn_Add.Visible = false;
                    this.btnSaveShiftSetting.Visible = false;
                    this.btnSaveApprovalSet.Visible = false;
                }
                if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
                {
                    this.lnkbtnmyReferences.Visible = true;
                }
                else
                {
                    this.lnkbtnmyReferences.Visible = false;
                }
            }
            else
            {
                Response.Redirect("OrganizationLandingPage.aspx");
            }
        }
        catch
        {
        }
    }
    #endregion
    #region Button Click Events
    private void getCompanyID(DropDownList ddl)
    {
        if (ddl.SelectedValue != "0")
            intCompanyId = Convert.ToInt32(ddl.SelectedValue);
        else
        {
            lbl_Error.Text = rm.GetString("Alert_Select_Company", ci);
            return;
        }
    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {

            #region VariableDeclaration
            ShiftSettingsEventData getShift = new ShiftSettingsEventData();
            int organization, individualEmployee, notFlexible, ignorePunch = 0, AfterShiftTime = 0, BeforeShiftTime = 0, WorkHrs = 0, intSuccessiveDays = 0, intCompensation = 0, isRequestingforCompOff = 0;
            bool IsLunchDeduction = false;
            string LunchDeductionHours = "00:00", IsOption = "Holiday";
            int otStatus = 0, shiftSettingId = 0, LateMintsperDay = 0, LateDaysPerMonth = 0, EarlyExitperDay = 0, EarlyExitDaysPerMonth = 0, EnableAbsent = 0, specialOvertime1 = 0, specialOvertime2 = 0, flexibleStatus = 0, flexibleValue = 0;
            int iFullDayAttendance = 1, iHalfDayAttendance = 0, isCarryForwardCOff = 0, intLateEntry = 0, intEarlyEntry = 0, intLateExit = 0, intEarlyExit = 0;
            #endregion
            LinkButton btnSave = (LinkButton)sender;
            try
            {
                if (btnSave.ID.ToString() == "btn_Add")
                    getCompanyID(ddlCompanyOT);
                else
                    getCompanyID(ddlCompany);
                gstrDateFormat = Convert.ToString(Session["MDateFormat"]);
                strMonthClosureDate = objClassCommon.DateConvertion(gstrDateFormat, txtMonthClosureDate.Text);
                if (txtHalfDayComoff.Text == "")
                    txtHalfDayComoff.Text = "00:00";
                if (txtFullDayComoff.Text == "")
                    txtFullDayComoff.Text = "00:00";
                if (txtValidsDays.Text == "")
                    txtValidsDays.Text = "0";
                if (btnSave.ID.ToString() == "btn_Add")
                {
                    #region OvertimeTab
                    intCompensation = (txtCompensationDays.Text == "") ? 0 : Convert.ToInt32(txtCompensationDays.Text);
                    isCarryForwardCOff = (rbtnCompCarryYes.Checked) ? 1 : 0;
                    isRequestingforCompOff = (rbtCompoffRequestYes.Checked) ? 1 : 0;
                    AfterShiftTime = (chkboxAfterShiftTime.Checked == true) ? 1 : 0;
                    BeforeShiftTime = (chkboxBeforeShiftTime.Checked == true) ? 1 : 0;
                    WorkHrs = (rbtnDefinedWorkHoursYes.Checked == true) ? 1 : 0;
                    if (rbtnWeekoff.Checked)
                        IsOption = "WeeklyOff";
                    if (txt_OvertimeOnWeeklyOff.Text == string.Empty)
                        txt_OvertimeOnWeeklyOff.Text = "0";
                    if (txt_OvertmeOnholidays.Text == string.Empty)
                        txt_OvertmeOnholidays.Text = "0";

                    if (Convert.ToString(txtspecialOvertim1.Text) != "")
                        specialOvertime1 = Convert.ToInt16(txtspecialOvertim1.Text);
                    if (Convert.ToString(txtspecialOvertim2.Text) != "")
                        specialOvertime2 = Convert.ToInt16(txtspecialOvertim2.Text);
                    otStatus = (rbtnOTEnable.Checked) ? 1 : 0;
                    if (Session["Demo"] != null && Convert.ToString(Session["Demo"]) != "Express")
                    {
                        shiftSettingId = getShift.insertShiftSetting
                            (
                                "OT",
                                intCompanyId,
                                Convert.ToString(this.txtBeforeShiftMax.Text),
                                Convert.ToString(this.txtAfterShiftMax.Text),
                                Convert.ToString(this.txtShiftBreak.Text),
                                Convert.ToString(this.txtShiftMaxBreak.Text),
                                Convert.ToString(this.txtWorkingHoursMonth.Text),
                                Convert.ToString(this.txtWorkingHoursWeek.Text),
                                Convert.ToString(Session["EmpAutoID"]),
                                Convert.ToString(this.txt_OvertmeOnholidays.Text),
                                Convert.ToString(this.txt_OvertimeOnWeeklyOff.Text.Trim()),
                                Convert.ToString(this.txtBeforeShiftMax_24HrsShift.Text),
                                Convert.ToString(this.txtWeekOffStartHours_24HrsShift.Text),
                                IsOption,
                                strMonthClosureDate,
                                flexibleStatus,
                                flexibleValue,
                                otStatus,
                                iFullDayAttendance,
                                iHalfDayAttendance,
                                Convert.ToString(this.txtWeekOffStartHours.Text),
                                ignorePunch,
                                txtTimeInterval.Text,
                                AfterShiftTime,
                                BeforeShiftTime,
                                WorkHrs,
                                intSuccessiveDays,
                                intCompensation,
                                Convert.ToDateTime(txtHalfDayComoff.Text).ToString("hh:mm"),
                                Convert.ToDateTime(txtFullDayComoff.Text).ToString("hh:mm"),
                                Convert.ToInt16(txtValidsDays.Text),
                                intLateEntry,
                                intEarlyEntry,
                                intEarlyExit,
                                intLateExit,
                                IsLunchDeduction,
                                LunchDeductionHours,
                                chkflexAfter.Checked == true ? 1 : 0,
                                chkflexBefore.Checked == true ? 1 : 0,
                                0,
                                ddlWeekStartDay.SelectedValue.ToString(), ddlWeekEndDay.SelectedValue.ToString(),
                                Convert.ToString(this.txtDefaultLunch.Text),
                                Convert.ToString(this.txtLunchHrs.Text.Trim()),
                                Convert.ToString(this.txtExceptionHours.Text), isCarryForwardCOff, isRequestingforCompOff,
                                chkboxFreescan.Checked,
                                Convert.ToInt16(specialOvertime1),
                                Convert.ToInt16(specialOvertime2)
                                , LateMintsperDay, LateDaysPerMonth
                                , EarlyExitperDay, EarlyExitDaysPerMonth
                                , EnableAbsent
                            );
                    }
                    else
                    {
                        shiftSettingId = getShift.insertShiftSetting("OT", intCompanyId,
                            Convert.ToString(this.txtBeforeShiftMax.Text),
                            Convert.ToString(this.txtAfterShiftMax.Text),
                            Convert.ToString(this.txtShiftBreak.Text),
                            Convert.ToString(this.txtShiftMaxBreak.Text),
                            Convert.ToString(this.txtWorkingHoursMonth.Text),
                            Convert.ToString(this.txtWorkingHoursWeek.Text),
                            Convert.ToString(Session["EmpAutoID"]),
                            Convert.ToString(this.txt_OvertmeOnholidays.Text),
                            Convert.ToString(this.txt_OvertimeOnWeeklyOff.Text.Trim()),
                            Convert.ToString(this.txtBeforeShiftMax_24HrsShift.Text), Convert.ToString(this.txtWeekOffStartHours_24HrsShift.Text),
                            IsOption, strMonthClosureDate, flexibleStatus, flexibleValue, otStatus, iFullDayAttendance, iHalfDayAttendance,
                            Convert.ToString(this.txtWeekOffStartHours.Text),
                            ignorePunch, txtTimeInterval.Text, AfterShiftTime, BeforeShiftTime, WorkHrs, intSuccessiveDays, intCompensation,
                            Convert.ToDateTime(txtHalfDayComoff.Text).ToString("hh:mm"),
                           Convert.ToDateTime(txtFullDayComoff.Text).ToString("hh:mm"),
                            100, intLateEntry, intEarlyEntry, intEarlyExit, intLateExit, IsLunchDeduction, LunchDeductionHours, 0, 0, 0,
                            ddlWeekStartDay.SelectedValue.ToString(), ddlWeekEndDay.SelectedValue.ToString(),
                                Convert.ToString(this.txtDefaultLunch.Text),
                                Convert.ToString(this.txtLunchHrs.Text.Trim()),
                                Convert.ToString(this.txtExceptionHours.Text), isCarryForwardCOff, isRequestingforCompOff, chkboxFreescan.Checked,
                                Convert.ToInt16(specialOvertime1),
                                Convert.ToInt16(specialOvertime2)
                                , LateMintsperDay, LateDaysPerMonth
                                , EarlyExitperDay, EarlyExitDaysPerMonth
                                , EnableAbsent
                            );
                    }

                    #endregion
                }
                else
                {
                    #region GeneralTab
                    if (flexibleStatus == 0)
                    {
                        iFullDayAttendance = 1;
                        iHalfDayAttendance = 1;
                    }
                    intSuccessiveDays = (txtNoOfSuccessiveDays.Text == "") ? 0 : Convert.ToInt32(txtNoOfSuccessiveDays.Text);
                    if (rbtnYesLunch.Checked == true)
                    {
                        IsLunchDeduction = true;
                        LunchDeductionHours = txtDeductionHours.Text.Trim();
                    }
                    if (chkboxExceptionDetails.Items[0].Selected == true)
                    {
                        intLateEntry = 1;
                    }
                    if (chkboxExceptionDetails.Items[1].Selected == true)
                    {
                        intEarlyEntry = 1;
                    }
                    if (chkboxExceptionDetails.Items[2].Selected == true)
                    {
                        intEarlyExit = 1;
                    }
                    if (chkboxExceptionDetails.Items[3].Selected == true)
                    {
                        intLateExit = 1;
                    }
                    if (Convert.ToString(txtLatePerDay.Text) != "")
                        LateMintsperDay = Convert.ToInt32(txtLatePerDay.Text);
                    if (Convert.ToString(txtLateMonth.Text) != "")
                        LateDaysPerMonth = Convert.ToInt32(txtLateMonth.Text);
                    if (Convert.ToString(txtEarlyExitPerDay.Text) != "")
                        EarlyExitperDay = Convert.ToInt32(txtEarlyExitPerDay.Text);
                    if (Convert.ToString(txtEarlyExitDayperMonth.Text) != "")
                        EarlyExitDaysPerMonth = Convert.ToInt32(txtEarlyExitDayperMonth.Text);
                    EnableAbsent = (chkEnableAbsent.Checked) ? 1 : 0;
                    if (rbFullDayNo.Checked)
                    {
                        iFullDayAttendance = 0;
                    }
                    if (rbHalfDayYes.Checked)
                    {
                        iHalfDayAttendance = 1;
                    }
                    ignorePunch = (rbtIgnoreDuplicatesYes.Checked) ? 1 : 0;
                    if (rbtnYes.Checked)
                    {
                        flexibleValue = (rbtnOrganization.Checked) ? 1 : 2;
                        flexibleStatus = 1;
                    }
                    else
                    {
                        flexibleStatus = 0;
                        flexibleValue = 0;
                    }
                    if (rbtnYes.Checked)
                    {
                        if (rbtnOrganization.Checked)
                        {
                            organization = 1;
                        }
                        else if (rbtnIndividualEmployee.Checked)
                        {
                            individualEmployee = 2;
                        }
                    }
                    else
                    {
                        notFlexible = 0;
                    }
                    if (Session["Demo"] != null && Convert.ToString(Session["Demo"]) != "Express")    //surguru
                    {
                        shiftSettingId = getShift.insertShiftSetting
                            (
                                "Gen",
                                intCompanyId,
                                Convert.ToString(this.txtBeforeShiftMax.Text),
                                Convert.ToString(this.txtAfterShiftMax.Text),
                                Convert.ToString(this.txtShiftBreak.Text),
                                Convert.ToString(this.txtShiftMaxBreak.Text),
                                Convert.ToString(this.txtWorkingHoursMonth.Text),
                               Convert.ToString(this.txtWorkingHoursWeek.Text),
                                Convert.ToString(Session["EmpAutoID"]),
                                Convert.ToString(this.txt_OvertmeOnholidays.Text),
                                Convert.ToString(this.txt_OvertimeOnWeeklyOff.Text.Trim()),
                                Convert.ToString(this.txtBeforeShiftMax_24HrsShift.Text),
                                Convert.ToString(this.txtWeekOffStartHours_24HrsShift.Text),
                                IsOption,
                                strMonthClosureDate,
                                flexibleStatus,
                                flexibleValue,
                                otStatus,
                                iFullDayAttendance,
                                iHalfDayAttendance,
                                Convert.ToString(this.txtWeekOffStartHours.Text),
                                ignorePunch,
                                txtTimeInterval.Text,
                                AfterShiftTime,
                                BeforeShiftTime,
                                WorkHrs,
                                intSuccessiveDays,
                                intCompensation,
                                Convert.ToDateTime(txtHalfDayComoff.Text).ToString("hh:mm"),
                                Convert.ToDateTime(txtFullDayComoff.Text).ToString("hh:mm"),
                                Convert.ToInt16(txtValidsDays.Text),
                                intLateEntry,
                                intEarlyEntry,
                                intEarlyExit,
                                intLateExit,
                                IsLunchDeduction,
                                LunchDeductionHours,
                                chkflexAfter.Checked == true ? 1 : 0,
                                chkflexBefore.Checked == true ? 1 : 0,
                                0,
                                ddlWeekStartDay.SelectedValue.ToString(), ddlWeekEndDay.SelectedValue.ToString(),
                                Convert.ToString(this.txtDefaultLunch.Text),
                                Convert.ToString(this.txtLunchHrs.Text.Trim()),
                                Convert.ToString(this.txtExceptionHours.Text), isCarryForwardCOff, isRequestingforCompOff
                                , chkboxFreescan.Checked,
                                Convert.ToInt16(specialOvertime1),
                                Convert.ToInt16(specialOvertime2)
                               , LateMintsperDay, LateDaysPerMonth
                               , EarlyExitperDay, EarlyExitDaysPerMonth
                               , EnableAbsent
                            );
                    }
                    else
                    {
                        shiftSettingId = getShift.insertShiftSetting(
                            "Gen",
                            intCompanyId,
                            Convert.ToString(this.txtBeforeShiftMax.Text),
                            Convert.ToString(this.txtAfterShiftMax.Text),
                            Convert.ToString(this.txtShiftBreak.Text),
                            Convert.ToString(this.txtShiftMaxBreak.Text),
                            Convert.ToString(this.txtWorkingHoursMonth.Text),
                            Convert.ToString(this.txtWorkingHoursWeek.Text),
                            Convert.ToString(Session["EmpAutoID"]),
                            Convert.ToString(this.txt_OvertmeOnholidays.Text),
                            Convert.ToString(this.txt_OvertimeOnWeeklyOff.Text.Trim()),
                            Convert.ToString(this.txtBeforeShiftMax_24HrsShift.Text), Convert.ToString(this.txtWeekOffStartHours_24HrsShift.Text),
                            IsOption, strMonthClosureDate, flexibleStatus, flexibleValue, otStatus, iFullDayAttendance, iHalfDayAttendance,
                            Convert.ToString(this.txtWeekOffStartHours.Text),
                            ignorePunch, txtTimeInterval.Text, AfterShiftTime, BeforeShiftTime, WorkHrs, intSuccessiveDays, intCompensation,
                            Convert.ToDateTime(txtHalfDayComoff.Text).ToString("hh:mm"),
                            Convert.ToDateTime(txtFullDayComoff.Text).ToString("hh:mm"),
                            100, intLateEntry, intEarlyEntry, intEarlyExit, intLateExit, IsLunchDeduction, LunchDeductionHours, 0, 0, 0,
                            ddlWeekStartDay.SelectedValue.ToString(), ddlWeekEndDay.SelectedValue.ToString(),
                                Convert.ToString(this.txtDefaultLunch.Text),
                                Convert.ToString(this.txtLunchHrs.Text.Trim()),
                                Convert.ToString(this.txtExceptionHours.Text), isCarryForwardCOff, isRequestingforCompOff,
                                chkboxFreescan.Checked,
                                Convert.ToInt16(specialOvertime1),
                                Convert.ToInt16(specialOvertime2)
                               , LateMintsperDay, LateDaysPerMonth
                               , EarlyExitperDay, EarlyExitDaysPerMonth
                               , EnableAbsent
                            );
                    }
                    #endregion
                }
                if (shiftSettingId != 0)
                {
                    if (rbtnOTEnable.Checked)
                    {
                        #region OvertimeRoundOff
                        string strOTRoundoff = hdf_OTRoundoff.Value;
                        if (strOTRoundoff != string.Empty && strOTRoundoff != null)
                        {
                            string[] aOTRoundoff = strOTRoundoff.Split('*');
                            for (int i = 0; i < aOTRoundoff.Length; i++)
                            {
                                string[] rOTRoundoff = aOTRoundoff[i].ToString().Split(',');
                                string startTime = rOTRoundoff[0].ToString();
                                string endTime = rOTRoundoff[1].ToString();
                                string roundedAs = rOTRoundoff[2].ToString();
                                float startMins = ConvertHoursMinsToMinutes(startTime);
                                float endMins = ConvertHoursMinsToMinutes(endTime);
                                if (i == 0)
                                {
                                    getShift.DeleteOTRoundoffSetting(shiftSettingId);
                                }
                                getShift.InsertOTRoundoffSetting(shiftSettingId, startTime, endTime, startMins, endMins, roundedAs);
                            }
                        }
                        #endregion
                    }
                    string str = string.Empty;
                    if (btnSave.ID.ToString() == "btn_Add")
                        str = "alert('" + rm.GetString("Alert_OTCompOff_Settings_saved_successfully", ci) + "');location.replace('Organization_shiftSetting.aspx')";
                    else
                        str = "alert('" + rm.GetString("Alert_Shift_Settings_saved_successfully", ci) + "');location.replace('Organization_shiftSetting.aspx')";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
                }
                else
                {
                    string str = "alert('Please fill general Tab configuration fields values first for the selected company')";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
                }
            }
            catch (Exception ex)
            {
                base.Message(ex.ToString());
                //throw (ex);
            }
        }
    }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        ShiftSettingsEventData getShift = new ShiftSettingsEventData();
        int shiftSettingId = 0;
        shiftSettingId = getShift.UpdateShiftReportSetting(Convert.ToString(ddlWeekStartDay.SelectedValue), Convert.ToString(ddlWeekEndDay.SelectedValue), Convert.ToString(ddlMonthStrDate.SelectedValue), Convert.ToString(ddlMonthEndDate.SelectedValue), Convert.ToString(txtmapkey.Text));
        //Overwrite Map key value into web config alone. 
        OverwriteApplicationConnectionString(txtmapkey.Text, "googleMapKey");
        if (shiftSettingId != 0)
        {
            Session["WeekStartDay"] = Convert.ToString(ddlWeekStartDay.SelectedValue);
            Session["WeekEndDay"] = Convert.ToString(ddlWeekEndDay.SelectedValue);
            Session["MonthStartDay"] = Convert.ToString(ddlMonthStrDate.SelectedValue);
            Session["MonthEndDay"] = Convert.ToString(ddlMonthEndDate.SelectedValue);
            string str = "alert('" + rm.GetString("Alert_Report_Settings_saved_successfully", ci) + "');location.replace('Organization_shiftSetting.aspx')";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
    }
    protected void btnSaveApprovalSet_Click(object sender, EventArgs e)
    {
        if (ddlApprovalCompany.SelectedIndex == 0)
        {
            base.Message(rm.GetString("Alert_Select_a_Company_to_Save_Approval_Settings", ci));
        }
        else
        {
            int intApproval = 0, intOnDutyEntry = 0, intManualEntry = 0, intPermissionSanction = 0, intLeaveSanction = 0, intOTApproval = 0, intRoster = 0, intPattern = 0, intCompanyId = 0;
            intCompanyId = Convert.ToInt32(ddlApprovalCompany.SelectedValue);
            intPattern = rbtnYesPattern.Checked == true ? 1 : 0;
            intRoster = rbtnYesRoster.Checked == true ? 1 : 0;
            intOTApproval = rbtnYesOTApproval.Checked == true ? 1 : 0;
            intLeaveSanction = rbtnYesLeaveSanction.Checked == true ? 1 : 0;
            intPermissionSanction = rbtnYesPermissionSanction.Checked == true ? 1 : 0;
            intManualEntry = rbtnYesManualEntry.Checked == true ? 1 : 0;
            intOnDutyEntry = rbtnYesOnDutyEntry.Checked == true ? 1 : 0;
            intApproval = rbtnYesApproval.Checked == true ? 1 : 0;
            objShift.InsertUpdateApprovalSettings(intCompanyId, intPattern, intRoster, intOTApproval, intLeaveSanction, intPermissionSanction, intManualEntry, intOnDutyEntry, intApproval, Convert.ToInt32(Session["EmpAutoID"]), (rbtnwebclkYes.Checked == true) ? true : false);
            base.MessageWithRedirect(rm.GetString("Alert_Approval_Settings_Saved_Successfully", ci), "Organization_shiftSetting.aspx");
        }
    }
    protected void lnkMailConfig_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                int isRequired = 0;
                isRequired = (chkboxIsRequired.Checked) ? 1 : 0;
                if (rbtnAuthenticationYes.Checked == true)
                {
                    if (txtUserName.Text.Trim() == string.Empty)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, GetType(), "Javascript", "javascript:AuthenticateUserEnableDisable(1); ", true);
                        base.Message(rm.GetString("Alert_EnterUserName", ci));
                        return;
                    }
                    if (txtPassword.Text.Trim() == string.Empty)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, GetType(), "Javascript", "javascript:AuthenticateUserEnableDisable(1); ", true);
                        base.Message(rm.GetString("Alert_EnterPassword", ci));
                        return;
                    }
                }

                OverwriteApplicationConnectionString("", "isRequiredEmail");
                OverwriteApplicationConnectionString("", "SMTPClientHost");
                OverwriteApplicationConnectionString("", "FromId");
                OverwriteApplicationConnectionString("", "SMTPPort");
                OverwriteApplicationConnectionString("", "SSLEnable");
                OverwriteApplicationConnectionString("", "MailAuthentication");
                OverwriteApplicationConnectionString("", "MailAuthenticateUser");
                OverwriteApplicationConnectionString("", "MailAuthenticatePassword");
                int sslEnabled = 0;
                sslEnabled = (rbtnSSLYes.Checked == true) ? 1 : 0;
                int authenticationEnabled = 0;
                authenticationEnabled = (rbtnSSLYes.Checked == true) ? 1 : 0;
                authenticationEnabled = 1;
                string password = string.Empty;
                if (txtPassword.Text != string.Empty)
                    password = Cryptographys.Cryptography.Encrypt(txtPassword.Text.Trim(), "TimecheckPhaseI");
                // insert or update with key of date and time format            
                ShiftExchange obj = new ShiftExchange();
                obj.InsertMailConfiguration(txtMailId.Text, txtIPAddress.Text, txtSMTPPort.Text, sslEnabled, authenticationEnabled, txtUserName.Text, password, isRequired);
                base.MessageWithRedirect(rm.GetString("Alert_MailConfigurationSavedSuccessfully", ci), "../Index.aspx");

            }
        }
        catch (Exception ex)
        {
            base.Message(ex.ToString());
        }
    }

    public void OverwriteApplicationConnectionString(string ConnStr, string strValue)
    {
        XmlDocument doc = new XmlDocument();
        string WebConfigFilename = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath).FilePath;
        doc.Load(WebConfigFilename);
        XmlNodeList oList = doc.SelectNodes("configuration/location/appSettings/add");
        for (int i = 0; i < oList.Count; i++)
        {
            XmlAttribute oKey = oList[i].Attributes["key"];
            XmlAttribute oValue = oList[i].Attributes["value"];
            if (oKey.Value == strValue)
            {
                switch (oKey.Value)
                {
                    case "googleMapKey":
                        if (oValue.Value.Contains("API_KEY"))
                        {
                            string replaceString = oValue.Value.Replace("API_KEY", Convert.ToString(txtmapkey.Text));
                            oValue.Value = replaceString;
                        }
                        break;
                    case "isRequiredEmail":
                        if (chkboxIsRequired.Checked == true)
                        {
                            oValue.Value = "1";
                        }
                        else
                        {
                            oValue.Value = "0";
                        }
                        break;
                    case "SMTPClientHost":
                        oValue.Value = txtIPAddress.Text.ToString().Trim();
                        break;
                    case "FromId":
                        oValue.Value = txtMailId.Text.ToString().Trim();
                        break;
                    case "SMTPPort":
                        oValue.Value = txtSMTPPort.Text.ToString().Trim();
                        break;
                    case "SSLEnable":
                        if (rbtnSSLYes.Checked == true)
                        { oValue.Value = "1"; }
                        else
                        { oValue.Value = "0"; }
                        break;
                    case "MailAuthentication":
                        if (rbtnAuthenticationYes.Checked == true)
                        { oValue.Value = "1"; }
                        else
                        { oValue.Value = "0"; }
                        break;
                    case "MailAuthenticateUser":
                        if (rbtnAuthenticationYes.Checked == true)
                            oValue.Value = txtUserName.Text.ToString();
                        else
                            oValue.Value = "";
                        break;
                    case "MailAuthenticatePassword":
                        if (rbtnAuthenticationYes.Checked == true)
                            oValue.Value = Cryptographys.Cryptography.Encrypt(txtPassword.Text.Trim(), "TimecheckPhaseI");
                        else
                            oValue.Value = "";
                        break;
                    case "LDAPDomainName":
                        oValue.Value = ConnStr;
                        break;
                    case "LDAAuthenticalUser":
                        oValue.Value = ConnStr;
                        break;
                    case "LDAAuthenticalUserPwd":
                        oValue.Value = Cryptographys.Cryptography.Encrypt(ConnStr, "TimecheckPhaseI");
                        break;
                    case "LDAPrequired":
                        oValue.Value = ConnStr;
                        break;
                    default:
                        break;
                }
            }
        }
        //Un comment the following while creating setup
        doc.Save(WebConfigFilename);
    }

    //public void OverwriteApplicationConnectionString(string ConnStr, string strValue)
    //{
    //    XmlDocument doc = new XmlDocument();
    //    string WebConfigFilename = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath).FilePath;
    //    doc.Load(WebConfigFilename);
    //    XmlNodeList oList = doc.SelectNodes("configuration/location/appSettings/add");
    //    for (int i = 0; i < oList.Count; i++)
    //    {
    //        XmlAttribute oKey = oList[i].Attributes["key"];
    //        XmlAttribute oValue = oList[i].Attributes["value"];
    //        if (oKey.Value == strValue)
    //        {
    //            switch (oKey.Value)
    //            {
    //                case "googleMapKey":
    //                    if (oValue.Value.Contains("API_KEY"))
    //                    {
    //                        string replaceString = oValue.Value.Replace("API_KEY", Convert.ToString(txtmapkey.Text));
    //                        oValue.Value = replaceString;
    //                    }
    //                    break;
    //                case "FromId":
    //                    oValue.Value = txtMailId.Text;
    //                    break;
    //                case "SMTPClientHost":
    //                    oValue.Value = txtIPAddress.Text;
    //                    break;
    //                case "SMTPPort":
    //                    oValue.Value = txtSMTPPort.Text;
    //                    break;
    //                case "SSLEnable":
    //                    int intChecked = 0;
    //                    if (rbtnSSLYes.Checked == true)
    //                        intChecked = 1;
    //                    oValue.Value = intChecked.ToString();
    //                    break;
    //                case "MailAuthentication":
    //                    int intMailAuthChecked = 0;
    //                    if (rbtnAuthenticationYes.Checked == true)
    //                        intMailAuthChecked = 1;
    //                    oValue.Value = intMailAuthChecked.ToString();
    //                    break;
    //                case "MailAuthenticateUser":
    //                    if (rbtnAuthenticationNo.Checked == true)
    //                        oValue.Value = string.Empty;
    //                    else
    //                        oValue.Value = txtUserName.Text;
    //                    break;
    //                case "MailAuthenticatePassword":
    //                    if (rbtnAuthenticationNo.Checked == true)
    //                        oValue.Value = string.Empty;
    //                    else
    //                        oValue.Value = Cryptographys.Cryptography.Encrypt(txtPassword.Text.Trim(), "TimecheckPhaseI");
    //                    break;
    //                default:
    //                    break;
    //                case "LDAPDomainName":
    //                    oValue.Value = ConnStr;
    //                    break;
    //                case "LDAAuthenticalUser":
    //                    oValue.Value = ConnStr;
    //                    break;
    //                case "LDAAuthenticalUserPwd":
    //                    oValue.Value = Cryptographys.Cryptography.Encrypt(ConnStr, "TimecheckPhaseI");
    //                    break;
    //                case "LDAPrequired":
    //                    oValue.Value = ConnStr;
    //                    break;
    //            }
    //        }
    //    }
    //    //Un comment the following while creating setup
    //    doc.Save(WebConfigFilename);
    //}
    // inser or update could be done while saving the date and time format
    private void InsertOrUpdate(string strDate, string strTime)
    {
        // while inserting or updating a new date time format
        // the date and time format key is assigned to session's date and time format 
        // for applying the format to other pages of application
        Session["IDateFormat"] = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings[strDate]);
        Session["ITimeFormat"] = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings[strTime]);
        Session["MDateFormat"] = strDate;
        Session["MTimeFormat"] = strTime;
        int empId = Convert.ToInt32(Session["EmpAutoID"]);
        // inert or update the changed date and time format to database
        string AdminPassword = "";
        if (txt_AdminPassword.Text != "")
            AdminPassword = Encryption.Encrypt(txt_AdminPassword.Text, "Domain");
        objshift.InsertorUpdate_DateandTimeFormat(strDate, strTime, empId, Convert.ToInt32(rbtDomain.SelectedValue), Convert.ToString(txt_DomainName.Text), Convert.ToString(txt_AdminUserName.Text), AdminPassword);
        OverwriteApplicationConnectionString(txt_DomainName.Text, "LDAPDomainName");
        OverwriteApplicationConnectionString(txt_AdminUserName.Text, "LDAAuthenticalUser");
        OverwriteApplicationConnectionString(txt_AdminPassword.Text, "LDAAuthenticalUserPwd");
        OverwriteApplicationConnectionString((rbtDomain.Items[0].Selected) ? "1" : "0", "LDAPrequired");

        //Clear All Session For Current Login user Code By A.K.T.MOORTHI(25-Dec-2013) <-- START
        if (Session["EmployeeId"] != null)
        {
            string userId = Convert.ToString(Session["EmployeeId"]);
            string sUser = Convert.ToString(Cache[Session["EmployeeId"].ToString().ToUpper()]);
            if (sUser != null && sUser != String.Empty)
            {
                ObjEmployeeEventData.InsertUpdateLastLogout(userId);
                HttpContext.Current.Cache.Remove(Convert.ToString(Session["EmployeeId"]).ToUpper());
                Session.Clear();
            }
        }
        // END -->
        string strScript = string.Empty;
        LoadDefaultPage();
        strScript = strScript + "<script language='javascript'>";
        strScript = strScript + "alert('" + rm.GetString("Alert_SaveMyReferences") + "');location.replace('../Index.aspx');";
        strScript = strScript + "</script>";
        Page.RegisterStartupScript("AlertLogOut", strScript);
    }
    //Save the default page in web config
    private void LoadDefaultPage()
    {
        XmlDocument doc = new XmlDocument();
        string WebConfigFilename = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath).FilePath;
        doc.Load(WebConfigFilename);
        XmlNodeList oList = doc.SelectNodes("configuration/location/system.webServer/defaultDocument/files/add");
        for (int i = 0; i < oList.Count; i++)
        {
            XmlAttribute oValue = oList[i].Attributes["value"];
            if (rbtDomain.SelectedValue == "0")
            {
                oValue.Value = "GetWindows_Login.aspx";
            }
            else
            {
                oValue.Value = "index.aspx";
            }
        }
        oList = doc.SelectNodes("configuration/location/system.webServer/security/authentication/anonymousAuthentication");
        for (int i = 0; i < oList.Count; i++)
        {
            XmlAttribute oValue = oList[i].Attributes["enabled"];
            if (rbtDomain.SelectedValue == "0")
            {
                oValue.Value = "false";
            }
            else
            {
                oValue.Value = "true";
            }
        }
        oList = doc.SelectNodes("configuration/location/system.webServer/security/authentication/windowsAuthentication");
        for (int i = 0; i < oList.Count; i++)
        {
            XmlAttribute oValue = oList[i].Attributes["enabled"];
            if (rbtDomain.SelectedValue == "0")
            {
                oValue.Value = "true";
            }
            else
            {
                oValue.Value = "false";
            }
        }
        doc.Save(WebConfigFilename);
    }
    //Getting Information from resource file and display it in label
    private void LoadMailConfiguration()
    {
        XmlDocument doc = new XmlDocument();
        string WebConfigFilename = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath).FilePath;
        doc.Load(WebConfigFilename);
        XmlNodeList oList = doc.SelectNodes("configuration/location/appSettings/add");
        for (int i = 0; i < oList.Count; i++)
        {
            XmlAttribute oKey = oList[i].Attributes["key"];
            XmlAttribute oValue = oList[i].Attributes["value"];
            switch (oKey.Value)
            {
                case "FromId":
                    txtMailId.Text = oValue.Value.ToString();
                    break;
                case "SMTPClientHost":
                    txtIPAddress.Text = oValue.Value.ToString();
                    break;
                case "SMTPPort":
                    txtSMTPPort.Text = oValue.Value.ToString();
                    break;
                case "SSLEnable":
                    if (Convert.ToString(oValue.Value) == "0")
                        rbtnSSLNo.Checked = true;
                    else
                        rbtnSSLYes.Checked = true;
                    break;
                case "MailAuthentication":
                    if (Convert.ToString(oValue.Value) == "0")
                    {
                        rbtnAuthenticationNo.Checked = true;
                        txtUserName.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                        txtPassword.BackColor = System.Drawing.ColorTranslator.FromHtml("#d3dbe7");
                        txtUserName.Enabled = false;
                    }
                    else
                    {
                        rbtnAuthenticationYes.Checked = true;
                        txtUserName.Enabled = true;
                        txtPassword.Enabled = true;
                    }
                    break;
                case "MailAuthenticateUser":
                    txtUserName.Text = oValue.Value.ToString();
                    break;
                case "MailAuthenticatePassword":
                    txtPassword.Enabled = true;
                    txtPassword.Text = oValue.Value.ToString();
                    break;
                case "LDAPDomainName":
                    txt_DomainName.Text = oValue.Value.ToString();
                    break;
                case "LDAAuthenticalUser":
                    txt_AdminUserName.Text = oValue.Value.ToString();
                    break;
                case "LDAAuthenticalUserPwd":
                    txt_AdminPassword.Text = Cryptographys.Cryptography.Decrypt(oValue.Value.ToString(), "TimecheckPhaseI");
                    txt_AdminPassword.Attributes.Add("value", Cryptographys.Cryptography.Decrypt(oValue.Value.ToString(), "TimecheckPhaseI"));
                    break;
                case "LDAPrequired":
                    if (oValue.Value.ToString() == "1")
                    {
                        rbtDomain.Items[0].Selected = true;
                        rbtDomain.Items[1].Selected = false;
                        txt_AdminUserName.Enabled = true;
                        txt_AdminPassword.Enabled = true;
                        txt_DomainName.Enabled = true;
                    }
                    else
                    {
                        rbtDomain.Items[0].Selected = false;
                        rbtDomain.Items[1].Selected = true;
                        txt_AdminUserName.Enabled = false;
                        txt_AdminPassword.Enabled = false;
                        txt_DomainName.Enabled = false;
                    }
                    break;
                case "isRequiredEmail":
                    if (Convert.ToString(oValue.Value) == "1")
                    {
                        chkboxIsRequired.Checked = true;
                    }
                    else
                    {
                        chkboxIsRequired.Checked = false;
                    }
                    break;
                case "googleMapKey":
                    string[] stringSeparators = new string[] { "key=" };
                    string[] firstNames = oValue.Value.Split(stringSeparators, StringSplitOptions.None);
                    if (firstNames.Length > 1)
                    {
                        txtmapkey.Text = firstNames[1];
                    }
                    break;
            }
        }
    }
    protected void lnkbtnmyReferences_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                if (rbtDomain.SelectedValue == "0")
                {
                    try
                    {
                        string DomainName = "";
                        DirectoryEntry myDirectoryEntry = new DirectoryEntry();
                        DirectorySearcher mySearcher = new DirectorySearcher();
                        SearchResultCollection results;
                        DomainName = txt_DomainName.Text;
                        myDirectoryEntry = new DirectoryEntry("LDAP://" + DomainName, Convert.ToString(txt_AdminUserName.Text), Convert.ToString(txt_AdminPassword.Text));
                        mySearcher = new DirectorySearcher(myDirectoryEntry, "(&(SAMAccountName=" + Convert.ToString(txt_AdminUserName.Text) + ")(objectClass=user)(objectCategory=person))");
                        results = mySearcher.FindAll();
                    }
                    catch (Exception ex)
                    {
                        base.Message(ex.Message.ToString());
                        return;
                    }
                }
                if (rbtnddmmyyyy.Checked)
                {
                    strDate = rbtnddmmyyyy.Text;
                }
                if (rbtnmmddyyyy.Checked)
                {
                    strDate = rbtnmmddyyyy.Text;
                }
                if (rbtnddmmmyy.Checked)
                {
                    strDate = rbtnddmmmyy.Text;
                }
                if (rbtnhhmmsstt.Checked)
                {
                    strTime = rbtnhhmmsstt.Text;
                }
                if (rbtnHHmmss.Checked)
                {
                    strTime = rbtnHHmmss.Text;
                }
                if (fp_Upload.FileName != string.Empty)
                {
                    findex = fp_Upload.FileName.LastIndexOf(".");
                    strFileName = fp_Upload.FileName;
                    str_imgType = strFileName.Substring(findex + 1).ToUpper();
                    if (str_imgType == "JPEG" || str_imgType == "JPG" || str_imgType == "BMP" || str_imgType == "GIF")
                    {
                        img_Cuslogo = fp_Upload.FileBytes;
                        obj_Branding.InsertCustomerLogo(img_Cuslogo);
                    }
                    else
                    {
                        base.Message(rm.GetString("Alert_PleaseselectGifJPEGJPGBMPFiles", ci));
                        return;
                    }
                }
                // insert or update with key of date and time format            
                InsertOrUpdate(strDate, strTime);
            }
        }
        catch (Exception ex)
        {
            base.Message(ex.ToString());
        }
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        int intLogoCount = 0;
        intLogoCount = obj_Branding.DeleteLogo();
        if (intLogoCount > 0)
        {
            liMyPref.Attributes.Add("Class", "active");
            liMailConfig.Attributes.Add("Class", "");
            liGeneral.Attributes.Add("Class", "");
            liApproval.Attributes.Add("Class", "");
            liOTCompoff.Attributes.Add("Class", "");
            lirepConfig.Attributes.Add("Class", "");
            tab5.Attributes.Add("Class", "tab-pane active");
            tab1.Attributes.Add("Class", "tab-pane");
            tab2.Attributes.Add("Class", "tab-pane");
            tab3.Attributes.Add("Class", "tab-pane");
            tab4.Attributes.Add("Class", "tab-pane");
            tab6.Attributes.Add("Class", "tab-pane");
            string str = "alert('" + rm.GetString("Alert_Customerlogodeletedsuccessfully", ci) + "');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
    }
    protected void lnhbtnTestDomain_Click(object sender, EventArgs e)
    {
    }
    protected void lnkTestEmail_Click(object sender, EventArgs e)
    {
        try
        {
            if (txtMailId.Text == "" || txtMailId.Text == string.Empty)
            {
                Message("Admin Mail Id");
                txtMailId.Focus();
                return;
            }
            if (txtIPAddress.Text == "" || txtIPAddress.Text == string.Empty)
            {
                Message("Server IP/Host Name");
                txtIPAddress.Focus();
                return;
            }
            if (txtSMTPPort.Text == "" || txtSMTPPort.Text == string.Empty)
            {
                Message("Server IP/Host Name");
                txtSMTPPort.Focus();
                return;
            }
            if (rbtnAuthenticationYes.Checked == true)
            {
                if (txtUserName.Text == "" || txtUserName.Text == string.Empty)
                {
                    Message("Enter the User Name");
                    txtUserName.Focus();
                    return;
                }
            }
            if (txtEmailIDTest.Text == "" || txtEmailIDTest.Text == string.Empty)
            {
                Message("Email ID can not be empty");
                txtSMTPPort.Focus();
                return;
            }
            bool ValidateEmailID = isValidEmail(txtEmailIDTest.Text);
            if (ValidateEmailID == false)
            {
                Message("Enter Valid Email Id");
                txtEmailIDTest.Focus();
                return;
            }
            if (Convert.ToInt32(ConfigurationManager.AppSettings.Get("isRequiredEmail")) == 1)
            {
                switch (mailSendingmethod.Text)
                {
                    case "1":
                        MailMessage mailMessage = new MailMessage();
                        mailMessage.From = new MailAddress(Convert.ToString(txtMailId.Text));
                        mailMessage.To.Add(new MailAddress(Convert.ToString(txtEmailIDTest.Text)));
                        mailMessage.Subject = rm.GetString("Testemail_Subject", ci);
                        mailMessage.Body = rm.GetString("Testemail_Body", ci) + "<br/><br/> Regards, <br/>TimeCheck";
                        objClassCommon.SendMail(mailMessage);
                        Message("Mail Send Successfully");
                        break;
                    case "2":
                        EmailTriggering2();
                        break;
                    case "3":
                        EmailTriggering3();
                        break;
                    default:
                        EmailTriggering1();
                        break;
                }
            }
            else
            {
                Message("Enable Email Notification first and then try test email");
            }
            txtEmailIDTest.Text = "";
        }
        catch (Exception ex)
        {
            string strErr = Convert.ToString(ex.Message);
            string str3 = "alert('Email sending failure :\"" + strErr.Replace("\r", "").Replace("\n", "") + "\"');";
            Message(str3);
            return;
        }
    }
    public static bool isValidEmail(string inputEmail)
    {
        string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
              @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
              @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
        Regex re = new Regex(strRegex);
        if (re.IsMatch(inputEmail))
            return (true);
        else
            return (false);
    }
    private void EmailTriggering1()
    {
        string strFromEmailId = string.Empty;
        MailMessage mailMessage = new MailMessage();
        string strMailStatus = string.Empty;
        try
        {
            mailMessage.From = new MailAddress(Convert.ToString(txtMailId.Text));
            mailMessage.To.Add(new MailAddress(Convert.ToString(txtEmailIDTest.Text)));
            mailMessage.Subject = rm.GetString("Testemail_Subject", ci);
            mailMessage.Body = rm.GetString("Testemail_Body", ci) + "<br/><br/> Regards <br/> TimeCheck";
            string strSMTPPort = Convert.ToString(txtSMTPPort.Text);
            SmtpClient loSMTPServer = new SmtpClient(strSMTPPort, Convert.ToInt32(strSMTPPort));
            loSMTPServer.Host = Convert.ToString(txtIPAddress.Text);
            string strHost = Convert.ToString(txtIPAddress.Text);
            string strSSLEnable = (rbtnSSLYes.Checked) ? "1" : "2";
            string strMailAuthentication = (rbtnAuthenticationYes.Checked) ? "1" : "0";
            string strMailAuthenticateUser = Convert.ToString(txtUserName.Text);
            string strMailAuthenticatePassword = ConfigurationManager.AppSettings.Get("MailAuthenticatePassword");
            if (strMailAuthentication == "1")
                strMailAuthenticatePassword = Cryptographys.Cryptography.Decrypt(strMailAuthenticatePassword, "TimecheckPhaseI");
            loSMTPServer.Port = Convert.ToInt32(strSMTPPort);
            if (strSSLEnable == "1")
                loSMTPServer.EnableSsl = true;
            else
                loSMTPServer.EnableSsl = false;
            if (strMailAuthentication == "0")
                loSMTPServer.UseDefaultCredentials = true;
            else
                loSMTPServer.UseDefaultCredentials = false;
            mailMessage.IsBodyHtml = true;
            if (strMailAuthentication == "1")
            {
                System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate (object s,
             System.Security.Cryptography.X509Certificates.X509Certificate certificate,
             System.Security.Cryptography.X509Certificates.X509Chain chain,
             System.Net.Security.SslPolicyErrors sslPolicyErrors)
                {
                    return true;
                };
                loSMTPServer.Credentials = new System.Net.NetworkCredential(strMailAuthenticateUser, strMailAuthenticatePassword);
                loSMTPServer.Send(mailMessage);
                string str3 = "alert('Mail Send Successfully');";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str3, true);
                return;
            }
            else
            {
                loSMTPServer.DeliveryMethod = SmtpDeliveryMethod.Network;
                loSMTPServer.Send(mailMessage);
                string str3 = "alert('Mail Send Successfully');";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str3, true);
                return;
            }
        }
        catch (Exception Ex)
        {
            string strErr = Convert.ToString(Ex.Message);
            string str3 = "alert('Email sending failure :\"" + strErr.Replace("\r", "").Replace("\n", "") + "\"');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str3, true);
            return;
        }
    }
    public void EmailTriggering2()
    {
        string FromEmailId = string.Empty;
        string SMTPHost = string.Empty;
        string SMTPPort = string.Empty;
        string NetUserName = string.Empty;
        string NetPassword = string.Empty;
        MailMessage message = new MailMessage();
        try
        {
            FromEmailId = Convert.ToString(txtMailId.Text);
            SMTPHost = Convert.ToString(txtIPAddress.Text);
            SMTPPort = Convert.ToString(txtSMTPPort.Text);
            NetUserName = Convert.ToString(txtUserName.Text);
            NetPassword = ConfigurationManager.AppSettings.Get("MailAuthenticatePassword");
            //client.Host = SMTPHost;
            //client.Port = Convert.ToInt32(5);
            // while using smtp.gmail.com in host field..we need to give the below format then only it will work otherwise its throws some error 
            // like network errors.
            //SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            NetworkCredential crdntl = new NetworkCredential();
            SmtpClient client = new SmtpClient(SMTPHost, Convert.ToInt32(SMTPPort));
            if (NetUserName != string.Empty && NetPassword != string.Empty)
            {
                client.UseDefaultCredentials = false;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                NetPassword = Cryptographys.Cryptography.Decrypt(NetPassword, "TimecheckPhaseI");
                crdntl = new NetworkCredential(NetUserName, NetPassword);
                client.Credentials = crdntl;
                client.EnableSsl = true;
            }
            message.IsBodyHtml = true;
            message.Subject = rm.GetString("Testemail_Subject", ci);
            message.Body = rm.GetString("Testemail_Body", ci) + "<br/><br/> Regards <br/> TimeCheck";
            message.From = new MailAddress(FromEmailId);
            char[] split = { ';' };
            string[] strToEmailIds = Convert.ToString(txtEmailIDTest.Text).Split(split);
            foreach (string strToMail in strToEmailIds)
            {
                if (strToMail != string.Empty)
                {
                    message.To.Add(strToMail);
                }
            }
            client.Send(message);
            string str3 = "alert('Mail Send Successfully');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str3, true);
            return;
        }
        catch (Exception errorInSendingMail)
        {
            string strErr = Convert.ToString(errorInSendingMail.Message);
            string str3 = "alert('Email sending failure :\"" + strErr.Replace("\r", "").Replace("\n", "") + "\"');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str3, true);
            return;
        }
    }
    private void EmailTriggering3()
    {
        string strFromEmailId = string.Empty;
        MailMessage mailMessage = new MailMessage();
        SmtpClient loSMTPServer = new SmtpClient();
        System.Net.Mime.ContentType loTextType = new System.Net.Mime.ContentType("text/plain");
        System.Net.Mime.ContentType loHTMLType = new System.Net.Mime.ContentType("text/html");
        string strMailStatus = string.Empty;
        AlternateView loHTMLView = null;
        try
        {
            mailMessage.From = new MailAddress(Convert.ToString(txtMailId.Text));
            mailMessage.To.Add(new MailAddress(Convert.ToString(txtEmailIDTest.Text)));
            mailMessage.Subject = rm.GetString("Testemail_Subject", ci);
            mailMessage.Body = rm.GetString("Testemail_Body", ci) + "<br/><br/> Regards <br/> TimeCheck";
            loHTMLView = AlternateView.CreateAlternateViewFromString(mailMessage.Body, loHTMLType);
            mailMessage.AlternateViews.Add(loHTMLView);
            loSMTPServer.Host = Convert.ToString(txtIPAddress.Text);
            string strHost = Convert.ToString(txtIPAddress.Text);
            string strSMTPPort = Convert.ToString(txtSMTPPort.Text);
            string strSSLEnable = (rbtnSSLYes.Checked) ? "1" : "2";
            string strMailAuthentication = (rbtnAuthenticationYes.Checked) ? "1" : "0";
            string strMailAuthenticateUser = Convert.ToString(txtUserName.Text);
            string strMailAuthenticatePassword = ConfigurationManager.AppSettings.Get("MailAuthenticatePassword");
            if (strMailAuthentication == "1")
            {
                strMailAuthenticatePassword = Cryptographys.Cryptography.Decrypt(strMailAuthenticatePassword, "TimecheckPhaseI");
            }
            loSMTPServer.Port = Convert.ToInt32(strSMTPPort);
            if (strSSLEnable == "1")
            {
                loSMTPServer.EnableSsl = true;
            }
            else
            {
                loSMTPServer.EnableSsl = false;
            }
            if (strMailAuthentication == "0")
            {
                loSMTPServer.UseDefaultCredentials = true;
            }
            else
            {
                loSMTPServer.UseDefaultCredentials = false;
            }
            if (strMailAuthentication == "1")
            {
                NetworkCredential myCreds = new NetworkCredential(strMailAuthenticateUser, strMailAuthenticatePassword, strHost);
                CredentialCache myCredentialCache = new CredentialCache();
                myCredentialCache.Add(strHost, Convert.ToInt32(strSMTPPort), "Basic", myCreds);
                myCredentialCache.Add(strHost, Convert.ToInt32(strSMTPPort), "NTLM", myCreds);
                myCredentialCache.Add(strHost, Convert.ToInt32(strSMTPPort), "Digest", myCreds);
                myCredentialCache.Add(strHost, Convert.ToInt32(strSMTPPort), "Kerberos", myCreds);
                myCredentialCache.Add(strHost, Convert.ToInt32(strSMTPPort), "Negotiate", myCreds);
                loSMTPServer.Credentials = myCredentialCache.GetCredential(strHost, Convert.ToInt32(strSMTPPort), "NTLM");
            }
            loSMTPServer.DeliveryMethod = SmtpDeliveryMethod.Network;
            loSMTPServer.Send(mailMessage);
            string str3 = "alert('Mail Send Successfully');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str3, true);
            return;
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
    #endregion
}
