2using System.Collections.Generic;
4using System.Xml.Serialization;
17[XmlType(TypeName =
"productionRouting")]
23 private int _leadTime;
24 private List<WorkCenterReference> _workCenters =
new();
79 throw new ArgumentOutOfRangeException(
82 "The production-routing identifier cannot be negative.");
86 SetProperty(ref _id, value);
94 [XmlAttribute(
"itemId")]
103 throw new ArgumentOutOfRangeException(
106 "The item identifier cannot be negative.");
110 SetProperty(ref _itemId, value);
118 [XmlAttribute(
"plantId")]
127 throw new ArgumentOutOfRangeException(
130 "The plant identifier cannot be negative.");
134 if (SetProperty(ref _plantId, value))
147 [XmlAttribute(
"leadTime")]
156 throw new ArgumentOutOfRangeException(
159 "The production lead time cannot be negative.");
163 SetProperty(ref _leadTime, value);
174 [XmlArray(
"workCenters")]
175 [XmlArrayItem(
"workCenterReference")]
182 List<WorkCenterReference> newValue =
183 value ??
new List<WorkCenterReference>();
186 if (ReferenceEquals(_workCenters, newValue))
191 _workCenters = newValue;
224 ArgumentNullException.ThrowIfNull(workCenter);
231 throw new InvalidOperationException(
232 $
"Work center {workCenter.WorkCenterId} belongs to plant " +
233 $
"{workCenter.PlantId}, whereas routing {Id} belongs " +
234 $
"to plant {PlantId}.");
238 bool alreadyExists = _workCenters.Any(
240 current.RefersToSameWorkCenter(workCenter));
244 throw new InvalidOperationException(
245 $
"Work center {workCenter.WorkCenterId} of plant " +
246 $
"{workCenter.PlantId} is already assigned " +
247 $
"to routing {Id}.");
251 _workCenters.Add(workCenter);
281 ArgumentNullException.ThrowIfNull(workCenter);
285 _workCenters.FirstOrDefault(
287 current.RefersToSameWorkCenter(workCenter));
289 if (existingReference is
null)
295 bool removed = _workCenters.Remove(existingReference);
314 _workCenters.FirstOrDefault(
316 reference.PlantId ==
PlantId &&
317 reference.WorkCenterId == workCenterId);
319 if (existingReference is
null)
334 return _workCenters.Any(
336 reference.PlantId ==
PlantId &&
337 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 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.