目前我有以下内容
if ((int)dpRepeatType.SelectedValue == (int)Constants.RepeatType.Weekly)
{
wrule = new WeeklyRecurrenceRule(Convert.ToDateTime(dtDateStart.Value),WeekDays.Monday, 1);
_newAppointment.RecurrenceRule = wrule.ToString();
}
屏幕上有 7 个复选框,代表一周中的几天。周日到周六我的问题是 WeekDay 是基于以下内容的 Telerik rad 调度程序的内部枚举。
我的问题是,不是在各个复选框上执行 if 语句来查看用户选择的哪一天或哪一天可以多个,我目前如何使用 linq 执行此操作我正在使用 if 语句执行此操作但我确信有更好的方法。
[Flags]
public enum WeekDays
{
//
// Summary:
// Specifies none of the days
None = 0,
//
// Summary:
// Specifies the first day of the week
Sunday = 1,
//
// Summary:
// Specifies the second day of the week
Monday = 2,
//
// Summary:
// Specifies the third day of the week
Tuesday = 4,
//
// Summary:
// Specifies the fourth day of the week
Wednesday = 8,
//
// Summary:
// Specifies the fifth of the week
Thursday = 16,
//
// Summary:
// Specifies the sixth of the week
Friday = 32,
//
// Summary:
// Specifies the work days of the week
WorkDays = 62,
//
// Summary:
// Specifies the seventh of the week
Saturday = 64,
//
// Summary:
// Specifies the weekend days of the week
WeekendDays = 65,
//
// Summary:
// Specifies every day of the week
EveryDay = 127
}
}
这就是我想要实现的用户界面。
最佳答案
假设表单中唯一的 CheckBox
控件是与工作日相关的控件,其 Name
属性遵循以下模式:
CheckBoxMonday
CheckBoxTuesday
...
一种解决方案可能如下:
WeekDays wd = WeekDays.None;
foreach (CheckBox checkBox in this.Controls.OfType<CheckBox>())
{
if (checkBox.IsChecked)
wd |= (WeekDays)Enum.Parse(typeof(WeekDays), checkBox.Name.Replace("CheckBox", ""));
}
演示代码here .
关于c# - 将枚举映射到用户选择复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47970630/