diff --git a/CampusAppWP8/CampusAppWP8/Model/TimeTable/AppointmentModel.cs b/CampusAppWP8/CampusAppWP8/Model/TimeTable/AppointmentModel.cs index 73344ca4..a2284ceb 100644 --- a/CampusAppWP8/CampusAppWP8/Model/TimeTable/AppointmentModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/TimeTable/AppointmentModel.cs @@ -28,13 +28,14 @@ namespace CampusAppWP8.Model.TimeTable private static double DAY_HOUR_SPACING = 50; /// The Visual object. - private Rectangle rect = null; - private Canvas canvas = null; - private double offsetY = 0; - private double height = 0; - private double width = 100; + //private Rectangle rect = null; + //private Canvas canvas = null; + //private double offsetY = 0; + //private double height = 0; + //private double width = 100; private ICalObject icalObj = null; + //private ICalObject eventICalObj = null; public delegate void OnAppointmentClick(AppointmentModel sender); public event OnAppointmentClick OnClick = null; @@ -55,72 +56,23 @@ namespace CampusAppWP8.Model.TimeTable this.icalObj.AddProperty(newVersion); this.icalObj.AddProperty(newProdID); - this.rect = new Rectangle(); - this.canvas = new Canvas(); - this.canvas.DoubleTap += new EventHandler(this.OnCanvasClick); - this.canvas.SizeChanged += new SizeChangedEventHandler(this.OnCanvasSizeChanged); + //this.rect = new Rectangle(); + //this.canvas = new Canvas(); + //this.canvas.DoubleTap += new EventHandler(this.OnCanvasClick); + //this.canvas.SizeChanged += new SizeChangedEventHandler(this.OnCanvasSizeChanged); } public AppointmentModel(string icsData) : this() { this.icalObj = ICSManager.ImportFromICS(icsData); - this.Calc(); - } - - public void Calc() - { - this.CalcYOffset(); - this.CalcHeight(); - this.CalcRect(); - } - - public static double HourSpacing - { - get - { - return DAY_HOUR_SPACING; - } - set - { - DAY_HOUR_SPACING = value; - } - } - - public double GetYOffset - { - get - { - return this.offsetY; - } - } - - public double GetPosRight - { - get - { - return (this.canvas.Margin.Left + this.rect.Width); - } - } - - public Canvas Canvas - { - get - { - return this.canvas; - } - set - { - this.canvas = value; - } } public int IsDate(DateTime date, int daySpan = 0) { int retValue = -1; - ICalObject eventICal = this.GetVEventObj(); - - DTStart startTime = eventICal.GetProperty(ICSTag.DT_START) as DTStart; + DateTime startTime = this.Start; + DateTime endTime = this.End; if (startTime != null) { @@ -130,9 +82,8 @@ namespace CampusAppWP8.Model.TimeTable { DateTime tempDT = date.AddDays(toDaySpan); - if (startTime.Value.Year.Equals(tempDT.Year) - && startTime.Value.Month.Equals(tempDT.Month) - && startTime.Value.Day.Equals(tempDT.Day)) + if(startTime.Date <= tempDT.Date && tempDT.Date <= endTime.Date) + //if (tempDT.Date.Equals(startTime.Date) == true) { retValue = toDaySpan; } @@ -148,21 +99,19 @@ namespace CampusAppWP8.Model.TimeTable { bool retValue = false; - Rectangle modelRect = model.rect; - Canvas modelCanvas = model.canvas; - - if ((this.canvas.Margin.Left >= modelCanvas.Margin.Left - && this.canvas.Margin.Left <= (modelCanvas.Margin.Left + modelRect.Width) - && this.canvas.Margin.Top >= modelCanvas.Margin.Top - && this.canvas.Margin.Top <= (modelCanvas.Margin.Top + modelRect.Height)) - || (modelCanvas.Margin.Left >= this.canvas.Margin.Left - && modelCanvas.Margin.Left <= (this.canvas.Margin.Left + this.rect.Width) - && modelCanvas.Margin.Top >= this.canvas.Margin.Top - && modelCanvas.Margin.Top <= (this.canvas.Margin.Top + this.rect.Height))) + DateTime modelStart = model.Start; + DateTime modelEnd = model.End; + DateTime thisStart = this.Start; + DateTime thisEnd = this.End; + + if ((modelStart <= thisStart && thisStart <= modelEnd) + || (modelStart <= thisEnd && thisEnd <= modelEnd) + || (thisStart <= modelStart && modelStart <= thisEnd) + || (thisStart <= modelEnd && modelEnd <= thisEnd)) { retValue = true; } - + return retValue; } @@ -203,6 +152,27 @@ namespace CampusAppWP8.Model.TimeTable vevent.AddProperty(value); } + public Canvas GetCanvas(double width, double hourSpacing, DateTime date) + { + Canvas retValue = new Canvas(); + + if (this.End.Date.Equals(this.Start.Date) == false) + { + + } + else + { + TimeSpan span = this.End.Subtract(this.Start); + retValue.Height = span.TotalHours * hourSpacing; + retValue.Width = width; + } + + + + return retValue; + } + +/* private void CalcRect() { this.canvas.Children.Clear(); @@ -232,24 +202,12 @@ namespace CampusAppWP8.Model.TimeTable txtTitle.SetValue(Canvas.LeftProperty, 5.0); txtTitle.SetValue(Canvas.TopProperty, 5.0); - /* - Description desc = eventObj.GetProperty(ICSTag.DESCRIPTION) as Description; - - TextBlock txtDesc = new TextBlock(); - txtDesc.Text = desc.Value; - txtDesc.FontSize = 12; - txtDesc.TextWrapping = TextWrapping.Wrap; - txtDesc.Width = this.rect.Width - 4.0; - txtDesc.SetValue(Canvas.LeftProperty, 2.0); - txtDesc.SetValue(Canvas.TopProperty, 20.0); - txtDesc.Height = this.height - 22.0; - */ - this.canvas.Children.Add(txtTitle); //this.canvas.Children.Add(txtDesc); } } - +*/ +/* private void CalcYOffset() { ICalObject eventObj = this.GetVEventObj(); @@ -265,7 +223,8 @@ namespace CampusAppWP8.Model.TimeTable this.offsetY = (startTimeValue.Hour * AppointmentModel.DAY_HOUR_SPACING) + (startTimeValue.Minute / 60.0 * AppointmentModel.DAY_HOUR_SPACING); } - +*/ +/* private void CalcHeight() { ICalObject eventObj = this.GetVEventObj(); @@ -299,19 +258,23 @@ namespace CampusAppWP8.Model.TimeTable this.height = AppointmentModel.DAY_HOUR_SPACING / 4; } } - - public void SetWidth(double maxWidth) +*/ +/* + public void SetWidth(double newWidth) { - this.width = maxWidth - this.canvas.Margin.Left; - - if (this.width < 200) + if (this.width != newWidth) { - this.width = 200; - } - - this.CalcRect(); - } + this.width = newWidth; + if (this.width < 10) + { + this.width = 10; + } + + this.CalcRect(); + } + } +*/ private ICalObject GetVEventObj(bool create = false) { ICalObject retValue = this.icalObj.GetProperty(ICSTag.VEVENT) as ICalObject; @@ -422,5 +385,44 @@ namespace CampusAppWP8.Model.TimeTable return retValue; } } + + public DateTime Start + { + get + { + ICalObject eventICal = this.GetVEventObj(); + DTStart retVal = eventICal.GetProperty(ICSTag.DT_START) as DTStart; + + if (retVal != null) + { + return retVal.Value; + } + + return DateTime.MinValue; + } + } + + public DateTime End + { + get + { + ICalObject eventICal = this.GetVEventObj(); + DTEnd end = eventICal.GetProperty(ICSTag.DT_END) as DTEnd; + CampusAppWP8.Utility.ICSProperties.Duration dur = eventICal.GetProperty(ICSTag.DURATION) as CampusAppWP8.Utility.ICSProperties.Duration; + + if (end == null && dur == null) + { + throw new KeyNotFoundException(); + } + else if (end != null) + { + return end.Value; + } + else + { + return this.Start.Add(dur.Value); + } + } + } } } diff --git a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/Appointment.xaml b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/Appointment.xaml index 5c4f1f52..89f9cb2a 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/Appointment.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/Appointment.xaml @@ -9,7 +9,7 @@ FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" - SupportedOrientations="Portrait" Orientation="Portrait" + SupportedOrientations="PortraitOrLandscape" Orientation="Portrait" mc:Ignorable="d" shell:SystemTray.IsVisible="True"> diff --git a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTable.cs b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTable.cs index 9687ef9a..81a2cb84 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTable.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTable.cs @@ -24,8 +24,8 @@ namespace CampusAppWP8.Pages.TimeTable { private static AppointmentListModel appList //= null; = new AppointmentListModel(new AppointmentModel[] { - new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:ownCloud Calendar 0.6.3\r\nX-WR-CALNAME:Das is der Titel\r\nBEGIN:VEVENT\r\nCREATED;VALUE=DATE-TIME:20130827T113216Z\r\nUID:c9904ea73c\r\nLAST-MODIFIED;VALUE=DATE-TIME:20130827T113216Z\r\nDTSTAMP;VALUE=DATE-TIME:20130827T113216Z\r\nSUMMARY:Das is der Titel\r\nDTSTART;VALUE=DATE-TIME:20130914T113500Z\r\nDTEND;VALUE=DATE-TIME:20130914T152000Z\r\nCLASS:PUBLIC\r\nLOCATION:BTU Campus\r\nDESCRIPTION:For Outlook 2003, the behavior is peculiar. It can save the sa\r\n me calendar entry in both .ics and .vcs format, but it only read & displa\r\n y .vcs file correctly. It can read .ics file but it omits some fields and \r\n does not display it in calendar mode. My guess is that back then Microsoft\r\n wanted to provide .ics to be compatible with Mac's iCal but not quite com\r\n mitted to v2.0 yet.\r\nCATEGORIES:Projekte\r\nEND:VEVENT\r\nEND:VCALENDAR"), - new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:http://www.example.com/calendarapplication/\r\nMETHOD:PUBLISH\r\nBEGIN:VEVENT\r\nUID:461092315540@example.com\r\nORGANIZER:MAILTO:alice@example.com\r\nLOCATION:Somewhere\r\nSUMMARY:Eine Kurzinfo\r\nDESCRIPTION:Beschreibung des Termines\r\nCLASS:PUBLIC\r\nDTSTART:20130916T110000Z\r\nDTEND:20130916T195900Z\r\nDTSTAMP:20130916T125900Z\r\nEND:VEVENT\r\nEND:VCALENDAR"), + new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:ownCloud Calendar 0.6.3\r\nX-WR-CALNAME:Das is der Titel\r\nBEGIN:VEVENT\r\nCREATED;VALUE=DATE-TIME:20130827T113216Z\r\nUID:c9904ea73c\r\nLAST-MODIFIED;VALUE=DATE-TIME:20130827T113216Z\r\nDTSTAMP;VALUE=DATE-TIME:20130827T113216Z\r\nSUMMARY:Das is der Titel\r\nDTSTART;VALUE=DATE-TIME:20130930T113500Z\r\nDTEND;VALUE=DATE-TIME:20130930T152000Z\r\nCLASS:PUBLIC\r\nLOCATION:BTU Campus\r\nDESCRIPTION:For Outlook 2003, the behavior is peculiar. It can save the sa\r\n me calendar entry in both .ics and .vcs format, but it only read & displa\r\n y .vcs file correctly. It can read .ics file but it omits some fields and \r\n does not display it in calendar mode. My guess is that back then Microsoft\r\n wanted to provide .ics to be compatible with Mac's iCal but not quite com\r\n mitted to v2.0 yet.\r\nCATEGORIES:Projekte\r\nEND:VEVENT\r\nEND:VCALENDAR"), + new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:http://www.example.com/calendarapplication/\r\nMETHOD:PUBLISH\r\nBEGIN:VEVENT\r\nUID:461092315540@example.com\r\nORGANIZER:MAILTO:alice@example.com\r\nLOCATION:Somewhere\r\nSUMMARY:Eine Kurzinfo\r\nDESCRIPTION:Beschreibung des Termines\r\nCLASS:PUBLIC\r\nDTSTART:20131002T110000Z\r\nDTEND:20131002T195900Z\r\nDTSTAMP:20131002T125900Z\r\nEND:VEVENT\r\nEND:VCALENDAR"), new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\nBEGIN:VEVENT\r\nUID:uid1@example.com\r\nDTSTAMP:19970714T170000Z\r\nORGANIZER;CN=John Doe:MAILTO:john.doe@example.com\r\nDTSTART:20130914T150000Z\r\nDTEND:20130915T035959Z\r\nSUMMARY:Bastille Day Party\r\nEND:VEVENT\r\nEND:VCALENDAR"), new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:1.0\r\nBEGIN:VEVENT\r\nCATEGORIES:MEETING\r\nSTATUS:TENTATIVE\r\nDTSTART:20130917T033000Z\r\nDTEND:20130917T043000Z\r\nSUMMARY:Your Proposal Review\r\nDESCRIPTION:Steve and John to review newest proposal material bla fsdfasfsdfsdfgsdafg sfdgfdsgf dsfg dsfgds fgds\r\nCLASS:PRIVATE\r\nEND:VEVENT\r\nEND:VCALENDAR"), new AppointmentModel("BEGIN:VCALENDAR\r\nPRODID:-//bobbin v0.1//NONSGML iCal Writer//EN\r\nVERSION:2.0\r\nCALSCALE:GREGORIAN\r\nMETHOD:PUBLISH\r\nBEGIN:VEVENT\r\nDTSTART:20130918T080000Z\r\nDTEND:20130918T110000Z\r\nDTSTAMP:20091130T213238Z\r\nUID:1285935469767a7c7c1a9b3f0df8003a@yoursever.com\r\nCREATED:20091130T213238Z\r\nDESCRIPTION:Example event 1\r\nLAST-MODIFIED:20091130T213238Z\r\nSEQUENCE:0\r\nSTATUS:CONFIRMED\r\nSUMMARY:Example event 1\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nEND:VCALENDAR"), diff --git a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableProperties.xaml b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableProperties.xaml index 02482620..63a88889 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableProperties.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableProperties.xaml @@ -10,7 +10,7 @@ FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" - SupportedOrientations="Portrait" Orientation="Portrait" + SupportedOrientations="PortraitOrLandscape" Orientation="Portrait" mc:Ignorable="d" shell:SystemTray.IsVisible="True"> diff --git a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableWeek.xaml b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableWeek.xaml index c20c4089..bcdac4e7 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableWeek.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableWeek.xaml @@ -18,6 +18,9 @@ - - + + + + + \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableWeek.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableWeek.xaml.cs index 4337cd69..aa735579 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableWeek.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableWeek.xaml.cs @@ -23,106 +23,400 @@ namespace CampusAppWP8.Pages.TimeTable public partial class TimeTableWeek : PhoneApplicationPage { - private static readonly double WEEK_TABLE_CELL_HEIGHT = 30; - private static readonly double WEEK_TABLE_HEAD_WIDTH = 30; + private static readonly double WEEK_TABLE_CELL_HEIGHT = 40; + private static readonly double WEEK_TABLE_HEAD_WIDTH = 40; private static readonly double WEEK_TABLE_HEAD_THICKNESS = 2; private static readonly double WEEK_TABLE_HEAD_HALF = 15; private static readonly double WEEK_TABLE_INNER_THICKNESS = 1; - + private static readonly int WEEK_TABLE_ZINDEX_MAX = 10; + private static readonly double WEEK_TABLE_ZINDEX_SHIFT = 3; + private struct PageItem { public Canvas Content { get; set; } public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } public char WeekChar { get; set; } + public int WeekNumber { get; set; } } private static readonly int PIVOT_PAGES = 3; + private static readonly int PIVOT_PAGES_HALF_DOWN = 1; + private PageItem[] itemPages = new PageItem[PIVOT_PAGES]; - + private int lastSelectedIndex = 0; + //private double APP_BAR_SPACE = 0; + public TimeTableWeek() { this.InitializeComponent(); + DateTime firstDay = this.GetFirstDayOfWeek(DateTime.Now).AddDays(-7 * PIVOT_PAGES_HALF_DOWN); + for (int i = 0; i < PIVOT_PAGES; i++) { - this.CreatePage(i, DateTime.Now); - - Rectangle testRect = new Rectangle(); - testRect.Width = 50; - testRect.Height = 50; - testRect.Fill = new SolidColorBrush(Colors.Red); - - this.itemPages[i].Content.Children.Add(testRect); + this.CreatePage(i, firstDay); + firstDay = firstDay.AddDays(7); } - //this.DrawBackground(this.TestCanvas); + ApplicationBarIconButton dayViewBtn = new ApplicationBarIconButton(); + dayViewBtn.Text = AppResources.DayView; + dayViewBtn.IconUri = new Uri(Icons.Info, UriKind.Relative); + dayViewBtn.Click += new EventHandler(this.OnClickDayView); + ApplicationBar.Buttons.Add(dayViewBtn); + + ApplicationBarIconButton todayBtn = new ApplicationBarIconButton(); + todayBtn.Text = AppResources.ToDay; + todayBtn.IconUri = new Uri(Icons.Info, UriKind.Relative); + todayBtn.Click += new EventHandler(this.OnClickToday); + ApplicationBar.Buttons.Add(todayBtn); + + ApplicationBarIconButton propBtn = new ApplicationBarIconButton(); + propBtn.Text = AppResources.Properties; + propBtn.IconUri = new Uri(Icons.Info, UriKind.Relative); + propBtn.Click += new EventHandler(this.OnClickProperties); + ApplicationBar.Buttons.Add(propBtn); + + ApplicationBarIconButton addBtn = new ApplicationBarIconButton(); + addBtn.Text = AppResources.Add; + addBtn.IconUri = new Uri(Icons.Add, UriKind.Relative); + addBtn.Click += new EventHandler(this.OnClickCreate); + ApplicationBar.Buttons.Add(addBtn); + + //this.APP_BAR_SPACE = ApplicationBar.DefaultSize; } protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); - + if (e.NavigationMode == NavigationMode.Back) + { + TimeTable.AppointmentsModel.Appointments.CollectionChanged -= this.OnListChanged; + } + else + { + this.ThePivot.SelectedIndex = PIVOT_PAGES_HALF_DOWN; + this.lastSelectedIndex = this.ThePivot.SelectedIndex; + this.ThePivot.SelectionChanged += new SelectionChangedEventHandler(this.OnPivotSelectionChanged); + } } - private void EventAutoScroll(object sender, RoutedEventArgs e) + private DateTime GetFirstDayOfWeek(DateTime dayInWeek) + { + DateTime retValue = dayInWeek.Date; + + while(retValue.DayOfWeek.Equals(DayOfWeek.Monday) == false) + { + retValue = retValue.AddDays(-1); + } + + return retValue; + } + + private int GetDayOfWeekIndex(DateTime dayInWeek) + { + int retValue = -1; + + switch (dayInWeek.DayOfWeek) + { + case DayOfWeek.Monday: retValue = 0; break; + case DayOfWeek.Tuesday: retValue = 1; break; + case DayOfWeek.Wednesday: retValue = 2; break; + case DayOfWeek.Thursday: retValue = 3; break; + case DayOfWeek.Friday: retValue = 4; break; + case DayOfWeek.Saturday: retValue = 5; break; + case DayOfWeek.Sunday: retValue = 6; break; + } + + return retValue; + } + + private void OnClickDayView(object sender, EventArgs e) + { + Uri url = new Uri("/Pages/TimeTable/TimeTableDay.xaml", UriKind.Relative); + Page page = App.RootFrame.Content as Page; + page.NavigationService.Navigate(url); + } + + private void OnClickToday(object sender, EventArgs e) { } + private void OnClickProperties(object sender, EventArgs e) + { + Uri url = new Uri("/Pages/TimeTable/TimeTableProperties.xaml", UriKind.Relative); + Page page = App.RootFrame.Content as Page; + page.NavigationService.Navigate(url); + } + + private void OnClickCreate(object sender, EventArgs e) + { + TimeTable.AppointmentsModel.Appointments.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnListChanged); + + Uri url = new Uri("/Pages/TimeTable/AppointmentEdit.xaml", UriKind.Relative); + Page page = App.RootFrame.Content as Page; + page.NavigationService.Navigate(url); + } + + private void OnPivotSelectionChanged(object sender, SelectionChangedEventArgs e) + { + + int delta = this.ThePivot.SelectedIndex - this.lastSelectedIndex; + + /* + <- + -1 = 0 - 1 -> 2 + -1 = 1 - 2 -> 0 + 2 = 2 - 0 -> 1 + + -> + 1 = 1 - 0 -> 2 + 1 = 2 - 1 -> 0 + -2 = 0 - 2 -> 1 + */ + + if (delta < -1) delta = 1; + else if (delta > 1) delta = -1; + + int index = (this.ThePivot.SelectedIndex + delta + PIVOT_PAGES) % PIVOT_PAGES; + + if (delta < 0) + { + this.itemPages[index].DateFrom = this.itemPages[this.ThePivot.SelectedIndex].DateFrom.AddDays(-7); + this.itemPages[index].DateTo = this.itemPages[this.ThePivot.SelectedIndex].DateTo.AddDays(-7); + } + else if (delta == 0) + { + return; + } + else + { + this.itemPages[index].DateFrom = this.itemPages[this.ThePivot.SelectedIndex].DateFrom.AddDays(7); + this.itemPages[index].DateTo = this.itemPages[this.ThePivot.SelectedIndex].DateTo.AddDays(7); + } + + this.itemPages[index].Content.Children.Clear(); + this.itemPages[index].WeekNumber = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar.GetWeekOfYear( + this.itemPages[index].DateFrom, + System.Globalization.CalendarWeekRule.FirstDay, + DayOfWeek.Monday); + this.itemPages[index].WeekChar = ((this.itemPages[index].WeekNumber % 2) == 0) ? 'B' : 'A'; + + ((this.ThePivot.Items[index] as PivotItem).Header as Grid).Children.Clear(); + + this.DrawHeader(((this.ThePivot.Items[index] as PivotItem).Header as Grid), string.Format("{0:dd.MM.yyyy} < {1:c} > {2:dd.MM.yyyy}", this.itemPages[index].DateFrom, this.itemPages[index].WeekChar, this.itemPages[index].DateTo)); + + this.SetupPage(index); + + this.lastSelectedIndex = this.ThePivot.SelectedIndex; + } + + private void OnAutoScroll(object sender, RoutedEventArgs e) + { + if ((sender as ScrollViewer).VerticalOffset == 0.0) + { + (sender as ScrollViewer).ScrollToVerticalOffset(WEEK_TABLE_CELL_HEIGHT * TimeTable.AutoScrollToHour); + } + } + + private void OnAppointmentClick(AppointmentModel sender) + { + int index = TimeTable.AppointmentsModel.Appointments.IndexOf(sender); + + if (index >= 0) + { + TimeTable.AppointmentsModel.Appointments.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnListChanged); + + string urlString = "/Pages/TimeTable/Appointment.xaml?" + Constants.Param_Appointment_Index + "=" + index; + + Uri url = new Uri(urlString, UriKind.Relative); + Page page = App.RootFrame.Content as Page; + page.NavigationService.Navigate(url); + } + } + + private void OnListChanged(object sender, NotifyCollectionChangedEventArgs e) + { + AppointmentModel tempModel = null; + + if (e.Action == NotifyCollectionChangedAction.Add) + { + tempModel = e.NewItems[0] as AppointmentModel; + } + else if (e.Action == NotifyCollectionChangedAction.Remove) + { + tempModel = e.OldItems[0] as AppointmentModel; + } + + if (tempModel != null) + { + for (int i = 0; i < PIVOT_PAGES; i++) + { + if (tempModel.IsDate(this.itemPages[i].DateFrom, 4) > -1) + { + this.SetupPage(i); + } + } + } + } + + private void OnCanvasSizeChanged(object sender, SizeChangedEventArgs e) + { + if (e.NewSize.Width.Equals(e.PreviousSize.Width) == false) + { + Canvas tempContainer = (sender as Canvas); + Canvas tempBG = (tempContainer.Children[0] as Canvas); + Canvas tempContent = (tempContainer.Children[1] as Canvas); + tempBG.Width = e.NewSize.Width; + tempBG.Height = e.NewSize.Height; + tempContent.Width = e.NewSize.Width; + tempContent.Height = e.NewSize.Height; + + PivotItem pvItem = ((tempContainer.Parent as ScrollViewer).Parent as PivotItem); + Grid headGrid = pvItem.Header as Grid; + int index = this.ThePivot.Items.IndexOf(pvItem); + + headGrid.Width = e.NewSize.Width; + this.DrawHeader(headGrid, string.Format("{0:dd.MM.yyyy} < {1:c} > {2:dd.MM.yyyy}", this.itemPages[index].DateFrom, this.itemPages[index].WeekChar, this.itemPages[index].DateTo)); + + this.DrawBackground(tempBG); + + this.SetupPage(index); + } + } + + private void SetupPage(int index) + { + this.itemPages[index].Content.Children.Clear(); + + List[] tempList = new List[5]; + + for(int i = 0; i < 5; i++) + { + tempList[i] = new List(); + } + + for (int i = 0; i < TimeTable.AppointmentsModel.Appointments.Count(); i++) + { + int appointmentIndex = -1; + + if ((appointmentIndex = TimeTable.AppointmentsModel.Appointments[i].IsDate(this.itemPages[index].DateFrom, 4)) > -1) + { + tempList[appointmentIndex].Add(TimeTable.AppointmentsModel.Appointments[i]); + } + } + // ------------------------------------------------------- + for(int k = 0; k < 5; k++) + { + for (int i = 0; i < tempList[k].Count(); i++) + { + this.DrawAppointment(tempList[k][i], index, k, 1.0, 0, 0); + } + } + } + private void CreatePage(int itemIndex, DateTime weekStart) { this.itemPages[itemIndex].Content = new Canvas(); this.itemPages[itemIndex].Content.Height = WEEK_TABLE_CELL_HEIGHT * 24; this.itemPages[itemIndex].DateFrom = weekStart; - this.itemPages[itemIndex].DateTo = weekStart.AddDays(7); - this.itemPages[itemIndex].WeekChar = 'A'; - - + this.itemPages[itemIndex].DateTo = weekStart.AddDays(6); + this.itemPages[itemIndex].WeekNumber = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar.GetWeekOfYear( + weekStart, + System.Globalization.CalendarWeekRule.FirstDay, + DayOfWeek.Monday); + this.itemPages[itemIndex].WeekChar = ((this.itemPages[itemIndex].WeekNumber % 2) == 0) ? 'B' : 'A'; + ScrollViewer sv = new ScrollViewer(); - sv.Loaded += new RoutedEventHandler(this.EventAutoScroll); + sv.Loaded += new RoutedEventHandler(this.OnAutoScroll); Canvas container = new Canvas(); container.Height = WEEK_TABLE_CELL_HEIGHT * 24; Canvas canBG = new Canvas(); canBG.Height = WEEK_TABLE_CELL_HEIGHT * 24; PivotItem pvItem = new PivotItem(); - this.DrawBackground(canBG); + //this.DrawBackground(canBG); container.Children.Add(canBG); container.Children.Add(this.itemPages[itemIndex].Content); + container.SizeChanged += new SizeChangedEventHandler(this.OnCanvasSizeChanged); sv.Content = container; pvItem.Content = sv; - /* Grid headGrid = new Grid(); - ColumnDefinition col_0 = new ColumnDefinition(); - ColumnDefinition col_1 = new ColumnDefinition(); - ColumnDefinition col_2 = new ColumnDefinition(); - - col_0.Width = GridLength.Auto; - col_1.Width = GridLength.Auto; - col_2.Width = GridLength.Auto; - - headGrid.ColumnDefinitions.Add(col_0); - headGrid.ColumnDefinitions.Add(col_1); - headGrid.ColumnDefinitions.Add(col_2); - */ - - TextBlock tbHead = new TextBlock(); - tbHead.HorizontalAlignment = HorizontalAlignment.Center; - tbHead.Text = string.Format("{0:dd.MM.yyyy} < {1:c} > {2:dd.MM.yyyy}", this.itemPages[itemIndex].DateFrom, this.itemPages[itemIndex].WeekChar, this.itemPages[itemIndex].DateTo); - tbHead.FontSize = 24; - - pvItem.Header = tbHead; + + pvItem.Header = headGrid; this.ThePivot.Items.Add(pvItem); } - + + private void DrawAppointment(AppointmentModel model, int index, int xIndex, double opacity = 1.0, int zIndex = 0, int modelCount = 0) + { + model.OnClick += new AppointmentModel.OnAppointmentClick(this.OnAppointmentClick); + model.Canvas.Opacity = opacity; + model.Canvas.SetValue(Canvas.ZIndexProperty, WEEK_TABLE_ZINDEX_MAX - zIndex); + model.Canvas.Margin = new Thickness(WEEK_TABLE_HEAD_WIDTH + 2 + (zIndex * WEEK_TABLE_ZINDEX_SHIFT) + (xIndex * ((this.itemPages[index].Content.Width - WEEK_TABLE_HEAD_WIDTH) / 5)), model.GetYOffset, 0, 0); + model.SetWidth(((this.itemPages[index].Content.Width - WEEK_TABLE_HEAD_WIDTH) / 5) - 2 - 2 - (modelCount * WEEK_TABLE_ZINDEX_SHIFT)); + this.itemPages[index].Content.Children.Add(model.Canvas); + } + + private void DrawHeader(Grid grid, string text) + { + RowDefinition row_0 = new RowDefinition(); + RowDefinition row_1 = new RowDefinition(); + row_0.Height = GridLength.Auto; + row_1.Height = GridLength.Auto; + + grid.RowDefinitions.Add(row_0); + grid.RowDefinitions.Add(row_1); + + TextBlock newTB = new TextBlock(); + newTB.Text = text; + newTB.HorizontalAlignment = HorizontalAlignment.Center; + newTB.FontSize = 24; + newTB.SetValue(Grid.RowProperty, 0); + + grid.Children.Add(newTB); + + Canvas headCan = new Canvas(); + + string[] dayStr = new string[] {"Mo", "Di", "Mi", "Do", "Fr" }; + + double w = (grid.Width - WEEK_TABLE_HEAD_WIDTH) / 5; + + for (int i = 0; i < 5; i++) + { + Rectangle dayRect = new Rectangle(); + dayRect.Width = w; + dayRect.Height = 30; + dayRect.StrokeThickness = WEEK_TABLE_HEAD_THICKNESS; + dayRect.Stroke = new SolidColorBrush(Colors.White); + dayRect.Stretch = Stretch.Fill; + dayRect.Margin = new Thickness(WEEK_TABLE_HEAD_WIDTH - 9 + i * w, 0, 0, 0); + + headCan.Children.Add(dayRect); + + TextBlock dayTB = new TextBlock(); + dayTB.Text = dayStr[i]; + dayTB.TextAlignment = TextAlignment.Center; + dayTB.HorizontalAlignment = HorizontalAlignment.Center; + dayTB.Width = w; + dayTB.FontSize = 16; + dayTB.Margin = new Thickness(WEEK_TABLE_HEAD_WIDTH - 9 + i * w, 4, 0, 0); + + headCan.Children.Add(dayTB); + } + + headCan.SetValue(Grid.RowProperty, 1); + + grid.Children.Add(headCan); + } + private void DrawBackground(Canvas can) { Line vertLine = new Line(); @@ -186,7 +480,7 @@ namespace CampusAppWP8.Pages.TimeTable TextBlock timeStamp = new TextBlock(); timeStamp.Text = i.ToString("00") + ":00"; timeStamp.Margin = new Thickness(0, (WEEK_TABLE_CELL_HEIGHT * i) + 2, 0, 0); - timeStamp.FontSize = 10; + timeStamp.FontSize = WEEK_TABLE_CELL_HEIGHT / 3; can.Children.Add(timeStamp); } @@ -195,20 +489,32 @@ namespace CampusAppWP8.Pages.TimeTable for (int i = 1; i < 5; i++) { Line dayLine = new Line(); - dayLine.X1 = WEEK_TABLE_HEAD_WIDTH + (i * (720 - WEEK_TABLE_HEAD_WIDTH) / 5); + dayLine.X1 = WEEK_TABLE_HEAD_WIDTH + (i * (can.Width - WEEK_TABLE_HEAD_WIDTH) / 5); dayLine.Y1 = 0; dayLine.X2 = dayLine.X1; dayLine.Y2 = (WEEK_TABLE_CELL_HEIGHT * 24); dayLine.Stroke = new SolidColorBrush(Colors.White); dayLine.Stretch = Stretch.Fill; dayLine.HorizontalAlignment = HorizontalAlignment.Left; - dayLine.Margin = new Thickness(WEEK_TABLE_HEAD_WIDTH, 0, 0, 0); + dayLine.Margin = new Thickness(0, 0, 0, 0); dayLine.StrokeThickness = WEEK_TABLE_HEAD_THICKNESS / 2; can.Children.Add(dayLine); } + can.Children.Add(vertLine); + + Rectangle newrect = new Rectangle(); + newrect.Stroke = new SolidColorBrush(Colors.White); + newrect.StrokeThickness = WEEK_TABLE_HEAD_THICKNESS; + newrect.Stretch = Stretch.Fill; + newrect.Width = can.Width - WEEK_TABLE_HEAD_WIDTH; + newrect.Height = can.Height; + newrect.Margin = new Thickness(WEEK_TABLE_HEAD_WIDTH, 0, 0, 0); + + can.Children.Add(newrect); + } } } \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs b/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs index 5aeb8bbf..a6045ec0 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs +++ b/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs @@ -258,6 +258,15 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Tagesansicht ähnelt. + /// + public static string DayView { + get { + return ResourceManager.GetString("DayView", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Bachelor ähnelt. /// @@ -1329,6 +1338,15 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Wochenansicht ähnelt. + /// + public static string WeekView { + get { + return ResourceManager.GetString("WeekView", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Willkommen zur BTU-CampusApp WP8 ähnelt. /// diff --git a/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx b/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx index 33971a31..f2645401 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx +++ b/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx @@ -532,6 +532,7 @@ Erstellen + Barrierefreiheit @@ -547,4 +548,10 @@ Type + + Tagesansicht + + + Wochenansicht + \ No newline at end of file