Files
win8phoneApp/CampusAppWP8/CampusAppWP8/Model/Lecture/LecturePageModel.cs
2013-08-08 15:15:15 +02:00

327 lines
8.8 KiB
C#

//-----------------------------------------------------------------------
// <copyright file="LecturePageModel.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>18.06.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWP8.Model.Lecture
{
using System.Runtime.Serialization;
using CampusAppWP8.Model.Setting;
using CampusAppWP8.Model.Utility;
/// <summary>
/// Model for the LecturePage
/// </summary>
[DataContract]
public class LecturePageModel
{
#region Members
/// <summary>
/// Variable for the courseIndex
/// </summary>
[DataMember]
public int selectCourseIndex;
/// <summary>
/// Variable for the degreeIndex
/// </summary>
[DataMember]
public int selectDegreeIndex;
/// <summary>
/// Variable for the semesterIndex
/// </summary>
[DataMember]
public int selectSemesterIndex;
/// <summary>
/// Variable for the fromIndex
/// </summary>
[DataMember]
public int selectFromIndex;
/// <summary>
/// Variable for the toIndex
/// </summary>
[DataMember]
public int selectToIndex;
/// <summary>
/// List for the courses of the BTU
/// </summary>
/// <remarks>
/// need to be extend to full list
/// </remarks>
private ListPickerItemListModel courseList;
/// <summary>
/// List of the degrees
/// </summary>
private ListPickerItemListModel degreeList;
/// <summary>
/// List of the semester
/// </summary>
private ListPickerItemListModel semesterList;
/// <summary>
/// List for the number of semester (from)
/// </summary>
private ListPickerItemListModel fromNumberList;
/// <summary>
/// List for the number of semester (to)
/// </summary>
private ListPickerItemListModel toNumberList;
#endregion
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="LecturePageModel" /> class.
/// </summary>
public LecturePageModel()
{
this.courseList = new CourseListPickerItemListModel();
this.degreeList = new DegreeListPickerItemListModel();
this.semesterList = new SemesterListPickerItemListModel();
}
#endregion
#region Proberty
/// <summary>
/// Gets or sets the selected course index
/// </summary>
public int SelectCourseIndex
{
get
{
return this.selectCourseIndex;
}
set
{
if (value != this.selectCourseIndex && this.courseList != null && value < this.courseList.List.Count)
{
this.selectCourseIndex = value;
}
}
}
/// <summary>
/// Gets or sets the selected degree index
/// </summary>
public int SelectDegreeIndex
{
get
{
return this.selectDegreeIndex;
}
set
{
if (value != this.selectDegreeIndex && this.degreeList != null && value < this.degreeList.List.Count)
{
this.selectDegreeIndex = value;
}
}
}
/// <summary>
/// Gets or sets the selected semester-index
/// </summary>
public int SelectSemesterIndex
{
get
{
return this.selectSemesterIndex;
}
set
{
if (value != this.selectSemesterIndex && this.semesterList != null && value < this.semesterList.List.Count)
{
this.selectSemesterIndex = value;
}
}
}
/// <summary>
/// Gets or sets the selected from-index
/// </summary>
public int SelectFromIndex
{
get
{
return this.selectFromIndex;
}
set
{
if (value != this.selectFromIndex && this.fromNumberList != null && value < this.fromNumberList.List.Count)
{
this.selectFromIndex = value;
}
}
}
/// <summary>
/// Gets or sets the selected to-index
/// </summary>
public int SelectToIndex
{
get
{
return this.selectToIndex;
}
set
{
if (value != this.selectToIndex && this.toNumberList != null && value < this.toNumberList.List.Count)
{
this.selectToIndex = value;
}
}
}
/// <summary>
/// Gets List for the courses of the BTU
/// </summary>
public ListPickerItemListModel CourseList
{
get
{
return this.courseList;
}
}
/// <summary>
/// Gets List of the degrees
/// </summary>
public ListPickerItemListModel DegreeList
{
get
{
return this.degreeList;
}
}
/// <summary>
/// Gets List of the semester
/// </summary>
public ListPickerItemListModel SemesterList
{
get
{
return this.semesterList;
}
}
/// <summary>
/// Gets List for the number of semester
/// </summary>
public ListPickerItemListModel FromNumberList
{
get
{
return this.fromNumberList;
}
}
/// <summary>
/// Gets the NumberList
/// </summary>
public ListPickerItemListModel ToNumberList
{
get
{
return this.toNumberList;
}
}
#endregion
#region Methods
#region public
/// <summary>
/// Load all ListPickerLists
/// </summary>
public void LoadLists()
{
this.LoadFromNumberList();
this.LoadToNumberList();
UserProfilModel userModel = Settings.UserProfil;
this.selectCourseIndex = this.courseList.GetIndexOrDefault(((int)userModel.Course).ToString().PadLeft(3, '0'));
this.selectDegreeIndex = this.degreeList.GetIndexOrDefault(((int)userModel.Degree).ToString());
this.selectSemesterIndex = this.semesterList.GetIndexOrDefault(((int)userModel.Semester).ToString());
}
#endregion
#region private
/// <summary>
/// Load the NumberList
/// </summary>
public void LoadFromNumberList()
{
string selectValue = null;
if (this.fromNumberList != null && this.fromNumberList.List.Count > 0)
{
selectValue = this.fromNumberList.List[this.SelectFromIndex].Value;
}
this.fromNumberList = this.CreateNumberList(1, 10);
this.SelectFromIndex = this.fromNumberList.GetIndexOrDefault(selectValue);
}
/// <summary>
/// Load the NumberList
/// </summary>
public void LoadToNumberList()
{
string selectValue = null;
if (this.toNumberList != null && this.toNumberList.List.Count > 0)
{
selectValue = this.toNumberList.List[this.SelectToIndex].Value;
}
this.toNumberList = this.CreateNumberList(this.SelectFromIndex + 1, 10);
this.SelectToIndex = this.toNumberList.GetIndexOrDefault(selectValue);
}
/// <summary>
/// Method create a NumberList
/// </summary>
/// <param name="startvalue">startValue of the list</param>
/// <param name="endvalue">endValue of the list</param>
/// <returns>return list</returns>
private ListPickerItemListModel CreateNumberList(int startvalue, int endvalue)
{
ListPickerItemListModel list = new ListPickerItemListModel();
string degree = this.DegreeList.List[this.SelectDegreeIndex].Value;
for (int i = startvalue; i <= endvalue; i++)
{
if ((i > 4 && "88".Equals(degree)) || (i > 6 && "82".Equals(degree)))
{
break;
}
list.AddItem(i.ToString(), i.ToString());
}
return list;
}
#endregion
#endregion
}
}