private static void AddItemEnd(this Grid grid, BoxView bv, int rowspan_bv, MyCalendarItem2 item, double standard_rowheight) { double new_rowheight1 = 1 + (standard_rowheight - 1) * item.End.Minute / 59; double new_rowheight2 = standard_rowheight - new_rowheight1; AddRow(grid, new_rowheight1); AddRow(grid, new_rowheight2); Grid.SetRowSpan(bv, rowspan_bv + 1); }
public MyRoosterPage() { InitializeComponent(); MyCalendarItem2 item = new MyCalendarItem2(new DateTime(2018, 4, 28, 9, 30, 0), new DateTime(2018, 4, 28, 11, 30, 0), "ICT-Lab", "Omar"); BoxView bv = new BoxView { Color = Color.Gray }; //Color labelbackcolor = Color.Gray; //int row = -1; //for(int hour = 0; hour < 24; hour++) { // Label newlabel = new Label { Text = hour + ":00", BackgroundColor = labelbackcolor }; // MyGrid.Children.Add(newlabel); // Grid.SetColumn(newlabel, 0); // row = row + 2; // Grid.SetRow(newlabel, row); //} }
private static int AddItemStart(this Grid grid, BoxView bv, MyCalendarItem2 item, double standard_rowheight) { double new_rowheight1 = standard_rowheight * item.Start.Minute / 60; int count = 0; if (new_rowheight1 > 0) { double new_rowheight2 = standard_rowheight - new_rowheight1; AddRow(grid, new_rowheight1); count++; } RowDefinition rd = new RowDefinition { Height = new_rowheight1 }; AddRow(grid, rd); Grid.SetRow(bv, Grid.GetRow(rd)); count++; return(count); }
public static void DrawCalendar(this Grid grid, int hour_start, int hour_end, MyCalendarItem2 item, double standard_rowheight) { grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); //Console.WriteLine("columns added"); BoxView bv = new BoxView(); Grid.SetColumn(bv, 1); bool count_rows_for_bv = false; int rowspan_bv = 1; for (int hour = hour_start; hour <= hour_end; hour++) { Console.WriteLine("hour: " + hour); if (hour != hour_start) { grid.AddLine(hour, Color.Gray); if (count_rows_for_bv) { rowspan_bv++; } } if (item.Start.Hour == hour) { rowspan_bv = grid.AddItemStart(bv, item, standard_rowheight); count_rows_for_bv = true; } else if (item.End.Hour == hour) { grid.AddItemEnd(bv, rowspan_bv, item, standard_rowheight); count_rows_for_bv = false; } else { grid.AddRow(standard_rowheight); if (count_rows_for_bv) { rowspan_bv++; } } } }
public RoosterTest3() { InitializeComponent(); PlatformIndep.IDroidButtonsBar statusbarc = DependencyService.Get <PlatformIndep.IDroidButtonsBar>(); statusbarc?.SetDroidButtonsBarWhite(); List <Models.Lesson> lessons = Models.APIResultToModelConvertor.ConvertToLessons("lessons! :D"); List <Models.Reservation> reservations = Models.APIResultToModelConvertor.ConvertToReservations("reservations! :D"); List <CalenderItem> calender_items = new List <CalenderItem>(); lessons.ForEach((l) => calender_items.Add(new CalenderItem { Start = l.StartDateTime, End = l.EndDateTime, Text = l.Subject.Name, TextColor = Color.GhostWhite, BackgroundColor = Color.Red })); reservations.ForEach((r) => calender_items.Add(new CalenderItem { Start = r.StartDateTime, End = r.EndDateTime, Text = "Res " + r.RoomID, TextColor = Color.GhostWhite, BackgroundColor = Color.Blue })); item = GetItem(); calendar_line_labels = new List <Label>(); //columns TestGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); //new GridLength(10, GridUnitType.Auto) }); TestGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); //rows and content int begin = 0; int end = 24; double standard_height = 40; Color line_color = Color.LightGray; int rowcount = -1; //for calendaritem double amount_start = (double)item.Start.Minute / 60 * standard_height; if (amount_start == 0) { amount_start = 1; } if (amount_start == standard_height) { amount_start = standard_height - 1; } double amount_end = (double)item.End.Minute / 60 * standard_height; if (amount_end == 0) { amount_end = 1; } if (amount_end == standard_height) { amount_end = standard_height - 1; } int row_start = item.Start.Hour * 2 - 1; //gets updated in for loop below int row_end = item.End.Hour * 2 - 1; //gets updated in for loop below for (int hour = begin; hour < end; hour++) { // lines if (hour != begin) { TestGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Absolute) }); rowcount++; Label lbl = new Label { Text = "", BackgroundColor = line_color }; Grid.SetRow(lbl, rowcount); Grid.SetColumn(lbl, 0); Grid.SetColumnSpan(lbl, 2); TestGrid.Children.Add(lbl); calendar_line_labels.Add(lbl); } // calendar items RowDefinition rd = new RowDefinition { Height = new GridLength(standard_height, GridUnitType.Absolute) }; TestGrid.RowDefinitions.Add(rd); rowcount++; Label timelabel = new Label { Text = hour + ":00", TextColor = Color.Gray }; Grid.SetColumn(timelabel, 0); Grid.SetRow(timelabel, rowcount); TestGrid.Children.Add(timelabel); if (item.Start.Hour == hour) { row_start = rowcount; } if (item.End.Hour == hour) { row_end = rowcount; } } // item Grid new_g = new Grid { ColumnSpacing = 0, RowSpacing = 0, Margin = new Thickness(5, 0, 4, 0) }; if (row_start == row_end) { new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(amount_start, GridUnitType.Absolute) }); // "empty" new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(amount_end - amount_start, GridUnitType.Absolute), }); // item new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(standard_height - amount_end, GridUnitType.Absolute) }); // "empty" Label LblForColor = new Label { BackgroundColor = Color.LightSeaGreen }; Grid.SetColumn(LblForColor, 0); Grid.SetRow(LblForColor, 1); new_g.Children.Add(LblForColor); Label lbl = new Label { Text = item.Content, TextColor = Color.Purple, FontAttributes = FontAttributes.Bold }; Grid.SetColumn(lbl, 0); Grid.SetRow(lbl, 1); new_g.Children.Add(lbl); Grid.SetColumn(new_g, 1); Grid.SetRow(new_g, row_start); TestGrid.Children.Add(new_g); } else { new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(amount_start, GridUnitType.Absolute) }); new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(standard_height - amount_start, GridUnitType.Absolute) }); new_g.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star }); new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(amount_end, GridUnitType.Absolute) }); new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(standard_height - amount_end, GridUnitType.Absolute) }); Label lbl = new Label { Text = item.Content, TextColor = Color.Purple, BackgroundColor = Color.LightGreen }; Grid.SetColumn(lbl, 0); Grid.SetRow(lbl, 1); Grid.SetRowSpan(lbl, 3); new_g.Children.Add(lbl); Grid.SetColumn(new_g, 1); Grid.SetRow(new_g, row_start); Grid.SetRowSpan(new_g, row_end - row_start + 1); TestGrid.Children.Add(new_g); } DateLabel.Text = item.Start.ToString("dd-MM-yyyy"); DayButton.IsEnabled = false; }
private void Draw(MyCalendarItem2 item) { //columns TestGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); //new GridLength(10, GridUnitType.Auto) }); TestGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); TestGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); TestGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); TestGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); TestGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); TestGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); TestGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); //rows and content int begin = 0; int end = 24; double standard_height = 40; Color line_color = Color.LightGray; int rowcount = -1; //for calendaritem double amount_start = (double)item.Start.Minute / 60 * standard_height; if (amount_start == 0) { amount_start = 1; } if (amount_start == standard_height) { amount_start = standard_height - 1; } double amount_end = (double)item.End.Minute / 60 * standard_height; if (amount_end == 0) { amount_end = 1; } if (amount_end == standard_height) { amount_end = standard_height - 1; } int row_start = item.Start.Hour * 2 - 1; //gets updated in for loop below int row_end = item.End.Hour * 2 - 1; //gets updated in for loop below for (int hour = begin; hour < end; hour++) { // lines if (hour != begin) { TestGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Absolute) }); rowcount++; Label lbl = new Label { Text = "", BackgroundColor = line_color }; Grid.SetRow(lbl, rowcount); Grid.SetColumn(lbl, 0); Grid.SetColumnSpan(lbl, TestGrid.ColumnDefinitions.Count); TestGrid.Children.Add(lbl); } // calendar items RowDefinition rd = new RowDefinition { Height = new GridLength(standard_height, GridUnitType.Absolute) }; TestGrid.RowDefinitions.Add(rd); rowcount++; Label timelabel = new Label { Text = hour + ":00", TextColor = Color.Gray, Margin = new Thickness(0, 0, 2, 0) }; Grid.SetColumn(timelabel, 0); Grid.SetRow(timelabel, rowcount); TestGrid.Children.Add(timelabel); if (item.Start.Hour == hour) { row_start = rowcount; } if (item.End.Hour == hour) { row_end = rowcount; } } // item Grid new_g = new Grid { ColumnSpacing = 0, RowSpacing = 0, Margin = new Thickness(2, 0, 2, 0) }; if (row_start == row_end) { new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(amount_start, GridUnitType.Absolute) }); // "empty" new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(amount_end - amount_start, GridUnitType.Absolute), }); // item new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(standard_height - amount_end, GridUnitType.Absolute) }); // "empty" Label LblForColor = new Label { BackgroundColor = Color.LightSeaGreen }; Grid.SetColumn(LblForColor, 0); Grid.SetRow(LblForColor, 1); new_g.Children.Add(LblForColor); Label lbl = new Label { Text = item.Content, TextColor = Color.Purple, FontAttributes = FontAttributes.Bold }; Grid.SetColumn(lbl, 0); Grid.SetRow(lbl, 1); new_g.Children.Add(lbl); Grid.SetColumn(new_g, 1); Grid.SetRow(new_g, row_start); TestGrid.Children.Add(new_g); } else { new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(amount_start, GridUnitType.Absolute) }); new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(standard_height - amount_start, GridUnitType.Absolute) }); new_g.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star }); new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(amount_end, GridUnitType.Absolute) }); new_g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(standard_height - amount_end, GridUnitType.Absolute) }); Label lbl = new Label { Text = item.Content, TextColor = Color.Purple, BackgroundColor = Color.LightGreen }; Grid.SetColumn(lbl, 0); Grid.SetRow(lbl, 1); Grid.SetRowSpan(lbl, 3); new_g.Children.Add(lbl); Grid.SetColumn(new_g, 1); Grid.SetRow(new_g, row_start); Grid.SetRowSpan(new_g, row_end - row_start + 1); TestGrid.Children.Add(new_g); } }