LotSizingDataModel.Core 2.0.1
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
DistributionCenterSourcing.cs
Go to the documentation of this file.
1using System;
2using System.Xml.Serialization;
5
7
8/// <summary>
9/// Represents the ability of a distribution center to source
10/// a given item from a given warehouse inventory.
11///
12/// Corresponds to the UML association class "Achat"
13/// between Stock and Centre de distribution.
14///
15/// The referenced inventory is identified by:
16/// - the item identifier;
17/// - the warehouse reference.
18/// </summary>
19[Serializable]
20[XmlType(TypeName = "distributionCenterSourcing")]
21public sealed partial class DistributionCenterSourcing : ModelObject
22{
23 private int _distributionCenterId;
24 private int _itemId;
25 private WarehouseReference _warehouse = new();
26
27 /// <summary>
28 /// Initializes an empty distribution-center sourcing relationship.
29 ///
30 /// This public parameterless constructor is required
31 /// by <see cref="XmlSerializer"/>.
32 /// </summary>
34 {
35 }
36
37 /// <summary>
38 /// Initializes a distribution-center sourcing relationship.
39 /// </summary>
40 /// <param name="distributionCenterId">
41 /// Identifier of the distribution center.
42 /// </param>
43 /// <param name="itemId">
44 /// Identifier of the item obtained from the inventory.
45 /// </param>
46 /// <param name="warehouse">
47 /// Reference to the warehouse holding the inventory.
48 /// </param>
50 int distributionCenterId,
51 int itemId,
52 WarehouseReference warehouse)
53 {
54 // Initialize sourcing properties (validation occurs in setters)
55 DistributionCenterId = distributionCenterId;
56 ItemId = itemId;
57 Warehouse = warehouse;
58 }
59
60 /// <summary>
61 /// Gets or sets the identifier of the distribution center
62 /// that can obtain the item from the referenced inventory.
63 /// </summary>
64 [XmlAttribute("distributionCenterId")]
66 {
67 get => _distributionCenterId;
68 set
69 {
70 // Validate that the distribution center identifier is non-negative
71 if (value < 0)
72 {
73 throw new ArgumentOutOfRangeException(
74 nameof(value),
75 value,
76 "The distribution-center identifier cannot be negative.");
77 }
78
79 // Update the backing field and notify property change if value differs
80 SetProperty(
81 ref _distributionCenterId,
82 value);
83 }
84 }
85
86 /// <summary>
87 /// Gets or sets the identifier of the item contained
88 /// in the referenced inventory.
89 /// </summary>
90 [XmlAttribute("itemId")]
91 public int ItemId
92 {
93 get => _itemId;
94 set
95 {
96 // Validate that the item identifier is non-negative
97 if (value < 0)
98 {
99 throw new ArgumentOutOfRangeException(
100 nameof(value),
101 value,
102 "The item identifier cannot be negative.");
103 }
104
105 // Update the backing field and notify property change if value differs
106 SetProperty(ref _itemId, value);
107 }
108 }
109
110 /// <summary>
111 /// Gets or sets the warehouse holding the inventory
112 /// from which the distribution center can obtain the item.
113 /// </summary>
114 [XmlElement("warehouse")]
116 {
117 get => _warehouse;
118 set
119 {
120 // Ensure the warehouse reference is never null
121 ArgumentNullException.ThrowIfNull(value);
122
123 // Update and notify dependent properties if the reference changed
124 if (SetProperty(ref _warehouse, value))
125 {
128 }
129 }
130 }
131
132 /// <summary>
133 /// Gets the kind of referenced warehouse.
134 ///
135 /// This convenience property is calculated
136 /// and is not serialized.
137 /// </summary>
138 [XmlIgnore]
140 Warehouse.Kind;
141
142 /// <summary>
143 /// Gets the identifier used to reference the warehouse.
144 ///
145 /// For a standalone warehouse, this is its own identifier.
146 /// For a plant warehouse, this is the owning-plant identifier.
147 /// </summary>
148 [XmlIgnore]
150 Warehouse.ReferenceId;
151
152 /// <summary>
153 /// Creates a sourcing relationship involving
154 /// a standalone warehouse.
155 /// </summary>
156 public static DistributionCenterSourcing
158 int distributionCenterId,
159 int itemId,
160 int standaloneWarehouseId)
161 {
162 // Factory method that builds a warehouse reference for a standalone warehouse
164 distributionCenterId,
165 itemId,
167 standaloneWarehouseId));
168 }
169
170 /// <summary>
171 /// Creates a sourcing relationship involving
172 /// a warehouse attached to a plant.
173 /// </summary>
174 public static DistributionCenterSourcing
176 int distributionCenterId,
177 int itemId,
178 int plantId)
179 {
180 // Factory method that builds a warehouse reference for a plant warehouse
182 distributionCenterId,
183 itemId,
185 plantId));
186 }
187
188 /// <summary>
189 /// Determines whether this object represents the same
190 /// distribution-center/inventory relationship as another object.
191 /// </summary>
194 {
195 // Compare distribution center, item, and warehouse reference for equality
196 return other is not null
198 other.DistributionCenterId
199 && ItemId == other.ItemId
200 && Warehouse.Kind == other.Warehouse.Kind
201 && Warehouse.ReferenceId ==
203 }
204
205 /// <summary>
206 /// Determines whether this relationship concerns
207 /// the specified distribution center.
208 /// </summary>
210 int distributionCenterId)
211 {
212 // Check if the distribution center ID matches
213 return DistributionCenterId ==
214 distributionCenterId;
215 }
216
217 /// <summary>
218 /// Determines whether this relationship concerns
219 /// the specified item.
220 /// </summary>
221 public bool ConcernsItem(int itemId)
222 {
223 // Check if the item ID matches
224 return ItemId == itemId;
225 }
226
227 /// <summary>
228 /// Determines whether this relationship concerns
229 /// the specified warehouse inventory.
230 /// </summary>
231 public bool ConcernsInventory(
232 int itemId,
233 WarehouseReference warehouse)
234 {
235 // Ensure the warehouse parameter is not null
236 ArgumentNullException.ThrowIfNull(warehouse);
237
238 // Check if both item and warehouse reference match
239 return ItemId == itemId
240 && Warehouse.Kind == warehouse.Kind
241 && Warehouse.ReferenceId ==
242 warehouse.ReferenceId;
243 }
244}
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.
Represents the ability of a distribution center to source a given item from a given warehouse invento...
bool ConcernsItem(int itemId)
Determines whether this relationship concerns the specified item.
static DistributionCenterSourcing FromPlantWarehouse(int distributionCenterId, int itemId, int plantId)
Creates a sourcing relationship involving a warehouse attached to a plant.
bool ConcernsInventory(int itemId, WarehouseReference warehouse)
Determines whether this relationship concerns the specified warehouse inventory.
int DistributionCenterId
Gets or sets the identifier of the distribution center that can obtain the item from the referenced i...
bool RefersToSameSourcing(DistributionCenterSourcing? other)
Determines whether this object represents the same distribution-center/inventory relationship as anot...
static DistributionCenterSourcing FromStandaloneWarehouse(int distributionCenterId, int itemId, int standaloneWarehouseId)
Creates a sourcing relationship involving a standalone warehouse.
DistributionCenterSourcing()
Initializes an empty distribution-center sourcing relationship.
DistributionCenterSourcing(int distributionCenterId, int itemId, WarehouseReference warehouse)
Initializes a distribution-center sourcing relationship.
WarehouseReference Warehouse
Gets or sets the warehouse holding the inventory from which the distribution center can obtain the it...
int WarehouseReferenceId
Gets the identifier used to reference the warehouse.
int ItemId
Gets or sets the identifier of the item contained in the referenced inventory.
WarehouseReferenceKind WarehouseKind
Gets the kind of referenced warehouse.
bool ConcernsDistributionCenter(int distributionCenterId)
Determines whether this relationship concerns the specified distribution center.
WarehouseReferenceKind
Identifies the type of warehouse referenced by a relationship.