LotSizingDataModel.Core 2.0.1
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
ProductionCharacteristic.cs
Go to the documentation of this file.
1using System;
2using System.Xml.Serialization;
5
7
8/// <summary>
9/// Represents the production characteristics of an item
10/// on a specific work center.
11///
12/// Corresponds to the UML association class
13/// "Caracteristique Production" between Article and Poste de Charge.
14///
15/// Period-dependent capacity consumptions and costs will be added
16/// through other partial declarations of this class.
17/// </summary>
18[Serializable]
19[XmlType(TypeName = "productionCharacteristic")]
20public sealed partial class ProductionCharacteristic : ModelObject
21{
22 private int _itemId;
23 private WorkCenterReference _workCenter = new();
24
25 /// <summary>
26 /// Initializes an empty production characteristic.
27 ///
28 /// This public parameterless constructor is required
29 /// by <see cref="XmlSerializer"/>.
30 /// </summary>
32 {
33 }
34
35 /// <summary>
36 /// Initializes a production characteristic.
37 /// </summary>
38 /// <param name="itemId">
39 /// Identifier of the item being manufactured.
40 /// </param>
41 /// <param name="workCenter">
42 /// Reference to the work center manufacturing the item.
43 /// </param>
45 int itemId,
46 WorkCenterReference workCenter)
47 {
48 // Initialize production characteristic properties (validation occurs in setters)
49 ItemId = itemId;
50 WorkCenter = workCenter;
51 }
52
53 /// <summary>
54 /// Initializes a production characteristic from identifiers.
55 /// </summary>
56 /// <param name="itemId">
57 /// Identifier of the item being manufactured.
58 /// </param>
59 /// <param name="plantId">
60 /// Identifier of the plant owning the work center.
61 /// </param>
62 /// <param name="workCenterId">
63 /// Identifier of the work center inside the plant.
64 /// </param>
66 int itemId,
67 int plantId,
68 int workCenterId)
69 : this(
70 itemId,
72 plantId,
73 workCenterId)) // Create work center reference from IDs
74 {
75 }
76
77 /// <summary>
78 /// Gets or sets the identifier of the item manufactured
79 /// on the referenced work center.
80 /// </summary>
81 [XmlAttribute("itemId")]
82 public int ItemId
83 {
84 get => _itemId;
85 set
86 {
87 // Validate that the item identifier is non-negative
88 if (value < 0)
89 {
90 throw new ArgumentOutOfRangeException(
91 nameof(value),
92 value,
93 "The item identifier cannot be negative.");
94 }
95
96 // Update the backing field and notify property change if value differs
97 SetProperty(ref _itemId, value);
98 }
99 }
100
101 /// <summary>
102 /// Gets or sets the referenced work center.
103 ///
104 /// The reference contains both the plant identifier
105 /// and the work-center identifier.
106 /// </summary>
107 [XmlElement("workCenter")]
109 {
110 get => _workCenter;
111 set
112 {
113 // Validate that the work center reference is not null
114 ArgumentNullException.ThrowIfNull(value);
115
116 // Update the backing field and notify property change if value differs
117 SetProperty(ref _workCenter, value);
118 }
119 }
120
121 /// <summary>
122 /// Gets the identifier of the plant owning the work center.
123 ///
124 /// This convenience property is calculated and is not serialized.
125 /// </summary>
126 [XmlIgnore]
127 public int PlantId => WorkCenter.PlantId;
128
129 /// <summary>
130 /// Gets the identifier of the referenced work center.
131 ///
132 /// This convenience property is calculated and is not serialized.
133 /// </summary>
134 [XmlIgnore]
135 public int WorkCenterId => WorkCenter.WorkCenterId;
136
137 /// <summary>
138 /// Determines whether this object represents the same
139 /// item/work-center association as another object.
140 /// </summary>
143 {
144 // Compare both item ID and work center reference for equality
145 return other is not null
146 && ItemId == other.ItemId
147 && WorkCenter.RefersToSameWorkCenter(
148 other.WorkCenter);
149 }
150
151 /// <summary>
152 /// Determines whether this production characteristic
153 /// concerns a specified item.
154 /// </summary>
155 public bool ConcernsItem(int itemId)
156 {
157 return ItemId == itemId;
158 }
159
160 /// <summary>
161 /// Determines whether this production characteristic
162 /// concerns a specified work center.
163 /// </summary>
165 int plantId,
166 int workCenterId)
167 {
168 // Check if the work center reference matches both plant and work center IDs
169 return WorkCenter.PlantId == plantId
170 && WorkCenter.WorkCenterId == workCenterId;
171 }
172}
Base class for model objects that notify listeners when one of their properties changes.
Represents a serializable reference to a work center.
WorkCenterReference WorkCenter
Gets or sets the referenced work center.
int WorkCenterId
Gets the identifier of the referenced work center.
ProductionCharacteristic()
Initializes an empty production characteristic.
ProductionCharacteristic(int itemId, WorkCenterReference workCenter)
Initializes a production characteristic.
ProductionCharacteristic(int itemId, int plantId, int workCenterId)
Initializes a production characteristic from identifiers.
int PlantId
Gets the identifier of the plant owning the work center.
bool RefersToSameAssociation(ProductionCharacteristic? other)
Determines whether this object represents the same item/work-center association as another object.
bool ConcernsItem(int itemId)
Determines whether this production characteristic concerns a specified item.
int ItemId
Gets or sets the identifier of the item manufactured on the referenced work center.
bool ConcernsWorkCenter(int plantId, int workCenterId)
Determines whether this production characteristic concerns a specified work center.