1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
//LOOP FOR CURRENT AND UPCOMING STATUSES
//Set statuses from the month of the current control to the end month
bool isControlMonthFound = false;
int frequencyCounter = 0;
int lateIncr = 0;
DateTime computedStartDate = DateTimeHelper.Now > calendarStartDate ? DateTimeHelper.Now : calendarStartDate;
for (int year = computedStartDate.Year; year <= calendarEndDate.Year; year++)
{
//Setting start and end months based on year
int startMonth = 1, endMonth = 12;
if (year == computedStartDate.Year)
startMonth = computedStartDate.Month;
if (year == calendarEndDate.Year)
endMonth = calendarEndDate.Month;
//Looping through months - store current status, current action and upcoming statuses
for (int month = startMonth; month <= endMonth; month++)
{
//init vars
int upcomingStatus = -1;
int upcomingAction = -1;
bool isCurrentControl = false;
bool isTicked = false;
string key = year + "-" + month;
bool isMissingDeadLine = false;
DateTime cursorDate = new DateTime(year, month, DateTime.DaysInMonth(year, month));
isCurrentControl = controlData.RegularEndDate.Value == cursorDate;
if (isCurrentControl)
{
//If current control is in current month and status is good
if (controlData.RegularEndDate.Value.Year == DateTimeHelper.Now.Year
&& controlData.RegularEndDate.Value.Month == DateTimeHelper.Now.Month
&& controlData.StatusRef == (int)Statuses.Good)
{
upcomingStatus = controlData.StatusRef;
if (controlData.ControlStateRef == (int)ControlStates.Validated)
{
isTicked = true;
}
}
else
{
//If current control is in current month and status is LATE
if (controlData.RegularEndDate.Value.Year == DateTimeHelper.Now.Year
&& controlData.RegularEndDate.Value.Month == DateTimeHelper.Now.Month
&& controlData.StatusRef == (int) Statuses.Late)
isMissingDeadLine = true;
upcomingStatus = 0;
}
upcomingAction = controlData.ControlActionRef;
isControlMonthFound = true;
frequencyCounter = 0;
}
if (frequencyCounter % frequencyMonthsCount == 0)
{//Set next controls based on the control frequency
frequencyCounter = 0;
}
if (frequencyCounter == 0 && cursorDate > controlData.EndDate.Value)
{
upcomingStatus = 0;
}
if (controlData.StatusRef != (int)Statuses.Good && lateIncr <= lateCount)
{
upcomingStatus = controlData.StatusRef;
upcomingAction = controlData.ControlActionRef;
lateIncr++;
}
if (controlData.StatusRef == (int)Statuses.Late //si précédent status en "Late"
&& controlData.FrequencyRef == 1) //et une fréquence "Monthly"
{
upcomingStatus = (int)Statuses.Late;
}
//if (controlData.StatusRef == (int)Statuses.Good && lastMonthIsGAP)
//{//Check if previous status is bad and if current month is empty (means it's a month of GAP resolution)
// upcomingStatus = controlData.StatusRef;
// if (controlData.ControlStateRef == (int)ControlStates.Validated)
// {
// isTicked = true;
// }
// lastMonthIsGAP = false;
//}
//Fill in the planning dictionnary
var spl = new StatusPlanning()
{
StatusRef = upcomingStatus,
ActionRef = upcomingAction,
IsCurrent = isCurrentControl,
IsMissingDeadline = isMissingDeadLine,
IsTicked = isTicked
};
if (statusPlanning.ContainsKey(key))
{
if (statusPlanning[key].StatusRef != (int)Statuses.Good)
statusPlanning[key] = spl;
}
else
statusPlanning.Add(key, spl);
frequencyCounter++;
}
} |
Partager