From c2871bb3d110b569210102cc5ca774f2dc8a2c79 Mon Sep 17 00:00:00 2001 From: stubbfel Date: Wed, 24 Jul 2013 11:00:55 +0200 Subject: [PATCH] add validation userprofile --- CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj | 4 +- .../{UserProfil => Setting}/UserProfilFile.cs | 29 +- .../Model/Setting/UserProfilModel.cs | 278 ++++++++++++++++++ .../Model/UserProfil/UserProfilModel.cs | 161 ---------- .../Resources/Constants.Designer.cs | 63 ++++ .../CampusAppWP8/Resources/Constants.resx | 21 ++ CampusAppWP8/CampusAppWP8/Settings.cs | 27 +- 7 files changed, 401 insertions(+), 182 deletions(-) rename CampusAppWP8/CampusAppWP8/File/{UserProfil => Setting}/UserProfilFile.cs (81%) create mode 100644 CampusAppWP8/CampusAppWP8/Model/Setting/UserProfilModel.cs delete mode 100644 CampusAppWP8/CampusAppWP8/Model/UserProfil/UserProfilModel.cs diff --git a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj index 366beb46..a39c91ea 100644 --- a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj +++ b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj @@ -98,8 +98,8 @@ - - + + UserProfil.xaml diff --git a/CampusAppWP8/CampusAppWP8/File/UserProfil/UserProfilFile.cs b/CampusAppWP8/CampusAppWP8/File/Setting/UserProfilFile.cs similarity index 81% rename from CampusAppWP8/CampusAppWP8/File/UserProfil/UserProfilFile.cs rename to CampusAppWP8/CampusAppWP8/File/Setting/UserProfilFile.cs index 8323f5fa..0f7e2471 100644 --- a/CampusAppWP8/CampusAppWP8/File/UserProfil/UserProfilFile.cs +++ b/CampusAppWP8/CampusAppWP8/File/Setting/UserProfilFile.cs @@ -5,41 +5,38 @@ // stubbfel // 23.07.2013 //---------------------------------------------------------------------- -namespace CampusAppWP8.File.UserProfil +namespace CampusAppWP8.File.Setting { - using CampusAppWP8.Model; - using CampusAppWP8.Model.UserProfil; - using CampusAppWP8.Resources; - using CampusAppWP8.Utility; - using System; - using System.Collections.Generic; using System.IO; - using System.Linq; - using System.Text; - using System.Threading.Tasks; + using CampusAppWP8.Model; + using CampusAppWP8.Model.Setting; + using CampusAppWP8.Resources; + /// + /// Class for handle the user-profile-file + /// public class UserProfilFile : XmlModel { - #region Constructor + /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// automatic loading of the data - public UserProfilFile(bool autoload = false) : base(ModelType.File, Constants.FileProfil_User) + public UserProfilFile(bool autoLoad = false) + : base(ModelType.File, Constants.FileProfil_User) { this.isFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDateOnLoad); this.isFileUpToDateOnSave += new IsFileUpToDate(this.CheckIsFileUpToDateOnSave); - if (autoload) + if (autoLoad) { this.LoadData(); } } - + // Constructor #endregion - /// /// Method implement CheckIsFileUpToDate()-Method . /// diff --git a/CampusAppWP8/CampusAppWP8/Model/Setting/UserProfilModel.cs b/CampusAppWP8/CampusAppWP8/Model/Setting/UserProfilModel.cs new file mode 100644 index 00000000..97e16619 --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Model/Setting/UserProfilModel.cs @@ -0,0 +1,278 @@ +//----------------------------------------------------------------------- +// +// Company copyright tag. +// +// stubbfel +// 23.07.2013 +//---------------------------------------------------------------------- +namespace CampusAppWP8.Model.Setting +{ + using System.Xml.Serialization; + using CampusAppWP8.Resources; + + /// + /// Model for the profile of an user + /// + [XmlRoot("root")] + public class UserProfilModel + { + #region Members + + /// + /// constant for the first validate semester + /// + private static readonly int FirstSemester = int.Parse(Constants.Valid_FirstSemseter); + + /// + /// constant for the last validate semester + /// + private static readonly int LastSemester = int.Parse(Constants.Valid_LastSemseter); + + /// + /// constant for the max. number of a validate course + /// + private static readonly int MaxCourseNumber = int.Parse(Constants.Valid_MaxCourseNumber); + + /// + /// constant for the default value of a semester + /// + private static readonly int DefaultSemester = int.Parse(Constants.Setting_DefaultSemester); + + /// + /// constant for the default value of a courseNumber + /// + private static readonly int DefaultCourseNumber = int.Parse(Constants.Setting_DefaultSemester); + + /// + /// constant for the default value of a role + /// + private static readonly int DefaultRole = int.Parse(Constants.Setting_DefaultRole); + + /// + /// constant for the default value of a degree + /// + private static readonly int DefaultDegree = int.Parse(Constants.Setting_DefaultDegree); + + /// + /// Flag which indicates that any properties has been changed + /// + private bool changed = false; + + /// + /// Gets or Sets the course of the user + /// + private int course; + + /// + /// Gets or Sets the role of the user + /// + private RoleType role = RoleType.DEFAULT; + + /// + /// Gets or Sets the degree of the user + /// + private DegreeType degree = DegreeType.DEFAULT; + + /// + /// Gets or Sets the semester of the user + /// + private int semester = UserProfilModel.DefaultSemester; + + #endregion + + #region Enums + /// + /// Specifies the degrees. + /// + public enum DegreeType + { + /// + /// Default value + /// + DEFAULT = UserProfilModel.DefaultRole, + + /// + /// bachelor degree + /// + BACHELOR = 82, + + /// + /// master degree + /// + MASTER = 88, + + /// + /// diploma degree + /// + DIPLOM = 11 + } + + /// + /// Specifies the role of the user. + /// + public enum RoleType + { + /// + /// Default value + /// + DEFAULT = UserProfilModel.DefaultRole, + + /// + /// for students (01). + /// + STUDENT = 1, + + /// + /// for staffs (10). + /// + STAFF = 2, + } + + #endregion + + #region Proberties + /// + /// Gets or sets the course of the user + /// + [XmlElement("Course")] + public int Course + { + get + { + return this.course; + } + + set + { + if (value != this.course && this.ValditateCourse(value)) + { + this.course = value; + this.changed = true; + } + } + } + + /// + /// Gets or sets the role of the user + /// + [XmlElement("Role")] + public RoleType Role + { + get + { + return this.role; + } + + set + { + if (value != this.role) + { + this.role = value; + this.changed = true; + } + } + } + + /// + /// Gets or sets the degree of the user + /// + [XmlElement("Degere")] + public DegreeType Degree + { + get + { + return this.degree; + } + + set + { + if (value != this.degree) + { + this.degree = value; + this.changed = true; + } + } + } + + /// + /// Gets or sets the semester of the user + /// + [XmlElement("Semseter")] + public int Semester + { + get + { + return this.semester; + } + + set + { + if (value != this.semester && this.ValditateSemester(value)) + { + this.semester = value; + this.changed = true; + } + } + } + #endregion + + #region Methods + + #region public + + /// + /// Method return the changed flag + /// + /// if is true, set changed flag to false, otherwise do nothing (bypass) + /// return true, if any properties has changed, otherwise false + public bool HasChanged(bool reset = true) + { + bool result = this.changed; + + if (reset) + { + this.changed = false; + } + + return result; + } + + #endregion + + #region private + + /// + /// Methods check if a value could be a valid semester + /// + /// value which has to be checked + /// true if it is an valid semester, otherwise false + private bool ValditateSemester(int possibleSemester) + { + if (possibleSemester < UserProfilModel.FirstSemester || possibleSemester > UserProfilModel.LastSemester) + { + return false; + } + + return true; + } + + /// + /// Methods check if a value could be a valid course + /// + /// value which has to be checked + /// true if it is an valid course, otherwise false + private bool ValditateCourse(int possibleCourse) + { + if (possibleCourse > UserProfilModel.MaxCourseNumber) + { + return false; + } + + return true; + } + + #endregion + + #endregion + } +} diff --git a/CampusAppWP8/CampusAppWP8/Model/UserProfil/UserProfilModel.cs b/CampusAppWP8/CampusAppWP8/Model/UserProfil/UserProfilModel.cs deleted file mode 100644 index cfa9f398..00000000 --- a/CampusAppWP8/CampusAppWP8/Model/UserProfil/UserProfilModel.cs +++ /dev/null @@ -1,161 +0,0 @@ -//----------------------------------------------------------------------- -// -// Company copyright tag. -// -// stubbfel -// 23.07.2013 -//---------------------------------------------------------------------- -namespace CampusAppWP8.Model.UserProfil -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - using System.Xml.Serialization; - - /// - /// Model for the profil of an user - /// - [XmlRoot("root")] - public class UserProfilModel - { - - private bool changed = false; - /// - /// Gets or Sets the course of the user - /// - private string course; - - /// - /// Gets or Sets the role of the user - /// - private int role; - - /// - /// Gets or Sets the degree of the user - /// - private string degree; - - - /// - /// Gets or Sets the semester of the user - /// - private string semester; - - /// - /// Gets or Sets the course of the user - /// - [XmlElement("Course")] - public string Course - { - get - { - return this.course; - } - set - { - if (value != this.course) - { - this.course = value; - this.changed = true; - } - } - } - - /// - /// Gets or Sets the role of the user - /// - [XmlElement("Role")] - public int Role - { - get - { - return this.role; - } - set - { - if (value != this.role) - { - this.role = value; - this.changed = true; - } - } - } - - - /// - /// Gets or Sets the degree of the user - /// - [XmlElement("Degere")] - public string Degree - { - get - { - return this.degree; - } - set - { - if (value != this.degree) - { - this.degree = value; - this.changed = true; - } - } - } - - - /// - /// Gets or Sets the semester of the user - /// - [XmlElement("Semseter")] - public string Semester - { - get - { - return this.semester; - } - set - { - if (value != this.semester) - { - this.semester = value; - this.changed = true; - } - } - } - - - /// - /// Specifies the role of the user. - /// - public enum RoleType - { - /// - /// Invalid/unset state. - /// - INVALID = 0, - - /// - /// for students (01). - /// - Student = 1, - - /// - /// for staffs (10). - /// - Staff = 2, - } - - public bool HasChanged(bool reset = true) - { - bool result = this.changed; - - if (reset) - { - changed = false; - } - return result; - } - } -} diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs b/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs index 9f836c95..8d36a1aa 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.Designer.cs @@ -429,6 +429,42 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die 767 ähnelt. + /// + public static string Setting_DefaultCourseNumber { + get { + return ResourceManager.GetString("Setting_DefaultCourseNumber", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die 82 ähnelt. + /// + public static string Setting_DefaultDegree { + get { + return ResourceManager.GetString("Setting_DefaultDegree", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die 1 ähnelt. + /// + public static string Setting_DefaultRole { + get { + return ResourceManager.GetString("Setting_DefaultRole", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die 20131 ähnelt. + /// + public static string Setting_DefaultSemester { + get { + return ResourceManager.GetString("Setting_DefaultSemester", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die ToggleContent ähnelt. /// @@ -537,6 +573,33 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die 20121 ähnelt. + /// + public static string Valid_FirstSemseter { + get { + return ResourceManager.GetString("Valid_FirstSemseter", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die 20502 ähnelt. + /// + public static string Valid_LastSemseter { + get { + return ResourceManager.GetString("Valid_LastSemseter", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die 999 ähnelt. + /// + public static string Valid_MaxCourseNumber { + get { + return ResourceManager.GetString("Valid_MaxCourseNumber", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die root ähnelt. /// diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx index e76644ca..2b9355db 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx @@ -279,4 +279,25 @@ /Pages/Setting/UserProfil.xaml + + 767 + + + 82 + + + 1 + + + 20131 + + + 20121 + + + 20502 + + + 999 + \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Settings.cs b/CampusAppWP8/CampusAppWP8/Settings.cs index 2012e0ce..7ba1d747 100644 --- a/CampusAppWP8/CampusAppWP8/Settings.cs +++ b/CampusAppWP8/CampusAppWP8/Settings.cs @@ -1,20 +1,41 @@ -using CampusAppWP8.File.UserProfil; +//----------------------------------------------------------------------- +// +// Company copyright tag. +// +// stubbfel +// 23.07.2013 +//---------------------------------------------------------------------- namespace CampusAppWP8 { + using CampusAppWP8.File.Setting; + + /// + /// Class handle all setting (files) + /// public class Settings { + /// + /// reference of the user-profile-file + /// private static UserProfilFile userProfil = new UserProfilFile(true); + /// + /// Gets or sets the user-profile-file + /// public static UserProfilFile UserProfil { get { - return UserProfil; + return Settings.userProfil; } + set { - UserProfil = value; + if (value != Settings.userProfil) + { + Settings.userProfil = value; + } } } }