|
| 1 | +/* |
| 2 | +MIT License |
| 3 | +
|
| 4 | +Copyright (c) 2016 Kent Randall |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +of this software and associated documentation files (the "Software"), to deal |
| 8 | +in the Software without restriction, including without limitation the rights |
| 9 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +copies of the Software, and to permit persons to whom the Software is |
| 11 | +furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in all |
| 14 | +copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +SOFTWARE. |
| 23 | +*/ |
| 24 | + |
| 25 | + |
| 26 | +using System; |
| 27 | + |
| 28 | +namespace Point85.ShiftSharp.Schedule |
| 29 | +{ |
| 30 | + /// <summary> |
| 31 | + /// Class Named represents a named object such as a Shift or Team. |
| 32 | + /// </summary> |
| 33 | + public abstract class Named |
| 34 | + { |
| 35 | + // name |
| 36 | + private string name; |
| 37 | + |
| 38 | + // description |
| 39 | + private string description; |
| 40 | + |
| 41 | + // database primary key |
| 42 | + private int primaryKey; |
| 43 | + |
| 44 | + protected Named() |
| 45 | + { |
| 46 | + |
| 47 | + } |
| 48 | + |
| 49 | + protected Named(string name, string description) |
| 50 | + { |
| 51 | + SetName(name); |
| 52 | + SetDescription(description); |
| 53 | + } |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Get name |
| 57 | + /// </summary> |
| 58 | + /// <returns>Name</returns> |
| 59 | + public string GetName() |
| 60 | + { |
| 61 | + return name; |
| 62 | + } |
| 63 | + |
| 64 | + /// <summary> |
| 65 | + /// Set name |
| 66 | + /// </summary> |
| 67 | + /// <param name="name">Name</param> |
| 68 | + public void SetName(string name) |
| 69 | + { |
| 70 | + if (name == null) |
| 71 | + { |
| 72 | + throw new Exception(WorkSchedule.GetMessage("name.not.defined")); |
| 73 | + } |
| 74 | + this.name = name; |
| 75 | + } |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// Get description |
| 79 | + /// </summary> |
| 80 | + /// <returns>Description</returns> |
| 81 | + public string GetDescription() |
| 82 | + { |
| 83 | + return description; |
| 84 | + } |
| 85 | + |
| 86 | + /// <summary> |
| 87 | + /// Set description |
| 88 | + /// </summary> |
| 89 | + /// <param name="description"> Description</param> |
| 90 | + public void SetDescription(string description) |
| 91 | + { |
| 92 | + this.description = description; |
| 93 | + } |
| 94 | + |
| 95 | + /// <summary> |
| 96 | + /// Check for equality |
| 97 | + /// </summary> |
| 98 | + /// <param name="other">other Quantity</param> |
| 99 | + /// <returns>True if equal</returns> |
| 100 | + public override bool Equals(Object other) |
| 101 | + { |
| 102 | + |
| 103 | + if (other == null || GetType() != other.GetType()) |
| 104 | + { |
| 105 | + return false; |
| 106 | + } |
| 107 | + |
| 108 | + return GetName().Equals(((Named)other).GetName()); |
| 109 | + } |
| 110 | + |
| 111 | + /// <summary> |
| 112 | + /// Compute a hash code |
| 113 | + /// </summary> |
| 114 | + /// <returns>Hash code</returns> |
| 115 | + public override int GetHashCode() |
| 116 | + { |
| 117 | + return GetName().GetHashCode(); |
| 118 | + } |
| 119 | + |
| 120 | + /// <summary> |
| 121 | + /// Get a string representation of a named object |
| 122 | + /// </summary> |
| 123 | + /// <returns>String value</returns> |
| 124 | + public override string ToString() |
| 125 | + { |
| 126 | + return GetName() + " (" + GetDescription() + ")"; |
| 127 | + } |
| 128 | + } |
| 129 | +} |
0 commit comments