|
@@ -13,6 +13,7 @@ using System.Windows.Controls;
|
|
using System.Windows.Media.Media3D;
|
|
using System.Windows.Media.Media3D;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
+using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
@@ -151,8 +152,11 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- // 批次号和包号只能导入,只允许编辑发运数量和备注列
|
|
|
|
- col.IsReadOnly = header.Equals("发运数量*") || header.Equals("备注") ? false : true;
|
|
|
|
|
|
+ // 发运数量列必录,所有列都可编辑
|
|
|
|
+ if (header.Equals("发运数量"))
|
|
|
|
+ {
|
|
|
|
+ col.Header = "发运数量*";
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (_deliveryPageCategroy == DeliveryPageCategroy.Receipt)
|
|
else if (_deliveryPageCategroy == DeliveryPageCategroy.Receipt)
|
|
@@ -192,10 +196,21 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- // todo 其他列的 * 去掉
|
|
|
|
-
|
|
|
|
- // 只允许编辑接收数量和备注列
|
|
|
|
- col.IsReadOnly = header.Equals("接收数量*") || header.Equals("备注") ? false : true;
|
|
|
|
|
|
+ // 接收数量列必录且可编辑
|
|
|
|
+ if (header.Equals("接收数量"))
|
|
|
|
+ {
|
|
|
|
+ col.IsReadOnly = false;
|
|
|
|
+ col.Header = "接收数量*";
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 备注列可编辑
|
|
|
|
+ if (header.Equals("备注"))
|
|
|
|
+ {
|
|
|
|
+ col.IsReadOnly = false;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 其他列只读
|
|
|
|
+ col.IsReadOnly = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (_deliveryPageCategroy == DeliveryPageCategroy.Usage)
|
|
else if (_deliveryPageCategroy == DeliveryPageCategroy.Usage)
|
|
@@ -209,7 +224,10 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
// 发运字段不可编辑
|
|
// 发运字段不可编辑
|
|
page.tBlkShippedDate.Text = "发运时间:";
|
|
page.tBlkShippedDate.Text = "发运时间:";
|
|
page.dpShippedDate.IsEnabled = page.fieldShippedMan.IsEnabled = page.fieldShippedTel.IsEnabled = false;
|
|
page.dpShippedDate.IsEnabled = page.fieldShippedMan.IsEnabled = page.fieldShippedTel.IsEnabled = false;
|
|
- // todo 接收字段不可编辑 下拉列表的标题去掉 *
|
|
|
|
|
|
+
|
|
|
|
+ // 接收字段不可编辑
|
|
|
|
+ page.tBlkReceivedStatus.Text = "收货单状态:";
|
|
|
|
+ page.dpReceivedDate.IsEnabled = page.fieldReceivedMan.IsEnabled = page.fieldReceivedTel.IsEnabled = page.cbReceivedStatus.IsEnabled = false;
|
|
|
|
|
|
// 隐藏明细发货和接收按钮
|
|
// 隐藏明细发货和接收按钮
|
|
page.btnAddDtl.Visibility = page.btnDeleteDtl.Visibility = page.sep2.Visibility = page.btnImportDtl.Visibility = page.btnExportDtl.Visibility = page.btnReceiveDtl.Visibility = Visibility.Collapsed;
|
|
page.btnAddDtl.Visibility = page.btnDeleteDtl.Visibility = page.sep2.Visibility = page.btnImportDtl.Visibility = page.btnExportDtl.Visibility = page.btnReceiveDtl.Visibility = Visibility.Collapsed;
|
|
@@ -233,14 +251,27 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
- // 只允许编辑使用数量和备注列
|
|
|
|
- col.IsReadOnly = header.Equals("使用数量*") || header.Equals("备注") ? false : true;
|
|
|
|
|
|
+ // 使用数量列必录且可编辑
|
|
|
|
+ if (header.Equals("使用数量"))
|
|
|
|
+ {
|
|
|
|
+ col.IsReadOnly = false;
|
|
|
|
+ col.Header = "使用数量*";
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 备注列可编辑
|
|
|
|
+ if (header.Equals("备注"))
|
|
|
|
+ {
|
|
|
|
+ col.IsReadOnly = false;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 其他列只读
|
|
|
|
+ col.IsReadOnly = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// CallMethodAction 不需要注册命令,可以传递事件参数。参数列表必须与事件自带的参数列表保持一致
|
|
// CallMethodAction 不需要注册命令,可以传递事件参数。参数列表必须与事件自带的参数列表保持一致
|
|
- public void DeliverySelectionChanged(object sender, SelectionChangedEventArgs args)
|
|
|
|
|
|
+ public void fdgDelivery_SelectionChanged(object sender, SelectionChangedEventArgs args)
|
|
{
|
|
{
|
|
// 手动屏蔽本事件
|
|
// 手动屏蔽本事件
|
|
if (!_isExcute) { return; }
|
|
if (!_isExcute) { return; }
|
|
@@ -350,7 +381,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
// 发运数量:自动汇总子表
|
|
// 发运数量:自动汇总子表
|
|
// 联系电话:手动输入
|
|
// 联系电话:手动输入
|
|
|
|
|
|
- OnPropertyChanged(CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.CurrDeliveryReceipt);
|
|
|
|
|
|
+ OnPropertyChanged(new PropertyChangedEventArgs("CurrDeliveryReceipt"));
|
|
}
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
[RelayCommand]
|
|
@@ -414,67 +445,27 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
if (CurrDeliveryReceipt == null) { return; }
|
|
if (CurrDeliveryReceipt == null) { return; }
|
|
if (CurrDeliveryReceipt.IsExportDelivery || CurrDeliveryReceipt.IsExportReceive || CurrDeliveryReceipt.IsExportUsage) { return; }
|
|
if (CurrDeliveryReceipt.IsExportDelivery || CurrDeliveryReceipt.IsExportReceive || CurrDeliveryReceipt.IsExportUsage) { return; }
|
|
|
|
|
|
- // todo 主表和子表 带 * 的列必录
|
|
|
|
- // 判断主表必录项:主表不允许编辑,判断编辑界面控件的值
|
|
|
|
|
|
+ // 删除子表空行
|
|
|
|
+ DeleteEmptyRows();
|
|
|
|
+
|
|
|
|
+ // 保存前校验
|
|
|
|
+ bool canSave = false;
|
|
switch (_deliveryPageCategroy)
|
|
switch (_deliveryPageCategroy)
|
|
{
|
|
{
|
|
case DeliveryPageCategroy.Delivery:
|
|
case DeliveryPageCategroy.Delivery:
|
|
- // todo 清空日期选择框,但 发运日期 并不会清空
|
|
|
|
- if (string.IsNullOrWhiteSpace(page.dpShippedDate.Text)) // DateTime 类型永远不等于 null
|
|
|
|
- {
|
|
|
|
- MessageBox.Show("发运时间为空,不允许保存!");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ canSave = VerifyDelivery(page.dpShippedDate);
|
|
break;
|
|
break;
|
|
case DeliveryPageCategroy.Receipt:
|
|
case DeliveryPageCategroy.Receipt:
|
|
- if (string.IsNullOrEmpty(CurrDeliveryReceipt.ReceivedStatus))
|
|
|
|
- {
|
|
|
|
- MessageBox.Show("收货单状态为空,不允许保存!");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ canSave = VerifyReceipt();
|
|
break;
|
|
break;
|
|
case DeliveryPageCategroy.Usage:
|
|
case DeliveryPageCategroy.Usage:
|
|
- if (CurrDeliveryReceipt.Licence == null)
|
|
|
|
- {
|
|
|
|
- MessageBox.Show("未上传许可证,不允许保存!");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ canSave = VerifyUsage();
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- // 判断子表必录项:带 * 的列必录(不好实现,先固定检查每一列)
|
|
|
|
- var nullBatchNoRows = CurrDeliveryReceipt.DeliveryReceiptDetails.Where(x => string.IsNullOrEmpty(x.BatchNo));
|
|
|
|
- var nullPackageNoRows = CurrDeliveryReceipt.DeliveryReceiptDetails.Where(x => string.IsNullOrEmpty(x.PacketNo));
|
|
|
|
- var nullShippedQty = CurrDeliveryReceipt.DeliveryReceiptDetails.Where(x => x.ShippedQuantity == 0);
|
|
|
|
- var nullReceivedQty = CurrDeliveryReceipt.DeliveryReceiptDetails.Where(x => x.ReceiveQuantity == 0);
|
|
|
|
- var nullUsageQty = CurrDeliveryReceipt.DeliveryReceiptDetails.Where(x => x.UsageQuantity == 0);
|
|
|
|
- // 根据页面类型校验子表必录项
|
|
|
|
-
|
|
|
|
- // 删除子表空行
|
|
|
|
- DeleteEmptyRows();
|
|
|
|
-
|
|
|
|
- // todo 子表新增行和删除行和修改列时实时计算
|
|
|
|
- // 计算发运包数和发运数量
|
|
|
|
- int packNum = CurrDeliveryReceipt.DeliveryReceiptDetails.Count;
|
|
|
|
- CurrDeliveryReceipt.ShippedPackets = packNum;
|
|
|
|
- double shippedQty = CurrDeliveryReceipt.DeliveryReceiptDetails.Select(x => x.ShippedQuantity).Sum();
|
|
|
|
- CurrDeliveryReceipt.ShippedQty = shippedQty;
|
|
|
|
-
|
|
|
|
- // 检查发运数量不能超出可发运数量
|
|
|
|
- if (CurrDeliveryReceipt.ShippedQty >= CurrDeliveryReceipt.RemainQty)
|
|
|
|
- {
|
|
|
|
- MessageBox.Show("发货数量超出可发运数量,请检查数据后重新保存!");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 检查子表的包号不允许重复
|
|
|
|
- // 保存时检查材料名称是否存在重复项
|
|
|
|
- var repeatPacketNos = CurrDeliveryReceipt.DeliveryReceiptDetails.GroupBy(x => x.PacketNo).Where(g => g.Count() > 1).Select(g => g.Key);
|
|
|
|
- if (repeatPacketNos.Any())
|
|
|
|
|
|
+ // 校验不通过,直接返回
|
|
|
|
+ if (!canSave)
|
|
{
|
|
{
|
|
- // 若存在重复项则提示后返回
|
|
|
|
- string repeatPacketNoText = string.Join("、", repeatPacketNos.ToArray());
|
|
|
|
- MessageBox.Show("材料包号列存在以下重复值,请修改后保存:" + repeatPacketNoText, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -493,7 +484,6 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
{
|
|
{
|
|
// 已保存行更新到数据库
|
|
// 已保存行更新到数据库
|
|
// todo 主表已保存,但子表明细 新增/删除/修改 怎么保存
|
|
// todo 主表已保存,但子表明细 新增/删除/修改 怎么保存
|
|
-
|
|
|
|
_service.Update(CurrDeliveryReceipt);
|
|
_service.Update(CurrDeliveryReceipt);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -509,6 +499,41 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ [RelayCommand]
|
|
|
|
+ public void Check(ComboBox cbReceivedStatus)
|
|
|
|
+ {
|
|
|
|
+ if (CurrDeliveryReceipt == null) { return; }
|
|
|
|
+
|
|
|
|
+ var sele00 = cbReceivedStatus.SelectedItem;
|
|
|
|
+ string status = CurrDeliveryReceipt.ReceivedStatus ?? string.Empty;
|
|
|
|
+ if (status.Equals("已复核"))
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("当前接收单已复核,不用重复复核。");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 校验子表接收数量列
|
|
|
|
+ StringBuilder nullHint = new StringBuilder();
|
|
|
|
+ foreach (var dtl in CurrDeliveryReceipt.DeliveryReceiptDetails)
|
|
|
|
+ {
|
|
|
|
+ var 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新为已复核
|
|
|
|
+ CurrDeliveryReceipt.ReceivedStatus = "已复核";
|
|
|
|
+ var sele11 = cbReceivedStatus.SelectedItem;
|
|
|
|
+ }
|
|
|
|
+
|
|
[RelayCommand]
|
|
[RelayCommand]
|
|
public void DetailSelectionChanged(DataGrid fdgDeliveryDetail)
|
|
public void DetailSelectionChanged(DataGrid fdgDeliveryDetail)
|
|
{
|
|
{
|
|
@@ -524,21 +549,58 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
//fdgDeliveryDetail.CancelEdit();
|
|
//fdgDeliveryDetail.CancelEdit();
|
|
}
|
|
}
|
|
|
|
|
|
- [RelayCommand]
|
|
|
|
- public void DetailCellChanged(DataGrid fdgDeliveryDetail)
|
|
|
|
|
|
+ public void fdgDeliveryDetail_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
|
|
{
|
|
{
|
|
- fdgDeliveryDetail.BeginEdit(); // 单击进入编辑状态
|
|
|
|
- //fdgDeliveryDetail.CommitEdit();
|
|
|
|
-
|
|
|
|
|
|
+ DataGrid? fdgDeliveryDetail = sender as DataGrid;
|
|
|
|
+ if (fdgDeliveryDetail == null) { return; }
|
|
|
|
|
|
- var items = fdgDeliveryDetail.Items;
|
|
|
|
- DeliveryReceiptDetail? row = fdgDeliveryDetail.CurrentCell.Item as DeliveryReceiptDetail;
|
|
|
|
- if (row != null)
|
|
|
|
|
|
+ if (e.RemovedCells.Count > 0)
|
|
{
|
|
{
|
|
- int rowIndex = DeliveryDetails.IndexOf(row);
|
|
|
|
- int colIndex = fdgDeliveryDetail.CurrentCell.Column.DisplayIndex;
|
|
|
|
|
|
+ // 离开单元格时提交编辑
|
|
|
|
+ fdgDeliveryDetail.CommitEdit();
|
|
|
|
+
|
|
|
|
+ // 如果编辑的列是发运数量/接收数量/使用数量,自动汇总至主表 更新使用状态
|
|
|
|
+ foreach (var cellInfo in e.RemovedCells)
|
|
|
|
+ {
|
|
|
|
+ if (cellInfo.Column.Header.Equals("发运数量*"))
|
|
|
|
+ {
|
|
|
|
+ SummaryDeliveryDetail();
|
|
|
|
+ }
|
|
|
|
+ else if (cellInfo.Column.Header.Equals("接收数量*"))
|
|
|
|
+ {
|
|
|
|
+ SummaryReceiveDetail();
|
|
|
|
+ }
|
|
|
|
+ else if (cellInfo.Column.Header.Equals("使用数量*"))
|
|
|
|
+ {
|
|
|
|
+ DeliveryReceiptDetail? detail = cellInfo.Item as DeliveryReceiptDetail;
|
|
|
|
+ if (detail == null) { continue; }
|
|
|
|
+
|
|
|
|
+ var usageQty = detail.UsageQuantity;
|
|
|
|
+ if (usageQty < 0)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("使用数量非法,请重新输入!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ else if (usageQty > detail.ReceiveQuantity)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("使用数量不能超过接收数量,请重新输入!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ detail.UsageStatus = usageQty == null || usageQty == 0 ? "未使用" : usageQty < detail.ReceiveQuantity ? "部分使用" : "全部使用";
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 手动触发值更新事件
|
|
|
|
+ OnPropertyChanged(new PropertyChangedEventArgs("CurrDeliveryReceipt"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 单元格切换时,Added 里的是新单元格;Removed是旧单元格
|
|
|
|
+ if (e.AddedCells.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ // 进入单元格时自动进入编辑状态
|
|
|
|
+ fdgDeliveryDetail.BeginEdit();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
[RelayCommand]
|
|
@@ -547,27 +609,28 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
// 若当前主表行为空,则直接返回
|
|
// 若当前主表行为空,则直接返回
|
|
if (CurrDeliveryReceipt == null) { return; }
|
|
if (CurrDeliveryReceipt == null) { return; }
|
|
|
|
|
|
|
|
+ // 已导出数据包的发货的不允许再新增明细
|
|
|
|
+ if (CurrDeliveryReceipt.IsExportDelivery)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("当前发货单已导出数据包,不允许新增明细!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
// 新增一行子表
|
|
// 新增一行子表
|
|
DeliveryReceiptDetail detail = new DeliveryReceiptDetail();
|
|
DeliveryReceiptDetail detail = new DeliveryReceiptDetail();
|
|
//DeliveryDetails.Add(detail);
|
|
//DeliveryDetails.Add(detail);
|
|
- // 当前子表数据绑定到主表 todo 主表行切换子表展示数据清空(但保存在主表中)
|
|
|
|
|
|
+ // 当前子表数据绑定到主表
|
|
|
|
+ // todo 主表行切换子表展示数据清空(但保存在主表中)
|
|
CurrDeliveryReceipt!.DeliveryReceiptDetails.Add(detail);
|
|
CurrDeliveryReceipt!.DeliveryReceiptDetails.Add(detail);
|
|
}
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
[RelayCommand]
|
|
- public void DeleteDetail(DataGrid dataGridDeliveryDetail)
|
|
|
|
|
|
+ public void DeleteDetail(DataGrid fdgDeliveryDetail)
|
|
{
|
|
{
|
|
// todo 多选删除
|
|
// todo 多选删除
|
|
// 主表行为空直接返回
|
|
// 主表行为空直接返回
|
|
if (CurrDeliveryReceipt == null) { return; }
|
|
if (CurrDeliveryReceipt == null) { return; }
|
|
|
|
|
|
- // 已导出数据包的发货的不允许再新增明细
|
|
|
|
- if (CurrDeliveryReceipt.IsExportDelivery)
|
|
|
|
- {
|
|
|
|
- MessageBox.Show("当前发货单已导出数据包,不允许新增明细!");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// 已导出数据包的发货的不允许再删除明细
|
|
// 已导出数据包的发货的不允许再删除明细
|
|
if (CurrDeliveryReceipt.IsExportDelivery)
|
|
if (CurrDeliveryReceipt.IsExportDelivery)
|
|
{
|
|
{
|
|
@@ -576,51 +639,69 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
}
|
|
}
|
|
|
|
|
|
// 若没有选择行,直接返回
|
|
// 若没有选择行,直接返回
|
|
- DeliveryReceiptDetail? detail = dataGridDeliveryDetail.SelectedItem as DeliveryReceiptDetail;
|
|
|
|
- if (detail == null) { return; }
|
|
|
|
-
|
|
|
|
- // 未保存行直接删除
|
|
|
|
- if (detail.IsNewRow)
|
|
|
|
|
|
+ var selectedRows = CurrDeliveryReceipt.DeliveryReceiptDetails.Where(x => x.IsSelected);
|
|
|
|
+ if (!selectedRows.Any())
|
|
{
|
|
{
|
|
- CurrDeliveryReceipt.DeliveryReceiptDetails.Remove(detail);
|
|
|
|
- dataGridDeliveryDetail.Items.Refresh(); // 刷新索引
|
|
|
|
|
|
+ MessageBox.Show("请选择行后删除!");
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- // 已保存行 则询问
|
|
|
|
- else
|
|
|
|
|
|
+ int selectedCount = selectedRows.Count();
|
|
|
|
+
|
|
|
|
+ int newRowCount = 0;
|
|
|
|
+ StringBuilder hint = new StringBuilder();
|
|
|
|
+ foreach (var detail in selectedRows)
|
|
{
|
|
{
|
|
- // 判断当前行是否已修改
|
|
|
|
- EntityState? state = App.Current.Services.GetService<IDataBaseService<DeliveryReceiptDetail>>()?.Entry(detail);
|
|
|
|
- if (state == null)
|
|
|
|
|
|
+ // 未保存行直接删除
|
|
|
|
+ if (detail.IsNewRow)
|
|
{
|
|
{
|
|
- MessageBox.Show("判断当前行状态出错!");
|
|
|
|
- return;
|
|
|
|
|
|
+ CurrDeliveryReceipt.DeliveryReceiptDetails.Remove(detail);
|
|
|
|
+ newRowCount++;
|
|
|
|
+ // fdgDeliveryDetail.Items.Refresh(); // 刷新索引:删除后单元格变化,不允许刷新索引
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 已保存行判断是否修改
|
|
|
|
+ EntityState? state = App.Current.Services.GetService<IDataBaseService<DeliveryReceiptDetail>>()?.Entry(detail);
|
|
|
|
+ if (state == null) { continue; }
|
|
switch (state)
|
|
switch (state)
|
|
{
|
|
{
|
|
|
|
+ // 未改变的行,直接询问,没有提示信息
|
|
|
|
+ case EntityState.Added: // 不会是新增行(IsNewRow)
|
|
|
|
+ case EntityState.Deleted: // 正常情况下不会出现 Deleted (删除后刷新界面)
|
|
|
|
+ case EntityState.Detached: // 正常情况下不会出现 Detached
|
|
case EntityState.Unchanged:
|
|
case EntityState.Unchanged:
|
|
- {
|
|
|
|
- // 已保存行询问,不删除则跳过
|
|
|
|
- MessageBoxResult result = MessageBox.Show("是否确定删除当前行?", "询问", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
|
|
|
- if (result != MessageBoxResult.Yes) { return; }
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- //case EntityState.Added: // 不会是新增行(IsNewRow)
|
|
|
|
- //case EntityState.Deleted: // 正常情况下不会出现 Deleted (删除后刷新界面)
|
|
|
|
- //case EntityState.Detached: // 正常情况下不会出现 Detached
|
|
|
|
|
|
+ break;
|
|
case EntityState.Modified: // 询问
|
|
case EntityState.Modified: // 询问
|
|
{
|
|
{
|
|
- // 已修改行询问,不删除则跳过
|
|
|
|
- MessageBoxResult result = MessageBox.Show("当前行数据已修改,是否确定删除当前行?", "询问", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
|
|
|
- if (result != MessageBoxResult.Yes) { return; }
|
|
|
|
|
|
+ int index = CurrDeliveryReceipt.DeliveryReceiptDetails.IndexOf(detail);
|
|
|
|
+ hint.AppendLine($"第 {index + 1} 行");
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- default: break;
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 已保存行 则询问后删除
|
|
|
|
+ if (newRowCount < selectedCount)
|
|
|
|
+ {
|
|
|
|
+ string msg = string.Empty;
|
|
|
|
+ if (hint.Length > 0)
|
|
|
|
+ {
|
|
|
|
+ msg = "是否确定删除选中行?";
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ msg = "以下数据已修改,是否确定删除选中行?\n" + hint;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 已保存行询问,不删除则跳过
|
|
|
|
+ MessageBoxResult result = MessageBox.Show(msg, "询问", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
|
|
|
+ if (result != MessageBoxResult.Yes) { return; }
|
|
|
|
+
|
|
// ×界面删除当前行
|
|
// ×界面删除当前行
|
|
// 数据库删除当前行
|
|
// 数据库删除当前行
|
|
// 刷新界面
|
|
// 刷新界面
|
|
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -774,6 +855,36 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
ExcelUtil.CreateExcelFromDataTable(dtDetail, saveFileDialog.FileName);
|
|
ExcelUtil.CreateExcelFromDataTable(dtDetail, saveFileDialog.FileName);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ [RelayCommand]
|
|
|
|
+ public void ReceiveAll()
|
|
|
|
+ {
|
|
|
|
+ if (CurrDeliveryReceipt == null) { return; }
|
|
|
|
+
|
|
|
|
+ var details = CurrDeliveryReceipt.DeliveryReceiptDetails;
|
|
|
|
+ if (details == null || details.Count == 0) { return; }
|
|
|
|
+
|
|
|
|
+ // 全部接收:将发货数量列赋值到接收数量列
|
|
|
|
+ foreach (var dtl in details)
|
|
|
|
+ {
|
|
|
|
+ dtl.ReceiveQuantity = dtl.ShippedQuantity;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [RelayCommand]
|
|
|
|
+ public void UseAll()
|
|
|
|
+ {
|
|
|
|
+ if (CurrDeliveryReceipt == null) { return; }
|
|
|
|
+
|
|
|
|
+ var details = CurrDeliveryReceipt.DeliveryReceiptDetails;
|
|
|
|
+ if (details == null || details.Count == 0) { return; }
|
|
|
|
+
|
|
|
|
+ // 全部接收:将发货数量列赋值到接收数量列
|
|
|
|
+ foreach (var dtl in details)
|
|
|
|
+ {
|
|
|
|
+ dtl.UsageQuantity = dtl.ReceiveQuantity;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 加载发货单数据
|
|
/// 加载发货单数据
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -931,6 +1042,135 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
|
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void SummaryDeliveryDetail()
|
|
|
|
+ {
|
|
|
|
+ var details = CurrDeliveryReceipt!.DeliveryReceiptDetails;
|
|
|
|
+ int deliCount = details.Where(x => x.ShippedQuantity > 0).Count();
|
|
|
|
+ CurrDeliveryReceipt.ShippedPackets = deliCount;
|
|
|
|
+ double deliQty = details.Where(x => x.ShippedQuantity > 0).Select(x => x.ShippedQuantity).Sum();
|
|
|
|
+ CurrDeliveryReceipt.ShippedQty = deliQty;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void SummaryReceiveDetail()
|
|
|
|
+ {
|
|
|
|
+ var details = CurrDeliveryReceipt!.DeliveryReceiptDetails;
|
|
|
|
+ int receCount = details.Where(x => x.ReceiveQuantity != null && x.ReceiveQuantity > 0).Count();
|
|
|
|
+ CurrDeliveryReceipt.ReceivedPackets = receCount;
|
|
|
|
+ double? receQty = details.Where(x => x.ReceiveQuantity != null && x.ReceiveQuantity > 0).Select(x => x.ReceiveQuantity).Sum();
|
|
|
|
+ CurrDeliveryReceipt.ReceivedQty = receQty ?? 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void SummaryUsageDetail()
|
|
|
|
+ {
|
|
|
|
+ var details = CurrDeliveryReceipt!.DeliveryReceiptDetails;
|
|
|
|
+ foreach (var dtl in details)
|
|
|
|
+ {
|
|
|
|
+ if (dtl.UsageQuantity < dtl.ReceiveQuantity)
|
|
|
|
+ {
|
|
|
|
+ dtl.UsageStatus = "";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private bool VerifyDelivery(DatePicker datePicker)
|
|
|
|
+ {
|
|
|
|
+ // 检查主表必录项
|
|
|
|
+ // todo 清空日期选择框,但 发运日期 并不会清空
|
|
|
|
+ if (string.IsNullOrWhiteSpace(datePicker.Text)) // DateTime 类型永远不等于 null
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("发运时间为空,不允许保存!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 检查子表必录项
|
|
|
|
+ var nullBatchNoRows = CurrDeliveryReceipt!.DeliveryReceiptDetails.Where(x => string.IsNullOrEmpty(x.BatchNo));
|
|
|
|
+ var nullPackageNoRows = CurrDeliveryReceipt.DeliveryReceiptDetails.Where(x => string.IsNullOrEmpty(x.PacketNo));
|
|
|
|
+ var nullShippedQty = CurrDeliveryReceipt.DeliveryReceiptDetails.Where(x => x.ShippedQuantity == 0);
|
|
|
|
+ StringBuilder nullFields = new StringBuilder();
|
|
|
|
+ if (nullBatchNoRows.Any())
|
|
|
|
+ {
|
|
|
|
+ nullFields.Append("批次号、");
|
|
|
|
+ }
|
|
|
|
+ if (nullPackageNoRows.Any())
|
|
|
|
+ {
|
|
|
|
+ nullFields.Append("材料包号、");
|
|
|
|
+ }
|
|
|
|
+ if (nullPackageNoRows.Any())
|
|
|
|
+ {
|
|
|
|
+ nullFields.Append("发运数量、");
|
|
|
|
+ }
|
|
|
|
+ if (nullFields.Length > 0)
|
|
|
|
+ {
|
|
|
|
+ nullFields = nullFields.Remove(nullFields.Length - 1, 1);
|
|
|
|
+ MessageBox.Show($"明细表的{nullFields}存在空值,不允许保存!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // todo 子表新增行和删除行和修改列时实时计算
|
|
|
|
+ // 计算发运包数和发运数量
|
|
|
|
+ int packNum = CurrDeliveryReceipt.DeliveryReceiptDetails.Count;
|
|
|
|
+ CurrDeliveryReceipt.ShippedPackets = packNum;
|
|
|
|
+ double shippedQty = CurrDeliveryReceipt.DeliveryReceiptDetails.Select(x => x.ShippedQuantity).Sum();
|
|
|
|
+ CurrDeliveryReceipt.ShippedQty = shippedQty;
|
|
|
|
+
|
|
|
|
+ // 检查发运数量不能超出可发运数量
|
|
|
|
+ if (CurrDeliveryReceipt.ShippedQty >= CurrDeliveryReceipt.RemainQty)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("发货数量超出可发运数量,请检查数据后重新保存!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 检查子表的包号不允许重复
|
|
|
|
+ // 保存时检查材料名称是否存在重复项
|
|
|
|
+ var repeatPacketNos = CurrDeliveryReceipt.DeliveryReceiptDetails.GroupBy(x => x.PacketNo).Where(g => g.Count() > 1).Select(g => g.Key);
|
|
|
|
+ if (repeatPacketNos.Any())
|
|
|
|
+ {
|
|
|
|
+ // 若存在重复项则提示后返回
|
|
|
|
+ string repeatPacketNoText = string.Join("、", repeatPacketNos.ToArray());
|
|
|
|
+ MessageBox.Show("材料包号列存在以下重复值,请修改后保存:" + repeatPacketNoText, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private bool VerifyReceipt()
|
|
|
|
+ {
|
|
|
|
+ var nullReceivedQty = CurrDeliveryReceipt!.DeliveryReceiptDetails.Where(x => x.ReceiveQuantity == 0);
|
|
|
|
+ if (string.IsNullOrEmpty(CurrDeliveryReceipt.ReceivedStatus))
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("收货单状态为空,不允许保存!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (nullReceivedQty.Any())
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("明细表的接收数量存在空值,不允许保存!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private bool VerifyUsage()
|
|
|
|
+ {
|
|
|
|
+ var nullUsageQty = CurrDeliveryReceipt!.DeliveryReceiptDetails.Where(x => x.UsageQuantity == 0);
|
|
|
|
+ if (CurrDeliveryReceipt.Licence == null)
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("未上传许可证,不允许保存!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (nullUsageQty.Any())
|
|
|
|
+ {
|
|
|
|
+ MessageBox.Show("明细表的使用数量存在空值,不允许保存!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|