From b78250401cd412345ed080e2772b047cd81c17c2 Mon Sep 17 00:00:00 2001 From: stubbfel Date: Mon, 22 Jul 2013 14:46:44 +0200 Subject: [PATCH] finish #119 --- .../Model/Lecture/LecturePageModel.cs | 214 ++++++++++++++++-- .../Pages/Lecture/LecturePage.xaml | 4 +- .../Pages/Lecture/LecturePage.xaml.cs | 46 +++- 3 files changed, 238 insertions(+), 26 deletions(-) diff --git a/CampusAppWP8/CampusAppWP8/Model/Lecture/LecturePageModel.cs b/CampusAppWP8/CampusAppWP8/Model/Lecture/LecturePageModel.cs index c0446795..d570d3cf 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Lecture/LecturePageModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Lecture/LecturePageModel.cs @@ -40,9 +40,39 @@ namespace CampusAppWP8.Model.Lecture private List semesterList; /// - /// List for the number of semester + /// List for the number of semester (from) /// - private List numberList; + private List fromNumberList; + + /// + /// List for the number of semester (to) + /// + private List toNumberList; + + /// + /// Variable for the courseIndex + /// + private int selectCourseIndex; + + /// + /// Variable for the degreeIndex + /// + private int selectDegreeIndex; + + /// + /// Variable for the semesterIndex + /// + private int selectSemesterIndex; + + /// + /// Variable for the fromIndex + /// + private int selectFromIndex; + + /// + /// Variable for the toIndex + /// + private int selectToIndex; #endregion @@ -62,31 +92,101 @@ namespace CampusAppWP8.Model.Lecture /// Gets or sets the selected course index /// [DataMember] - public int SelectCourseIndex { get; set; } + public int SelectCourseIndex + { + get + { + return this.selectCourseIndex; + } + + set + { + if (value != this.selectCourseIndex && this.courseList != null && value < this.courseList.Count) + { + this.selectCourseIndex = value; + } + } + } /// /// Gets or sets the selected degree index /// [DataMember] - public int SelectDegreeIndex { get; set; } + public int SelectDegreeIndex + { + get + { + return this.selectDegreeIndex; + } + + set + { + if (value != this.selectDegreeIndex && this.degreeList != null && value < this.degreeList.Count) + { + this.selectDegreeIndex = value; + } + } + } /// /// Gets or sets the selected semester-index /// [DataMember] - public int SelectSemesterIndex { get; set; } + public int SelectSemesterIndex + { + get + { + return this.selectSemesterIndex; + } + + set + { + if (value != this.selectSemesterIndex && this.semesterList != null && value < this.semesterList.Count) + { + this.selectSemesterIndex = value; + } + } + } /// /// Gets or sets the selected from-index /// [DataMember] - public int SelectFromIndex { get; set; } + public int SelectFromIndex + { + get + { + return this.selectFromIndex; + } + + set + { + if (value != this.selectFromIndex && this.fromNumberList != null && value < this.fromNumberList.Count) + { + this.selectFromIndex = value; + } + } + } /// /// Gets or sets the selected to-index /// [DataMember] - public int SelectToIndex { get; set; } + public int SelectToIndex + { + get + { + return this.selectToIndex; + } + + set + { + if (value != this.selectToIndex && this.toNumberList != null && value < this.toNumberList.Count) + { + this.selectToIndex = value; + } + } + } /// /// Gets List for the courses of the BTU @@ -124,11 +224,22 @@ namespace CampusAppWP8.Model.Lecture /// /// Gets List for the number of semester /// - public List NumberList + public List FromNumberList { get { - return this.numberList; + return this.fromNumberList; + } + } + + /// + /// Gets the NumberList + /// + public List ToNumberList + { + get + { + return this.toNumberList; } } #endregion @@ -144,7 +255,8 @@ namespace CampusAppWP8.Model.Lecture { this.LoadCourseList(); this.LoadDegreeList(); - this.LoadNumberList(); + this.LoadFromNumberList(); + this.LoadToNumberList(); this.LoadSemesterList(); } @@ -155,20 +267,55 @@ namespace CampusAppWP8.Model.Lecture /// /// Load the NumberList /// - private void LoadNumberList() + public void LoadFromNumberList() { - this.numberList = new List(); - this.numberList.Add(new ListPickerItemModel() { Text = "1", Value = "1" }); - this.numberList.Add(new ListPickerItemModel() { Text = "2", Value = "2" }); - this.numberList.Add(new ListPickerItemModel() { Text = "3", Value = "3" }); - this.numberList.Add(new ListPickerItemModel() { Text = "4", Value = "4" }); - this.numberList.Add(new ListPickerItemModel() { Text = "5", Value = "5" }); - this.numberList.Add(new ListPickerItemModel() { Text = "5", Value = "6" }); - this.numberList.Add(new ListPickerItemModel() { Text = "7", Value = "7" }); - this.numberList.Add(new ListPickerItemModel() { Text = "8", Value = "8" }); - this.numberList.Add(new ListPickerItemModel() { Text = "9", Value = "9" }); - this.numberList.Add(new ListPickerItemModel() { Text = "10", Value = "10" }); + string selectValue = null; + if (this.fromNumberList != null) + { + selectValue = this.fromNumberList[this.SelectFromIndex].Value; + } + this.fromNumberList = this.CreateNumberList(1, 10); + this.SelectFromIndex = this.GetIndexOrDefault(this.fromNumberList, selectValue); + } + + /// + /// Load the NumberList + /// + public void LoadToNumberList() + { + string selectValue = null; + if (this.toNumberList != null) + { + selectValue = this.toNumberList[this.SelectToIndex].Value; + } + + this.toNumberList = this.CreateNumberList(this.SelectFromIndex + 1, 10); + this.SelectToIndex = this.GetIndexOrDefault(this.toNumberList, selectValue); + } + + /// + /// Method create a NumberList + /// + /// startValue of the list + /// endValue of the list + /// return list + private List CreateNumberList(int startvalue, int endvalue) + { + List list = new List(); + string degree = this.DegreeList[this.SelectDegreeIndex].Value; + + for (int i = startvalue; i <= endvalue; i++) + { + if ((i > 4 && "88".Equals(degree)) || (i > 6 && "82".Equals(degree))) + { + break; + } + + list.Add(new ListPickerItemModel() { Text = i.ToString(), Value = i.ToString() }); + } + + return list; } /// @@ -244,6 +391,29 @@ namespace CampusAppWP8.Model.Lecture this.courseList = this.courseList.OrderBy(o => o.Text).ToList(); } + /// + /// Method return a the Index of an item which has a certain value + /// + /// list for items + /// a certain value + /// return index of value or default(0) + private int GetIndexOrDefault(List list, string value) + { + int index = 0; + int i = 0; + foreach (ListPickerItemModel item in list) + { + if (item.Value.Equals(value)) + { + index = i; + break; + } + + i++; + } + + return index; + } #endregion #endregion diff --git a/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml b/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml index d67c3cee..acc05203 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml @@ -77,7 +77,7 @@ - + @@ -100,7 +100,7 @@ - + diff --git a/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml.cs index d1b83c22..8afc016e 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml.cs @@ -39,6 +39,11 @@ namespace CampusAppWP8.Pages.Lecture /// private LecturePageModel pageModel; + /// + /// flag for initialed page + /// + private bool init; + #endregion #region Constructor @@ -48,8 +53,10 @@ namespace CampusAppWP8.Pages.Lecture public LecturePage() { this.InitializeComponent(); + this.init = false; this.LoadPageModel(); this.SetupListPickers(); + this.init = true; } #endregion @@ -98,8 +105,8 @@ namespace CampusAppWP8.Pages.Lecture { this.Course.ItemsSource = this.pageModel.CourseList; this.Degree.ItemsSource = this.pageModel.DegreeList; - this.From.ItemsSource = this.pageModel.NumberList; - this.To.ItemsSource = this.pageModel.NumberList; + this.From.ItemsSource = this.pageModel.FromNumberList; + this.To.ItemsSource = this.pageModel.ToNumberList; this.Semester.ItemsSource = this.pageModel.SemesterList; // load values from last request @@ -198,6 +205,41 @@ namespace CampusAppWP8.Pages.Lecture NavigationService.Navigate(url); } + /// + /// EventHandler for changed degree selection + /// + /// sender object + /// some args + private void DegreeSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) + { + if (!this.init) + { + return; + } + + this.pageModel.SelectDegreeIndex = this.Degree.SelectedIndex; + this.pageModel.LoadFromNumberList(); + this.From.ItemsSource = this.pageModel.FromNumberList; + } + + /// + /// EventHandler for changed from selection + /// + /// sender object + /// some args + private void FromSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) + { + if (!this.init) + { + return; + } + + this.pageModel.SelectDegreeIndex = this.Degree.SelectedIndex; + this.pageModel.SelectFromIndex = this.From.SelectedIndex; + this.pageModel.LoadToNumberList(); + this.To.ItemsSource = this.pageModel.ToNumberList; + } + #endregion #endregion