using BBWY.Client.Models; using BBWY.Controls; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows; namespace BBWY.Client.Views.Order { /// /// RelationPurchaseOrder.xaml 的交互逻辑 /// public partial class RelationPurchaseOrder : BWindow { public IList OrderDropShippingList { get; set; } public IList RelationPurchaseOrderSkuList { get; set; } public IList PurchaseAccountList { get; set; } public string OrderId { get; set; } public decimal TotalCost { get => totalCost; set { Set(ref totalCost, value); } } private decimal totalCost; public RelationPurchaseOrder(string orderId, IList purchaseAccountList, IList orderDropShippingList, IList relationPurchaseOrderSkuList) { InitializeComponent(); this.DataContext = this; this.PurchaseAccountList = purchaseAccountList; this.OrderId = orderId; OrderDropShippingList = new ObservableCollection(); if (orderDropShippingList != null) { foreach (var ods in orderDropShippingList) { var ods1 = ods.Clone() as OrderDropShipping; ods1.PurchaseFreightStr = ods1.PurchaseFreight.ToString(); var currentOdsSkuList = relationPurchaseOrderSkuList.Where(rsku => rsku.OrderDropShippingId == ods1.Id); foreach (var rsku in currentOdsSkuList) ods.RelationPurchaseOrderSkuList.Add(rsku); OrderDropShippingList.Add(ods1); ods1.OnPurchaseAmountChanged = OnPurchaseAmountChanged; } } this.RelationPurchaseOrderSkuList = relationPurchaseOrderSkuList; foreach (var sku in RelationPurchaseOrderSkuList) sku.OnSkuAmountChanged = OnSkuAmountChanged; OnPurchaseAmountChanged(); } private void OnSkuAmountChanged() { foreach (var ods in OrderDropShippingList) ods.SkuAmount = ods.RelationPurchaseOrderSkuList.Sum(sku => sku.SkuAmount); } private void OnPurchaseAmountChanged() { TotalCost = OrderDropShippingList.Sum(ods => ods.PurchaseAmount); } private void btn_Save_Click(object sender, System.Windows.RoutedEventArgs e) { //if (string.IsNullOrEmpty(OrderDropShipping.PurchaseOrderId) || // string.IsNullOrEmpty(OrderDropShipping.SellerAccount) || // string.IsNullOrEmpty(OrderDropShipping.BuyerAccount) || // OrderDropShipping.PurchaseAmount == 0) //{ // MessageBox.Show("关联订单信息不全", "提示"); // return; //} this.DialogResult = true; this.Close(); } } }