949 lines
40 KiB
C#
949 lines
40 KiB
C#
//-----------------------------------------------------------------------------
|
|
// <copyright file="TimeTableWeek.xaml.cs" company="BTU/IIT">
|
|
// Company copyright tag.
|
|
// </copyright>
|
|
// <author>fiedlchr</author>
|
|
// <sience>30.09.2013</sience>
|
|
//-----------------------------------------------------------------------------
|
|
namespace CampusAppWP8.Pages.TimeTable
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using Microsoft.Phone.Controls;
|
|
using Microsoft.Phone.Shell;
|
|
using CampusAppWP8.Model.TimeTable;
|
|
using CampusAppWP8.Resources;
|
|
|
|
public partial class TimeTableWeek : PhoneApplicationPage
|
|
{
|
|
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 static readonly int WEEK_DAYS_IN_WEEK = 5;
|
|
|
|
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; }
|
|
//public List<List<AppointmentModel>>[] Stacks { get; set; }
|
|
public List<List<AppointmentModel>> Stacks { get; set; }
|
|
}
|
|
|
|
private static readonly int PIVOT_PAGES = 3;
|
|
private static readonly int PIVOT_PAGES_HALF_DOWN = 1;
|
|
private static readonly int PIVOT_PAGES_COLUMNS = 5; // days in week
|
|
|
|
private PageItem[] itemPages = new PageItem[PIVOT_PAGES];
|
|
private int lastSelectedIndex = 0;
|
|
//private double APP_BAR_SPACE = 0;
|
|
private string[] testPiIt = new string[3] { "bla_1", "bla_2", "bla_3" };
|
|
|
|
public TimeTableWeek()
|
|
{
|
|
this.InitializeComponent();
|
|
|
|
DateTime firstDay = this.GetFirstDayOfWeek(DateTime.Now).AddDays(-7 * PIVOT_PAGES_HALF_DOWN);
|
|
|
|
this.ThePivot.ItemsSource = this.testPiIt;
|
|
/*
|
|
for (int i = 0; i < PIVOT_PAGES; i++)
|
|
{
|
|
/*
|
|
this.itemPages[i].Stacks = new List<List<AppointmentModel>>[5]
|
|
{
|
|
new List<List<AppointmentModel>>(),
|
|
new List<List<AppointmentModel>>(),
|
|
new List<List<AppointmentModel>>(),
|
|
new List<List<AppointmentModel>>(),
|
|
new List<List<AppointmentModel>>()
|
|
};
|
|
*/
|
|
/*
|
|
this.itemPages[i].Stacks = new List<List<AppointmentModel>>();
|
|
this.CreatePage(i, firstDay);
|
|
firstDay = firstDay.AddDays(7);
|
|
}
|
|
*/
|
|
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.lastSelectedIndex = PIVOT_PAGES_HALF_DOWN;
|
|
this.ThePivot.SelectedIndex = PIVOT_PAGES_HALF_DOWN;
|
|
}
|
|
}
|
|
|
|
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(Constants.PathTimeTable_Day, UriKind.Relative);
|
|
Page page = App.RootFrame.Content as Page;
|
|
page.NavigationService.Navigate(url);
|
|
}
|
|
|
|
private void OnClickToday(object sender, EventArgs e)
|
|
{
|
|
DateTime firstDay = this.GetFirstDayOfWeek(DateTime.Now).AddDays(-7 * PIVOT_PAGES_HALF_DOWN);
|
|
this.ThePivot.SelectedIndex = PIVOT_PAGES_HALF_DOWN;
|
|
|
|
for (int i = 0; i < PIVOT_PAGES; i++)
|
|
{
|
|
this.itemPages[i].DateFrom = firstDay;
|
|
this.itemPages[i].DateTo = this.itemPages[i].DateFrom.AddDays(6);
|
|
this.itemPages[i].WeekNumber = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar.GetWeekOfYear(
|
|
this.itemPages[i].DateFrom,
|
|
System.Globalization.CalendarWeekRule.FirstDay,
|
|
DayOfWeek.Monday);
|
|
this.itemPages[i].WeekChar = ((this.itemPages[i].WeekNumber % 2) == 0) ? 'B' : 'A';
|
|
|
|
firstDay = firstDay.AddDays(7);
|
|
|
|
this.SetupPage(i);
|
|
}
|
|
}
|
|
|
|
private void OnClickProperties(object sender, EventArgs e)
|
|
{
|
|
Uri url = new Uri(Constants.PathTimeTable_Properties, 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(Constants.PathTimeTable_AppointmentEdit, 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;
|
|
|
|
if (delta < -1) delta = 1;
|
|
else if (delta > 1) delta = -1;
|
|
|
|
int index = (this.ThePivot.SelectedIndex + (delta * PIVOT_PAGES_HALF_DOWN) + PIVOT_PAGES) % PIVOT_PAGES;
|
|
|
|
if (delta == 0)
|
|
{
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
this.itemPages[index].DateFrom = this.itemPages[this.ThePivot.SelectedIndex].DateFrom.AddDays((7 * delta));
|
|
this.itemPages[index].DateTo = this.itemPages[this.ThePivot.SelectedIndex].DateTo.AddDays((7 * delta));
|
|
}
|
|
|
|
//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.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(object sender, System.Windows.Input.GestureEventArgs e)
|
|
{
|
|
int index = TimeTable.AppointmentsModel.Appointments.IndexOf((sender as Canvas).Tag as AppointmentModel);
|
|
|
|
if (index >= 0)
|
|
{
|
|
TimeTable.AppointmentsModel.Appointments.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnListChanged);
|
|
|
|
string urlString = Constants.PathTimeTable_Appointment + "?" + 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 OnMultiBubbleClick(object sender, System.Windows.Input.GestureEventArgs e)
|
|
{
|
|
int indexVal = (int)(sender as Canvas).Tag;
|
|
int dayIndex = (indexVal >> 24) & 0xF;
|
|
int index = (indexVal >> 12) & 0xFFF;
|
|
int listIndex = (indexVal) & 0xFFF;
|
|
|
|
//AppointmentModel tempModel = this.itemPages[index].Stacks[dayIndex][listIndex].First();
|
|
//this.itemPages[index].Stacks[dayIndex][listIndex].Remove(tempModel);
|
|
//this.itemPages[index].Stacks[dayIndex][listIndex].Add(tempModel);
|
|
AppointmentModel tempModel = this.itemPages[index].Stacks[listIndex].First();
|
|
this.itemPages[index].Stacks[listIndex].Remove(tempModel);
|
|
this.itemPages[index].Stacks[listIndex].Add(tempModel);
|
|
|
|
//for (int i = 0; i < this.itemPages[index].Stacks[dayIndex][listIndex].Count(); i++)
|
|
for (int i = 0; i < this.itemPages[index].Stacks[listIndex].Count(); i++)
|
|
{
|
|
//tempModel = this.itemPages[index].Stacks[dayIndex][listIndex][i];
|
|
tempModel = this.itemPages[index].Stacks[listIndex][i];
|
|
|
|
this.RemoveContentUIElement(index, tempModel);
|
|
|
|
for (int day = 0; day < 5; day++)
|
|
{
|
|
if (tempModel.IsDate(this.itemPages[index].DateFrom.Date.AddDays(day)) > -1)
|
|
{
|
|
if (i > 0)
|
|
{
|
|
//this.DrawAppointment(this.itemPages[index].Stacks[dayIndex][listIndex][i], index, day, 0.5, i, this.itemPages[index].Stacks[dayIndex][listIndex].Count - 1 - i);
|
|
this.DrawAppointment(this.itemPages[index].Stacks[listIndex][i], index, day, 0.5, i, this.itemPages[index].Stacks[listIndex].Count - 1 - i);
|
|
}
|
|
else
|
|
{
|
|
//this.DrawAppointment(this.itemPages[index].Stacks[dayIndex][listIndex][i], index, day, 1.0, i, this.itemPages[index].Stacks[dayIndex][listIndex].Count - 1 - i);
|
|
this.DrawAppointment(this.itemPages[index].Stacks[listIndex][i], index, day, 1.0, i, this.itemPages[index].Stacks[listIndex].Count - 1 - i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
this.RemoveContentUIElement(index, sender as Canvas);
|
|
|
|
bool bubbleDrawn = false;
|
|
|
|
for (int day = 0; day < 5; day++)
|
|
{
|
|
if (this.itemPages[index].Stacks[listIndex][0].IsDate(this.itemPages[index].DateFrom.Date.AddDays(day)) > -1 && bubbleDrawn == false)
|
|
{
|
|
bubbleDrawn = true;
|
|
Canvas[] tempCan = this.GetModelCanvasFromContent(index, this.itemPages[index].Stacks[listIndex][0]);
|
|
this.DrawMultiBubble(
|
|
index,
|
|
day,
|
|
listIndex,
|
|
this.itemPages[index].Stacks[listIndex].Count(),
|
|
tempCan[0].Width + tempCan[0].Margin.Left,
|
|
tempCan[0].Margin.Top);
|
|
}
|
|
}
|
|
}
|
|
|
|
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.DrawBackground(tempBG);
|
|
|
|
this.SetupPage(index);
|
|
}
|
|
}
|
|
|
|
private void SetupPage(int index)
|
|
{
|
|
// Header
|
|
|
|
((this.ThePivot.Items[index] as PivotItem).Header as Grid).Children.Clear();
|
|
|
|
this.DrawHeader(index);
|
|
|
|
// Items
|
|
|
|
// List<AppointmentModel>[] tempList = new List<AppointmentModel>[5];
|
|
List<AppointmentModel> tempList = new List<AppointmentModel>();
|
|
|
|
/*
|
|
for(int i = 0; i < 5; i++)
|
|
{
|
|
this.itemPages[index].Stacks[i].Clear();
|
|
}
|
|
/**/
|
|
this.itemPages[index].Stacks.Clear();
|
|
|
|
// this.itemPages[index].Content.Children.Clear();
|
|
/*
|
|
for(int i = 0; i < 5; i++)
|
|
{
|
|
tempList[i] = new List<AppointmentModel>();
|
|
}
|
|
*/
|
|
for (int i = 0; i < TimeTable.AppointmentsModel.Appointments.Count(); i++)
|
|
{
|
|
/*
|
|
for (int k = 0; k < 5; k++)
|
|
{
|
|
if (TimeTable.AppointmentsModel.Appointments[i].IsDate(this.itemPages[index].DateFrom.Date.AddDays(k)) > -1)
|
|
{
|
|
tempList[k].Add(TimeTable.AppointmentsModel.Appointments[i]);
|
|
}
|
|
}
|
|
*/
|
|
if (TimeTable.AppointmentsModel.Appointments[i].IsDate(this.itemPages[index].DateFrom.Date, 4) > -1)
|
|
{
|
|
tempList.Add(TimeTable.AppointmentsModel.Appointments[i]);
|
|
}
|
|
}
|
|
// -------------------------------------------------------
|
|
for (int i = 0; i < tempList.Count(); i++)
|
|
{
|
|
int[] intersectIndex = tempList[i].IntersectArray(tempList.ToArray());
|
|
|
|
if (intersectIndex.Count() == 0)
|
|
{
|
|
for (int day = 0; day < 5; day++)
|
|
{
|
|
if (tempList[i].IsDate(this.itemPages[index].DateFrom.Date.AddDays(day)) > -1)
|
|
{
|
|
this.DrawAppointment(tempList[i], index, day);
|
|
}
|
|
}
|
|
}
|
|
else if (intersectIndex.Count() == 1)
|
|
{
|
|
int addIndex = -1;
|
|
|
|
for (int k = 0; k < this.itemPages[index].Stacks.Count(); k++)
|
|
{
|
|
//if (this.itemPages[index].Stacks[day][k].IndexOf(tempList[day][intersectIndex[0]]) > -1)
|
|
if(this.itemPages[index].Stacks[k].IndexOf(tempList[intersectIndex[0]]) > -1)
|
|
{
|
|
addIndex = k;
|
|
}
|
|
}
|
|
|
|
if (addIndex >= 0)
|
|
{
|
|
//this.itemPages[index].Stacks[day][addIndex].Add(tempList[day][i]);
|
|
this.itemPages[index].Stacks[addIndex].Add(tempList[i]);
|
|
}
|
|
else
|
|
{
|
|
List<AppointmentModel> newList = new List<AppointmentModel>();
|
|
//newList.Add(tempList[day][i]);
|
|
//this.itemPages[index].Stacks[day].Add(newList);
|
|
newList.Add(tempList[i]);
|
|
this.itemPages[index].Stacks.Add(newList);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
List<List<AppointmentModel>> intersectLists = new List<List<AppointmentModel>>();
|
|
|
|
for (int k = 0; k < intersectIndex.Count(); k++)
|
|
{
|
|
//for (int m = 0; m < this.itemPages[index].Stacks[day].Count(); m++)
|
|
for(int m = 0; m < this.itemPages[index].Stacks.Count(); m++)
|
|
{
|
|
//if (this.itemPages[index].Stacks[day][m].IndexOf(tempList[day][intersectIndex[k]]) > -1)
|
|
if(this.itemPages[index].Stacks[m].IndexOf(tempList[intersectIndex[k]]) > -1)
|
|
{
|
|
//if (intersectLists.IndexOf(this.itemPages[index].Stacks[day][m]) < 0)
|
|
if(intersectLists.IndexOf(this.itemPages[index].Stacks[m]) < 0)
|
|
{
|
|
//intersectLists.Add(this.itemPages[index].Stacks[day][m]);
|
|
intersectLists.Add(this.itemPages[index].Stacks[m]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (intersectLists.Count() == 0)
|
|
{
|
|
List<AppointmentModel> newList = new List<AppointmentModel>();
|
|
//newList.Add(tempList[day][i]);
|
|
//this.itemPages[index].Stacks[day].Add(newList);
|
|
newList.Add(tempList[i]);
|
|
this.itemPages[index].Stacks.Add(newList);
|
|
}
|
|
else if (intersectLists.Count() == 1)
|
|
{
|
|
//intersectLists[0].Add(tempList[day][i]);
|
|
intersectLists[0].Add(tempList[i]);
|
|
}
|
|
else
|
|
{
|
|
for (int k = 1; k < intersectLists.Count(); k++)
|
|
{
|
|
intersectLists[0].AddRange(intersectLists[k].ToArray());
|
|
//this.itemPages[index].Stacks[day].Remove(intersectLists[k]);
|
|
this.itemPages[index].Stacks.Remove(intersectLists[k]);
|
|
}
|
|
|
|
//intersectLists[0].Add(tempList[day][i]);
|
|
intersectLists[0].Add(tempList[i]);
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
for (int day = 0; day < 5; day++)
|
|
{
|
|
for (int i = 0; i < tempList[day].Count(); i++)
|
|
{
|
|
int[] intersectIndex = tempList[day][i].IntersectArray(tempList[day].ToArray());
|
|
|
|
if (intersectIndex.Count() == 0)
|
|
{
|
|
this.DrawAppointment(tempList[day][i], index, day);
|
|
}
|
|
else if (intersectIndex.Count() == 1)
|
|
{
|
|
int addIndex = -1;
|
|
|
|
for (int k = 0; k < this.itemPages[index].Stacks[day].Count(); k++)
|
|
{
|
|
if (this.itemPages[index].Stacks[day][k].IndexOf(tempList[day][intersectIndex[0]]) > -1)
|
|
{
|
|
addIndex = k;
|
|
}
|
|
}
|
|
|
|
if (addIndex >= 0)
|
|
{
|
|
this.itemPages[index].Stacks[day][addIndex].Add(tempList[day][i]);
|
|
}
|
|
else
|
|
{
|
|
List<AppointmentModel> newList = new List<AppointmentModel>();
|
|
newList.Add(tempList[day][i]);
|
|
this.itemPages[index].Stacks[day].Add(newList);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
List<List<AppointmentModel>> intersectLists = new List<List<AppointmentModel>>();
|
|
|
|
for (int k = 0; k < intersectIndex.Count(); k++)
|
|
{
|
|
for (int m = 0; m < this.itemPages[index].Stacks[day].Count(); m++)
|
|
{
|
|
if (this.itemPages[index].Stacks[day][m].IndexOf(tempList[day][intersectIndex[k]]) > -1)
|
|
{
|
|
if (intersectLists.IndexOf(this.itemPages[index].Stacks[day][m]) < 0)
|
|
{
|
|
intersectLists.Add(this.itemPages[index].Stacks[day][m]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (intersectLists.Count() == 0)
|
|
{
|
|
List<AppointmentModel> newList = new List<AppointmentModel>();
|
|
newList.Add(tempList[day][i]);
|
|
this.itemPages[index].Stacks[day].Add(newList);
|
|
}
|
|
else if (intersectLists.Count() == 1)
|
|
{
|
|
intersectLists[0].Add(tempList[day][i]);
|
|
}
|
|
else
|
|
{
|
|
for (int k = 1; k < intersectLists.Count(); k++)
|
|
{
|
|
intersectLists[0].AddRange(intersectLists[k].ToArray());
|
|
this.itemPages[index].Stacks[day].Remove(intersectLists[k]);
|
|
}
|
|
|
|
intersectLists[0].Add(tempList[day][i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
*/
|
|
// stack draw
|
|
//for (int day = 0; day < 5; day++)
|
|
{
|
|
//for (int i = 0; i < this.itemPages[index].Stacks[day].Count(); i++)
|
|
for(int i = 0; i < this.itemPages[index].Stacks.Count(); i++)
|
|
{
|
|
//for (int k = 0; k < this.itemPages[index].Stacks[day][i].Count(); k++)
|
|
for(int k = 0; k < this.itemPages[index].Stacks[i].Count(); k++)
|
|
{
|
|
if (k > 0)
|
|
{
|
|
//this.DrawAppointment(this.itemPages[index].Stacks[day][i][k], index, day, 0.5, k, this.itemPages[index].Stacks[day][i].Count() - 1 - k);
|
|
for (int day = 0; day < 5; day++)
|
|
{
|
|
this.DrawAppointment(this.itemPages[index].Stacks[i][k], index, day, 0.5, k, this.itemPages[index].Stacks[i].Count() - 1 - k);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//this.DrawAppointment(this.itemPages[index].Stacks[day][i][k], index, day, 1.0, k, this.itemPages[index].Stacks[day][i].Count() - 1 - k);
|
|
for (int day = 0; day < 5; day++)
|
|
{
|
|
this.DrawAppointment(this.itemPages[index].Stacks[i][k], index, day, 1.0, k, this.itemPages[index].Stacks[i].Count() - 1 - k);
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
Canvas[] tempCan = this.GetModelCanvasFromContent(index, this.itemPages[index].Stacks[day][i][0]);
|
|
// FIXME: tempCan[0] ->
|
|
this.DrawMultiBubble(
|
|
index,
|
|
day,
|
|
i,
|
|
this.itemPages[index].Stacks[day][i].Count(),
|
|
tempCan[0].Width + tempCan[0].Margin.Left,
|
|
tempCan[0].Margin.Top);
|
|
*/
|
|
for (int day = 0; day < 5; day++)
|
|
{
|
|
if (this.itemPages[index].Stacks[i][0].IsDate(this.itemPages[index].DateFrom.Date.AddDays(day)) > -1)
|
|
{
|
|
Canvas[] tempCan = this.GetModelCanvasFromContent(index, this.itemPages[index].Stacks[i][0]);
|
|
this.DrawMultiBubble(
|
|
index,
|
|
day,
|
|
i,
|
|
this.itemPages[index].Stacks[i].Count(),
|
|
tempCan[0].Width + tempCan[0].Margin.Left,
|
|
tempCan[0].Margin.Top);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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(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.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);
|
|
|
|
//container.Children.Add(canBG);
|
|
//container.Children.Add(this.itemPages[itemIndex].Content);
|
|
container.SizeChanged += new SizeChangedEventHandler(this.OnCanvasSizeChanged);
|
|
|
|
Grid mainItGrid = new Grid();
|
|
mainItGrid.Height = WEEK_TABLE_CELL_HEIGHT * 24;
|
|
RowDefinition row_0 = new RowDefinition();
|
|
row_0.Height = new GridLength(WEEK_TABLE_CELL_HEIGHT * 24, GridUnitType.Pixel);
|
|
ColumnDefinition col_0 = new ColumnDefinition();
|
|
col_0.Width = new GridLength(WEEK_TABLE_HEAD_WIDTH, GridUnitType.Pixel);
|
|
ColumnDefinition col_day = new ColumnDefinition();
|
|
col_day.Width = new GridLength(1, GridUnitType.Star);
|
|
mainItGrid.RowDefinitions.Add(row_0);
|
|
mainItGrid.ColumnDefinitions.Add(col_0); // left
|
|
|
|
// day columns
|
|
for (int i = 0; i < PIVOT_PAGES_COLUMNS; i++)
|
|
{
|
|
mainItGrid.ColumnDefinitions.Add(col_day);
|
|
}
|
|
|
|
sv.Content = mainItGrid;
|
|
pvItem.Content = sv;
|
|
|
|
Grid headGrid = new Grid();
|
|
|
|
pvItem.Header = headGrid;
|
|
|
|
this.ThePivot.Items.Add(pvItem);
|
|
|
|
}
|
|
|
|
private void RemoveContentUIElement(int index, UIElement elem)
|
|
{
|
|
// if (this.itemPages[index].Content.Children.Remove(elem) == false)
|
|
{
|
|
throw new ArgumentException();
|
|
}
|
|
}
|
|
|
|
private void RemoveContentUIElement(int index, AppointmentModel model)
|
|
{
|
|
Canvas[] list = this.GetModelCanvasFromContent(index, model);
|
|
|
|
if (list.Count() > 0)
|
|
{
|
|
foreach (Canvas can in list)
|
|
{
|
|
// this.itemPages[index].Content.Children.Remove(can);
|
|
}
|
|
}
|
|
}
|
|
|
|
private Canvas[] GetModelCanvasFromContent(int index, AppointmentModel model)
|
|
{
|
|
List<Canvas> retValue = new List<Canvas>();
|
|
|
|
// foreach (FrameworkElement elem in this.itemPages[index].Content.Children)
|
|
{
|
|
// if (elem.Tag.GetType().Equals(typeof(AppointmentModel)))
|
|
{
|
|
// if ((elem.Tag as AppointmentModel).Equals(model))
|
|
{
|
|
// retValue.Add(elem as Canvas);
|
|
}
|
|
}
|
|
}
|
|
|
|
return retValue.ToArray();
|
|
}
|
|
|
|
|
|
private void DrawAppointment(AppointmentModel model, int index, int xIndex, double opacity = 1.0, int zIndex = 0, int modelCount = 0)
|
|
{
|
|
/*
|
|
Canvas modelCan = model.GetCanvas(
|
|
((this.itemPages[index].Content.Width - WEEK_TABLE_HEAD_WIDTH) / 5) - 2 - 2 - (modelCount * WEEK_TABLE_ZINDEX_SHIFT),
|
|
WEEK_TABLE_CELL_HEIGHT,
|
|
this.itemPages[index].DateFrom.Date.AddDays(xIndex));
|
|
|
|
modelCan.DoubleTap += new EventHandler<System.Windows.Input.GestureEventArgs>(this.OnAppointmentClick);
|
|
modelCan.Opacity = opacity;
|
|
modelCan.SetValue(Canvas.ZIndexProperty, WEEK_TABLE_ZINDEX_MAX - zIndex);
|
|
modelCan.Margin = new Thickness(
|
|
(WEEK_TABLE_HEAD_WIDTH + 2 + (zIndex * WEEK_TABLE_ZINDEX_SHIFT) + (xIndex * ((this.itemPages[index].Content.Width - WEEK_TABLE_HEAD_WIDTH) / 5))),
|
|
modelCan.Margin.Top,
|
|
0,
|
|
0);
|
|
|
|
this.itemPages[index].Content.Children.Add(modelCan);
|
|
*/
|
|
}
|
|
|
|
private void DrawMultiBubble(int index, int dayIndex, int listIndex, int number, double xOffset, double yOffset)
|
|
{
|
|
Canvas can = new Canvas();
|
|
|
|
can.Width = WEEK_TABLE_CELL_HEIGHT * 2;
|
|
can.Height = WEEK_TABLE_CELL_HEIGHT * 2;
|
|
|
|
Rectangle rect = new Rectangle();
|
|
rect.Width = WEEK_TABLE_CELL_HEIGHT / 2;
|
|
rect.Height = WEEK_TABLE_CELL_HEIGHT / 2;
|
|
rect.RadiusX = WEEK_TABLE_CELL_HEIGHT / 4;
|
|
rect.RadiusY = WEEK_TABLE_CELL_HEIGHT / 4;
|
|
rect.StrokeThickness = 1;
|
|
rect.Stroke = new SolidColorBrush(Colors.DarkGray);
|
|
rect.Fill = new SolidColorBrush(Colors.Black);
|
|
|
|
TextBlock block = new TextBlock();
|
|
block.Height = WEEK_TABLE_CELL_HEIGHT / 2;
|
|
block.Width = WEEK_TABLE_CELL_HEIGHT / 2;
|
|
block.Text = "" + number;
|
|
block.HorizontalAlignment = HorizontalAlignment.Center;
|
|
block.VerticalAlignment = VerticalAlignment.Center;
|
|
block.FontWeight = FontWeights.Bold;
|
|
block.FontSize = WEEK_TABLE_CELL_HEIGHT / 3;
|
|
block.Padding = new Thickness(WEEK_TABLE_CELL_HEIGHT / 6.5, 0, 0, 0);
|
|
|
|
can.Children.Add(rect);
|
|
rect.SetValue(Canvas.TopProperty, WEEK_TABLE_CELL_HEIGHT / 2);
|
|
rect.SetValue(Canvas.LeftProperty, WEEK_TABLE_CELL_HEIGHT / 2);
|
|
|
|
can.Children.Add(block);
|
|
block.SetValue(Canvas.TopProperty, WEEK_TABLE_CELL_HEIGHT / 2);
|
|
block.SetValue(Canvas.LeftProperty, WEEK_TABLE_CELL_HEIGHT / 2);
|
|
|
|
can.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(this.OnMultiBubbleClick);
|
|
can.Tag = ((dayIndex & 0xF) << 24) | ((index & 0xFFF) << 12) | (listIndex & 0xFFF);
|
|
can.SetValue(Canvas.LeftProperty, xOffset - rect.Width - (WEEK_TABLE_CELL_HEIGHT / 2));
|
|
can.SetValue(Canvas.TopProperty, yOffset - (WEEK_TABLE_CELL_HEIGHT / 2));
|
|
can.SetValue(Canvas.ZIndexProperty, WEEK_TABLE_ZINDEX_MAX + 1);
|
|
|
|
// this.itemPages[index].Content.Children.Add(can);
|
|
}
|
|
|
|
private void DrawHeader(int index)
|
|
{
|
|
Grid grid = ((this.ThePivot.Items[index] as PivotItem).Header as Grid);
|
|
string text = string.Format("{0:dd.MM.yyyy} < {1:c} > {2:dd.MM.yyyy}", this.itemPages[index].DateFrom, this.itemPages[index].WeekChar, this.itemPages[index].DateTo);
|
|
|
|
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();
|
|
TextBlock dayTB = new TextBlock();
|
|
|
|
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);
|
|
|
|
if (this.itemPages[index].DateFrom.Date.AddDays(i).Equals(DateTime.Now.Date))
|
|
{
|
|
dayRect.Fill = new SolidColorBrush(Colors.White);
|
|
dayTB.Foreground = new SolidColorBrush(Colors.Black);
|
|
}
|
|
|
|
headCan.Children.Add(dayRect);
|
|
|
|
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();
|
|
vertLine.X1 = 0;
|
|
vertLine.Y1 = 0;
|
|
vertLine.X2 = 0;
|
|
vertLine.Y2 = (WEEK_TABLE_CELL_HEIGHT * 24);
|
|
vertLine.Stroke = new SolidColorBrush(Colors.White);
|
|
vertLine.Stretch = Stretch.Fill;
|
|
vertLine.HorizontalAlignment = HorizontalAlignment.Left;
|
|
vertLine.Margin = new Thickness(WEEK_TABLE_HEAD_WIDTH, 0, 0, 0);
|
|
vertLine.StrokeThickness = WEEK_TABLE_HEAD_THICKNESS;
|
|
|
|
for (int i = 0; i <= 24; i++)
|
|
{
|
|
// lines
|
|
Line hLineHead = new Line();
|
|
hLineHead.X1 = 0;
|
|
hLineHead.Y1 = 0;
|
|
hLineHead.X2 = WEEK_TABLE_HEAD_WIDTH;
|
|
hLineHead.Y2 = 0;
|
|
hLineHead.Stroke = new SolidColorBrush(Colors.White);
|
|
hLineHead.Stretch = Stretch.Fill;
|
|
hLineHead.HorizontalAlignment = HorizontalAlignment.Left;
|
|
hLineHead.Margin = new Thickness(0, (WEEK_TABLE_CELL_HEIGHT * i), 0, 0);
|
|
hLineHead.StrokeThickness = WEEK_TABLE_HEAD_THICKNESS;
|
|
|
|
Line hLineHalf = new Line();
|
|
hLineHalf.X1 = 0;
|
|
hLineHalf.Y1 = 0;
|
|
hLineHalf.X2 = WEEK_TABLE_HEAD_HALF;
|
|
hLineHalf.Y2 = 0;
|
|
hLineHalf.Stroke = new SolidColorBrush(Colors.Gray);
|
|
hLineHalf.Stretch = Stretch.Fill;
|
|
hLineHalf.HorizontalAlignment = HorizontalAlignment.Left;
|
|
hLineHalf.Margin = new Thickness((WEEK_TABLE_HEAD_WIDTH - WEEK_TABLE_HEAD_HALF), (WEEK_TABLE_CELL_HEIGHT * i) + (WEEK_TABLE_CELL_HEIGHT / 2), 0, 0);
|
|
hLineHalf.StrokeThickness = WEEK_TABLE_HEAD_THICKNESS;
|
|
|
|
Line hLineInn = new Line();
|
|
hLineInn.X1 = 0;
|
|
hLineInn.Y1 = 0;
|
|
hLineInn.X2 = 1000;
|
|
hLineInn.Y2 = 0;
|
|
hLineInn.Stroke = new SolidColorBrush(Colors.DarkGray);
|
|
hLineInn.Stretch = Stretch.Fill;
|
|
hLineInn.HorizontalAlignment = HorizontalAlignment.Left;
|
|
hLineInn.Margin = new Thickness(WEEK_TABLE_HEAD_WIDTH, (WEEK_TABLE_CELL_HEIGHT * i), 0, 0);
|
|
hLineInn.StrokeDashArray = new DoubleCollection();
|
|
hLineInn.StrokeDashArray.Add(2);
|
|
hLineInn.StrokeDashArray.Add(4);
|
|
hLineInn.StrokeThickness = WEEK_TABLE_INNER_THICKNESS;
|
|
|
|
can.Children.Add(hLineHead);
|
|
can.Children.Add(hLineInn);
|
|
|
|
if (i < 24)
|
|
{
|
|
can.Children.Add(hLineHalf);
|
|
|
|
// text
|
|
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 = WEEK_TABLE_CELL_HEIGHT / 3;
|
|
|
|
can.Children.Add(timeStamp);
|
|
}
|
|
}
|
|
|
|
for (int i = 1; i < 5; i++)
|
|
{
|
|
Line dayLine = new Line();
|
|
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(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);
|
|
|
|
}
|
|
}
|
|
} |