我需要制定一种方法来根据与这些天相关的数字显示序列词。
所以,我以每天(学期)为基础,设置一个特定的数字。
星期日= 1,星期一= 2,星期二= 4,星期三= 8,星期四= 16,星期五= 32,星期六= 64
如果用户选择了所有工作日,例如,周一至周五= 62, 或周末星期六-周日= 65。
我必须启动该方法以显示该学期中那些日子的每周。
当前代码以在日历中显示该字词
var terminDates = dataAccess.GetTerminDate(personal.LPE_Nr, date, DateTime.DaysInMonth(date.Year, date.Month));
for (int i = 0; i < terminDates.Count; i++)
{
T_TERMINE _TERMINE = new T_TERMINE();
List<T_TERMINE> terminList = dataAccess.GetListTermins(personal.LPE_Nr, terminDates[i]);
string serId = null;
foreach (var termin in terminList)
{
_TERMINE.TER_Betreff = termin.TER_Betreff;
_TERMINE.TER_ID = termin.TER_ID;
serId = termin.TER_TRS_ID;
}
List<T_TERMINSERIE> serieTermins = dataAccess.GetSerieTermins(serId);
T_TERMINSERIE _TERMINSERIE = new T_TERMINSERIE();
foreach (var ser_termin in serieTermins)
{
_TERMINSERIE.TRS_StartZeit = ser_termin.TRS_StartZeit;
_TERMINSERIE.TRS_EndZeit = ser_termin.TRS_EndZeit;
_TERMINSERIE.TRS_TagWoche = ser_termin.TRS_TagWoche; //(16)here I get the number of the bit of the mask
_TERMINSERIE.TRS_StartDatum = ser_termin.TRS_StartDatum;
}
/* how now to include method to make that custom event appear
whenever the method renders, me now CustomEvent is only
displayed for the first time, how to include it and Event for each time the method finds that day in a single week?*/
//FindNextDay()?
CustomEvent ce = new CustomEvent() { IgnoreTimeComponent = true,
Date = terminDates[i],
EventText = _TERMINE.TER_Betreff,
EventColor = Color.BlueViolet };
if (!generatedEvents.Any(x => x.Date == ce.Date))
{
calendar1.AddEvent(ce);
generatedEvents.Add(ce);
}
}
现在最重要的是基于我将从基数中读取的数字的方法,我的意思是枚举中的数字。 每周重复一次。
[Flags]
enum DaysBitMask { Sun = 1, Mon = 2, Tues = 4, Wed = 8, Thu = 16, Fri = 32, Sat = 64 }
static DayOfWeek FindNextDay(DaysBitMask mask, DayOfWeek currentDay)
{
DayOfWeek dayCursor = currentDay;
int counter = 0;
do
{
int cursorMask = 0x01 << (int)dayCursor;
int operationResult = (cursorMask & (int)mask);
if (operationResult > 0)
return dayCursor;
dayCursor = (DayOfWeek)(((int)dayCursor + 1) % 7);
counter++;
}
while (counter < 7);
throw new InvalidOperationException("Wrong flow. We shouldn't be here");
}
这是我当前设计的代码,该代码无法正常工作,如果您可以更正我的方法“ FindNextDay”,并告诉我如何应用该代码才能正确显示该字词,请执行以下操作。谢谢大家的时间。
答案 0 :(得分:0)
尝试下面的代码
[Flags]
enum DaysBitMask { Sun = 1, Mon = 2, Tues = 4, Wed = 8, Thu = 16, Fri = 32, Sat = 64 }
static DayOfWeek FindNextDay(DaysBitMask mask, DayOfWeek currentDay)
{
DayOfWeek dayCursor = currentDay;
for (int counter = 0; counter < 7; counter++)
{
int cursorMask = 0x01 << (int)dayCursor;
int operationResult = (cursorMask & (int)mask);
if (operationResult > 0)
return dayCursor;
dayCursor = (DayOfWeek)(((int)dayCursor + 1) % 7);
}
throw new InvalidOperationException("We shouldn't be here");
}