Exemplo n.º 1
0
        public ReservationStatusPerDay(DateTime date)
        {
            InitializeComponent();

            this.date = date;

            DateTextBlock.Content = Essential.dateTimeToString(date);

            rearrangeGrid();

            nowSelectedStatusControl = null;
            nowSelectedRow           = -1;
            nowSelectedColumn[0]     = nowSelectedColumn[1] = -1;

            ResetBackground();
        }
        public void refresh()
        {
            try {
                scrollViewContentPanel.Children.Clear();
                for (int i = 0; i < 7; i++)
                {
                    if (displayDate.AddDays(i).DayOfWeek != 0)
                    {
                        var view = new ReservationStatusPerDay(displayDate.AddDays(i));
                        view.onOneSelected = onOneSelected;
                        if (i == 0)
                        {
                            view.mainBorder.BorderThickness = new Thickness(0);
                        }
                        scrollViewContentPanel.Children.Add(view);
                    }
                }

                //remake leftLabelGrid
                leftLabelsGrid.Children.Clear();
                leftLabelsGrid.RowDefinitions.Clear();
                List <string> classroomList    = ServerClient.getInstance().classroomList;
                Label         nowBuildingLabel = null;
                for (int row = 0; row < classroomList.Count; row++)
                {
                    //Add RowDefinition
                    RowDefinition rowDef = new RowDefinition();
                    rowDef.Height = new GridLength(1, GridUnitType.Star);
                    leftLabelsGrid.RowDefinitions.Add(rowDef);

                    //Get building name and classroom name
                    string buildingName  = (classroomList[row] as string).Split(':')[0];
                    string classroomName = (classroomList[row] as string).Split(':')[1];

                    //Add label to Grid
                    Label classroomLabel = new Label();
                    classroomLabel.Content    = classroomName;
                    classroomLabel.Background = (row % 2 == 0) ? backgroundEven : backgroundOdd;
                    classroomLabel.HorizontalContentAlignment = HorizontalAlignment.Center;
                    classroomLabel.VerticalContentAlignment   = VerticalAlignment.Center;

                    Grid.SetRow(classroomLabel, row);
                    Grid.SetColumn(classroomLabel, 1);

                    leftLabelsGrid.Children.Add(classroomLabel);

                    //Adjust building label
                    if (nowBuildingLabel != null && nowBuildingLabel.Content.Equals(buildingName))
                    {
                        Grid.SetRowSpan(nowBuildingLabel, Grid.GetRowSpan(nowBuildingLabel) + 1);
                    }
                    else
                    {
                        Label buildingLabel = new Label();
                        buildingLabel.Content = buildingName;
                        buildingLabel.Style   = Resources["LabelStyle"] as Style;

                        Grid.SetRow(buildingLabel, row);
                        Grid.SetColumn(buildingLabel, 0);
                        Grid.SetRowSpan(buildingLabel, 1);

                        nowBuildingLabel = buildingLabel;
                        leftLabelsGrid.Children.Add(buildingLabel);
                    }
                }

                //remake reservationStatusControls
                List <StatusItem> items = ServerClient.getInstance().reservationListWeek(displayDate);
                var views = scrollViewContentPanel.Children;
                foreach (ReservationStatusPerDay view in views)
                {
                    view.clear();
                    view.rearrangeGrid();
                    foreach (StatusItem item in items)
                    {
                        if (view.date.Day == item.date.Day)
                        {
                            int row = Int32.Parse(item.classroom);
                            view.putData(row + 2, item.classtime - 1, item);
                        }
                    }
                }

                endDateLable.Content = " ~ " + Essential.dateTimeToString(displayDate.AddDays(6));
            } catch (Exception ex) {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace, "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }