private void ShippingBillSelectionChanged(object obj)
        {
            if (obj != null)
            {
                SelectedShippingBill = (ShippingBillModel)obj;
                ShippingBillEntries.Clear();

                _shippingService.GetAllShippingBillEntryById(SelectedShippingBill.Id).ToList().ForEach(x => ShippingBillEntries.Add(x));
            }
        }
 private void GetAllShippingBillEntriesById(int id)
 {
     ShippingBillEntries.Clear();
     _shippingService.GetAllShippingBillEntryById(id).ToList().ForEach(x => ShippingBillEntries.Add(x));
 }
        private void AddShippingBillEntry(object obj)
        {
            if (SelectedShippingBill == null)
            {
                MessageBox.Show("请先选择主表行记录,再新增明细");
                return;
            }

            ShippingBillEntryModel   entry;
            ShippingBillEntryAddView view = new ShippingBillEntryAddView();
            var copyEntry = ShippingBillEntries.LastOrDefault();

            if (copyEntry == null)
            {
                entry = new ShippingBillEntryModel {
                    MainId = SelectedShippingBill.Id, EntryId = 1, IsSystem = false, Amount = 0
                }
            }
            ;
            else
            {
                entry = new ShippingBillEntryModel
                {
                    MainId   = copyEntry.MainId,
                    EntryId  = copyEntry.EntryId + 1,
                    IsSystem = false
                }
            };
            (view.DataContext as ShippingBillEntryAddViewModel).WithParam(entry, (type, shippingBillEntry) =>
            {
                view.Close();

                if (type == 1)
                {
                    SelectedShippingBill.TotalQuantity += shippingBillEntry.Quantity;
                    SelectedShippingBill.TotalAmount   += shippingBillEntry.Amount;


                    // 新增条目,修改后台分摊金额
                    if (shippingBillEntry.GoodsType == 1 || shippingBillEntry.GoodsType == 3)
                    {
                        SelectedShippingBill.SystemApportionedAmount   += shippingBillEntry.Amount;
                        SelectedShippingBill.SystemApportionedQuantity += shippingBillEntry.Quantity;
                        _shippingService.AddShipingBillEntry(shippingBillEntry);       //添加明细
                        _shippingService.UpdateShipingBillEntry(SelectedShippingBill); //分摊金额
                    }
                    else
                    {
                        SelectedShippingBill.UnApportionedAmount += shippingBillEntry.Amount;
                        _shippingService.AddShipingBillEntry2(shippingBillEntry);
                    }

                    // 更新主表
                    _shippingService.UpdateShipingBill2(SelectedShippingBill);

                    // 重新加载明细
                    GetAllShippingBillEntriesById(shippingBillEntry.MainId);
                }
            });
            view.ShowDialog();
        }
        private void DeleteShippingBill(object obj)
        {
            MessageBoxResult result = MessageBox.Show($"将会将合并此单的销售调拨数据\r\n还原到未合并前的状态 \r\n \r\n 物流单号:【{SelectedShippingBill.LogisticsBillNo}】\r\n  总金额:【{SelectedShippingBill.TotalAmount}】"
                                                      + $"\r\n   总重量:【{SelectedShippingBill.TotalQuantity}】"
                                                      + $"\r\n  系统单号:【{SelectedShippingBill.BillNo}】"
                                                      + $"\r\n  托运日期:【{SelectedShippingBill.BillDate}】"
                                                      , "【删除警告!!!】", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.Yes)
            {
                int id = SelectedShippingBill.Id;

                if (SelectedShippingBill.IsSystem == 0)
                {
                    bool succ = _shippingService.DeleteNonSystemShipingBill(id);
                    if (succ)
                    {
                        ShippingBills.Remove(SelectedShippingBill);
                        ShippingBillEntries.Clear();
                        QuerySignmentBill(null);
                    }
                    else
                    {
                        MessageBox.Show("删除出现异常");
                        return;
                    }
                }
                else
                {
                    string billNos = _consignmentService.GetConsignmentBillNosByShippingBillId(id);
                    if (!string.IsNullOrEmpty(billNos))
                    {
                        string lockMessage = _consignmentService.GetConsignmentBillLock(billNos);
                        if (string.IsNullOrEmpty(lockMessage))
                        {
                            string rollbackMessage = _shippingService.DeleteShipingBill(id);
                            if (string.IsNullOrEmpty(rollbackMessage))
                            {
                                ShippingBills.Remove(SelectedShippingBill);
                                ShippingBillEntries.Clear();
                                QuerySignmentBill(null);
                            }
                            else
                            {
                                MessageBox.Show(rollbackMessage);
                            }
                        }
                        else
                        {
                            MessageBox.Show(lockMessage);
                        }
                    }
                    else
                    {
                        MessageBox.Show("合成此托运单的明细单据丢失,请联系管理员");
                    }
                }

                _commonService.WriteActionLog(new ActionOperationLogModel {
                    ActionName = "DeleteShippingBill", ActionDesc = "删除托运单", UserId = user.ID, MainMenuId = 7, PKId = id, HostName = _hostName
                });
            }
        }