public static void GenerateBirthdayInboxMessage(DatabaseConnection dbConn, int UserID, int NoticeDaysBefore, int NoticeDaysAfter) { if (NoticeDaysBefore < 0) { NoticeDaysBefore = 30; } if (NoticeDaysAfter < 0) { NoticeDaysAfter = 30; } const string INBOX_TYPE = EInbox.INBOX_TYPE_DATE_OF_BIRTH; DBFilter DateOfBirthFilter = new DBFilter(); DateOfBirthFilter.add(AppUtils.AddRankDBTerm(UserID, "EmpID", true)); //DateOfBirthFilter.add(new Match("EmpDateOfBirth", ">=", AppUtils.ServerDateTime().Date.AddYears(-YEAR_DIFFERENT).AddDays(-NOTICEDAYSAFTER))); //DateOfBirthFilter.add(new Match("EmpDateOfBirth", "<=", AppUtils.ServerDateTime().Date.AddYears(-YEAR_DIFFERENT).AddDays(NOTICEDAYSBEFORE))); DBFilter existsInboxFilter = new DBFilter(); existsInboxFilter.add(new MatchField(EEmpPersonalInfo.db.dbclass.tableName + ".EmpID", EInbox.db.dbclass.tableName + ".EmpID")); existsInboxFilter.add(new MatchField(EEmpPersonalInfo.db.dbclass.tableName + ".EmpID", EInbox.db.dbclass.tableName + ".InboxRelatedRecID")); existsInboxFilter.add(new MatchField(EEmpPersonalInfo.db.dbclass.tableName + ".EmpDateOfBirth", EInbox.db.dbclass.tableName + ".InboxRelatedReferenceDate")); existsInboxFilter.add(new Match(EInbox.db.dbclass.tableName + ".InboxType", INBOX_TYPE)); existsInboxFilter.add(new Match(EInbox.db.dbclass.tableName + ".UserID", UserID)); existsInboxFilter.add(new Match(EInbox.db.dbclass.tableName + ".InboxCreateDate", ">=", AppUtils.ServerDateTime().Date.AddDays(-(NoticeDaysBefore + NoticeDaysAfter)))); Exists existsInbox = new Exists(EInbox.db.dbclass.tableName, existsInboxFilter, true); DateOfBirthFilter.add(existsInbox); DBFilter existsEmpTerminationFilter = new DBFilter(); existsEmpTerminationFilter.add(new MatchField(EEmpPersonalInfo.db.dbclass.tableName + ".EmpID", EEmpTermination.db.dbclass.tableName + ".EmpID")); existsEmpTerminationFilter.add(new Match("EmpTermLastDate", "<=", AppUtils.ServerDateTime().Date)); Exists notExistsEmpTermination = new Exists(EEmpTermination.db.dbclass.tableName, existsEmpTerminationFilter, true); DateOfBirthFilter.add(notExistsEmpTermination); System.Collections.ArrayList empInfoList = EEmpPersonalInfo.db.select(dbConn, DateOfBirthFilter); DateTime BirthdayPeriodFrom = AppUtils.ServerDateTime().Date.AddDays(-NoticeDaysAfter); DateTime BirthdayPeriodTo = AppUtils.ServerDateTime().Date.AddDays(NoticeDaysBefore); foreach (EEmpPersonalInfo empInfo in empInfoList) { DateTime dateOfBirth = empInfo.EmpDateOfBirth; int yearCount = 0; while (dateOfBirth <= BirthdayPeriodFrom) { yearCount++; dateOfBirth = empInfo.EmpDateOfBirth.AddYears(yearCount); } if (dateOfBirth <= BirthdayPeriodTo) { EInbox.CreateAndSaveInboxMessage(dbConn, UserID, 0, empInfo.EmpID, empInfo.EmpID, string.Empty, INBOX_TYPE, string.Empty, string.Empty, empInfo.EmpDateOfBirth); } } }
public static void GenerateWorkPermitExpiryInboxMessage(DatabaseConnection dbConn, int UserID, int NoticeDaysBefore, int NoticeDaysAfter) { if (NoticeDaysBefore < 0) { NoticeDaysBefore = 30; } if (NoticeDaysAfter < 0) { NoticeDaysAfter = 30; } const string INBOX_TYPE = EInbox.INBOX_TYPE_WORKPERMITEXPIRY; DBFilter WorkPermitExpiryFilter = new DBFilter(); WorkPermitExpiryFilter.add(AppUtils.AddRankDBTerm(UserID, "EmpID", true)); WorkPermitExpiryFilter.add(new Match("EmpPermitExpiryDate", ">=", AppUtils.ServerDateTime().Date.AddDays(-NoticeDaysAfter))); WorkPermitExpiryFilter.add(new Match("EmpPermitExpiryDate", "<=", AppUtils.ServerDateTime().Date.AddDays(NoticeDaysBefore))); DBFilter existsInboxFilter = new DBFilter(); existsInboxFilter.add(new MatchField(EEmpPermit.db.dbclass.tableName + ".EmpID", EInbox.db.dbclass.tableName + ".EmpID")); existsInboxFilter.add(new MatchField(EEmpPermit.db.dbclass.tableName + ".EmpPermitID", EInbox.db.dbclass.tableName + ".InboxRelatedRecID")); existsInboxFilter.add(new MatchField(EEmpPermit.db.dbclass.tableName + ".EmpPermitExpiryDate", EInbox.db.dbclass.tableName + ".InboxRelatedReferenceDate")); existsInboxFilter.add(new Match(EInbox.db.dbclass.tableName + ".InboxType", INBOX_TYPE)); existsInboxFilter.add(new Match(EInbox.db.dbclass.tableName + ".UserID", UserID)); existsInboxFilter.add(new Match(EInbox.db.dbclass.tableName + ".InboxCreateDate", ">=", AppUtils.ServerDateTime().Date.AddDays(-(NoticeDaysBefore + NoticeDaysAfter)))); Exists existsInbox = new Exists(EInbox.db.dbclass.tableName, existsInboxFilter, true); WorkPermitExpiryFilter.add(existsInbox); DBFilter existsEmpTerminationFilter = new DBFilter(); existsEmpTerminationFilter.add(new MatchField(EEmpPermit.db.dbclass.tableName + ".EmpID", EEmpTermination.db.dbclass.tableName + ".EmpID")); existsEmpTerminationFilter.add(new Match("EmpTermLastDate", "<=", AppUtils.ServerDateTime().Date)); Exists notExistsEmpTermination = new Exists(EEmpTermination.db.dbclass.tableName, existsEmpTerminationFilter, true); WorkPermitExpiryFilter.add(notExistsEmpTermination); System.Collections.ArrayList empInfoList = EEmpPermit.db.select(dbConn, WorkPermitExpiryFilter); foreach (EEmpPermit empWorkPermit in empInfoList) { EInbox.CreateAndSaveInboxMessage(dbConn, UserID, 0, empWorkPermit.EmpID, empWorkPermit.EmpPermitID, string.Empty, INBOX_TYPE, string.Empty, string.Empty, empWorkPermit.EmpPermitExpiryDate); } }
public static void GenerateTerminationInboxMessage(DatabaseConnection dbConn, int UserID, int NoticeDaysBefore, int NoticeDaysAfter) { if (NoticeDaysBefore < 0) { NoticeDaysBefore = 15; } if (NoticeDaysAfter < 0) { NoticeDaysAfter = 15; } const string INBOX_TYPE = EInbox.INBOX_TYPE_TERMINATION; DBFilter TerminationFilter = new DBFilter(); TerminationFilter.add(AppUtils.AddRankDBTerm(UserID, "EmpID", true)); TerminationFilter.add(new Match("EmpTermLastDate", ">=", AppUtils.ServerDateTime().Date.AddDays(-NoticeDaysAfter))); TerminationFilter.add(new Match("EmpTermLastDate", "<=", AppUtils.ServerDateTime().Date.AddDays(NoticeDaysBefore))); DBFilter existsInboxFilter = new DBFilter(); existsInboxFilter.add(new MatchField(EEmpTermination.db.dbclass.tableName + ".EmpID", EInbox.db.dbclass.tableName + ".EmpID")); existsInboxFilter.add(new MatchField(EEmpTermination.db.dbclass.tableName + ".EmpTermID", EInbox.db.dbclass.tableName + ".InboxRelatedRecID")); existsInboxFilter.add(new MatchField(EEmpTermination.db.dbclass.tableName + ".EmpTermLastDate", EInbox.db.dbclass.tableName + ".InboxRelatedReferenceDate")); existsInboxFilter.add(new Match(EInbox.db.dbclass.tableName + ".InboxType", INBOX_TYPE)); existsInboxFilter.add(new Match(EInbox.db.dbclass.tableName + ".UserID", UserID)); existsInboxFilter.add(new Match(EInbox.db.dbclass.tableName + ".InboxCreateDate", ">=", AppUtils.ServerDateTime().Date.AddDays(-(NoticeDaysBefore + NoticeDaysAfter)))); Exists existsInbox = new Exists(EInbox.db.dbclass.tableName, existsInboxFilter, true); TerminationFilter.add(existsInbox); System.Collections.ArrayList empInfoList = EEmpTermination.db.select(dbConn, TerminationFilter); foreach (EEmpTermination empTerm in empInfoList) { //EEmpPersonalInfo empInfo = new EEmpPersonalInfo(); //empInfo.EmpID = empTerm.EmpID; //if (EEmpPersonalInfo.db.select(dbConn, empInfo)) EInbox.CreateAndSaveInboxMessage(dbConn, UserID, 0, empTerm.EmpID, empTerm.EmpTermID, string.Empty, INBOX_TYPE, string.Empty, string.Empty, empTerm.EmpTermLastDate); } }