|
@@ -1,5 +1,6 @@
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
+using DocumentFormat.OpenXml.Spreadsheet;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
using Microsoft.Win32;
|
|
|
using System.Collections.ObjectModel;
|
|
@@ -231,7 +232,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
Attachment = SelectedUnExportContract.Attachment;
|
|
|
ApplyAttachment = SelectedUnExportContract.ApplyAttachment;
|
|
|
|
|
|
- var existDetails = _contractDetailService.QueryNoTracking(x => x.ContractGuid == SelectedUnExportContract.Guid).Include(x=>x.Material).ToList();
|
|
|
+ var existDetails = _contractDetailService.QueryNoTracking(x => x.ContractGuid == SelectedUnExportContract.Guid).Include(x => x.Material).ToList();
|
|
|
ContractDetails.Clear();
|
|
|
foreach (var detail in existDetails)
|
|
|
{
|
|
@@ -570,6 +571,98 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 导出数据包
|
|
|
+ /// </summary>
|
|
|
+ [RelayCommand]
|
|
|
+ private void ExportDataPacket()
|
|
|
+ {
|
|
|
+ if (UnExportContracts.Count == 0) return;
|
|
|
+
|
|
|
+ List<ContractModel> selectedContracts = new List<ContractModel>();
|
|
|
+ foreach (var contract in UnExportContracts)
|
|
|
+ {
|
|
|
+ if (contract.IsSelected)
|
|
|
+ {
|
|
|
+ selectedContracts.Add(contract);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (selectedContracts.Count == 0) return;
|
|
|
+
|
|
|
+ var result = MessageBox.Show($"共选中{selectedContracts.Count}行合同数据,确认导出为合同数据包吗?(导出后将无法修改和删除)", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
|
|
|
+
|
|
|
+ if (result != MessageBoxResult.OK) return;
|
|
|
+
|
|
|
+ var contractList = _contractService.Query(x => !x.ExportStatus)
|
|
|
+ .Include(x => x.Company)
|
|
|
+ .Include(x => x.PurchaseCompany)
|
|
|
+ .Include(x => x.ContractDetails)
|
|
|
+ .ThenInclude(x => x.Material)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ //移除未勾选
|
|
|
+ for (int i = contractList.Count - 1; i >= 0; i--)
|
|
|
+ {
|
|
|
+ var contains = selectedContracts.Any(x => x.Guid == contractList[i].Guid);
|
|
|
+ if (!contains)
|
|
|
+ {
|
|
|
+ contractList.Remove(contractList[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //导出合同数据包
|
|
|
+ var contracts = contractList.ToArray();
|
|
|
+ var materialCompanies = contracts.Select(x => x.Company).Distinct().ToArray();//材料企业
|
|
|
+ var purchaseCompanies = contracts.Select(x => x.PurchaseCompany).Distinct().ToArray();//成品企业
|
|
|
+ var companies = materialCompanies.Concat(purchaseCompanies).ToArray(); //合并材料企业、成品企业
|
|
|
+ //获取合同明细
|
|
|
+ List<ContractDetail> details = [];
|
|
|
+ foreach (var contract in contracts)
|
|
|
+ {
|
|
|
+ foreach (var detail in contract.ContractDetails)
|
|
|
+ {
|
|
|
+ details.Add(detail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var materials = details.ToArray().Select(x => x.Material).Distinct().ToArray();
|
|
|
+
|
|
|
+ //(材料+成品)企业->合同->材料->合同明细
|
|
|
+ if (companies is { Length: > 0 })
|
|
|
+ {
|
|
|
+ DataBaseUtil.ExportTable(companies, "Companies", true);
|
|
|
+ }
|
|
|
+ if (contracts is { Length: > 0 })
|
|
|
+ {
|
|
|
+ DataBaseUtil.ExportTable(contracts, "Contracts");
|
|
|
+ }
|
|
|
+ if (materials is { Length: > 0 })
|
|
|
+ {
|
|
|
+ DataBaseUtil.ExportTable(materials, "Materials");
|
|
|
+ }
|
|
|
+ if (details is { Count: > 0 })
|
|
|
+ {
|
|
|
+ DataBaseUtil.ExportTable(details, "ContractDetails");
|
|
|
+ }
|
|
|
+
|
|
|
+ //对导出数据进行加密,用户选择保存位置
|
|
|
+ DataBaseUtil.ExportData();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 导入数据包
|
|
|
+ /// </summary>
|
|
|
+ [RelayCommand]
|
|
|
+ private void ImportDataPacket()
|
|
|
+ {
|
|
|
+ var path = DataBaseUtil.ImportData();
|
|
|
+
|
|
|
+ var result = DataBaseUtil.QueryAll<Contract>(path, q =>
|
|
|
+ q.Include(x => x.Company)
|
|
|
+ .Include(x => x.PurchaseCompany));
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 修改采购合同的导出状态
|
|
|
/// </summary>
|
|
@@ -998,8 +1091,6 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
ExportAttachment(attachment, fileName);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
#endregion
|
|
|
|
|
|
#region 公用私有方法
|