/// <summary> /// Validates the <see cref="BusinessObject"/>. /// </summary> public override void Validate() { base.Validate(); RelatedLinesChangePolicy relatedLinesChangePolicy = RelatedLinesChangePolicy.Unknown; WarehouseDocument warehouseParent = ((WarehouseDocument)this.Parent); if (warehouseParent != null) { relatedLinesChangePolicy = warehouseParent.DocumentType.WarehouseDocumentOptions.RelatedLinesChangePolicy; } bool skipQuantityValidation = ((WarehouseDocument)this.Parent).SkipQuantityValidation; if (!skipQuantityValidation && relatedLinesChangePolicy != RelatedLinesChangePolicy.ValueOnly) { if (this.Quantity <= 0) { throw new ClientException(ClientExceptionId.QuantityBelowOrEqualZero, null, "itemName:" + this.ItemName); } decimal quantityOnOrderRelation = this.CommercialWarehouseRelations.Children.Where(r => r.IsOrderRelation).Sum(rr => rr.Quantity); if (quantityOnOrderRelation > this.Quantity) { throw new ClientException(ClientExceptionId.UnableToEditOutcomeWarehouseDocument3); } } WarehouseDirection direction = ((WarehouseDocument)this.Parent).WarehouseDirection; if (relatedLinesChangePolicy != RelatedLinesChangePolicy.ValueOnly && direction == WarehouseDirection.Income && this.Price < 0) { throw new ClientException(ClientExceptionId.LinePriceBelowOrEqualZero); } if (this.IncomeOutcomeRelations != null) { this.IncomeOutcomeRelations.Validate(); } if (this.CommercialWarehouseValuations != null) { this.CommercialWarehouseValuations.Validate(); } if (this.CommercialWarehouseRelations != null) { this.CommercialWarehouseRelations.Validate(); } if (this.Attributes != null) { this.Attributes.Validate(); } }
/// <summary> /// Recursively creates new children (BusinessObjects) and loads settings from provided xml. /// </summary> /// <param name="element">Xml element to attach.</param> public override void Deserialize(XElement element) { base.Deserialize(element); //Nie dopisuj atrybutu DisableLinesChange jesli skongigurowane inaczej RelatedLinesChangePolicy relatedLinesChangePolicy = RelatedLinesChangePolicy.Unknown; if (((WarehouseDocument)this.Parent) != null) { relatedLinesChangePolicy = ((WarehouseDocument)this.Parent).DocumentType.WarehouseDocumentOptions.RelatedLinesChangePolicy; } if (relatedLinesChangePolicy != RelatedLinesChangePolicy.ValueOnly) { if (this.CommercialWarehouseRelations.HasChildren && this.Parent != null) { (this.Parent as Document).DisableLinesChange = DisableDocumentChangeReason.LINES_RELATED_COMMERCIAL_DOCUMENT; } if (this.IncomeOutcomeRelations.HasChildren && this.Parent != null && ((WarehouseDocument)this.Parent).WarehouseDirection == WarehouseDirection.Income) { (this.Parent as Document).DisableLinesChange = DisableDocumentChangeReason.LINES_RELATED_OUTCOMES; } } }