|
@@ -98,9 +98,9 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
[RelayCommand]
|
|
|
private void LoadData()
|
|
|
{
|
|
|
- SelectedInspectCategory = SelectedInspectCategory == null ? "" : SelectedInspectCategory;
|
|
|
- SelectedCompany = SelectedCompany == null ? "" : SelectedCompany;
|
|
|
- var materialName = SelectedMaterial == null ? "" : SelectedMaterial.Name;
|
|
|
+ SelectedInspectCategory = SelectedInspectCategory ?? "";
|
|
|
+ SelectedCompany = SelectedCompany ?? "";
|
|
|
+ var materialName = SelectedMaterial?.Name ?? string.Empty;
|
|
|
|
|
|
var inspectAppliesList = _inspectService.QueryNoTracking(x => x.Year == WorkYear && x.Company.Contains(SelectedCompany) && x.InspCategory.Contains(SelectedInspectCategory) && x.ProductName.Contains(materialName))
|
|
|
.Include(x => x.InspectApplyDetails)
|
|
@@ -208,18 +208,128 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
/// 导入报检数据包
|
|
|
/// </summary>
|
|
|
[RelayCommand]
|
|
|
- private void ImportInspectApplyData()
|
|
|
+ private async Task ImportInspectApplyData()
|
|
|
{
|
|
|
+ var result = MessageBox.Show("您正在导入报检数据包,确认继续?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
|
|
|
+ if (result != MessageBoxResult.OK) return;
|
|
|
|
|
|
+ //导入并解密db文件
|
|
|
+ var path = DataBaseUtil.ImportData();
|
|
|
+
|
|
|
+ var inspectApplies = DataBaseUtil.QueryAll<InspectApply>(path, p => p
|
|
|
+ .Include(x => x.Material)
|
|
|
+ .Include(x => x.MaterialCompany)
|
|
|
+ .Include(x => x.InspectApplyContractDetails)
|
|
|
+ .Include(x => x.InspectApplyDetails)).Result.ToList();
|
|
|
+
|
|
|
+ var serialNumbers = DataBaseUtil.QueryAll<SerialNumber>(path).Result.ToList();
|
|
|
+
|
|
|
+ var materials = inspectApplies.ToArray().Select(x => x.Material).Distinct().ToArray();
|
|
|
+ var companies = inspectApplies.ToArray().Select(x => x.MaterialCompany).Distinct().ToArray();
|
|
|
+ List<InspectApplyContractDetail> contractDetails = [];
|
|
|
+ List<InspectApplyDetail> details = [];
|
|
|
+ foreach (var inspectApply in inspectApplies)
|
|
|
+ {
|
|
|
+ foreach (var contractDetail in inspectApply.InspectApplyContractDetails)
|
|
|
+ {
|
|
|
+ contractDetails.Add(contractDetail);
|
|
|
+ }
|
|
|
+ foreach (var detail in inspectApply.InspectApplyDetails)
|
|
|
+ {
|
|
|
+ details.Add(detail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //导入相关表数据:材料->企业->检验申请->检验申请合同明细->检验申请明细,流水号表
|
|
|
+ await DataBaseUtil.ImportTable("Materials", materials);
|
|
|
+ await DataBaseUtil.ImportTable("Companies", companies);
|
|
|
+ await DataBaseUtil.ImportTable("InspectApplies", inspectApplies);
|
|
|
+ await DataBaseUtil.ImportTable("InspectApplyContractDetails", contractDetails);
|
|
|
+ await DataBaseUtil.ImportTable("InspectApplyDetails", details);
|
|
|
+ await DataBaseUtil.ImportTable("SerialNumbers", serialNumbers);
|
|
|
+
|
|
|
+ MessageBox.Show("导入报检数据包成功!");
|
|
|
+
|
|
|
+ //重新加载数据
|
|
|
+ LoadData();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 导出报检数据包
|
|
|
/// </summary>
|
|
|
[RelayCommand]
|
|
|
- private void ExportInspectApplyData()
|
|
|
+ private async Task ExportInspectApplyData()
|
|
|
{
|
|
|
+ var result = MessageBox.Show("确认导出报检数据包吗?(仅导出“导出状态”为“未导出”的检验申请单)", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
|
|
|
+ if (result != MessageBoxResult.OK) return;
|
|
|
+
|
|
|
+ //导出数据包:未导出状态的申请表
|
|
|
+ var inspectApplies = _inspectService.Query(x => !x.ExportStatus)
|
|
|
+ .Include(x => x.Material)
|
|
|
+ .Include(x => x.MaterialCompany)
|
|
|
+ .Include(x => x.InspectApplyContractDetails)
|
|
|
+ .Include(x => x.InspectApplyDetails).ToArray();
|
|
|
+ if (inspectApplies.Length == 0)
|
|
|
+ {
|
|
|
+ MessageBox.Show("不存在可导出的检验申请表!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //将导出状态更新为已导出
|
|
|
+ foreach (var inspect in inspectApplies)
|
|
|
+ {
|
|
|
+ inspect.ExportStatus = true;
|
|
|
+ }
|
|
|
+ var success = _inspectService.SaveChanges();
|
|
|
+ if (!success) return;
|
|
|
+
|
|
|
+ var serialNumbers = _serialService.Query().ToArray();
|
|
|
+
|
|
|
+ var materials = inspectApplies.Select(x => x.Material).Distinct().ToArray();
|
|
|
+ var companies = inspectApplies.Select(x => x.MaterialCompany).Distinct().ToArray();
|
|
|
+ List<InspectApplyContractDetail> contractDetails = [];
|
|
|
+ List<InspectApplyDetail> details = [];
|
|
|
+ foreach (var inspectApply in inspectApplies)
|
|
|
+ {
|
|
|
+ foreach (var contractDetail in inspectApply.InspectApplyContractDetails)
|
|
|
+ {
|
|
|
+ contractDetails.Add(contractDetail);
|
|
|
+ }
|
|
|
+ foreach (var detail in inspectApply.InspectApplyDetails)
|
|
|
+ {
|
|
|
+ details.Add(detail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //导入相关表数据:材料->企业->检验申请->检验申请合同明细->检验申请明细,流水号表
|
|
|
+ if (materials is { Length: > 0 })
|
|
|
+ {
|
|
|
+ DataBaseUtil.ExportTable(materials, "Materials", true);
|
|
|
+ }
|
|
|
+ if (companies is { Length: > 0 })
|
|
|
+ {
|
|
|
+ DataBaseUtil.ExportTable(companies, "Companies");
|
|
|
+ }
|
|
|
+ if (inspectApplies is { Length: > 0 })
|
|
|
+ {
|
|
|
+ DataBaseUtil.ExportTable(inspectApplies, "InspectApplies");
|
|
|
+ }
|
|
|
+ if (contractDetails is { Count: > 0 })
|
|
|
+ {
|
|
|
+ DataBaseUtil.ExportTable(contractDetails, "InspectApplyContractDetails");
|
|
|
+ }
|
|
|
+ if (details is { Count: > 0 })
|
|
|
+ {
|
|
|
+ DataBaseUtil.ExportTable(details, "InspectApplyDetails");
|
|
|
+ }
|
|
|
+ if (serialNumbers is { Length: > 0 })
|
|
|
+ {
|
|
|
+ DataBaseUtil.ExportTable(serialNumbers, "SerialNumbers");
|
|
|
+ }
|
|
|
+
|
|
|
+ await DataBaseUtil.ExportData();
|
|
|
|
|
|
+ MessageBox.Show("报检数据包导出成功!");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|