model can calc date of week date
This commit is contained in:
@@ -66,22 +66,6 @@ namespace CampusAppWP8.Pages.Mensa
|
||||
|
||||
#region Private
|
||||
|
||||
/// <summary>
|
||||
/// Method calculate this day of the week, which its gets new menus
|
||||
/// </summary>
|
||||
/// <returns>Date of NewMenuWeekDay</returns>
|
||||
private DateTime CalcNewMenuWeekDay()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
while (now.DayOfWeek != DayOfWeek.Monday)
|
||||
{
|
||||
now = now.Subtract(new TimeSpan(1, 0, 0, 0));
|
||||
}
|
||||
|
||||
DateTime monday = new DateTime(now.Year, now.Month, now.Day);
|
||||
return monday;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method check if the last modification was later as the NewMenuWeekDay
|
||||
/// </summary>
|
||||
@@ -89,7 +73,7 @@ namespace CampusAppWP8.Pages.Mensa
|
||||
/// <returns>true, if is up-to-date, otherwise false</returns>
|
||||
private bool CheckIsUpToDate(DateTime lastModified)
|
||||
{
|
||||
int diff = lastModified.CompareTo(this.CalcNewMenuWeekDay());
|
||||
int diff = lastModified.CompareTo(MenuWeekModel.CalcFirstWeekDay());
|
||||
|
||||
if (diff < 0)
|
||||
{
|
||||
|
||||
@@ -23,22 +23,22 @@ namespace CampusAppWP8.Model.Mensa
|
||||
/// Name for bio dinner
|
||||
/// </summary>
|
||||
private string bio = AppResources.MensaApp_NotToday;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Name for 1. dinner
|
||||
/// </summary>
|
||||
private string dinner1 = AppResources.MensaApp_NotToday;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Name for 2. dinner
|
||||
/// </summary>
|
||||
private string dinner2 = AppResources.MensaApp_NotToday;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Name for 3. dinner
|
||||
/// </summary>
|
||||
private string dinner3 = AppResources.MensaApp_NotToday;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Name for 4. dinner
|
||||
/// </summary>
|
||||
@@ -49,6 +49,21 @@ namespace CampusAppWP8.Model.Mensa
|
||||
/// </summary>
|
||||
private string action = AppResources.MensaApp_NotToday;
|
||||
|
||||
/// <summary>
|
||||
/// Name of the day
|
||||
/// </summary>
|
||||
private string dayName;
|
||||
|
||||
/// <summary>
|
||||
/// DateTime of the day
|
||||
/// </summary>
|
||||
private DateTime date;
|
||||
|
||||
/// <summary>
|
||||
/// DateTime of the monday
|
||||
/// </summary>
|
||||
private DateTime monday;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
@@ -58,6 +73,7 @@ namespace CampusAppWP8.Model.Mensa
|
||||
/// </summary>
|
||||
public MenuModel()
|
||||
{
|
||||
this.monday = MenuWeekModel.CalcFirstWeekDay();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -68,7 +84,38 @@ namespace CampusAppWP8.Model.Mensa
|
||||
/// Gets or sets the WeekDay
|
||||
/// </summary>
|
||||
[XmlElement("Wochentag")]
|
||||
public string Day { get; set; }
|
||||
public string Day
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.dayName;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
this.SetValue(value, ref this.dayName);
|
||||
this.CalcDateOfDay();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets of Date
|
||||
/// </summary>
|
||||
public DateTime Date
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.date;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != this.date)
|
||||
{
|
||||
this.date = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets dinner 1
|
||||
@@ -189,6 +236,34 @@ namespace CampusAppWP8.Model.Mensa
|
||||
property = StringManager.StripHTML(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method calculate the DateTime of the MenuDay
|
||||
/// </summary>
|
||||
private void CalcDateOfDay()
|
||||
{
|
||||
switch (this.dayName)
|
||||
{
|
||||
case "Montag":
|
||||
this.date = this.monday;
|
||||
break;
|
||||
case "Diensttag":
|
||||
this.date = this.monday.AddDays(1);
|
||||
break;
|
||||
case "Mittwoch":
|
||||
this.date = this.monday.AddDays(2);
|
||||
break;
|
||||
case "Donnerstag":
|
||||
this.date = this.monday.AddDays(3);
|
||||
break;
|
||||
case "Freitag":
|
||||
this.date = this.monday.AddDays(4);
|
||||
break;
|
||||
default:
|
||||
this.date = this.monday;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace CampusAppWP8.Model.Mensa
|
||||
[XmlRoot("root")]
|
||||
public class MenuWeekModel
|
||||
{
|
||||
#region Members
|
||||
/// <summary>
|
||||
/// Time when the model was created
|
||||
/// </summary>
|
||||
@@ -30,6 +31,10 @@ namespace CampusAppWP8.Model.Mensa
|
||||
this.createTime = DateTime.Now;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the menus for the week
|
||||
/// </summary>
|
||||
@@ -37,6 +42,9 @@ namespace CampusAppWP8.Model.Mensa
|
||||
[XmlArrayItem("Tagesmenu")]
|
||||
public ObservableCollection<MenuModel> Menus { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Proberty
|
||||
/// <summary>
|
||||
/// Gets the creation time of the model
|
||||
/// </summary>
|
||||
@@ -47,5 +55,27 @@ namespace CampusAppWP8.Model.Mensa
|
||||
return this.createTime;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Method calculate this day of the week, which its gets new menus
|
||||
/// </summary>
|
||||
/// <returns>Date of NewMenuWeekDay</returns>
|
||||
public static DateTime CalcFirstWeekDay()
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
while (now.DayOfWeek != DayOfWeek.Monday)
|
||||
{
|
||||
now = now.Subtract(new TimeSpan(1, 0, 0, 0));
|
||||
}
|
||||
|
||||
DateTime monday = new DateTime(now.Year, now.Month, now.Day);
|
||||
return monday;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<phone:Pivot.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Margin="12,0,12,0">
|
||||
<TextBlock Text="Datum : 01.01.1970"/>
|
||||
<TextBlock Text="{Binding Date, StringFormat='{}{0:dd.MM.yyyy}'}"/>
|
||||
<ScrollViewer>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
|
||||
Reference in New Issue
Block a user