|
@@ -175,7 +175,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
page.dpShippedDate.IsEnabled = page.fieldShippedMan.IsEnabled = page.fieldShippedTel.IsEnabled = false;
|
|
|
|
|
|
// 隐藏明细发货和使用按钮
|
|
|
- page.btnAddDtl.Visibility = page.btnDeleteDtl.Visibility = page.sep2.Visibility = page.btnImportDtl.Visibility = page.btnExportDtl.Visibility = page.btnUseDtl.Visibility = Visibility.Collapsed;
|
|
|
+ page.btnAddDtl.Visibility = page.btnDeleteDtls.Visibility = page.sep2.Visibility = page.btnImportDtl.Visibility = page.btnExportDtl.Visibility = page.btnUseDtl.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
foreach (var col in page.fdgDeliveryDetail.Columns)
|
|
|
{
|
|
@@ -230,7 +230,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
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.btnDeleteDtls.Visibility = page.sep2.Visibility = page.btnImportDtl.Visibility = page.btnExportDtl.Visibility = page.btnReceiveDtl.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
// 隐藏明细表发货字段
|
|
|
foreach (var col in page.fdgDeliveryDetail.Columns)
|
|
@@ -251,8 +251,9 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
+ // 打开 TabPage ,切换到其他 TabPage 再切换回来后,不可编辑了,改为 StartsWith()
|
|
|
// 使用数量列必录且可编辑
|
|
|
- if (header.Equals("使用数量"))
|
|
|
+ if (header.StartsWith("使用数量"))
|
|
|
{
|
|
|
col.IsReadOnly = false;
|
|
|
col.Header = "使用数量*";
|
|
@@ -346,7 +347,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
|
|
|
// 获取当前合同信息的已发运数量
|
|
|
string contractNo = _selectedContract.ContractNo;
|
|
|
- double hasShippedQty = (double)DeliveryReceipts.Where(x => x.ContractNo.Equals(contractNo)).Select(x => x.ShippedQty).Sum();
|
|
|
+ decimal hasShippedQty = (decimal)DeliveryReceipts.Where(x => x.ContractNo.Equals(contractNo)).Select(x => x.ShippedQty).Sum();
|
|
|
|
|
|
// 新增发货单
|
|
|
CurrDeliveryReceipt = new DeliveryReceipt();
|
|
@@ -531,7 +532,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
|
|
|
// 更新为已复核
|
|
|
CurrDeliveryReceipt.ReceivedStatus = "已复核";
|
|
|
- var sele11 = cbReceivedStatus.SelectedItem;
|
|
|
+ cbReceivedStatus.SelectedItem = "已复核";
|
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
@@ -562,6 +563,12 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
// 如果编辑的列是发运数量/接收数量/使用数量,自动汇总至主表 更新使用状态
|
|
|
foreach (var cellInfo in e.RemovedCells)
|
|
|
{
|
|
|
+ if (cellInfo.Column == null || cellInfo.Column.Header == null)
|
|
|
+ {
|
|
|
+ // DataGridCellInfo 类型的值永不等于 null
|
|
|
+ continue; // 删除行时为 null
|
|
|
+ }
|
|
|
+
|
|
|
if (cellInfo.Column.Header.Equals("发运数量*"))
|
|
|
{
|
|
|
SummaryDeliveryDetail();
|
|
@@ -591,16 +598,55 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 手动触发值更新事件
|
|
|
+ // 手动触发值更新事件:此时没有切换焦点,不会自动触发更新
|
|
|
OnPropertyChanged(new PropertyChangedEventArgs("CurrDeliveryReceipt"));
|
|
|
}
|
|
|
|
|
|
// 单元格切换时,Added 里的是新单元格;Removed是旧单元格
|
|
|
if (e.AddedCells.Count > 0)
|
|
|
{
|
|
|
- // 进入单元格时自动进入编辑状态
|
|
|
- fdgDeliveryDetail.BeginEdit();
|
|
|
+ foreach (var cellInfo in e.AddedCells)
|
|
|
+ {
|
|
|
+ // 进入单元格时自动进入编辑状态
|
|
|
+ fdgDeliveryDetail.BeginEdit();
|
|
|
+
|
|
|
+ // todo IsValid ?
|
|
|
+ if (cellInfo.IsValid) { }
|
|
|
+ if (cellInfo.Column == null)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 单击勾选/取消勾选行
|
|
|
+ if (cellInfo.Column is DataGridCheckBoxColumn colCheck)
|
|
|
+ {
|
|
|
+ var dtl = cellInfo.Item as DeliveryReceiptDetail;
|
|
|
+ if (dtl == null) { continue; }
|
|
|
+ //dtl.IsSelected = !dtl.IsSelected;
|
|
|
+ int rowIndex = CurrDeliveryReceipt.DeliveryReceiptDetails.IndexOf(dtl);
|
|
|
+
|
|
|
+
|
|
|
+ // 获取对应行
|
|
|
+ DataGridRow row = GetDataGridRow(fdgDeliveryDetail, rowIndex);
|
|
|
+ if (row == null) { continue; }
|
|
|
+
|
|
|
+ // 选中当前行:该列绑定 row.IsSelected 属性,整行选中。
|
|
|
+ // todo 不能多选,重写 DataGridCheckBoxColumn 的 Template 实现多选
|
|
|
+ row.IsSelected = !row.IsSelected;
|
|
|
+ // 不管用
|
|
|
+ //if (row.IsSelected)
|
|
|
+ //{
|
|
|
+ // fdgDeliveryDetail.SelectedItems.Add(row);
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // fdgDeliveryDetail.SelectedItems.Remove(row);
|
|
|
+ //}
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
@@ -625,7 +671,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
|
- public void DeleteDetail(DataGrid fdgDeliveryDetail)
|
|
|
+ public void DeleteDetails(DataGrid fdgDeliveryDetail)
|
|
|
{
|
|
|
// todo 多选删除
|
|
|
// 主表行为空直接返回
|
|
@@ -638,70 +684,115 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 若没有选择行,直接返回
|
|
|
- var selectedRows = CurrDeliveryReceipt.DeliveryReceiptDetails.Where(x => x.IsSelected);
|
|
|
- if (!selectedRows.Any())
|
|
|
+ var details = CurrDeliveryReceipt.DeliveryReceiptDetails;
|
|
|
+ var selectedRows = fdgDeliveryDetail.SelectedItems;
|
|
|
+
|
|
|
+ // 没选中行则提示后返回
|
|
|
+ var selectedCells = fdgDeliveryDetail.SelectedCells; // 一行8个单元格(因为表结构有8列)
|
|
|
+ if (selectedCells.Count == 0)
|
|
|
{
|
|
|
MessageBox.Show("请选择行后删除!");
|
|
|
return;
|
|
|
}
|
|
|
- int selectedCount = selectedRows.Count();
|
|
|
+
|
|
|
+ // todo 赋值失败,暂时不管
|
|
|
+ // 选中的单元格自动选中整行
|
|
|
+ foreach (var cellInfo in selectedCells)
|
|
|
+ {
|
|
|
+ var row = cellInfo.Item as DeliveryReceiptDetail;
|
|
|
+ if (row == null) { continue; }
|
|
|
+
|
|
|
+ // 跳过已选择行的单元格
|
|
|
+ if (selectedRows.Contains(row)) { continue; }
|
|
|
+
|
|
|
+ int index = CurrDeliveryReceipt.DeliveryReceiptDetails.IndexOf(row);
|
|
|
+ DataGridRow dgRow = GetDataGridRow(fdgDeliveryDetail, index);
|
|
|
+ dgRow.IsSelected = true; // 赋值失败
|
|
|
+ fdgDeliveryDetail.SelectedItems.Add(row); // 没有添加上
|
|
|
+ MessageBox.Show("看下是否选中");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 选中的整行
|
|
|
+ int selectedCount = selectedRows.Count;
|
|
|
+ if (selectedCount == 0)
|
|
|
+ {
|
|
|
+ // 选中的单元格
|
|
|
+ MessageBox.Show("请选择行后删除!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
int newRowCount = 0;
|
|
|
StringBuilder hint = new StringBuilder();
|
|
|
- foreach (var detail in selectedRows)
|
|
|
+ List<DeliveryReceiptDetail> savedRows = new List<DeliveryReceiptDetail>();
|
|
|
+ for (int i = details.Count - 1; i >= 0; i--)
|
|
|
{
|
|
|
+ var dtl = details[i];
|
|
|
+ if (!selectedRows.Contains(dtl)) { continue; }
|
|
|
+
|
|
|
// 未保存行直接删除
|
|
|
- if (detail.IsNewRow)
|
|
|
+ if (dtl.IsNewRow)
|
|
|
{
|
|
|
- CurrDeliveryReceipt.DeliveryReceiptDetails.Remove(detail);
|
|
|
+ details.Remove(dtl);
|
|
|
newRowCount++;
|
|
|
// fdgDeliveryDetail.Items.Refresh(); // 刷新索引:删除后单元格变化,不允许刷新索引
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
// 已保存行判断是否修改
|
|
|
- EntityState? state = App.Current.Services.GetService<IDataBaseService<DeliveryReceiptDetail>>()?.Entry(detail);
|
|
|
+ EntityState? state = App.Current.Services.GetService<IDataBaseService<DeliveryReceiptDetail>>()?.Entry(dtl);
|
|
|
if (state == null) { continue; }
|
|
|
switch (state)
|
|
|
{
|
|
|
- // 未改变的行,直接询问,没有提示信息
|
|
|
case EntityState.Added: // 不会是新增行(IsNewRow)
|
|
|
case EntityState.Deleted: // 正常情况下不会出现 Deleted (删除后刷新界面)
|
|
|
case EntityState.Detached: // 正常情况下不会出现 Detached
|
|
|
- case EntityState.Unchanged:
|
|
|
+ case EntityState.Unchanged: // 未改变的行,直接询问,没有提示信息
|
|
|
+ savedRows.Add(dtl);
|
|
|
break;
|
|
|
- case EntityState.Modified: // 询问
|
|
|
+ case EntityState.Modified: // 保存行已修改,提示已修改
|
|
|
{
|
|
|
- int index = CurrDeliveryReceipt.DeliveryReceiptDetails.IndexOf(detail);
|
|
|
- hint.AppendLine($"第 {index + 1} 行");
|
|
|
+ savedRows.Add(dtl);
|
|
|
+
|
|
|
+ int index = details.IndexOf(dtl);
|
|
|
+ hint.Append($"\n第 {index + 1} 行");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 已保存行 则询问后删除
|
|
|
- if (newRowCount < selectedCount)
|
|
|
+ if (newRowCount + savedRows.Count < 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; }
|
|
|
+ MessageBox.Show("存在异常行");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- // ×界面删除当前行
|
|
|
- // 数据库删除当前行
|
|
|
- // 刷新界面
|
|
|
+ // 已保存行 则询问后删除
|
|
|
+ string msg = "是否确定删除选中行?";
|
|
|
+ if (hint.Length > 0)
|
|
|
+ {
|
|
|
+ msg = msg.Insert(0, "以下数据已修改,") + hint;
|
|
|
+ }
|
|
|
+ MessageBoxResult result = MessageBox.Show(msg, "询问", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
|
|
|
+ if (result != MessageBoxResult.Yes) { return; }
|
|
|
|
|
|
+ // 删除行
|
|
|
+ var serviceDtl = App.Current.Services.GetService<IDataBaseService<DeliveryReceiptDetail>>();
|
|
|
+ foreach (DeliveryReceiptDetail dtl in savedRows)
|
|
|
+ {
|
|
|
+ // 界面删除
|
|
|
+ details.Remove(dtl);
|
|
|
+ fdgDeliveryDetail.Items.Refresh(); // 刷新索引
|
|
|
+ // 数据库删除
|
|
|
+ serviceDtl?.Delete(dtl);
|
|
|
+ }
|
|
|
|
|
|
+ // 保存到数据库
|
|
|
+ bool? isSuccess = serviceDtl?.SaveChanges();
|
|
|
+ if (isSuccess == null || !(bool)isSuccess)
|
|
|
+ {
|
|
|
+ // 删除失败提示
|
|
|
+ MessageBox.Show("删除失败!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -901,7 +992,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
// 可发运数量:合同数量 - 已发运数量
|
|
|
string contractNo = delivery.ContractNo;
|
|
|
string productName = delivery.ProductName;
|
|
|
- double hasShippedQty = (double)DeliveryReceipts.Where(x => x.ContractNo.Equals(contractNo) && x.ProductName.Equals(productName)).Select(x => x.ShippedQty).Sum();
|
|
|
+ decimal hasShippedQty = (decimal)DeliveryReceipts.Where(x => x.ContractNo.Equals(contractNo) && x.ProductName.Equals(productName)).Select(x => x.ShippedQty).Sum();
|
|
|
delivery.RemainQty = delivery.ContractQty - hasShippedQty;
|
|
|
|
|
|
// 是否为新行:否
|
|
@@ -1048,7 +1139,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
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();
|
|
|
+ decimal deliQty = details.Where(x => x.ShippedQuantity > 0).Select(x => x.ShippedQuantity).Sum();
|
|
|
CurrDeliveryReceipt.ShippedQty = deliQty;
|
|
|
}
|
|
|
|
|
@@ -1057,7 +1148,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
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();
|
|
|
+ decimal? receQty = details.Where(x => x.ReceiveQuantity != null && x.ReceiveQuantity > 0).Select(x => x.ReceiveQuantity).Sum();
|
|
|
CurrDeliveryReceipt.ReceivedQty = receQty ?? 0;
|
|
|
}
|
|
|
|
|
@@ -1111,7 +1202,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
// 计算发运包数和发运数量
|
|
|
int packNum = CurrDeliveryReceipt.DeliveryReceiptDetails.Count;
|
|
|
CurrDeliveryReceipt.ShippedPackets = packNum;
|
|
|
- double shippedQty = CurrDeliveryReceipt.DeliveryReceiptDetails.Select(x => x.ShippedQuantity).Sum();
|
|
|
+ decimal shippedQty = CurrDeliveryReceipt.DeliveryReceiptDetails.Select(x => x.ShippedQuantity).Sum();
|
|
|
CurrDeliveryReceipt.ShippedQty = shippedQty;
|
|
|
|
|
|
// 检查发运数量不能超出可发运数量
|
|
@@ -1171,6 +1262,21 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ private DataGridRow GetDataGridRow(DataGrid dataGrid, int index)
|
|
|
+ {
|
|
|
+ // 获取对应行
|
|
|
+ DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(index);
|
|
|
+ if (row == null)
|
|
|
+ {
|
|
|
+ // DataGrid 默认动态加载行,若获取不到新增行,则滚动到新增行后重试
|
|
|
+ dataGrid.UpdateLayout();
|
|
|
+ dataGrid.ScrollIntoView(dataGrid.Items[index]);
|
|
|
+ row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(index);
|
|
|
+ }
|
|
|
+
|
|
|
+ return row;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|