using System; using System.Collections.Generic; using System.Text; using TBF.Entities; using NHibernate; using FluentNHibernate; namespace TBF { /// /// Enum Grp.GID specifies GID-s of user groups. /// An instance of this class represenst a group, which contains a list of its members (users). /// Static private array 'groups' of this class, accesible through indexer, contains all groups. /// public class Grp { /// /// GID-s of user groups, each user is member of one or more groups. /// public enum GID { // The first NrOfGroups items are GroupID-s (0..NrOfGroups-1) Testers = 0, TestingSpecialists, HeadOfLab, MaintenanceSpecialists, Metrologists, CalibrationSpecialists, Administrators, // application / network / database administrator Custom1, Custom2, Custom3, NrOfGroups, // Number of groups (this is not a GroupID) None, // Not a GroupID, can be used to indicate no group membership is required Invalid = -1, // Not a GroupID, indicates a variable has not been properly set so far } /// /// Number of groups. /// public const int Count = (int)GID.NrOfGroups; // Static array of all groups. static Grp[] groups; /// /// Static constructor, creates all groups with no members. /// static Grp() { groups = new Grp[Count]; for (int i = 0; i < Count; i++) { groups[i] = new Grp((GID)i); } } /// /// Returns a Group from Id. /// /// Group Gid /// Entities.Group object reference public static Entities.Group FromId(GID gid) { int i = (int)gid; if (i >= 0 && i < Count) { return groups[i].group; } else { return null; } } ///////////////////// ^ static ^ ///////////////////// v instance v ///////////////////// /// Public properties public GID Gid { get { return (GID)group.Gid; } } public string Name { get { return group.Name; } set { group.Name = value; } } /// Private fields Entities.Group group; /// /// Instance constructor. /// /// public Grp(GID gid) { group = new Entities.Group(); this.group.Gid = (int)gid; this.group.Name = gid.ToString(); } } }