LotSizingDataModel.Core 2.0.1
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
SupplierDelivery.cs
Go to the documentation of this file.
1using System;
2using System.Xml.Serialization;
5
7
8/// <summary>
9/// Represents the ability of a supplier to deliver a given item
10/// to a given warehouse inventory.
11///
12/// Corresponds to the UML association class "Livraison"
13/// between Stock and Fournisseur.
14///
15/// The referenced inventory is identified by:
16/// - the item identifier;
17/// - the warehouse reference.
18/// </summary>
19[Serializable]
20[XmlType(TypeName = "supplierDelivery")]
21public sealed partial class SupplierDelivery : ModelObject
22{
23 private int _supplierId;
24 private int _itemId;
25 private WarehouseReference _warehouse = new();
26 private int _leadTime;
27
28 /// <summary>
29 /// Initializes an empty supplier-delivery relationship.
30 ///
31 /// This public parameterless constructor is required
32 /// by <see cref="XmlSerializer"/>.
33 /// </summary>
35 {
36 }
37
38 /// <summary>
39 /// Initializes a supplier-delivery relationship.
40 /// </summary>
41 /// <param name="supplierId">
42 /// Identifier of the supplier.
43 /// </param>
44 /// <param name="itemId">
45 /// Identifier of the delivered item.
46 /// </param>
47 /// <param name="warehouse">
48 /// Reference to the warehouse receiving the item.
49 /// </param>
50 /// <param name="leadTime">
51 /// Delivery lead time, expressed in planning periods.
52 /// Corresponds to l[f] in the source model.
53 /// </param>
55 int supplierId,
56 int itemId,
57 WarehouseReference warehouse,
58 int leadTime)
59 {
60 // Initialize delivery properties (validation occurs in setters)
61 SupplierId = supplierId;
62 ItemId = itemId;
63 Warehouse = warehouse;
64 LeadTime = leadTime;
65 }
66
67 /// <summary>
68 /// Gets or sets the identifier of the supplier.
69 ///
70 /// Corresponds to index f in the source model.
71 /// </summary>
72 [XmlAttribute("supplierId")]
73 public int SupplierId
74 {
75 get => _supplierId;
76 set
77 {
78 // Validate that the supplier identifier is non-negative
79 if (value < 0)
80 {
81 throw new ArgumentOutOfRangeException(
82 nameof(value),
83 value,
84 "The supplier identifier cannot be negative.");
85 }
86
87 // Update the backing field and notify property change if value differs
88 SetProperty(ref _supplierId, value);
89 }
90 }
91
92 /// <summary>
93 /// Gets or sets the identifier of the delivered item.
94 /// </summary>
95 [XmlAttribute("itemId")]
96 public int ItemId
97 {
98 get => _itemId;
99 set
100 {
101 // Validate that the item identifier is non-negative
102 if (value < 0)
103 {
104 throw new ArgumentOutOfRangeException(
105 nameof(value),
106 value,
107 "The item identifier cannot be negative.");
108 }
109
110 // Update the backing field and notify property change if value differs
111 SetProperty(ref _itemId, value);
112 }
113 }
114
115 /// <summary>
116 /// Gets or sets the warehouse receiving the item.
117 ///
118 /// For a plant warehouse, the warehouse is referenced through
119 /// the identifier of its owning plant.
120 /// </summary>
121 [XmlElement("warehouse")]
123 {
124 get => _warehouse;
125 set
126 {
127 // Ensure the warehouse reference is never null
128 ArgumentNullException.ThrowIfNull(value);
129
130 // Update and notify dependent properties if the reference changed
131 if (SetProperty(ref _warehouse, value))
132 {
135 }
136 }
137 }
138
139 /// <summary>
140 /// Gets or sets the supplier-delivery lead time.
141 ///
142 /// Corresponds to l[f] in the UML model.
143 /// The value is expressed as a number of planning periods.
144 /// </summary>
145 [XmlAttribute("leadTime")]
146 public int LeadTime
147 {
148 get => _leadTime;
149 set
150 {
151 // Validate that the lead time is non-negative
152 if (value < 0)
153 {
154 throw new ArgumentOutOfRangeException(
155 nameof(value),
156 value,
157 "The supplier-delivery lead time cannot be negative.");
158 }
159
160 // Update the backing field and notify property change if value differs
161 SetProperty(ref _leadTime, value);
162 }
163 }
164
165 /// <summary>
166 /// Gets the kind of referenced warehouse.
167 ///
168 /// This calculated property is not serialized.
169 /// </summary>
170 [XmlIgnore]
172 Warehouse.Kind;
173
174 /// <summary>
175 /// Gets the identifier used to reference the warehouse.
176 ///
177 /// This calculated property is not serialized.
178 /// </summary>
179 [XmlIgnore]
181 Warehouse.ReferenceId;
182
183 /// <summary>
184 /// Creates a delivery relationship involving
185 /// a standalone warehouse.
186 /// </summary>
188 int supplierId,
189 int itemId,
190 int standaloneWarehouseId,
191 int leadTime)
192 {
193 // Factory method that builds a warehouse reference for a standalone warehouse
194 return new SupplierDelivery(
195 supplierId,
196 itemId,
198 standaloneWarehouseId),
199 leadTime);
200 }
201
202 /// <summary>
203 /// Creates a delivery relationship involving
204 /// a warehouse attached to a plant.
205 /// </summary>
207 int supplierId,
208 int itemId,
209 int plantId,
210 int leadTime)
211 {
212 // Factory method that builds a warehouse reference for a plant warehouse
213 return new SupplierDelivery(
214 supplierId,
215 itemId,
217 plantId),
218 leadTime);
219 }
220
221 /// <summary>
222 /// Determines whether this object represents the same
223 /// supplier/inventory relationship as another object.
224 /// </summary>
226 SupplierDelivery? other)
227 {
228 // Compare supplier, item, and warehouse reference for equality
229 return other is not null
230 && SupplierId == other.SupplierId
231 && ItemId == other.ItemId
232 && Warehouse.Kind == other.Warehouse.Kind
233 && Warehouse.ReferenceId ==
235 }
236
237 /// <summary>
238 /// Determines whether this delivery concerns
239 /// the specified supplier.
240 /// </summary>
241 public bool ConcernsSupplier(int supplierId)
242 {
243 // Check if the supplier ID matches
244 return SupplierId == supplierId;
245 }
246
247 /// <summary>
248 /// Determines whether this delivery concerns
249 /// the specified item.
250 /// </summary>
251 public bool ConcernsItem(int itemId)
252 {
253 // Check if the item ID matches
254 return ItemId == itemId;
255 }
256
257 /// <summary>
258 /// Determines whether this delivery concerns
259 /// the specified inventory.
260 /// </summary>
261 public bool ConcernsInventory(
262 int itemId,
263 WarehouseReference warehouse)
264 {
265 // Ensure the warehouse parameter is not null
266 ArgumentNullException.ThrowIfNull(warehouse);
267
268 // Check if both item and warehouse reference match
269 return ItemId == itemId
270 && Warehouse.Kind == warehouse.Kind
271 && Warehouse.ReferenceId ==
272 warehouse.ReferenceId;
273 }
274}
Base class for model objects that notify listeners when one of their properties changes.
virtual void OnPropertyChanged([CallerMemberName] string? propertyName=null)
Raises the PropertyChanged event.
Represents a serializable reference to a warehouse.
int ReferenceId
Gets or sets the referenced identifier.
static WarehouseReference ForPlantWarehouse(int plantId)
Creates a reference to the warehouse attached to a plant.
static WarehouseReference ForStandaloneWarehouse(int warehouseId)
Creates a reference to a standalone warehouse.
WarehouseReferenceKind WarehouseKind
Gets the kind of referenced warehouse.
bool ConcernsItem(int itemId)
Determines whether this delivery concerns the specified item.
int SupplierId
Gets or sets the identifier of the supplier.
SupplierDelivery(int supplierId, int itemId, WarehouseReference warehouse, int leadTime)
Initializes a supplier-delivery relationship.
int WarehouseReferenceId
Gets the identifier used to reference the warehouse.
int ItemId
Gets or sets the identifier of the delivered item.
bool RefersToSameDelivery(SupplierDelivery? other)
Determines whether this object represents the same supplier/inventory relationship as another object.
static SupplierDelivery ToStandaloneWarehouse(int supplierId, int itemId, int standaloneWarehouseId, int leadTime)
Creates a delivery relationship involving a standalone warehouse.
int LeadTime
Gets or sets the supplier-delivery lead time.
static SupplierDelivery ToPlantWarehouse(int supplierId, int itemId, int plantId, int leadTime)
Creates a delivery relationship involving a warehouse attached to a plant.
SupplierDelivery()
Initializes an empty supplier-delivery relationship.
bool ConcernsInventory(int itemId, WarehouseReference warehouse)
Determines whether this delivery concerns the specified inventory.
WarehouseReference Warehouse
Gets or sets the warehouse receiving the item.
bool ConcernsSupplier(int supplierId)
Determines whether this delivery concerns the specified supplier.
WarehouseReferenceKind
Identifies the type of warehouse referenced by a relationship.