protected void LeaveAppDays_TextChanged(object sender, EventArgs e)
    {
        DateTime tmpLeaveAppDateFrom;
        double   tmpLeaveAppDay = 0;
        double   workhour       = 0;

        if (!DateTime.TryParse(RequestLeaveAppDateFrom.Value, out tmpLeaveAppDateFrom))
        {
            tmpLeaveAppDateFrom = AppUtils.ServerDateTime().Date;
        }
        if (double.TryParse(RequestLeaveDays.Text, out tmpLeaveAppDay) && tmpLeaveAppDay > 0)
        {
            EEmpPositionInfo currentEmpPos = AppUtils.GetLastPositionInfo(dbConn, tmpLeaveAppDateFrom, CurEmpID);
            if (currentEmpPos != null)
            {
                EWorkHourPattern workPattern = new EWorkHourPattern();
                workPattern.WorkHourPatternID = currentEmpPos.WorkHourPatternID;
                if (EWorkHourPattern.db.select(dbConn, workPattern))
                {
                    workhour = workPattern.GetDefaultWorkHour(dbConn, tmpLeaveAppDateFrom);
                }
            }
            if (workhour > 0)
            {
                RequestLeaveAppHours.Text = ((double)(workhour * tmpLeaveAppDay)).ToString("0.####");
            }
        }
    }
Example #2
0
    protected void Delete_Click(object sender, EventArgs e)
    {
        PageErrors errors = PageErrors.getErrors(db, Page.Master);

        errors.clear();

        EWorkHourPattern o = new EWorkHourPattern();

        o.WorkHourPatternID = CurID;
        db.select(dbConn, o);
        DBFilter empWorkHourPatternFilter = new DBFilter();

        empWorkHourPatternFilter.add(new Match("WorkHourPatternID", o.WorkHourPatternID));
        empWorkHourPatternFilter.add("empid", true);
        ArrayList empPosList = EEmpPositionInfo.db.select(dbConn, empWorkHourPatternFilter);

        if (empPosList.Count > 0)
        {
            int curEmpID = 0;
            errors.addError(string.Format(HROne.Translation.PageErrorMessage.ERROR_CODE_USED_BY_EMPLOYEE, new string[] { HROne.Common.WebUtility.GetLocalizedString("Work Hour Pattern"), o.WorkHourPatternCode }));
            foreach (EEmpPositionInfo empPos in empPosList)
            {
                EEmpPersonalInfo empInfo = new EEmpPersonalInfo();
                empInfo.EmpID = empPos.EmpID;
                if (EEmpPersonalInfo.db.select(dbConn, empInfo))
                {
                    if (curEmpID != empPos.EmpID)
                    {
                        errors.addError("- " + empInfo.EmpNo + ", " + empInfo.EmpEngFullName);
                        curEmpID = empPos.EmpID;
                    }
                }
                // Start 0000148, Ricky So, 2014/12/21
                // else
                //     EEmpPositionInfo.db.delete(dbConn, empPos);
                // Start 0000148, Ricky So, 2014/12/21
            }
            errors.addError(HROne.Translation.PageErrorMessage.ERROR_ACTION_ABORT);
            return;
        }
        else
        {
            WebUtils.StartFunction(Session, FUNCTION_CODE);
            db.delete(dbConn, o);
            WebUtils.EndFunction(dbConn);
        }

        HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "WorkHourPattern_List.aspx");
    }
    protected void LeaveAppTime_TextChanged(object sender, EventArgs e)
    {
        if (RequestLeaveAppUnit.SelectedValue.Equals("H"))
        {
            DateTime dtTimeFrom = new DateTime();
            if (!DateTime.TryParseExact(RequestLeaveAppTimeFrom.Text, "HH:mm", null, System.Globalization.DateTimeStyles.None, out dtTimeFrom))
            {
                RequestLeaveAppTimeFrom.Text = string.Empty;
            }

            DateTime dtTimeTo = new DateTime();
            if (!DateTime.TryParseExact(RequestLeaveAppTimeTo.Text, "HH:mm", null, System.Globalization.DateTimeStyles.None, out dtTimeTo))
            {
                RequestLeaveAppTimeTo.Text = string.Empty;
            }

            if (dtTimeFrom.Ticks.Equals(0) || dtTimeTo.Ticks.Equals(0))
            {
                return;
            }

            DateTime tmpLeaveAppDateFrom;
            if (DateTime.TryParse(RequestLeaveAppDateFrom.Value, out tmpLeaveAppDateFrom))
            {
                double           workhour      = 0;
                EEmpPositionInfo currentEmpPos = AppUtils.GetLastPositionInfo(dbConn, tmpLeaveAppDateFrom, CurEmpID);
                if (currentEmpPos != null)
                {
                    EWorkHourPattern workPattern = new EWorkHourPattern();
                    workPattern.WorkHourPatternID = currentEmpPos.WorkHourPatternID;
                    if (EWorkHourPattern.db.select(dbConn, workPattern))
                    {
                        workhour = workPattern.GetDefaultWorkHour(dbConn, tmpLeaveAppDateFrom);
                    }
                }
                if (workhour > 0)
                {
                    double timeDiff = ((TimeSpan)dtTimeTo.Subtract(dtTimeFrom)).TotalHours;
                    if (timeDiff < 0)
                    {
                        timeDiff += 1;
                    }
                    RequestLeaveDays.Text     = ((double)(timeDiff / workhour)).ToString("0.####");
                    RequestLeaveAppHours.Text = timeDiff.ToString("0.####");
                }
            }
        }
    }
Example #4
0
    protected bool loadObject()
    {
        EWorkHourPattern obj   = new EWorkHourPattern();
        bool             isNew = WebFormWorkers.loadKeys(db, obj, DecryptedRequest);

        if (!db.select(dbConn, obj))
        {
            return(false);
        }

        Hashtable values = new Hashtable();

        db.populate(obj, values);
        binding.toControl(values);


        return(true);
    }
Example #5
0
    protected void Save_Click(object sender, EventArgs e)
    {
        EWorkHourPattern c = new EWorkHourPattern();

        Hashtable values = new Hashtable();

        binding.toValues(values);

        PageErrors errors = PageErrors.getErrors(db, Page.Master);

        errors.clear();

        db.validate(errors, values);

        if (!errors.isEmpty())
        {
            return;
        }

        db.parse(values, c);
        if (!AppUtils.checkDuplicate(dbConn, db, c, errors, "WorkHourPatternCode"))
        {
            return;
        }

        WebUtils.StartFunction(Session, FUNCTION_CODE);
        if (CurID < 0)
        {
            db.insert(dbConn, c);
            CurID = c.WorkHourPatternID;
        }
        else
        {
            db.update(dbConn, c);
        }

        WebUtils.EndFunction(dbConn);


        HROne.Common.WebUtility.RedirectURLwithEncryptedQueryString(Response, Session, "WorkHourPattern_View.aspx?WorkHourPatternID=" + CurID);
    }
        private static DataRow CreateWorkingSummaryTemplateRow(DatabaseConnection dbConn, DataTable dataTable, Hashtable hierarchyLevelHashTable, EEmpPersonalInfo empInfo, DateTime PeriodFrom, DateTime PeriodTo, EWorkHourPattern currentWorkHourPattern)
        {
            double restDayCount                    = 0;
            double statutoryHolidayCount           = 0;
            double restDayTaken                    = 0;
            double statutoryHolidayTaken           = 0;
            double workHourPatternWorkingDaysCount = 0;
            double workHourPatternLunchTimeCount   = 0;
            double workHourPatternWorkingHourCount = 0;
            double totalWorkingDays                = 0;
            double totalWorkingHours               = 0;
            double totalLunchMins                  = 0;
            double totalWorkingHoursExpected       = 0;
            double totalLateMins                   = 0;
            double totalEarlyLeaveMins             = 0;
            double totalOvertimeMins               = 0;
            double totalLeaveApplicationDayTaken   = 0;

            EEmpTermination empTermination = EEmpTermination.GetObjectByEmpID(dbConn, empInfo.EmpID);

            bool hasStatutoryHolidayRosterCode = false;
            //  Check if Roster Code List contains Statutory Holiday Roster Code
            ArrayList rosterCodeList = ERosterCode.db.select(dbConn, new DBFilter());

            foreach (ERosterCode rosterCode in rosterCodeList)
            {
                if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_STATUTORYHOLIDAY))
                {
                    hasStatutoryHolidayRosterCode = true;
                    break;
                }
            }

            if (currentWorkHourPattern != null)
            {
                for (DateTime asOfDate = PeriodFrom; asOfDate <= PeriodTo; asOfDate = asOfDate.AddDays(1))
                {
                    if (EStatutoryHoliday.IsHoliday(dbConn, asOfDate))// && currentWorkHourPattern.WorkHourPatternUseStatutoryHolidayTable)
                    {
                        statutoryHolidayCount++;
                    }
                    //rest day must be integer and rest within 24 hour
                    restDayCount += (1 - currentWorkHourPattern.GetDefaultDayUnit(dbConn, asOfDate, false, false));

                    double workDayUnit   = 0;
                    double workHourUnit  = 0;
                    double LunchTimeUnit = 0;
                    if (empInfo.EmpDateOfJoin <= asOfDate)
                    {
                        workDayUnit   = currentWorkHourPattern.GetDefaultDayUnit(dbConn, asOfDate, false, false);
                        LunchTimeUnit = currentWorkHourPattern.GetDefaultLunch(dbConn, asOfDate);
                        workHourUnit  = currentWorkHourPattern.GetDefaultWorkHour(dbConn, asOfDate);
                        DBFilter leaveAppFilter = new DBFilter();
                        leaveAppFilter.add(new Match("EmpID", empInfo.EmpID));
                        leaveAppFilter.add(new Match("LeaveAppDateFrom", "<=", asOfDate));
                        leaveAppFilter.add(new Match("LeaveAppDateTo", ">=", asOfDate));
                        leaveAppFilter.add(new Match("LeaveAppNoPayProcess", false));

                        ArrayList leaveAppList = ELeaveApplication.db.select(dbConn, leaveAppFilter);
                        foreach (ELeaveApplication leaveApp in leaveAppList)
                        {
                            if (leaveApp.LeaveAppDateFrom.Equals(leaveApp.LeaveAppDateTo))
                            {
                                workDayUnit -= leaveApp.LeaveAppDays;
                                double currentDayDefaultDayUnit = currentWorkHourPattern.GetDefaultDayUnit(dbConn, asOfDate, false, false);
                                if (currentDayDefaultDayUnit * leaveApp.LeaveAppDays > 0)
                                {
                                    workHourUnit -= currentWorkHourPattern.GetDefaultWorkHour(dbConn, asOfDate) / currentDayDefaultDayUnit * leaveApp.LeaveAppDays;
                                }
                            }
                            else
                            {
                                workDayUnit   = 0;
                                workHourUnit  = 0;
                                LunchTimeUnit = 0;
                            }
                        }
                        if (workDayUnit < 0)
                        {
                            workDayUnit = 0;
                        }
                        if (workHourUnit < 0)
                        {
                            workHourUnit = 0;
                        }
                        if (workDayUnit < 1)
                        {
                            LunchTimeUnit = 0;
                        }
                        if (empTermination != null)
                        {
                            if (empTermination.EmpTermLastDate < asOfDate)
                            {
                                workDayUnit   = 0;
                                workHourUnit  = 0;
                                LunchTimeUnit = 0;
                            }
                        }
                    }
                    workHourPatternWorkingDaysCount += workDayUnit;
                    workHourPatternWorkingHourCount += workHourUnit;
                    workHourPatternLunchTimeCount   += LunchTimeUnit;
                }
                DBFilter leaveAppTakenFilter = new DBFilter();
                leaveAppTakenFilter.add(new Match("EmpID", empInfo.EmpID));
                leaveAppTakenFilter.add(new Match("LeaveAppDateFrom", "<=", PeriodTo));
                leaveAppTakenFilter.add(new Match("LeaveAppDateTo", ">=", PeriodFrom));
                leaveAppTakenFilter.add(new Match("LeaveAppNoPayProcess", false));
                ArrayList leaveAppTakenList = ELeaveApplication.db.select(dbConn, leaveAppTakenFilter);
                foreach (ELeaveApplication leaveApp in leaveAppTakenList)
                {
                    totalLeaveApplicationDayTaken += leaveApp.LeaveAppDays;
                }
            }
            DBFilter attendanceRecordFilter = new DBFilter();

            attendanceRecordFilter.add(new Match("EmpID", empInfo.EmpID));
            attendanceRecordFilter.add(new Match("AttendanceRecordDate", ">=", PeriodFrom));
            attendanceRecordFilter.add(new Match("AttendanceRecordDate", "<=", PeriodTo));
            attendanceRecordFilter.add("AttendanceRecordDate", true);
            ArrayList attendanceRecordList = EAttendanceRecord.db.select(dbConn, attendanceRecordFilter);

            foreach (EAttendanceRecord attendanceRecord in attendanceRecordList)
            {
                ERosterCode rosterCode = new ERosterCode();
                rosterCode.RosterCodeID = attendanceRecord.RosterCodeID;
                if (ERosterCode.db.select(dbConn, rosterCode))
                {
                    if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_RESTDAY))
                    {
                        restDayTaken++;
                    }
                    if (rosterCode.RosterCodeType.Equals(ERosterCode.ROSTERTYPE_CODE_STATUTORYHOLIDAY))
                    {
                        statutoryHolidayTaken++;
                    }
                }
                double workingHours = attendanceRecord.TotalWorkingHourTimeSpan(dbConn).TotalHours;
                if (workingHours <= 0)
                {
                    workingHours = attendanceRecord.AttendanceRecordActualWorkingHour + Convert.ToDouble(attendanceRecord.AttendanceRecordActualEarlyLeaveMins - attendanceRecord.AttendanceRecordActualLateMins + attendanceRecord.AttendanceRecordActualOvertimeMins) / 60.0;
                }

                totalWorkingDays          += attendanceRecord.AttendanceRecordActualWorkingDay;
                totalWorkingHours         += workingHours;
                totalWorkingHoursExpected += attendanceRecord.AttendanceRecordActualWorkingHour;
                totalLateMins             += attendanceRecord.AttendanceRecordActualLateMins;
                totalEarlyLeaveMins       += attendanceRecord.AttendanceRecordActualEarlyLeaveMins;
                totalOvertimeMins         += attendanceRecord.AttendanceRecordActualOvertimeMins;
                totalLunchMins            += attendanceRecord.AttendanceRecordActualLunchTimeMins;
            }
            if (totalWorkingDays <= 0 && totalWorkingHours <= 0 && totalLunchMins <= 0 && empInfo.EmpDateOfJoin <= PeriodFrom)
            {
                totalWorkingDays  = workHourPatternWorkingDaysCount;
                totalWorkingHours = workHourPatternWorkingHourCount;
                totalLunchMins    = workHourPatternLunchTimeCount * 60;
            }
            DataRow row = dataTable.NewRow();

            row[FIELD_EMP_NO]  = empInfo.EmpNo;
            row["EnglishName"] = empInfo.EmpEngFullName;
            row["ChineseName"] = empInfo.EmpChiFullName;

            DBFilter empPosFilter = new DBFilter();

            EEmpPositionInfo empPos = AppUtils.GetLastPositionInfo(dbConn, PeriodTo, empInfo.EmpID);

            if (empPos != null)
            {
                ECompany company = new ECompany();
                company.CompanyID = empPos.CompanyID;
                if (ECompany.db.select(dbConn, company))
                {
                    row["Company"] = company.CompanyCode;
                }
                DBFilter empHierarchyFilter = new DBFilter();
                empHierarchyFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                ArrayList empHierarchyList = EEmpHierarchy.db.select(dbConn, empHierarchyFilter);
                foreach (EEmpHierarchy empHierarchy in empHierarchyList)
                {
                    EHierarchyLevel hierarchyLevel = (EHierarchyLevel)hierarchyLevelHashTable[empHierarchy.HLevelID];
                    if (hierarchyLevel != null)
                    {
                        EHierarchyElement hierarchyElement = new EHierarchyElement();
                        hierarchyElement.HElementID = empHierarchy.HElementID;
                        if (EHierarchyElement.db.select(dbConn, hierarchyElement))
                        {
                            row[hierarchyLevel.HLevelDesc] = hierarchyElement.HElementCode;
                        }
                    }
                }
            }

            row[FIELD_AS_OF_DATE]        = PeriodTo;
            row[FIELD_REST_DAY_ENTITLED] = restDayCount - statutoryHolidayCount;
            if (hasStatutoryHolidayRosterCode)
            {
                row[FIELD_REST_DAY_TAKEN] = restDayTaken;
            }
            else
            {
                row[FIELD_REST_DAY_TAKEN] = restDayTaken > statutoryHolidayCount ? restDayTaken - statutoryHolidayCount : 0;
            }
            row[FIELD_TOTAL_WORKING_DAYS]                  = totalWorkingDays;
            row[FIELD_TOTAL_WORKING_HOURS]                 = totalWorkingHours;
            row[FIELD_TOTAL_LUNCH_HOURS]                   = totalLunchMins / 60.0;
            row[FIELD_EXTRA_TOTAL_STATUTORY_HOLIDAY]       = statutoryHolidayCount;
            row[FIELD_EXTRA_TOTAL_LEAVE_APPLICATION_TAKEN] = totalLeaveApplicationDayTaken;
            row[FIELD_EXTRA_TOTAL_WORKING_HOURS_EXPECTED]  = totalWorkingHoursExpected;
            row[FIELD_EXTRA_TOTAL_LATE_MINS]               = totalLateMins;
            row[FIELD_EXTRA_TOTAL_EARLYLEAVE_MINS]         = totalEarlyLeaveMins;
            row[FIELD_EXTRA_TOTAL_OVERTIME_MINS]           = totalOvertimeMins;
            dataTable.Rows.Add(row);
            return(row);
        }
        public static DataTable GenerateTemplate(DatabaseConnection dbConn, ArrayList EmpInfoList, DateTime PeriodFrom, DateTime PeriodTo)
        {
            DataTable tmpDataTable = new DataTable("WorkingSummary$");

            tmpDataTable.Columns.Add(FIELD_EMP_NO, typeof(string));
            tmpDataTable.Columns.Add("EnglishName", typeof(string));
            tmpDataTable.Columns.Add("ChineseName", typeof(string));

            tmpDataTable.Columns.Add("Company", typeof(string));

            DBFilter  hierarchyLevelFilter    = new DBFilter();
            Hashtable hierarchyLevelHashTable = new Hashtable();

            hierarchyLevelFilter.add("HLevelSeqNo", true);
            ArrayList hierarchyLevelList = EHierarchyLevel.db.select(dbConn, hierarchyLevelFilter);

            foreach (EHierarchyLevel hlevel in hierarchyLevelList)
            {
                tmpDataTable.Columns.Add(hlevel.HLevelDesc, typeof(string));
                hierarchyLevelHashTable.Add(hlevel.HLevelID, hlevel);
            }

            tmpDataTable.Columns.Add(FIELD_AS_OF_DATE, typeof(DateTime));
            tmpDataTable.Columns.Add(FIELD_REST_DAY_ENTITLED, typeof(double));
            tmpDataTable.Columns.Add(FIELD_REST_DAY_TAKEN, typeof(double));
            tmpDataTable.Columns.Add(FIELD_TOTAL_WORKING_DAYS, typeof(double));
            tmpDataTable.Columns.Add(FIELD_TOTAL_WORKING_HOURS, typeof(double));
            tmpDataTable.Columns.Add(FIELD_TOTAL_LUNCH_HOURS, typeof(double));

            //  Extra Information
            tmpDataTable.Columns.Add(FIELD_EXTRA_TOTAL_STATUTORY_HOLIDAY, typeof(double));
            tmpDataTable.Columns.Add(FIELD_EXTRA_TOTAL_LEAVE_APPLICATION_TAKEN, typeof(double));

            tmpDataTable.Columns.Add(FIELD_EXTRA_TOTAL_WORKING_HOURS_EXPECTED, typeof(double));
            tmpDataTable.Columns.Add(FIELD_EXTRA_TOTAL_OVERTIME_MINS, typeof(double));
            tmpDataTable.Columns.Add(FIELD_EXTRA_TOTAL_LATE_MINS, typeof(double));
            tmpDataTable.Columns.Add(FIELD_EXTRA_TOTAL_EARLYLEAVE_MINS, typeof(double));


            foreach (EEmpPersonalInfo empInfo in EmpInfoList)
            {
                if (EEmpPersonalInfo.db.select(dbConn, empInfo))
                {
                    DBFilter empPosFilter = new DBFilter();
                    empPosFilter.add(new Match("EmpID", empInfo.EmpID));
                    empPosFilter.add(new Match("EmpPosEffFr", "<=", PeriodTo));
                    OR empPosEffOR = new OR();
                    empPosEffOR.add(new Match("EmpPosEffTo", ">=", PeriodFrom));
                    empPosEffOR.add(new NullTerm("EmpPosEffTo"));
                    empPosFilter.add(empPosEffOR);
                    empPosFilter.add("EmpPosEffFr", true);

                    ArrayList empPosList = EEmpPositionInfo.db.select(dbConn, empPosFilter);

                    EWorkHourPattern currentWorkHourPattern = null;

                    DateTime lastStartDate = PeriodFrom;
                    foreach (EEmpPositionInfo empPos in empPosList)
                    {
                        if (currentWorkHourPattern == null)
                        {
                            EWorkHourPattern tempWorkHourPattern = new EWorkHourPattern();
                            tempWorkHourPattern.WorkHourPatternID = empPos.WorkHourPatternID;
                            if (EWorkHourPattern.db.select(dbConn, tempWorkHourPattern))
                            {
                                currentWorkHourPattern = tempWorkHourPattern;
                                if (empPos.EmpPosEffFr > PeriodFrom)
                                {
                                    //  generate working summary before the period for first join date

                                    CreateWorkingSummaryTemplateRow(dbConn, tmpDataTable, hierarchyLevelHashTable, empInfo, lastStartDate, empPos.EmpPosEffFr.AddDays(-1), currentWorkHourPattern);
                                    lastStartDate = empPos.EmpPosEffFr;
                                }
                            }
                        }
                        else if (currentWorkHourPattern.WorkHourPatternID != empPos.WorkHourPatternID)
                        {
                            EWorkHourPattern tempWorkHourPattern = new EWorkHourPattern();
                            tempWorkHourPattern.WorkHourPatternID = empPos.WorkHourPatternID;
                            if (EWorkHourPattern.db.select(dbConn, tempWorkHourPattern))
                            {
                                CreateWorkingSummaryTemplateRow(dbConn, tmpDataTable, hierarchyLevelHashTable, empInfo, lastStartDate, empPos.EmpPosEffFr.AddDays(-1), currentWorkHourPattern);
                                lastStartDate = empPos.EmpPosEffFr;

                                currentWorkHourPattern = tempWorkHourPattern;
                            }
                        }
                    }
                    EEmpTermination empTermination = EEmpTermination.GetObjectByEmpID(dbConn, empInfo.EmpID);
                    if (empTermination != null)
                    {
                        if (empTermination.EmpTermLastDate >= lastStartDate && empTermination.EmpTermLastDate < PeriodTo)
                        {
                            CreateWorkingSummaryTemplateRow(dbConn, tmpDataTable, hierarchyLevelHashTable, empInfo, lastStartDate, empTermination.EmpTermLastDate, currentWorkHourPattern);
                            lastStartDate = empTermination.EmpTermLastDate.AddDays(1);
                        }
                    }

                    CreateWorkingSummaryTemplateRow(dbConn, tmpDataTable, hierarchyLevelHashTable, empInfo, lastStartDate, PeriodTo, currentWorkHourPattern);
                    lastStartDate = PeriodTo.AddDays(1);
                }
            }
            return(tmpDataTable);
        }
    private void GenerateRosterTableData(ArrayList EmpInfoList, int year, int month)
    {
        DateTime dateStart      = new DateTime(year, month, 1);
        DateTime dateEnd        = new DateTime(year, month, DateTime.DaysInMonth(year, month));
        string   exportFileName = System.IO.Path.GetTempFileName();

        System.IO.File.Delete(exportFileName);
        exportFileName += ".xls";

        const string FIELD_EMP_NO = "Emp. No";

        const int COLUMN_HEADER_ROW = 2;


        NPOI.HSSF.UserModel.HSSFWorkbook workBook  = new NPOI.HSSF.UserModel.HSSFWorkbook();
        NPOI.HSSF.UserModel.HSSFSheet    workSheet = (NPOI.HSSF.UserModel.HSSFSheet)workBook.CreateSheet("RosterTable");

        NPOI.HSSF.UserModel.HSSFCellStyle upperLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        upperLineStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle bottomLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        bottomLineStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle leftLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        leftLineStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle rightLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        rightLineStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle upperLeftLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        upperLeftLineStyle.BorderTop  = NPOI.SS.UserModel.BorderStyle.THIN;
        upperLeftLineStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle bottomLeftLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        bottomLeftLineStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
        bottomLeftLineStyle.BorderLeft   = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle upperRightLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        upperRightLineStyle.BorderTop   = NPOI.SS.UserModel.BorderStyle.THIN;
        upperRightLineStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;

        NPOI.HSSF.UserModel.HSSFCellStyle bottomRightLineStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        bottomRightLineStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
        bottomRightLineStyle.BorderRight  = NPOI.SS.UserModel.BorderStyle.THIN;

        workSheet.CreateRow(0).CreateCell(0).SetCellValue("Year");
        workSheet.GetRow(0).CreateCell(1).SetCellValue(year);
        workSheet.CreateRow(1).CreateCell(0).SetCellValue("Month");
        workSheet.GetRow(1).CreateCell(1).SetCellValue(month);

        NPOI.HSSF.UserModel.HSSFRow headerRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(COLUMN_HEADER_ROW);
        DBFilter hLevelFilter = new DBFilter();

        hLevelFilter.add("HLevelSeqNo", true);

        int       HIERARCHYLEVEL_COLUMN = 0;
        ArrayList hLevelList            = EHierarchyLevel.db.select(dbConn, hLevelFilter);

        for (int levelIndex = 0; levelIndex < hLevelList.Count; levelIndex++)
        {
            EHierarchyLevel hLevel = (EHierarchyLevel)hLevelList[levelIndex];
            headerRow.CreateCell(HIERARCHYLEVEL_COLUMN + levelIndex).SetCellValue(hLevel.HLevelDesc);
        }

        int POSITION_COLUMN = headerRow.LastCellNum;

        headerRow.CreateCell(POSITION_COLUMN).SetCellValue(HROne.Common.WebUtility.GetLocalizedString("Position"));
        int EMPNO_COLUMN = headerRow.LastCellNum;

        headerRow.CreateCell(EMPNO_COLUMN).SetCellValue(FIELD_EMP_NO);
        headerRow.CreateCell(EMPNO_COLUMN + 1).SetCellValue(HROne.Common.WebUtility.GetLocalizedString("Name"));
        headerRow.CreateCell(EMPNO_COLUMN + 2).SetCellValue(HROne.Common.WebUtility.GetLocalizedString("Alias"));
        headerRow.CreateCell(EMPNO_COLUMN + 3).SetCellValue(HROne.Common.WebUtility.GetLocalizedString("Chinese Name"));

        NPOI.HSSF.UserModel.HSSFCellStyle sundayStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
        NPOI.HSSF.UserModel.HSSFFont      sundayFont  = (NPOI.HSSF.UserModel.HSSFFont)workBook.CreateFont();
        sundayFont.Color = NPOI.HSSF.Util.HSSFColor.RED.index;
        sundayStyle.SetFont(sundayFont);

        Hashtable styleList = new Hashtable();

        ArrayList availableRosterClientList     = new ArrayList();
        ArrayList availableRosterClientSiteList = new ArrayList();

        #region Create Column Header
        int ROSTER_DETAIL_COLUMN = headerRow.LastCellNum;

        for (int i = 1; i <= DateTime.DaysInMonth(year, month); i++)
        {
            //workSheet.Cells.Add(HEADER_ROW, ROSTAER_DETAIL_COLUMN + i - 1,i);
            NPOI.HSSF.UserModel.HSSFCell headerCell = (NPOI.HSSF.UserModel.HSSFCell)headerRow.CreateCell(ROSTER_DETAIL_COLUMN + i - 1);
            headerCell.SetCellValue(i);
            if (new DateTime(year, month, i).DayOfWeek == DayOfWeek.Sunday)
            {
                headerCell.CellStyle = sundayStyle;
            }
        }
        #endregion
        #region Create Employee Roster Detail
        int recordCount = 0;
        foreach (EEmpPersonalInfo empInfo in EmpInfoList)
        {
            if (EEmpPersonalInfo.db.select(dbConn, empInfo))
            {
                recordCount++;

                //workSheet.Cells.Add(HEADER_ROW + recordCount, 1,empInfo.EmpNo);
                //workSheet.Cells.Add(HEADER_ROW + recordCount, 2,empInfo.EmpEngFullName);

                NPOI.HSSF.UserModel.HSSFRow detailRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(COLUMN_HEADER_ROW + recordCount);
                EEmpPositionInfo            empPos    = AppUtils.GetLastPositionInfo(dbConn, dateEnd, empInfo.EmpID);
                if (empPos != null)
                {
                    for (int levelIndex = 0; levelIndex < hLevelList.Count; levelIndex++)
                    {
                        EHierarchyLevel hLevel             = (EHierarchyLevel)hLevelList[levelIndex];
                        DBFilter        empHierarchyFilter = new DBFilter();
                        empHierarchyFilter.add(new Match("EmpPosID", empPos.EmpPosID));
                        empHierarchyFilter.add(new Match("HLevelID", hLevel.HLevelID));
                        ArrayList empHierarchyList = EEmpHierarchy.db.select(dbConn, empHierarchyFilter);
                        if (empHierarchyList.Count > 0)
                        {
                            EEmpHierarchy     empHierarchy = (EEmpHierarchy)empHierarchyList[0];
                            EHierarchyElement hElement     = new EHierarchyElement();
                            hElement.HElementID = empHierarchy.HElementID;
                            if (EHierarchyElement.db.select(dbConn, hElement))
                            {
                                detailRow.CreateCell(HIERARCHYLEVEL_COLUMN + levelIndex).SetCellValue(hElement.HElementDesc);
                            }
                        }
                    }

                    EPosition position = new EPosition();
                    position.PositionID = empPos.PositionID;
                    if (EPosition.db.select(dbConn, position))
                    {
                        detailRow.CreateCell(POSITION_COLUMN).SetCellValue(position.PositionDesc);
                    }
                }
                detailRow.CreateCell(EMPNO_COLUMN).SetCellValue(empInfo.EmpNo);
                detailRow.CreateCell(EMPNO_COLUMN + 1).SetCellValue(empInfo.EmpEngFullName);
                detailRow.CreateCell(EMPNO_COLUMN + 2).SetCellValue(empInfo.EmpAlias);
                detailRow.CreateCell(EMPNO_COLUMN + 3).SetCellValue(empInfo.EmpChiFullName);



                DBFilter rosterTableFilter = new DBFilter();
                rosterTableFilter.add(new Match("EmpID", empInfo.EmpID));
                rosterTableFilter.add(new Match("RosterTableDate", ">=", dateStart));
                rosterTableFilter.add(new Match("RosterTableDate", "<=", dateEnd));
                ArrayList rosterTableList = ERosterTable.db.select(dbConn, rosterTableFilter);
                foreach (ERosterTable rosterTable in rosterTableList)
                {
                    ERosterCode rosterCode = new ERosterCode();
                    rosterCode.RosterCodeID = rosterTable.RosterCodeID;
                    if (ERosterCode.db.select(dbConn, rosterCode))
                    {
                        string value = string.Empty;
                        //if (workSheet.Rows[(ushort)(HEADER_ROW + recordCount)].CellExists ((ushort)(ROSTAER_DETAIL_COLUMN + rosterTable.RosterTableDate.Day - 1)) )
                        //    value = workSheet.Rows[(ushort)(HEADER_ROW+ recordCount)].CellAtCol( (ushort)(ROSTAER_DETAIL_COLUMN + rosterTable.RosterTableDate.Day - 1)).Value.ToString();
                        //if (string.IsNullOrEmpty(value))
                        //    workSheet.Cells.Add(HEADER_ROW + recordCount, ROSTAER_DETAIL_COLUMN + rosterTable.RosterTableDate.Day - 1,rosterCode.RosterCode);
                        //else
                        //    workSheet.Cells.Add(HEADER_ROW + recordCount, ROSTAER_DETAIL_COLUMN + rosterTable.RosterTableDate.Day - 1,value + "|" + rosterCode.RosterCode);

                        int cellColIndex = ROSTER_DETAIL_COLUMN + rosterTable.RosterTableDate.Day - 1;
                        NPOI.HSSF.UserModel.HSSFCell rosterCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.GetCell(cellColIndex);
                        if (rosterCell == null)
                        {
                            rosterCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(cellColIndex);
                        }
                        else
                        {
                            value = rosterCell.StringCellValue;
                        }
                        string rosterCodeValue = rosterCode.RosterCode;
                        if (!rosterTable.RosterTableOverrideInTime.Ticks.Equals(0) || !rosterTable.RosterTableOverrideOutTime.Ticks.Equals(0))
                        {
                            DateTime inTime  = rosterCode.RosterCodeInTime;
                            DateTime outTime = rosterCode.RosterCodeOutTime;
                            if (!rosterTable.RosterTableOverrideInTime.Ticks.Equals(0))
                            {
                                inTime = rosterTable.RosterTableOverrideInTime;
                            }
                            if (!rosterTable.RosterTableOverrideOutTime.Ticks.Equals(0))
                            {
                                outTime = rosterTable.RosterTableOverrideOutTime;
                            }
                            rosterCodeValue += "(" + inTime.ToString("HHmm") + "~" + outTime.ToString("HHmm") + ")";
                        }
                        if (string.IsNullOrEmpty(value))
                        {
                            rosterCell.SetCellValue(rosterCodeValue);
                            //if (!string.IsNullOrEmpty(rosterCode.RosterCodeColorCode))
                            //{
                            //    //System.Drawing.Color color = System.Drawing.ColorTranslator.FromHtml(rosterCode.RosterCodeColorCode);
                            //    //System.Drawing.Color fontcolor = WebUtils.ComputeTextColor(color);
                            //    //rosterCell.CellStyle.FillForegroundColor = workBook.GetCustomPalette().FindSimilarColor(color.R, color.G, color.B).GetIndex();
                            //    //rosterCell.CellStyle.FillPattern = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND;
                            //    //rosterCell.CellStyle.FillBackgroundColor = workBook.GetCustomPalette().FindSimilarColor(fontcolor.R, fontcolor.G, fontcolor.B).GetIndex();
                            //    string styleCode = "RosterCode" + "_" + rosterCode.RosterCode;
                            //    if (styleList.Contains(styleCode))
                            //        rosterCell.CellStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)styleList[styleCode];
                            //    else
                            //    {
                            //        NPOI.HSSF.UserModel.HSSFCellStyle rosterCodeStyle = (NPOI.HSSF.UserModel.HSSFCellStyle)workBook.CreateCellStyle();
                            //        System.Drawing.Color color = System.Drawing.ColorTranslator.FromHtml(rosterCode.RosterCodeColorCode);
                            //        System.Drawing.Color fontcolor = WebUtils.ComputeTextColor(color);
                            //        rosterCodeStyle.FillForegroundColor = workBook.GetCustomPalette().FindSimilarColor(color.R, color.G, color.B).GetIndex();
                            //        rosterCodeStyle.FillPattern = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND;
                            //        rosterCodeStyle.FillBackgroundColor = workBook.GetCustomPalette().FindSimilarColor(fontcolor.R, fontcolor.G, fontcolor.B).GetIndex();
                            //        styleList.Add(styleCode, rosterCodeStyle);
                            //        rosterCell.CellStyle = rosterCodeStyle;
                            //    }
                            //}
                        }
                        else
                        {
                            rosterCell.SetCellValue(value + "|" + rosterCodeValue);
                            //rosterCell.CellStyle=workBook.GetCellStyleAt(0);
                        }
                    }
                }
                for (DateTime dateIndex = dateStart; dateIndex <= dateEnd; dateIndex = dateIndex.AddDays(1))
                {
                    string value = string.Empty;
                    //if (workSheet.Rows[(ushort)(HEADER_ROW + recordCount)].CellExists((ushort)(ROSTAER_DETAIL_COLUMN + dateIndex.Day - 1)) )
                    //    value = workSheet.Rows[(ushort)(HEADER_ROW + recordCount)].CellAtCol((ushort)(ROSTAER_DETAIL_COLUMN + dateIndex.Day - 1)).Value.ToString();
                    int cellColIndex = ROSTER_DETAIL_COLUMN + dateIndex.Day - 1;
                    NPOI.HSSF.UserModel.HSSFCell rosterCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.GetCell(cellColIndex);
                    if (rosterCell == null)
                    {
                        rosterCell = (NPOI.HSSF.UserModel.HSSFCell)detailRow.CreateCell(cellColIndex);
                    }
                    else
                    {
                        value = rosterCell.StringCellValue;
                    }

                    if (string.IsNullOrEmpty(value))
                    {
                        EEmpPositionInfo empPosInfo = AppUtils.GetLastPositionInfo(dbConn, dateIndex, empInfo.EmpID);
                        if (empPosInfo != null)
                        {
                            if ((empPosInfo.EmpPosEffTo.Ticks.Equals(0) || dateIndex <= empPosInfo.EmpPosEffTo))
                            {
                                EWorkHourPattern workPattern = new EWorkHourPattern();
                                workPattern.WorkHourPatternID = empPosInfo.WorkHourPatternID;
                                if (EWorkHourPattern.db.select(dbConn, workPattern))
                                {
                                    ERosterCode rosterCode = new ERosterCode();
                                    rosterCode.RosterCodeID = workPattern.GetDefaultRosterCodeID(dbConn, dateIndex);
                                    if (ERosterCode.db.select(dbConn, rosterCode))
                                    {
                                        //workSheet.Cells.Add(HEADER_ROW + recordCount, ROSTAER_DETAIL_COLUMN + dateIndex.Day - 1, rosterCode.RosterCode);
                                        rosterCell.SetCellValue(rosterCode.RosterCode);
                                    }
                                }

                                DBFilter empRosterTableGroupListFilter = new DBFilter();
                                empRosterTableGroupListFilter.add(new Match("EmpID", empInfo.EmpID));
                                empRosterTableGroupListFilter.add(new Match("empRosterTableGroupEffFr", "<=", dateIndex));
                                OR orEmpPosEffToTerms = new OR();
                                orEmpPosEffToTerms.add(new Match("empRosterTableGroupEffTo", ">=", dateIndex));
                                orEmpPosEffToTerms.add(new NullTerm("empRosterTableGroupEffTo"));
                                empRosterTableGroupListFilter.add(orEmpPosEffToTerms);
                                ArrayList empRosterTableGroupList = EEmpRosterTableGroup.db.select(dbConn, empRosterTableGroupListFilter);

                                foreach (EEmpRosterTableGroup empRosterTableGroup in empRosterTableGroupList)
                                {
                                    ERosterTableGroup rosterTableGroup = new ERosterTableGroup();
                                    rosterTableGroup.RosterTableGroupID = empRosterTableGroup.RosterTableGroupID;
                                    if (ERosterTableGroup.db.select(dbConn, rosterTableGroup))
                                    {
                                        if (rosterTableGroup.RosterClientSiteID > 0)
                                        {
                                            if (!availableRosterClientSiteList.Contains(rosterTableGroup.RosterClientSiteID))
                                            {
                                                availableRosterClientSiteList.Add(rosterTableGroup.RosterClientSiteID);
                                            }
                                        }
                                        else if (rosterTableGroup.RosterClientID > 0)
                                        {
                                            if (!availableRosterClientList.Contains(rosterTableGroup.RosterClientID))
                                            {
                                                availableRosterClientList.Add(rosterTableGroup.RosterClientID);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                DBFilter leaveAppFilter = new DBFilter();
                leaveAppFilter.add(new Match("EmpID", empInfo.EmpID));
                leaveAppFilter.add(new Match("LeaveAppDateTo", ">=", dateStart));
                leaveAppFilter.add(new Match("LeaveAppDateFrom", "<=", dateEnd));
                ArrayList leaveAppList = ELeaveApplication.db.select(dbConn, leaveAppFilter);
                foreach (ELeaveApplication leaveApp in leaveAppList)
                {
                    ELeaveCode leaveCode = new ELeaveCode();
                    leaveCode.LeaveCodeID = leaveApp.LeaveCodeID;
                    if (ELeaveCode.db.select(dbConn, leaveCode))
                    {
                        //if (leaveCode.LeaveCodeColorCode.Length == 6)
                        //{
                        //    try
                        //    {
                        //        int red = System.Int32.Parse(leaveCode.LeaveCodeColorCode.Substring(0, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
                        //        int green = System.Int32.Parse(leaveCode.LeaveCodeColorCode.Substring(2, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
                        //        int blue = System.Int32.Parse(leaveCode.LeaveCodeColorCode.Substring(4, 2), System.Globalization.NumberStyles.AllowHexSpecifier);

                        //        string Color = System.Drawing.Color.FromArgb(red, green, blue).ToKnownColor().ToString();

                        //        for (DateTime dateIndex = leaveApp.LeaveAppDateFrom; dateIndex <= leaveApp.LeaveAppDateTo; dateIndex = dateIndex.AddDays(1))
                        //        {
                        //            org.in2bits.MyXls.Cell cell = workSheet.Rows[(ushort)(HEADER_ROW + recordCount)].CellAtCol((ushort)(ROSTAER_DETAIL_COLUMN + dateIndex.Day - 1));
                        //            //cell.Pattern = 1;
                        //            //cell.PatternColor = org.in2bits.MyXls.Colors.Yellow;

                        //        }
                        //    }
                        //    catch
                        //    {
                        //    }

                        //}
                    }
                }
            }
        }
        #endregion
        #region Create Roster Code Liet
        OR orRosterCodeTerm = new OR();
        foreach (int rosterClientID in availableRosterClientList)
        {
            AND andRosterCodeTerms = new AND();
            orRosterCodeTerm.add(new Match("RosterClientID", rosterClientID));
        }
        foreach (int rosterClientSiteID in availableRosterClientSiteList)
        {
            AND andRosterCodeTerms = new AND();
            orRosterCodeTerm.add(new Match("RosterClientSiteID", rosterClientSiteID));
        }
        orRosterCodeTerm.add(new Match("RosterClientID", 0));
        DBFilter rosterCodeListFilter = new DBFilter();
        rosterCodeListFilter.add(orRosterCodeTerm);
        rosterCodeListFilter.add("RosterCode", true);
        ArrayList rosterCodeList = ERosterCode.db.select(dbConn, rosterCodeListFilter);

        int ROSTER_CODE_START_ROW = COLUMN_HEADER_ROW + recordCount + 5;
        int rosterCodeCount       = 0;
        int maxColumnCount        = 3;
        int columnCellWidth       = 9;
        int maxRowCount           = (int)(rosterCodeList.Count / maxColumnCount) + (rosterCodeList.Count % maxColumnCount == 0 ? 0 : 1);
        foreach (ERosterCode rosterCode in rosterCodeList)
        {
            int currentRowNum    = rosterCodeCount % maxRowCount;
            int currentColumnNum = (rosterCodeCount / maxRowCount) * columnCellWidth;

            rosterCodeCount++;

            NPOI.HSSF.UserModel.HSSFRow rosterCodeRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.GetRow(ROSTER_CODE_START_ROW + currentRowNum);
            if (rosterCodeRow == null)
            {
                rosterCodeRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(ROSTER_CODE_START_ROW + currentRowNum);
            }

            NPOI.HSSF.UserModel.HSSFCell rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.CreateCell(ROSTER_DETAIL_COLUMN + currentColumnNum);
            rosterCell.SetCellValue(rosterCode.RosterCode);

            rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.CreateCell(ROSTER_DETAIL_COLUMN + currentColumnNum + 1);
            rosterCell.SetCellValue(rosterCode.RosterCodeDesc);

            if (rosterCodeCount.Equals(1))
            {
                rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.CreateCell(ROSTER_DETAIL_COLUMN - 1);
                rosterCell.SetCellValue("Code:");
            }
        }

        for (int rowIdx = ROSTER_CODE_START_ROW - 1; rowIdx < ROSTER_CODE_START_ROW + maxRowCount + 1; rowIdx++)
        {
            NPOI.HSSF.UserModel.HSSFRow rosterCodeRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.GetRow(rowIdx);
            if (rosterCodeRow == null)
            {
                rosterCodeRow = (NPOI.HSSF.UserModel.HSSFRow)workSheet.CreateRow(rowIdx);
            }

            if (rowIdx == ROSTER_CODE_START_ROW - 1)
            {
                for (int colIdx = ROSTER_DETAIL_COLUMN - 1; colIdx < ROSTER_DETAIL_COLUMN + maxColumnCount * columnCellWidth; colIdx++)
                {
                    NPOI.HSSF.UserModel.HSSFCell rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.GetCell(colIdx);
                    if (rosterCell == null)
                    {
                        rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.CreateCell(colIdx);
                    }
                    if (colIdx == ROSTER_DETAIL_COLUMN - 1)
                    {
                        rosterCell.CellStyle = upperLeftLineStyle;
                    }
                    else if (colIdx == ROSTER_DETAIL_COLUMN + maxColumnCount * columnCellWidth - 1)
                    {
                        rosterCell.CellStyle = upperRightLineStyle;
                    }
                    else
                    {
                        rosterCell.CellStyle = upperLineStyle;
                    }
                }
            }
            else if (rowIdx == ROSTER_CODE_START_ROW + maxRowCount)
            {
                for (int colIdx = ROSTER_DETAIL_COLUMN - 1; colIdx < ROSTER_DETAIL_COLUMN + maxColumnCount * columnCellWidth; colIdx++)
                {
                    NPOI.HSSF.UserModel.HSSFCell rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.GetCell(colIdx);
                    if (rosterCell == null)
                    {
                        rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.CreateCell(colIdx);
                    }
                    if (colIdx == ROSTER_DETAIL_COLUMN - 1)
                    {
                        rosterCell.CellStyle = bottomLeftLineStyle;
                    }
                    else if (colIdx == ROSTER_DETAIL_COLUMN + maxColumnCount * columnCellWidth - 1)
                    {
                        rosterCell.CellStyle = bottomRightLineStyle;
                    }
                    else
                    {
                        rosterCell.CellStyle = bottomLineStyle;
                    }
                }
            }
            else
            {
                for (int colIdx = ROSTER_DETAIL_COLUMN - 1; colIdx < ROSTER_DETAIL_COLUMN + maxColumnCount * columnCellWidth; colIdx++)
                {
                    NPOI.HSSF.UserModel.HSSFCell rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.GetCell(colIdx);
                    if (rosterCell == null)
                    {
                        rosterCell = (NPOI.HSSF.UserModel.HSSFCell)rosterCodeRow.CreateCell(colIdx);
                    }
                    if (colIdx == ROSTER_DETAIL_COLUMN - 1)
                    {
                        rosterCell.CellStyle = leftLineStyle;
                    }
                    else if (colIdx == ROSTER_DETAIL_COLUMN + maxColumnCount * columnCellWidth - 1)
                    {
                        rosterCell.CellStyle = rightLineStyle;
                    }
                    //else
                    //    rosterCell.CellStyle = bottomLineStyle;
                }
            }
        }
        #endregion

        //doc.FileName = exportFileName;
        //doc.Save();
        System.IO.FileStream file = new System.IO.FileStream(exportFileName, System.IO.FileMode.Create);
        workBook.Write(file);
        file.Close();

        WebUtils.TransmitFile(Response, exportFileName, "RosterTable_" + AppUtils.ServerDateTime().ToString("yyyyMMddHHmmss") + ".xls", true);
        Response.End();
    }
Example #9
0
    private void CheckWorkHourDetermineControl(EWorkHourPattern obj)
    {
        WorkHourPatternDaySettingsPanel.Visible       = true;
        lblRosterCodeHeader.Visible                   = false;
        WorkHourPatternSunDefaultRosterCodeID.Visible = false;
        WorkHourPatternMonDefaultRosterCodeID.Visible = false;
        WorkHourPatternTueDefaultRosterCodeID.Visible = false;
        WorkHourPatternWedDefaultRosterCodeID.Visible = false;
        WorkHourPatternThuDefaultRosterCodeID.Visible = false;
        WorkHourPatternFriDefaultRosterCodeID.Visible = false;
        WorkHourPatternSatDefaultRosterCodeID.Visible = false;

        lblDayUnitHeader.Visible = false;
        WorkHourPatternSunDefaultDayUnit.Visible = false;
        WorkHourPatternMonDefaultDayUnit.Visible = false;
        WorkHourPatternTueDefaultDayUnit.Visible = false;
        WorkHourPatternWedDefaultDayUnit.Visible = false;
        WorkHourPatternThuDefaultDayUnit.Visible = false;
        WorkHourPatternFriDefaultDayUnit.Visible = false;
        WorkHourPatternSatDefaultDayUnit.Visible = false;
        WorkHourPatternStatutoryHolidayDefaultRosterCodeID.Visible = false;
        WorkHourPatternPublicHolidayDefaultRosterCodeID.Visible    = false;

        WorkHoursPerDayHeaderCell.Visible      = false;
        LunchTimeHoursPerDayHeaderCell.Visible = false;
        WorkHoursPerDaySunCell.Visible         = false;
        LunchTimeHoursPerDaySunCell.Visible    = false;
        WorkHoursPerDayMonCell.Visible         = false;
        LunchTimeHoursPerDayMonCell.Visible    = false;
        WorkHoursPerDayTueCell.Visible         = false;
        LunchTimeHoursPerDayTueCell.Visible    = false;
        WorkHoursPerDayWedCell.Visible         = false;
        LunchTimeHoursPerDayWedCell.Visible    = false;
        WorkHoursPerDayThuCell.Visible         = false;
        LunchTimeHoursPerDayThuCell.Visible    = false;
        WorkHoursPerDayFriCell.Visible         = false;
        LunchTimeHoursPerDayFriCell.Visible    = false;
        WorkHoursPerDaySatCell.Visible         = false;
        LunchTimeHoursPerDaySatCell.Visible    = false;

        if (obj.WorkHourPatternWorkDayDetermineMethod.Equals(EWorkHourPattern.WORKDAYDETERMINDMETHOD_ROSTERTABLE))
        {
            WorkHourPerDayRow.Visible  = true;
            LunchTimePerDayRow.Visible = true;

            lblRosterCodeHeader.Visible = true;
            WorkHourPatternSunDefaultRosterCodeID.Visible = true;
            WorkHourPatternMonDefaultRosterCodeID.Visible = true;
            WorkHourPatternTueDefaultRosterCodeID.Visible = true;
            WorkHourPatternWedDefaultRosterCodeID.Visible = true;
            WorkHourPatternThuDefaultRosterCodeID.Visible = true;
            WorkHourPatternFriDefaultRosterCodeID.Visible = true;
            WorkHourPatternSatDefaultRosterCodeID.Visible = true;
            if (obj.WorkHourPatternUseStatutoryHolidayTable)
            {
                WorkHourPatternStatutoryHolidayDefaultRosterCodeID.Visible = true;
            }
            if (obj.WorkHourPatternUsePublicHolidayTable)
            {
                WorkHourPatternPublicHolidayDefaultRosterCodeID.Visible = true;
            }
        }
        else if (obj.WorkHourPatternWorkDayDetermineMethod.Equals(EWorkHourPattern.WORKDAYDETERMINDMETHOD_MANUALINPUT))
        {
            WorkHourPerDayRow.Visible  = true;
            LunchTimePerDayRow.Visible = true;

            lblDayUnitHeader.Visible = true;
            WorkHourPatternSunDefaultDayUnit.Visible = true;
            WorkHourPatternMonDefaultDayUnit.Visible = true;
            WorkHourPatternTueDefaultDayUnit.Visible = true;
            WorkHourPatternWedDefaultDayUnit.Visible = true;
            WorkHourPatternThuDefaultDayUnit.Visible = true;
            WorkHourPatternFriDefaultDayUnit.Visible = true;
            WorkHourPatternSatDefaultDayUnit.Visible = true;

            WorkHoursPerDayHeaderCell.Visible      = true;
            LunchTimeHoursPerDayHeaderCell.Visible = true;
            WorkHoursPerDaySunCell.Visible         = true;
            LunchTimeHoursPerDaySunCell.Visible    = true;
            WorkHoursPerDayMonCell.Visible         = true;
            LunchTimeHoursPerDayMonCell.Visible    = true;
            WorkHoursPerDayTueCell.Visible         = true;
            LunchTimeHoursPerDayTueCell.Visible    = true;
            WorkHoursPerDayWedCell.Visible         = true;
            LunchTimeHoursPerDayWedCell.Visible    = true;
            WorkHoursPerDayThuCell.Visible         = true;
            LunchTimeHoursPerDayThuCell.Visible    = true;
            WorkHoursPerDayFriCell.Visible         = true;
            LunchTimeHoursPerDayFriCell.Visible    = true;
            WorkHoursPerDaySatCell.Visible         = true;
            LunchTimeHoursPerDaySatCell.Visible    = true;
        }
        else
        {
            WorkHourPerDayRow.Visible  = true;
            LunchTimePerDayRow.Visible = true;
            WorkHourPatternDaySettingsPanel.Visible = false;
        }
    }
Example #10
0
        public override CrystalDecisions.CrystalReports.Engine.ReportDocument GenerateReport()
        {
            if (EmpIDList.Count > 0)
            {
                DataSet ds = new DataSet();
                ds.ReadXmlSchema(schemaXSDPath);
                DataTable empInfoTable          = ds.Tables["EmpInfo"];
                DataTable attendanceRecordTable = ds.Tables["AttendanceRecord"];

                DateTime periodFrom = new DateTime(year, month, 1);
                DateTime periodTo   = new DateTime(year, month, DateTime.DaysInMonth(year, month));

                foreach (int EmpID in EmpIDList)
                {
                    EEmpPersonalInfo empInfo = new EEmpPersonalInfo();
                    empInfo.EmpID = EmpID;
                    if (EEmpPersonalInfo.db.select(dbConn, empInfo))
                    {
                        DataRow empRow = empInfoTable.NewRow();
                        empRow["EmpID"]      = EmpID;
                        empRow["EmpNo"]      = empInfo.EmpNo;
                        empRow["EmpName"]    = empInfo.EmpEngFullName;
                        empRow["PeriodFrom"] = periodFrom;
                        empRow["PeriodTo"]   = periodTo;

                        EEmpPositionInfo empPos = AppUtils.GetLastPositionInfo(dbConn, periodTo, EmpID);
                        if (empPos != null)
                        {
                            EAuthorizationWorkFlow workFlow = new EAuthorizationWorkFlow();
                            workFlow.AuthorizationWorkFlowID = empPos.AuthorizationWorkFlowIDLeaveApp;
                            if (EAuthorizationWorkFlow.db.select(dbConn, workFlow))
                            {
                                empRow["Section"] = workFlow.AuthorizationWorkFlowDescription;
                            }

                            EWorkHourPattern workHourPattern = new EWorkHourPattern();
                            workHourPattern.WorkHourPatternID = empPos.WorkHourPatternID;
                            if (EWorkHourPattern.db.select(dbConn, workHourPattern))
                            {
                                empRow["RosterGroup"] = workHourPattern.WorkHourPatternCode + " - " + workHourPattern.WorkHourPatternDesc;
                            }
                        }
                        empInfoTable.Rows.Add(empRow);
                    }

                    DBFilter attendanceRecordFilter = new DBFilter();
                    attendanceRecordFilter.add(new Match("EmpID", EmpID));
                    attendanceRecordFilter.add(new Match("AttendanceRecordDate", ">=", periodFrom));
                    attendanceRecordFilter.add(new Match("AttendanceRecordDate", "<=", periodTo));
                    attendanceRecordFilter.add("AttendanceRecordDate", true);
                    ArrayList attendanceRecordList = EAttendanceRecord.db.select(dbConn, attendanceRecordFilter);

                    foreach (EAttendanceRecord attendanceRecord in attendanceRecordList)
                    {
                        DataRow attendanceRecordRow = attendanceRecordTable.NewRow();


                        attendanceRecordRow["AttendanceRecordID"] = attendanceRecord.AttendanceRecordID;
                        attendanceRecordRow["EmpID"] = attendanceRecord.EmpID;
                        attendanceRecordRow["AttendanceRecordDate"] = attendanceRecord.AttendanceRecordDate;
                        if (attendanceRecord.AttendanceRecordWorkStart.Ticks > 0)
                        {
                            attendanceRecordRow["AttendanceRecordWorkStart"] = attendanceRecord.AttendanceRecordWorkStart;
                        }
                        if (attendanceRecord.AttendanceRecordWorkEnd.Ticks > 0)
                        {
                            attendanceRecordRow["AttendanceRecordWorkEnd"] = attendanceRecord.AttendanceRecordWorkEnd;
                        }
                        attendanceRecordRow["AttendanceRecordLateMins"]       = attendanceRecord.AttendanceRecordActualLateMins;
                        attendanceRecordRow["AttendanceRecordEarlyLeaveMins"] = attendanceRecord.AttendanceRecordActualEarlyLeaveMins;
                        if (attendanceRecord.AttendanceRecordIsAbsent && string.IsNullOrEmpty(attendanceRecord.AttendanceRecordRemark))
                        {
                            attendanceRecordRow["AttendanceRecordRemark"] = "Absent";
                        }
                        else
                        {
                            attendanceRecordRow["AttendanceRecordRemark"] = attendanceRecord.AttendanceRecordRemark;
                        }
                        attendanceRecordRow["IsPublicHoliday"] = EPublicHoliday.IsHoliday(dbConn, attendanceRecord.AttendanceRecordDate) || attendanceRecord.AttendanceRecordDate.DayOfWeek == DayOfWeek.Sunday;
                        // Start 0000058, KuangWei, 2014-07-10
                        attendanceRecordRow["AttendanceRecordOvertimeMins"] = attendanceRecord.AttendanceRecordActualOvertimeMins;
                        // End 0000058, KuangWei, 2014-07-10
                        attendanceRecordTable.Rows.Add(attendanceRecordRow);
                    }
                }

                //System.Data.DataTable table = null;
                //foreach (int EmpID in EmpList)
                //{
                //    string select = "P.*,EmpPos.*,Pos.*,Comp.* ";
                //    string from = "from EmpPersonalInfo P LEFT JOIN EmpPositionInfo EmpPos ON P.EmpID=EmpPos.EmpID AND EmpPos.EmpPosEffTo IS NULL LEFT JOIN Position Pos ON EmpPos.PositionID=Pos.PositionID LEFT JOIN Company Comp ON EmpPos.CompanyID=Comp.CompanyID";
                //    DBFilter filter = new DBFilter();
                //    OR or = new OR();
                //    filter.add(new Match("P.EmpID", EmpID));
                //    System.Data.DataTable resulttable = filter.loadData(null, select, from);
                //    if (table == null)
                //        table = resulttable;
                //    else
                //        table.Merge(resulttable);
                //}
                //DBAESEncryptStringFieldAttribute.decode(table, "EmpHKID", true);
                //DBAESEncryptStringFieldAttribute.decode(table, "EmpPassportNo", false);


                //if (reportDocument == null)
                //{
                //    reportDocument = new ReportTemplate.Report_Employee_List();
                //}
                //else
                //{

                //}
                reportDocument.SetDataSource(ds);

                return(reportDocument);
            }
            else
            {
                return(null);
            }
        }