private void SelectedItem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var rec = sender as CreditorOrderLineClient; switch (e.PropertyName) { case "Item": var selectedItem = (InvItem)items?.Get(rec._Item); if (selectedItem != null) { if (selectedItem._AlternativeItem != null && selectedItem._UseAlternative == UseAlternativeItem.Always) { var altItem = (InvItem)items.Get(selectedItem._AlternativeItem); if (altItem != null && altItem._AlternativeItem == null) { rec.Item = selectedItem._AlternativeItem; return; } } var _priceLookup = this.PriceLookup; this.PriceLookup = null; // avoid that we call priceupdated in property change on Qty var Comp = api.CompanyEntity; if (selectedItem._PurchaseQty != 0d) { rec.Qty = selectedItem._PurchaseQty; } else if (Comp._PurchaseLineOne) { rec.Qty = 1d; } rec.SetItemValues(selectedItem, Comp._PurchaseLineStorage); if (_priceLookup != null) { this.PriceLookup = _priceLookup; _priceLookup.SetPriceFromItem(rec, selectedItem); } else if (selectedItem._PurchasePrice != 0 && Comp.SameCurrency(selectedItem._PurchaseCurrency, (byte)this.Order._Currency)) { rec.Price = selectedItem._PurchasePrice; } else { rec.Price = (exchangeRate == 0d) ? selectedItem._CostPrice : Math.Round(selectedItem._CostPrice * exchangeRate, 2); } if (selectedItem._StandardVariant != rec.standardVariant) { rec.Variant1 = null; rec.Variant2 = null; rec.variant2Source = null; rec.NotifyPropertyChanged("Variant2Source"); } setVariant(rec, false); TableField.SetUserFieldsFromRecord(selectedItem, rec); if (selectedItem._Blocked) { UtilDisplay.ShowErrorCode(ErrorCodes.ItemIsOnHold, null); } } break; case "Qty": if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices) { this.PriceLookup.GetCustomerPrice(rec, false); } break; case "Warehouse": if (warehouse != null) { var selected = (InvWarehouse)warehouse.Get(rec._Warehouse); setLocation(selected, (CreditorOrderLineClient)rec); } break; case "Location": if (string.IsNullOrEmpty(rec._Warehouse)) { rec._Location = null; } break; case "EAN": DebtorOfferLines.FindOnEAN(rec, this.items, api, this.PriceLookup); break; case "Total": RecalculateAmount(); break; case "Variant1": if (rec._Variant1 != null) { setVariant(rec, true); } if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices) { this.PriceLookup.GetCustomerPrice(rec, false); } break; case "Variant2": case "Variant3": case "Variant4": case "Variant5": if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices) { this.PriceLookup.GetCustomerPrice(rec, false); } break; case "Project": if (ProjectCache != null) { var selected = (ProjectClient)ProjectCache.Get(rec._Project); setTask(selected, rec); } break; case "Task": if (string.IsNullOrEmpty(rec._Project)) { rec._Task = null; } break; } }
private void ProjInvProposedLineGrid_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var rec = sender as ProjectInvoiceProposalLineClient; switch (e.PropertyName) { case "Item": var selectedItem = (InvItem)items?.Get(rec._Item); if (selectedItem != null) { if (selectedItem._AlternativeItem != null && selectedItem._UseAlternative == UseAlternativeItem.Always) { var altItem = (InvItem)items.Get(selectedItem._AlternativeItem); if (altItem != null && altItem._AlternativeItem == null) { rec.Item = selectedItem._AlternativeItem; return; } } var _priceLookup = this.PriceLookup; this.PriceLookup = null; // avoid that we call priceupdated in property change on Qty if (selectedItem._SalesQty != 0d) { rec.Qty = selectedItem._SalesQty; } else if (api.CompanyEntity._OrderLineOne) { rec.Qty = 1d; } rec.SetItemValues(selectedItem, api.CompanyEntity._OrderLineStorage); this.PriceLookup = _priceLookup; _priceLookup?.SetPriceFromItem(rec, selectedItem); if (company._InvoiceUseQtyNow) { rec.QtyNow = rec._Qty; } if (selectedItem._StandardVariant != rec.standardVariant) { rec.Variant1 = null; rec.Variant2 = null; rec.variant2Source = null; rec.NotifyPropertyChanged("Variant2Source"); } setVariant(rec, false); TableField.SetUserFieldsFromRecord(selectedItem, rec); if (selectedItem._Blocked) { UtilDisplay.ShowErrorCode(ErrorCodes.ItemIsOnHold, null); } globalEvents.NotifyRefreshViewer(NameOfControl, rec); } break; case "Qty": if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices) { this.PriceLookup.GetCustomerPrice(rec, false); } if (company._InvoiceUseQtyNow) { rec.QtyNow = rec._Qty; } break; case "Subtotal": case "Total": Dispatcher.BeginInvoke(new Action(() => { RecalculateAmount(); })); break; case "Employee": if (rec._Employee != null) { var item = (InvItem)items?.Get(rec._Item); if (item == null || item._ItemType == (byte)Uniconta.DataModel.ItemType.Service) { var emp = (Uniconta.DataModel.Employee)employees?.Get(rec._Employee); if (emp != null && emp._CostPrice != 0d) { rec.CostPrice = emp._CostPrice; } } } break; case "EAN": DebtorOfferLines.FindOnEAN(rec, this.items, api, this.PriceLookup); break; case "Variant1": if (rec._Variant1 != null) { setVariant(rec, true); } if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices) { this.PriceLookup.GetCustomerPrice(rec, false); } break; case "Variant2": case "Variant3": case "Variant4": case "Variant5": if (this.PriceLookup != null && this.PriceLookup.UseCustomerPrices) { this.PriceLookup.GetCustomerPrice(rec, false); } break; case "Variant": globalEvents.NotifyRefreshViewer(NameOfControl, rec); break; case "CustomerItemNumber": if (!string.IsNullOrEmpty(rec.CustomerItemNumber)) { DebtorOfferLines.FindItemFromCustomerItem(rec, Order, api, rec.CustomerItemNumber); } break; } }