|
@@ -8,8 +8,10 @@ using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Controls;
|
|
|
|
+using System.Windows.Controls.Primitives;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
+using DocumentFormat.OpenXml.Wordprocessing;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using UniformMaterialManagementSystem.Entities;
|
|
using UniformMaterialManagementSystem.Entities;
|
|
@@ -29,13 +31,13 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
private ObservableCollection<DeliveryReceipt> _deliveryReceipts = [];
|
|
private ObservableCollection<DeliveryReceipt> _deliveryReceipts = [];
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
- private ObservableCollection<DeliveryReceiptDetail> _deliveryDetails = [];
|
|
|
|
|
|
+ private ObservableCollection<DeliveryReceiptDetail> _deliveryReceiptDetails = [];
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
private DeliveryReceipt? _currDeliveryReceipt = null;
|
|
private DeliveryReceipt? _currDeliveryReceipt = null;
|
|
|
|
|
|
- // 删除时屏蔽行切换事件
|
|
|
|
- private bool _isExcute = true;
|
|
|
|
|
|
+ // 行切换事件内部屏蔽自身
|
|
|
|
+ private bool _isExcuting = false;
|
|
|
|
|
|
private string _exportFileName = "附件3成品生产企业报送接收数据模板";
|
|
private string _exportFileName = "附件3成品生产企业报送接收数据模板";
|
|
|
|
|
|
@@ -61,41 +63,34 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
|
|
|
public void FdgDelivery_SelectionChanged(object sender, SelectionChangedEventArgs args)
|
|
public void FdgDelivery_SelectionChanged(object sender, SelectionChangedEventArgs args)
|
|
{
|
|
{
|
|
- // 手动屏蔽本事件
|
|
|
|
- if (!_isExcute) { return; }
|
|
|
|
- //args.Handled = true;
|
|
|
|
-
|
|
|
|
if (sender is not DataGrid fdgDelivery) { return; }
|
|
if (sender is not DataGrid fdgDelivery) { return; }
|
|
|
|
|
|
- // 暂时屏蔽行切换事件
|
|
|
|
- _isExcute = false;
|
|
|
|
|
|
+ // 若本事件正在执行,则直接返回
|
|
|
|
+ if (_isExcuting) { return; }
|
|
|
|
+
|
|
|
|
+ // 暂时屏蔽本事件
|
|
|
|
+ _isExcuting = true;
|
|
|
|
|
|
// 离开行之前,判断当前行是否未保存
|
|
// 离开行之前,判断当前行是否未保存
|
|
if (args.RemovedItems.Count > 0)
|
|
if (args.RemovedItems.Count > 0)
|
|
{
|
|
{
|
|
- // 手动切换为切换前的行(为了主表编辑界面的值不切换)
|
|
|
|
if (args.RemovedItems[0] is not DeliveryReceipt leavingDelivery) { return; }
|
|
if (args.RemovedItems[0] is not DeliveryReceipt leavingDelivery) { return; }
|
|
- fdgDelivery.SelectedItem = leavingDelivery;
|
|
|
|
-
|
|
|
|
- // 判断当前行是否新增行或已修改
|
|
|
|
bool isChanged = IsChanged(leavingDelivery);
|
|
bool isChanged = IsChanged(leavingDelivery);
|
|
if (isChanged)
|
|
if (isChanged)
|
|
{
|
|
{
|
|
- // 询问是否切换
|
|
|
|
- MessageBoxResult res = MessageBox.Show("当前行已修改,切换行会丢失已修改的数据,是否确认切换行?", "询问", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
|
|
|
- // 不切换:重新赋值为切换前的行
|
|
|
|
|
|
+ // 询问之前切换回离开前的行,防止下方编辑界面的值切换
|
|
|
|
+ fdgDelivery.SelectedItem = leavingDelivery; // 会循环调用本事件,CurrDeliveryReceipt 双向绑定也会循环调用
|
|
|
|
+
|
|
|
|
+ MessageBoxResult res = MessageBox.Show("当前行未保存,是否确认切换行?", "询问", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
|
if (res != MessageBoxResult.Yes)
|
|
if (res != MessageBoxResult.Yes)
|
|
{
|
|
{
|
|
- // 取消切换行:当前行不变
|
|
|
|
- fdgDelivery.SelectedItem = leavingDelivery; // 重新赋值为旧行; CurrDeliveryReceipt 通过绑定自动更新
|
|
|
|
- fdgDelivery.Items.Refresh(); // 必须刷新界面
|
|
|
|
- // 直接赋值会循环调用本事件,CurrDeliveryReceipt 双向绑定也会循环调用
|
|
|
|
|
|
+ // 刷新界面:上方主表展示的行切换为旧行
|
|
|
|
+ fdgDelivery.Items.Refresh();
|
|
|
|
|
|
- // 取消屏蔽后返回
|
|
|
|
- _isExcute = true;
|
|
|
|
|
|
+ // 事件结束:不切换新行
|
|
|
|
+ _isExcuting = false;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- // 切换:则展示新行数据
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -103,20 +98,21 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
if (args.AddedItems.Count > 0)
|
|
if (args.AddedItems.Count > 0)
|
|
{
|
|
{
|
|
if (args.AddedItems[0] is not DeliveryReceipt newDelivery) { return; }
|
|
if (args.AddedItems[0] is not DeliveryReceipt newDelivery) { return; }
|
|
- fdgDelivery.SelectedItem = newDelivery; // 刚刚为了界面数据赋值,所以这里需要设置为切换后的行
|
|
|
|
- //fdgDelivery.Items.Refresh(); // 不必刷新前台界面
|
|
|
|
|
|
+ fdgDelivery.SelectedItem = newDelivery; // 自动更新DataGrid选中行和SelectedItem,但询问切换修改了值,需要手动切换回新行
|
|
|
|
+
|
|
|
|
+ // 更新子表的行
|
|
|
|
+ DeliveryReceiptDetails = new ObservableCollection<DeliveryReceiptDetail>(newDelivery.DeliveryReceiptDetails);
|
|
}
|
|
}
|
|
|
|
|
|
- // 取消屏蔽行切换
|
|
|
|
- _isExcute = true;
|
|
|
|
|
|
+ // 事件结束
|
|
|
|
+ _isExcuting = false;
|
|
}
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
[RelayCommand]
|
|
- public void Check(ComboBox cbReceivedStatus)
|
|
|
|
|
|
+ public void Check(DataGrid fdgDeliveryDetail)
|
|
{
|
|
{
|
|
if (CurrDeliveryReceipt == null) { return; }
|
|
if (CurrDeliveryReceipt == null) { return; }
|
|
|
|
|
|
- var sele00 = cbReceivedStatus.SelectedItem;
|
|
|
|
string status = CurrDeliveryReceipt.ReceivedStatus ?? string.Empty;
|
|
string status = CurrDeliveryReceipt.ReceivedStatus ?? string.Empty;
|
|
if (status.Equals("已复核"))
|
|
if (status.Equals("已复核"))
|
|
{
|
|
{
|
|
@@ -125,25 +121,11 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
}
|
|
}
|
|
|
|
|
|
// 校验子表接收数量列
|
|
// 校验子表接收数量列
|
|
- StringBuilder nullHint = new StringBuilder();
|
|
|
|
- foreach (DeliveryReceiptDetail dtl in CurrDeliveryReceipt.DeliveryReceiptDetails)
|
|
|
|
- {
|
|
|
|
- decimal? receQty = dtl.ReceiveQuantity;
|
|
|
|
- if (receQty == null || receQty == 0)
|
|
|
|
- {
|
|
|
|
- int index = CurrDeliveryReceipt.DeliveryReceiptDetails.IndexOf(dtl);
|
|
|
|
- nullHint.AppendLine($"第 {index + 1} 行");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (nullHint.Length > 0)
|
|
|
|
- {
|
|
|
|
- MessageBox.Show("子表中存在一下为空的接收数量,不允许复核!\n" + nullHint.ToString());
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ CheckDetailDataGrid(fdgDeliveryDetail, true);
|
|
|
|
+ // MessageBox.Show("子表中存在以下为空的接收数量,不允许复核!\n" + nullHint.ToString());
|
|
|
|
|
|
// 更新为已复核
|
|
// 更新为已复核
|
|
CurrDeliveryReceipt.ReceivedStatus = "已复核";
|
|
CurrDeliveryReceipt.ReceivedStatus = "已复核";
|
|
- cbReceivedStatus.SelectedItem = "已复核";
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// todo
|
|
// todo
|
|
@@ -152,7 +134,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
{
|
|
{
|
|
// 未选择行或者当前行已导出,直接返回
|
|
// 未选择行或者当前行已导出,直接返回
|
|
if (CurrDeliveryReceipt == null) { return; }
|
|
if (CurrDeliveryReceipt == null) { return; }
|
|
- if (CurrDeliveryReceipt.IsExportDelivery || CurrDeliveryReceipt.IsExportReceive || CurrDeliveryReceipt.IsExportUsage) { return; }
|
|
|
|
|
|
+ if (CurrDeliveryReceipt.IsExportReceive) { return; }
|
|
|
|
|
|
// 若 收货单状态 为空,默认赋值为 未复核
|
|
// 若 收货单状态 为空,默认赋值为 未复核
|
|
var selectedStatus = cbReceivedStatus.SelectedItem;
|
|
var selectedStatus = cbReceivedStatus.SelectedItem;
|
|
@@ -162,13 +144,17 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
}
|
|
}
|
|
|
|
|
|
// 子表存在空值时
|
|
// 子表存在空值时
|
|
- var nullReceivedQty = CurrDeliveryReceipt!.DeliveryReceiptDetails.Where(x => x.ReceiveQuantity == 0);
|
|
|
|
|
|
+ var nullReceivedQty = DeliveryReceiptDetails.Where(x => x.ReceiveQuantity == 0);
|
|
if (nullReceivedQty.Any())
|
|
if (nullReceivedQty.Any())
|
|
{
|
|
{
|
|
MessageBoxResult res = MessageBox.Show("明细表的接收数量存在空值,是否确认保存?", "询问", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
|
MessageBoxResult res = MessageBox.Show("明细表的接收数量存在空值,是否确认保存?", "询问", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
|
if (res != MessageBoxResult.Yes) { return; }
|
|
if (res != MessageBoxResult.Yes) { return; }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // todo 检查每一行的数据:防止输入文本或超出发运数量时,不切换单元格(获取单元格 DataGridCell ,DataGridCell.Content 是TextBlock/TextBox,获取文本)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
// 保存到数据库
|
|
// 保存到数据库
|
|
var serviceDtl = App.Current.Services.GetService<IDataBaseService<DeliveryReceiptDetail>>();
|
|
var serviceDtl = App.Current.Services.GetService<IDataBaseService<DeliveryReceiptDetail>>();
|
|
if (CurrDeliveryReceipt.IsNewRow)
|
|
if (CurrDeliveryReceipt.IsNewRow)
|
|
@@ -177,10 +163,13 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
CurrDeliveryReceipt.IsNewRow = false;
|
|
CurrDeliveryReceipt.IsNewRow = false;
|
|
_service.Insert(CurrDeliveryReceipt);
|
|
_service.Insert(CurrDeliveryReceipt);
|
|
|
|
|
|
- foreach (DeliveryReceiptDetail dtl in CurrDeliveryReceipt.DeliveryReceiptDetails)
|
|
|
|
|
|
+ foreach (DeliveryReceiptDetail dtl in DeliveryReceiptDetails)
|
|
{
|
|
{
|
|
- dtl.IsNewRow = false;
|
|
|
|
- serviceDtl?.Insert(dtl);
|
|
|
|
|
|
+ //dtl.IsNewRow = false;
|
|
|
|
+ //serviceDtl?.Insert(dtl);
|
|
|
|
+
|
|
|
|
+ // 已有发货数据,所以不用 Insert() 用 Update() todo 要不要分表,如果要分表,需要判断 IsNewRow 后插入/更新
|
|
|
|
+ serviceDtl?.Update(dtl);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -189,17 +178,18 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
// todo 主表已保存,但子表明细 新增/删除/修改 怎么保存
|
|
// todo 主表已保存,但子表明细 新增/删除/修改 怎么保存
|
|
_service.Update(CurrDeliveryReceipt);
|
|
_service.Update(CurrDeliveryReceipt);
|
|
|
|
|
|
- foreach (DeliveryReceiptDetail dtl in CurrDeliveryReceipt.DeliveryReceiptDetails)
|
|
|
|
|
|
+ foreach (DeliveryReceiptDetail dtl in DeliveryReceiptDetails)
|
|
{
|
|
{
|
|
- if (dtl.IsNewRow)
|
|
|
|
- {
|
|
|
|
- dtl.IsNewRow = false;
|
|
|
|
- serviceDtl?.Insert(dtl);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- serviceDtl?.Update(dtl);
|
|
|
|
- }
|
|
|
|
|
|
+ serviceDtl?.Update(dtl);
|
|
|
|
+ //if (dtl.IsNewRow)
|
|
|
|
+ //{
|
|
|
|
+ // dtl.IsNewRow = false;
|
|
|
|
+ // serviceDtl?.Insert(dtl);
|
|
|
|
+ //}
|
|
|
|
+ //else
|
|
|
|
+ //{
|
|
|
|
+ // serviceDtl?.Update(dtl);
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -212,6 +202,8 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
MessageBox.Show("数据库保存失败!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
MessageBox.Show("数据库保存失败!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ MessageBox.Show("保存成功");
|
|
}
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
[RelayCommand]
|
|
@@ -223,6 +215,8 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
[RelayCommand]
|
|
[RelayCommand]
|
|
public void ExportDB()
|
|
public void ExportDB()
|
|
{
|
|
{
|
|
|
|
+ // 成品企业-接收单导出附件3的时候赋值 IsExportReceive 字段为 true:导出后不可编辑,不可重复导出、
|
|
|
|
+
|
|
if (CurrDeliveryReceipt != null)
|
|
if (CurrDeliveryReceipt != null)
|
|
{
|
|
{
|
|
bool isChanged = IsChanged(CurrDeliveryReceipt);
|
|
bool isChanged = IsChanged(CurrDeliveryReceipt);
|
|
@@ -300,20 +294,25 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
// 离开单元格时提交编辑
|
|
// 离开单元格时提交编辑
|
|
fdgDeliveryDetail.CommitEdit();
|
|
fdgDeliveryDetail.CommitEdit();
|
|
|
|
|
|
- // 如果编辑的列是发运数量/接收数量/使用数量,自动汇总至主表 更新使用状态
|
|
|
|
|
|
+ // 如果编辑的列是 接收数量 ,并自动汇总至主表
|
|
foreach (DataGridCellInfo cellInfo in e.RemovedCells)
|
|
foreach (DataGridCellInfo cellInfo in e.RemovedCells)
|
|
{
|
|
{
|
|
- // 删除行时为 null
|
|
|
|
- if (cellInfo.Column == null || cellInfo.Column.Header == null) { continue; } // DataGridCellInfo 类型的值永不等于 null
|
|
|
|
|
|
+ // 忽略删除行导致的单元格切换
|
|
|
|
+ if (!cellInfo.IsValid) { continue; }
|
|
|
|
|
|
if (!cellInfo.Column.Header.Equals("接收数量*")) { continue; }
|
|
if (!cellInfo.Column.Header.Equals("接收数量*")) { continue; }
|
|
|
|
|
|
|
|
+ // todo 若输入的值不是 decimal,提示!
|
|
|
|
+
|
|
// 校验发运数量
|
|
// 校验发运数量
|
|
DeliveryReceiptDetail? dtl = cellInfo.Item as DeliveryReceiptDetail;
|
|
DeliveryReceiptDetail? dtl = cellInfo.Item as DeliveryReceiptDetail;
|
|
if (dtl?.ReceiveQuantity < 0)
|
|
if (dtl?.ReceiveQuantity < 0)
|
|
{
|
|
{
|
|
- dtl.ReceiveQuantity = 0;
|
|
|
|
- fdgDeliveryDetail.Items.Refresh();
|
|
|
|
|
|
+ DeliveryReceiptDetail? dtl0 = DeliveryReceiptDetails[0];
|
|
|
|
+ if (dtl0 == dtl) { } // true
|
|
|
|
+ dtl.ReceiveQuantity = 0; // todo 使用 ObserveCollection[] 会不会自动刷新前台?
|
|
|
|
+ fdgDeliveryDetail.Items.Refresh(); // 有效,但难免效率低一些
|
|
|
|
+ //OnPropertyChanged(nameof(DeliveryReceiptDetails)); // 无效。
|
|
MessageBox.Show("输入的数量异常,请重新输入!");
|
|
MessageBox.Show("输入的数量异常,请重新输入!");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -322,6 +321,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
dtl.ReceiveQuantity = dtl?.ShippedQuantity;
|
|
dtl.ReceiveQuantity = dtl?.ShippedQuantity;
|
|
// todo 效率低,更高效的写法?
|
|
// todo 效率低,更高效的写法?
|
|
fdgDeliveryDetail.Items.Refresh();
|
|
fdgDeliveryDetail.Items.Refresh();
|
|
|
|
+ // fdgDeliveryDetail.CommitEdit(); // 不能更新到前台
|
|
//OnPropertyChanged(nameof(dtl)); // 无效
|
|
//OnPropertyChanged(nameof(dtl)); // 无效
|
|
//OnPropertyChanged(nameof(CurrDeliveryReceipt.DeliveryReceiptDetails));
|
|
//OnPropertyChanged(nameof(CurrDeliveryReceipt.DeliveryReceiptDetails));
|
|
MessageBox.Show("接收数量不能超过发运数量,请重新输入");
|
|
MessageBox.Show("接收数量不能超过发运数量,请重新输入");
|
|
@@ -329,15 +329,15 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
}
|
|
}
|
|
|
|
|
|
// 汇总主表接收数量
|
|
// 汇总主表接收数量
|
|
- var validDtls = CurrDeliveryReceipt!.DeliveryReceiptDetails.Where(x => x.ReceiveQuantity != null && x.ReceiveQuantity > 0);
|
|
|
|
- CurrDeliveryReceipt.ReceivedPackets = validDtls.Count();
|
|
|
|
|
|
+ var validDtls = DeliveryReceiptDetails.Where(x => x.ReceiveQuantity != null && x.ReceiveQuantity > 0);
|
|
|
|
+ CurrDeliveryReceipt!.ReceivedPackets = validDtls.Count();
|
|
CurrDeliveryReceipt.ReceivedQty = validDtls.Select(x => x.ReceiveQuantity).Sum() ?? 0;
|
|
CurrDeliveryReceipt.ReceivedQty = validDtls.Select(x => x.ReceiveQuantity).Sum() ?? 0;
|
|
}
|
|
}
|
|
|
|
|
|
// 手动触发值更新事件:此时没有切换焦点,不会自动触发更新
|
|
// 手动触发值更新事件:此时没有切换焦点,不会自动触发更新
|
|
OnPropertyChanged(nameof(CurrDeliveryReceipt));
|
|
OnPropertyChanged(nameof(CurrDeliveryReceipt));
|
|
//OnPropertyChanged(nameof(CurrDeliveryReceipt.DeliveryReceiptDetails));
|
|
//OnPropertyChanged(nameof(CurrDeliveryReceipt.DeliveryReceiptDetails));
|
|
- fdgDeliveryDetail.Items.Refresh();
|
|
|
|
|
|
+ //fdgDeliveryDetail.Items.Refresh();
|
|
}
|
|
}
|
|
|
|
|
|
// 单元格切换时,Added 里的是新单元格;Removed是旧单元格
|
|
// 单元格切换时,Added 里的是新单元格;Removed是旧单元格
|
|
@@ -348,19 +348,12 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
// 进入单元格时自动进入编辑状态
|
|
// 进入单元格时自动进入编辑状态
|
|
fdgDeliveryDetail.BeginEdit();
|
|
fdgDeliveryDetail.BeginEdit();
|
|
|
|
|
|
- // todo IsValid ?
|
|
|
|
- if (cellInfo.IsValid) { }
|
|
|
|
- if (cellInfo.Column == null)
|
|
|
|
- {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // todo 点击两下才能勾选/取消勾选
|
|
|
|
// 勾选/取消勾选行
|
|
// 勾选/取消勾选行
|
|
if (cellInfo.Column is DataGridCheckBoxColumn colCheck)
|
|
if (cellInfo.Column is DataGridCheckBoxColumn colCheck)
|
|
{
|
|
{
|
|
if (cellInfo.Item is not DeliveryReceiptDetail dtl) { continue; }
|
|
if (cellInfo.Item is not DeliveryReceiptDetail dtl) { continue; }
|
|
dtl.IsSelected = !dtl.IsSelected;
|
|
dtl.IsSelected = !dtl.IsSelected;
|
|
|
|
+ fdgDeliveryDetail.CommitEdit(); // 前台刷新勾选状态
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -370,40 +363,86 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
public void ReceiveAll(MaterialReceiptPage page)
|
|
public void ReceiveAll(MaterialReceiptPage page)
|
|
{
|
|
{
|
|
if (CurrDeliveryReceipt == null) { return; }
|
|
if (CurrDeliveryReceipt == null) { return; }
|
|
|
|
+ if (DeliveryReceiptDetails == null || DeliveryReceiptDetails.Count == 0) { return; }
|
|
|
|
|
|
- ObservableCollection<DeliveryReceiptDetail> details = CurrDeliveryReceipt.DeliveryReceiptDetails;
|
|
|
|
- if (details == null || details.Count == 0) { return; }
|
|
|
|
|
|
+ // 提交编辑:
|
|
|
|
+ page.fdgDeliveryDetail.CommitEdit();
|
|
|
|
+ //page.fdgDeliveryDetail.UnselectAllCells(); // 会触发单元格切换,这里不用校验发货数量,直接更新就好
|
|
|
|
|
|
- // 全部接收:将发货数量列赋值到接收数量列
|
|
|
|
- decimal qtyAll = 0;
|
|
|
|
- foreach (DeliveryReceiptDetail dtl in details)
|
|
|
|
|
|
+ // 全部接收:将子表发货数量列赋值到接收数量列
|
|
|
|
+ var serviceDtl = App.Current.Services.GetService<IDataBaseService<DeliveryReceiptDetail>>();
|
|
|
|
+ foreach (DeliveryReceiptDetail dtl in DeliveryReceiptDetails)
|
|
{
|
|
{
|
|
- dtl.ReceiveQuantity = dtl.ShippedQuantity;
|
|
|
|
- qtyAll += dtl.ShippedQuantity;
|
|
|
|
|
|
+ if (dtl.ReceiveQuantity == dtl.ShippedQuantity) { continue; } // 若录入值=发货数量,不变
|
|
|
|
+
|
|
|
|
+ dtl.ReceiveQuantity = dtl.ShippedQuantity; // 如果没录入值,更新为发货数量;若录入值,但<发货数量,更新为发货数量;
|
|
|
|
+ // 录入值>发货数量的情况不会存在,在切换单元格/保存时会校验
|
|
|
|
+ serviceDtl?.Update(dtl);
|
|
|
|
+ //if (dtl.IsNewRow)
|
|
|
|
+ //{
|
|
|
|
+ // dtl.IsNewRow = false;
|
|
|
|
+ // serviceDtl?.Insert(dtl);
|
|
|
|
+ //}
|
|
|
|
+ //else
|
|
|
|
+ //{
|
|
|
|
+ // serviceDtl?.Update(dtl);
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
|
|
|
|
// 汇总到主表
|
|
// 汇总到主表
|
|
- CurrDeliveryReceipt.ReceivedPackets = details.Count();
|
|
|
|
|
|
+ int count = DeliveryReceiptDetails.Where(x => x.ReceiveQuantity > 0).Count();
|
|
|
|
+ CurrDeliveryReceipt.ReceivedPackets = count;
|
|
|
|
+ decimal qtyAll = DeliveryReceiptDetails.Select(x => x.ReceiveQuantity).Sum() ?? 0;
|
|
CurrDeliveryReceipt.ReceivedQty = qtyAll;
|
|
CurrDeliveryReceipt.ReceivedQty = qtyAll;
|
|
- OnPropertyChanged(nameof(CurrDeliveryReceipt));
|
|
|
|
- OnPropertyChanged(nameof(CurrDeliveryReceipt.DeliveryReceiptDetails));
|
|
|
|
|
|
|
|
- // 保存到数据库
|
|
|
|
- Save(page.cbReceivedStatus);
|
|
|
|
|
|
+ // 若 收货单状态 为空,默认赋值为 未复核
|
|
|
|
+ string? status = CurrDeliveryReceipt.ReceivedStatus;
|
|
|
|
+ if (status == null || string.IsNullOrEmpty(status))
|
|
|
|
+ {
|
|
|
|
+ CurrDeliveryReceipt.ReceivedStatus = "未复核";
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ if (CurrDeliveryReceipt.IsNewRow)
|
|
|
|
+ {
|
|
|
|
+ CurrDeliveryReceipt.IsNewRow = false;
|
|
|
|
+ _service.Insert(CurrDeliveryReceipt);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ _service.Update(CurrDeliveryReceipt);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bool isSuccessMain = _service.SaveChanges(); // DataContext.SaveChanges() 会自动更新所有与当前上下文关联的实体的更改,包括关联表的更改。
|
|
|
|
+ // EFCore 通过 DbContext 跟踪所有被加载到上下文中的实体。当你对这些实体进行修改、添加或删除操作时,EFCore 会记录这些更改。
|
|
|
|
+ // 如果你修改了某个实体的导航属性(例如,一对多关系中的集合属性),EFCore 会自动跟踪这些更改,并在调用 SaveChanges() 时将这些更改保存到数据库中。
|
|
|
|
+ // 在这种情况下,EFCore 会自动将新的 Book 实体保存到数据库中,并更新 Author 实体的关联表。
|
|
|
|
+ if (!isSuccessMain)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("更新到数据库失败,请联系系统管理员!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 检查子表有没有更新到数据库
|
|
|
|
+ var savedDtls = serviceDtl?.Query(x => x.DeliveryReceiptGuid.Equals(CurrDeliveryReceipt.Guid));
|
|
|
|
+ foreach (DeliveryReceiptDetail sDtl in savedDtls)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新到前台界面?
|
|
|
|
+ OnPropertyChanged(nameof(CurrDeliveryReceipt));
|
|
|
|
+ //OnPropertyChanged(nameof(CurrDeliveryReceipt.DeliveryReceiptDetails));
|
|
// 刷新子表数据:值已更新,但没有显示
|
|
// 刷新子表数据:值已更新,但没有显示
|
|
|
|
+ page.fdgDeliveryDetail.CommitEdit(); // 当正在编辑单元格时,刷新会报错(单元格在编辑状态时直接点击 全部接收 按钮会报错)
|
|
page.fdgDeliveryDetail.Items.Refresh();
|
|
page.fdgDeliveryDetail.Items.Refresh();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 加载接收单数据
|
|
/// 加载接收单数据
|
|
/// </summary>
|
|
/// </summary>
|
|
- private void LoadReceiptData()
|
|
|
|
|
|
+ internal void LoadReceiptData()
|
|
{
|
|
{
|
|
- // 材料企业-发货单导出数据包赋值 IsExportDelivery 字段为 true:导出后不可再修改、删除
|
|
|
|
- // 成品企业-接收单导出附件3的时候赋值 IsExportReceive 字段为 true:导出后不可编辑,不可重复导出
|
|
|
|
- // 成品企业-使用单导出附件4的时候赋值 IsExportUsage 字段为 true:导出后不可编辑,不可重复导出
|
|
|
|
- // 筛选当前工作年度、当前成品企业的所有发货单(数据包导入)
|
|
|
|
|
|
+ // 筛选当前工作年度、当前成品企业的所有发货单
|
|
var deliveryReceipts = _service.Query(x => x.WorkYear.Equals(_currUser!.WorkYear) && x.ReceivedCompanyName.Equals(_currUser.CompanyName))
|
|
var deliveryReceipts = _service.Query(x => x.WorkYear.Equals(_currUser!.WorkYear) && x.ReceivedCompanyName.Equals(_currUser.CompanyName))
|
|
.Include(x => x.DeliveryReceiptDetails);
|
|
.Include(x => x.DeliveryReceiptDetails);
|
|
DeliveryReceipts = new ObservableCollection<DeliveryReceipt>(deliveryReceipts);
|
|
DeliveryReceipts = new ObservableCollection<DeliveryReceipt>(deliveryReceipts);
|
|
@@ -413,16 +452,14 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
// 是否为新行:否
|
|
// 是否为新行:否
|
|
delivery.IsNewRow = false;
|
|
delivery.IsNewRow = false;
|
|
|
|
|
|
- // 收货单状态
|
|
|
|
- var status = delivery.ReceivedStatus;
|
|
|
|
-
|
|
|
|
- // 子表明细行
|
|
|
|
- var details = delivery.DeliveryReceiptDetails.OrderBy(x => x.PacketNo).ToArray();
|
|
|
|
- foreach (DeliveryReceiptDetail dtl in details)
|
|
|
|
- {
|
|
|
|
- dtl.IsNewRow = false;
|
|
|
|
- }
|
|
|
|
- delivery.DeliveryReceiptDetails = new ObservableCollection<DeliveryReceiptDetail>(details);
|
|
|
|
|
|
+ // todo 不分表不用判断,如果分表,需要判断
|
|
|
|
+ // 子表明细行:子表的 IsNewRow 用于保存子表是判断 Insert() / Update()
|
|
|
|
+ //var details = delivery.DeliveryReceiptDetails.OrderBy(x => x.PacketNo);
|
|
|
|
+ //foreach (DeliveryReceiptDetail dtl in details)
|
|
|
|
+ //{
|
|
|
|
+ // dtl.IsNewRow = false;
|
|
|
|
+ //}
|
|
|
|
+ //delivery.DeliveryReceiptDetails = new ObservableCollection<DeliveryReceiptDetail>(details);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -452,24 +489,76 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 会自动提交子表的编辑,不用手动 CommitEdit()
|
|
EntityState? detailState = App.Current.Services.GetService<IDataBaseService<DeliveryReceiptDetail>>()?.Entry(detail);
|
|
EntityState? detailState = App.Current.Services.GetService<IDataBaseService<DeliveryReceiptDetail>>()?.Entry(detail);
|
|
if (detailState != EntityState.Unchanged)
|
|
if (detailState != EntityState.Unchanged)
|
|
{
|
|
{
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
-
|
|
|
|
- // todo 如果子表删除了几行是什么情况?
|
|
|
|
}
|
|
}
|
|
|
|
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
|
- /// 汇总接收数据
|
|
|
|
- /// </summary>
|
|
|
|
- private void SummaryReceiveDetail()
|
|
|
|
|
|
+ private bool CheckDetailDataGrid(DataGrid fdgDeliveryDetail, bool isCheckZero)
|
|
{
|
|
{
|
|
|
|
+ foreach (DeliveryReceiptDetail dtl in fdgDeliveryDetail.Items)
|
|
|
|
+ {
|
|
|
|
+ // 获取行
|
|
|
|
+ DataGridRow? row = fdgDeliveryDetail.ItemContainerGenerator.ContainerFromItem(dtl) as DataGridRow;
|
|
|
|
+ if (row == null)
|
|
|
|
+ {
|
|
|
|
+ // 获取失败则滚动界面后重试
|
|
|
|
+ fdgDeliveryDetail.UpdateLayout();
|
|
|
|
+ fdgDeliveryDetail.ScrollIntoView(dtl);
|
|
|
|
+ row = fdgDeliveryDetail.ItemContainerGenerator.ContainerFromItem(dtl) as DataGridRow;
|
|
|
|
+ }
|
|
|
|
+ if (row == null) { continue; }
|
|
|
|
+
|
|
|
|
+ // 获取发运数量单元格
|
|
|
|
+ DataGridCellsPresenter? cellsPresenter = VisualUtil.FindVisualChild<DataGridCellsPresenter>(row);
|
|
|
|
+ DataGridCell? cell = cellsPresenter?.ItemContainerGenerator.ContainerFromIndex(3) as DataGridCell; // 不允许拖动改变列顺序
|
|
|
|
+ if (cell == null) { continue; }
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+ string? cellValue = "";
|
|
|
|
+ if (cell.Content is TextBox textBox)
|
|
|
|
+ {
|
|
|
|
+ cellValue = textBox.Text;
|
|
|
|
+ }
|
|
|
|
+ else if (cell.Content is TextBlock textBlock)
|
|
|
|
+ {
|
|
|
|
+ cellValue = textBlock.Text;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 非数值型:包括空?
|
|
|
|
+ bool isValid = decimal.TryParse(cellValue, out decimal receiveQty);
|
|
|
|
+ if (!isValid)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("子表[接受数量]列存在异常数据,请检查数据后重试!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // 负数
|
|
|
|
+ if (receiveQty < 0)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("子表[接受数量]列存在异常数据,请检查数据后重试!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // 0
|
|
|
|
+ if (isCheckZero && receiveQty == 0)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("子表[接受数量]列存在为 0 的数据,请检查数据后重试!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // 超出发运数量
|
|
|
|
+ if (receiveQty > dtl.ShippedQuantity)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("子表[接受数量]列存在为超出[发运数量]的数据,请检查数据后重试!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|