时隙不可用时无法禁用按钮

时间:2011-11-15 03:57:53

标签: c# silverlight

我想禁用具有根据时间表不可用的时间段的按钮。但是当我尝试调试这些代码行时,按钮仍然处于启用状态,我键入的代码是错误的?

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]);
        }
    }

1 个答案:

答案 0 :(得分:0)

您的代码没问题,

  • 尝试检查数据库检索查询

  • 始终使用
  • ReBuild解决方案(而Silverlight用于预构建,不会重新烘焙新文件

  • 使用IE逐行调试

让我知道是否有任何其他问题无法解决。分享有关如何在数据库条目检索中执行操作的更多详细信息。