void ButtonConfirmSelected_Click(object sender, RoutedEventArgs e) { if (this.DialogHandler == null) { return; } if (m_selectData.Count == 0) { this.CurrentWindow.Alert(ResProductPicker.Msg_PleaseSelect, MessageType.Warning); return; } //选择返回的数据 var result = new List <ProductVM>(); var list = m_selectData.Select(p => p.Value); #region 赠品数量的处理 //处理逻辑为如果多种商品选择同一增品,那赠品数应该合并为一个 //如果赠品数量大于onlineqty,那赠品数量=onlineqty //有可能赠品既是商品 var groupGiftList = list .GroupBy(p => new { SysNo = p.SysNo, SOPT = p.ProductType }); foreach (var item in groupGiftList) { var first = item.First(); first.MasterSysNos = new List <int>(); if (item.Count() == 1) { if (first.SOProductType == SOProductType.Gift) { first.Quantity = CalcGiftQty(first.RuleQty , GetData(first.MasterSysNo.Value, null).Quantity.Value , first.OnlineQty.Value); first.MasterSysNos.Add(first.MasterSysNo.Value); } } else { //多个商品对应一个赠品的情况,只有赠品才有这种情况出现 //赠品的online库存数,计算的时候为唯一 int giftOnlineQty = first.OnlineQty.Value; int giftCountQty = 0; foreach (var giftItem in item) { //商品的规则不一样,这里需要提出来单独计算 int masterQty = GetData(giftItem.MasterSysNo.Value, null).Quantity.Value; int giftQty = CalcGiftQty(giftItem.RuleQty, masterQty, giftOnlineQty); giftCountQty += giftQty; //减去onlineqty giftOnlineQty -= giftQty; first.MasterSysNos.Add(giftItem.MasterSysNo.Value); } first.Quantity = giftCountQty; } //需要每条想的主商品编号初始为null,避免混淆 first.MasterSysNo = null; result.Add(first); } #endregion #region 需要将延保转成商品 foreach (var item in list) { //延保只有一个数据 if (item.SOProductType == SOProductType.Product && item.ExtendedWarrantyList != null && item.ExtendedWarrantyList.Count == 1) { var extended = item.ExtendedWarrantyList[0]; ProductVM vm = new ProductVM(); vm.ProductID = string.Format("{0}E", item.ProductID); vm.Quantity = item.Quantity; vm.ProductName = extended.BriefName; vm.SOProductType = SOProductType.ExtendWarranty; vm.CurrentPrice = extended.ServiceUnitPrice; vm.MasterSysNo = item.SysNo; vm.SysNo = extended.SysNo; vm.TariffRate = item.TariffRate; vm.UnitCost = extended.ServiceCost; vm.AvgCost = extended.ServiceCost; result.Add(vm); } } #endregion this.DialogHandler.ResultArgs.Data = result; this.DialogHandler.ResultArgs.DialogResult = DialogResultType.OK; this.DialogHandler.Close(); }
public ProductSelectedEventArgs(ProductVM selectedProduct) { this.SelectedProduct = selectedProduct; }