1
時刻表に基づいてタイムスロットを使用できないボタンを無効にしたいとします。しかし、私はこれらのコード行をデバッグしようとすると、ボタンはまだ有効ですが、私が入力したコードは間違っていますか?タイムスロットが使用できないときにボタンを無効にすることはできません。
private void LoadMonday(LoadOperation<TimeTable> objTT)
{
List<TimeTableInfo> listTT = new List<TimeTableInfo>();
foreach (var item in objTT.Entities)
{
listTT.Add(new TimeTableInfo()
{
TimeTableID = item.TimeTableID,
LecturerID = item.LecturerID,
Course = item.Course,
ClassStartTime = (DateTime)item.ClassStartTime,
ClassEndTime = (DateTime)item.ClassEndTime,
ClassVenue = item.ClassVenue
});
}
DateTime monday = GetDayOfWeek(DayOfWeek.Monday);
string monDate = monday.ToShortDateString();
Button[] btnMonday = new Button[20];
for (int a = 0; a < 20; a++)
{
btnMonday[a] = new Button();
btnMonday[a].Height = 24;
btnMonday[a].Width = 160;
btnMonday[a].HorizontalAlignment = HorizontalAlignment.Center;
btnMonday[a].VerticalAlignment = VerticalAlignment.Center;
btnMonday[a].Content = monDate + " " + timeslot[a];
btnMonday[a].FontFamily = new FontFamily("eurostile");
btnMonday[a].FontSize = 14;
foreach (var checkClass in listTT)
{
DateTime startTime = checkClass.ClassStartTime;
DateTime endTime = checkClass.ClassEndTime;
DateTime temp;
if (DateTime.TryParse(btnMonday[a].Content.ToString(), out temp))
{
DateTime cmpTime = DateTime.Parse(btnMonday[a].Content.ToString());
var halfHour = GetHalfHour(startTime, endTime);
foreach (var period in halfHour)
{
int result = DateTime.Compare(cmpTime, period);
if (result == 0)
{
btnMonday[a].IsEnabled = false;
btnMonday[a].Content = checkClass.Course + " at " + checkClass.ClassVenue;
btnMonday[a].Foreground = new SolidColorBrush(Colors.White);
}
}
}
else
{
break;
}
}
btnMonday[a].Background = new SolidColorBrush(Colors.Red);
Grid.SetColumn(btnMonday[a], 1);
Grid.SetRow(btnMonday[a], a + 1);
btnMonday[a].Click += new RoutedEventHandler(btnMonday_Click);
TimeSlotLayoutRoot.Children.Add(btnMonday[a]);
}
}