2using System.ComponentModel;
3using System.Collections.Generic;
5using System.Xml.Serialization;
18[XmlType(TypeName =
"productionRouting")]
24 private int _leadTime;
25 private bool _operationOrderConfirmed;
26 private List<WorkCenterReference> _workCenters =
new();
81 throw new ArgumentOutOfRangeException(
84 "The production-routing identifier cannot be negative.");
88 SetProperty(ref _id, value);
96 [XmlAttribute(
"itemId")]
105 throw new ArgumentOutOfRangeException(
108 "The item identifier cannot be negative.");
112 SetProperty(ref _itemId, value);
120 [XmlAttribute(
"plantId")]
129 throw new ArgumentOutOfRangeException(
132 "The plant identifier cannot be negative.");
136 if (SetProperty(ref _plantId, value))
149 [XmlAttribute(
"leadTime")]
158 throw new ArgumentOutOfRangeException(
161 "The production lead time cannot be negative.");
165 SetProperty(ref _leadTime, value);
174 [DefaultValue(
false)]
175 [XmlAttribute(
"operationOrderConfirmed")]
178 get => _operationOrderConfirmed;
179 set => SetProperty(ref _operationOrderConfirmed, value);
189 [XmlArray(
"workCenters")]
190 [XmlArrayItem(
"workCenterReference")]
197 List<WorkCenterReference> newValue =
198 value ??
new List<WorkCenterReference>();
201 if (ReferenceEquals(_workCenters, newValue))
206 _workCenters = newValue;
239 ArgumentNullException.ThrowIfNull(workCenter);
246 throw new InvalidOperationException(
247 $
"Work center {workCenter.WorkCenterId} belongs to plant " +
248 $
"{workCenter.PlantId}, whereas routing {Id} belongs " +
249 $
"to plant {PlantId}.");
253 bool alreadyExists = _workCenters.Any(
255 current.RefersToSameWorkCenter(workCenter));
259 throw new InvalidOperationException(
260 $
"Work center {workCenter.WorkCenterId} of plant " +
261 $
"{workCenter.PlantId} is already assigned " +
262 $
"to routing {Id}.");
266 _workCenters.Add(workCenter);
296 ArgumentNullException.ThrowIfNull(workCenter);
300 _workCenters.FirstOrDefault(
302 current.RefersToSameWorkCenter(workCenter));
304 if (existingReference is
null)
310 bool removed = _workCenters.Remove(existingReference);
329 _workCenters.FirstOrDefault(
331 reference.PlantId ==
PlantId &&
332 reference.WorkCenterId == workCenterId);
334 if (existingReference is
null)
349 return _workCenters.Any(
351 reference.PlantId ==
PlantId &&
352 reference.WorkCenterId == workCenterId);
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 work center.
int PlantId
Gets or sets the identifier of the plant owning the referenced work center.
bool HasConsistentWorkCenterReferences
Gets a value indicating whether all referenced work centers belong to the plant associated with this ...
List< WorkCenterReference > WorkCenters
Gets or sets the work centers used by this routing.
ProductionRouting(int id, int itemId, int plantId, int leadTime)
Initializes a production routing.
bool UsesWorkCenter(int workCenterId)
Determines whether this routing uses a given work center.
ProductionRouting()
Initializes an empty production routing.
int ItemId
Gets or sets the identifier of the item manufactured through this routing.
bool OperationOrderConfirmed
Gets or sets whether the operator confirmed that the work-center references are listed in execution o...
bool RemoveWorkCenter(int workCenterId)
Removes a work center by its identifier.
bool RemoveWorkCenter(WorkCenterReference workCenter)
Removes a work-center reference from the routing.
int LeadTime
Gets or sets the production lead time.
int Id
Gets or sets the routing identifier.
void AddWorkCenter(int workCenterId)
Adds a work center by its identifier.
int PlantId
Gets or sets the identifier of the plant in which this routing is available.
void AddWorkCenter(WorkCenterReference workCenter)
Adds a work center to the routing.