private void AddConsignmentBill(object obj)
        {
            // 直接用 SelectedConsignmentBill
            if (SelectedConsignmentBill != null && SelectedConsignmentBill.SelectedStatus == 0)
            {
                // 后台查询该记录是否被别人操作了
                string ownerName = _consignmentService.GetConsignmentBillLockOwner(SelectedConsignmentBill.BillNo, SelectedConsignmentBill.UserId);
                if (string.IsNullOrEmpty(ownerName))
                {
                    // 修改选择状态
                    if (SelectedConsignmentBill.UndoQuantity == selectedConsignmentBill.CurrencyQuantity)
                    {
                        SelectedConsignmentBill.SelectedStatus = 2;
                    }
                    else
                    {
                        SelectedConsignmentBill.SelectedStatus = 1;
                    }

                    // 添加已选数据,求和
                    SelectedConsignmentBillLists.Insert(0, SelectedConsignmentBill);
                    SelectedConsignmentSum       = SelectedConsignmentBillLists.Where(m => m.SelectedStatus > 0).Sum(m => m.CurrencyQuantity);
                    SelectedConsignmentBillEntry = null;

                    // 同步数据到数据库
                    _consignmentService.AddConsignmentBill(SelectedConsignmentBill);
                }
                else
                {
                    MessageBox.Show($"【{ownerName}】,请选择其他数据");
                }
            }
        }
        private void InitQueryConSignmentBill()
        {
            QuerySignmentBill(null);

            SelectedConsignmentBillLists.Clear();
            _consignmentService.GetUserSelectedConsignmentBill(user.ID).ToList().ForEach(x => SelectedConsignmentBillLists.Add(x));
            SelectedConsignmentSum = SelectedConsignmentBillLists.Where(m => m.SelectedStatus > 0).Sum(m => m.CurrencyQuantity);
        }
 private void ClearSelectedConsignmentBillLists(object obj)
 {
     if (SelectedConsignmentBillLists.Count() > 0)
     {
         string ids = "'" + string.Join("','", SelectedConsignmentBillLists.Select(x => x.BillNo)) + "'";
         SelectedConsignmentBillLists.Clear();
         SelectedConsignmentSum = 0;
         ConsignmentBillEntries.Clear();
         _consignmentService.ClearSelectedConsignmentBills(ids);
         QuerySignmentBill(null);
     }
 }
        private void RemoveConsignmentBill(object obj)
        {
            if (SelectedConsignmentBill.SelectedStatus > 0)
            {
                //移除数据求和
                SelectedConsignmentBillLists.Remove(SelectedConsignmentBillLists.FirstOrDefault(x => x.InterId == SelectedConsignmentBill.InterId));
                SelectedConsignmentSum = SelectedConsignmentBillLists.Where(m => m.SelectedStatus > 0).Sum(m => m.CurrencyQuantity);

                // 修改选择状态
                SelectedConsignmentBill.SelectedStatus = 0;

                // 同步数据到数据库
                _consignmentService.DeleteConsignmentBill(SelectedConsignmentBill);
            }
        }
 private void MergeConsignmentBill(object obj)
 {
     if (SelectedConsignmentBillLists.Count() > 0)
     {
         string fInterIds   = string.Join(",", SelectedConsignmentBillLists.Select(m => m.InterId));
         string fbillNos    = "'" + string.Join("','", SelectedConsignmentBillLists.Select(m => m.BillNo)) + "'";
         string rollbackMsg = _consignmentService.MergeConsignmentBill(user.ID, fInterIds, fbillNos);
         if (string.IsNullOrEmpty(rollbackMsg))
         {
             SelectedConsignmentBillLists.Clear();
             SelectedConsignmentSum = 0;
             QuerySignmentBill(null);
             GetShippingBills();
         }
         else
         {
             MessageBox.Show(rollbackMsg);
         }
     }
 }
        private void UnSelectedAllConsignmentBill(object obj)
        {
            if (ConsignmentBills.Count == 0)
            {
                return;
            }

            if (ConsignmentBills.Where(m => m.SelectedStatus > 0).Count() > 0)// 反选
            {
                var bills = ConsignmentBills.Where(m => m.SelectedStatus > 0);
                if (bills.Count() > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var item in bills)
                    {
                        SelectedConsignmentBillLists.Remove(SelectedConsignmentBillLists.FirstOrDefault(x => x.InterId == item.InterId));
                        sb.Append(",'" + item.BillNo + "'");
                    }
                    _consignmentService.RemoveUserCurrencyOperation(sb.ToString().Substring(1));
                    SelectedConsignmentSum = SelectedConsignmentBillLists.Where(m => m.SelectedStatus > 0).Sum(m => m.CurrencyQuantity);
                    QuerySignmentBill(null);
                }
            }
        }
        private void SelectedAllConsignmentBill(object obj)
        {
            if (ConsignmentBills.Count == 0)
            {
                return;
            }

            if (ConsignmentBills.Where(m => m.SelectedStatus == 0).Count() > 0)
            {
                // 查询有没有被锁定的数据
                string        billNos    = "'" + string.Join("','", ConsignmentBills.Select(m => m.BillNo)) + "'";
                string        lockstring = _consignmentService.GetConsignmentBillLockOwner(user.ID, billNos);
                bool          r          = ConsignmentBills.Where(m => m.CurrencyQuantity == 0).Count() > 0;
                StringBuilder sb         = new StringBuilder();

                if (string.IsNullOrEmpty(lockstring) || r)
                {
                    foreach (var item in ConsignmentBills)
                    {
                        if (SelectedConsignmentBillLists.Where(x => x.InterId == item.InterId).Count() == 0)
                        {
                            item.SelectedStatus = item.TotalQuantity == item.CurrencyQuantity ? 2 : 1;
                            SelectedConsignmentBillLists.Add(item);
                            sb.Append(",'" + item.BillNo + "'");
                        }
                    }
                    _consignmentService.AddUserCurrencyOperation(user.ID, sb.ToString().Substring(1));
                    SelectedConsignmentSum = SelectedConsignmentBillLists.Where(m => m.SelectedStatus > 0).Sum(m => m.CurrencyQuantity);
                    QuerySignmentBill(null);
                }
                else
                {
                    MessageBox.Show(lockstring + "!\r\n 或者已选数据的当前数量不能为0 ,不能批量选择");
                }
            }
        }