Пример #1
0
        /// <summary>
        /// Sets the alternate version of the <see cref="BusinessObject"/>.
        /// </summary>
        /// <param name="alternate"><see cref="BusinessObject"/> that is to be considered as the alternate one.</param>
        public override void SetAlternateVersion(IBusinessObject alternate)
        {
            base.SetAlternateVersion(alternate);

            WarehouseDocumentLine line = (WarehouseDocumentLine)alternate;

            if (this.IncomeOutcomeRelations != null)
            {
                this.IncomeOutcomeRelations.SetAlternateVersion(line.IncomeOutcomeRelations);
            }

            if (this.CommercialWarehouseRelations != null)
            {
                this.CommercialWarehouseRelations.SetAlternateVersion(line.CommercialWarehouseRelations);
            }

            if (this.CommercialWarehouseValuations != null)
            {
                this.CommercialWarehouseValuations.SetAlternateVersion(line.CommercialWarehouseValuations);
            }

            if (this.Attributes != null)
            {
                this.Attributes.SetAlternateVersion(line.Attributes);
            }
        }
Пример #2
0
        /// <summary>
        /// Checks if the object has changed against <see cref="BusinessObject.AlternateVersion"/> and updates its own <see cref="BusinessObject.Status"/>.
        /// </summary>
        /// <param name="isNew">Value indicating whether the <see cref="BusinessObject"/> should be considered as the new one or the old one.</param>
        public override void UpdateStatus(bool isNew)
        {
            base.UpdateStatus(isNew);

            WarehouseDocument parent = (WarehouseDocument)this.Parent;

            WarehouseDocumentLine alternateLine = this.AlternateVersion as WarehouseDocumentLine;

            if (this.IncomeOutcomeRelations != null)
            {
                if (this.Status == BusinessObjectStatus.Deleted)
                {
                    this.IncomeOutcomeRelations.SetChildrenStatus(BusinessObjectStatus.Deleted);

                    //wywalamy wszystkie shifty ktore byly powiazane z ta pozycja bo zostana one usuniete w
                    //procedurze p_deleteWarehouseDocumentLine

                    ShiftTransaction st = ((WarehouseDocument)this.Parent).ShiftTransaction;

                    List <Shift> shiftsToDelete = new List <Shift>();

                    if (st != null)
                    {
                        foreach (var shift in st.Shifts.Children.Where(s => s.RelatedWarehouseDocumentLine == this))
                        {
                            //shift.Status = BusinessObjectStatus.Deleted;
                            shiftsToDelete.Add(shift);
                        }

                        foreach (var shift in shiftsToDelete)
                        {
                            st.Shifts.Remove(shift);
                        }

                        shiftsToDelete.Clear();
                    }

                    if (alternateLine != null)
                    {
                        WarehouseDocument alternateDocument = (WarehouseDocument)alternateLine.Parent;

                        if (alternateDocument.ShiftTransaction != null)
                        {
                            foreach (var shift in alternateDocument.ShiftTransaction.Shifts.Children.Where(ss => ss.RelatedWarehouseDocumentLine == alternateLine))
                            {
                                shiftsToDelete.Add(shift);
                            }

                            foreach (var shift in shiftsToDelete)
                            {
                                st.Shifts.Remove(shift);
                            }

                            shiftsToDelete.Clear();
                        }
                    }

                    //wywalamy wszystkie commercialWarehouseValuation
                    this.CommercialWarehouseValuations.RemoveAll();
                }
                else if (this.Status == BusinessObjectStatus.Modified &&
                         parent.WarehouseDirection == WarehouseDirection.Outcome &&
                         DictionaryMapper.Instance.GetWarehouse(this.WarehouseId).ValuationMethod == ValuationMethod.Fifo)
                {
                    ((WarehouseDocumentLine)this.AlternateVersion).IncomeOutcomeRelations.SetChildrenStatus(BusinessObjectStatus.Deleted);
                    this.IncomeOutcomeRelations.RemoveAll();
                }
                else if (this.IncomeOutcomeRelations != null)
                {
                    this.IncomeOutcomeRelations.UpdateStatus(isNew);
                }
            }

            if (this.CommercialWarehouseValuations != null)
            {
                this.CommercialWarehouseValuations.UpdateStatus(isNew);
            }

            if (this.CommercialWarehouseRelations != null)
            {
                this.CommercialWarehouseRelations.UpdateStatus(isNew);
            }

            if (this.Attributes != null)
            {
                this.Attributes.UpdateStatus(isNew);
            }

            //If RelatedLinesChangedPolicy is valueOnly, quantity and item cannot be changed
            if (parent.DocumentType.WarehouseDocumentOptions.RelatedLinesChangePolicy == RelatedLinesChangePolicy.ValueOnly)
            {
                bool throwException = false;

                if (alternateLine == null && !parent.IsNew && this.IsNew)
                {
                    throwException = true;
                }

                if (alternateLine != null &&
                    (this.Quantity != alternateLine.Quantity ||
                     this.ItemId != alternateLine.ItemId ||
                     this.ItemName != alternateLine.ItemName ||
                     this.ItemCode != alternateLine.ItemCode))
                {
                    throwException = true;
                }

                if (throwException)
                {
                    throw new ClientException(ClientExceptionId.OnlyLineValuesCanBeEdited);
                }
            }
        }