|
@@ -1,6 +1,7 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
@@ -8,6 +9,7 @@ using System.Windows;
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
+using Microsoft.Win32;
|
|
|
using UniformMaterialManagementSystem.Entities;
|
|
|
using UniformMaterialManagementSystem.Models;
|
|
|
using UniformMaterialManagementSystem.Services;
|
|
@@ -82,7 +84,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
//切换行
|
|
|
SelectedSampleRegistration = sample;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 新增
|
|
|
/// </summary>
|
|
@@ -131,7 +133,7 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
var validateDictionary = CustomValidate();
|
|
|
if (validateDictionary.ContainsKey("result") && !string.IsNullOrEmpty(validateDictionary["result"]))
|
|
|
{
|
|
|
- MessageBox.Show(validateDictionary["result"],"提示",MessageBoxButton.OK,MessageBoxImage.Error);
|
|
|
+ MessageBox.Show(validateDictionary["result"], "提示", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -171,7 +173,31 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
[RelayCommand]
|
|
|
private void ExportSampleRegistration()
|
|
|
{
|
|
|
+ if (SelectedSampleRegistration == null)
|
|
|
+ {
|
|
|
+ MessageBox.Show("请先选中一行抽样登记表,再执行导出操作!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const string templateFilePath = "Template\\被装材料产品抽样信息登记表模板.docx";
|
|
|
+ SaveFileDialog saveFileDialog = new SaveFileDialog()
|
|
|
+ {
|
|
|
+ Title = "请选择抽样信息登记表保存位置",
|
|
|
+ FileName = "抽样信息登记表-" + SelectedSampleRegistration.SampleNo + "-" + WordUtil.GenerateFileSerialNumber(),
|
|
|
+ Filter = "PDF文件格式 (*.pdf)|*.pdf",
|
|
|
+ };
|
|
|
+ if (saveFileDialog.ShowDialog() == false) return;
|
|
|
+ var destinationFile = saveFileDialog.FileName;
|
|
|
+
|
|
|
+ var dictionary = CreateDictionary(SelectedSampleRegistration);
|
|
|
+ var tempFile = $"Template\\temp_{WordUtil.GenerateFileSerialNumber()}.docx";
|
|
|
+
|
|
|
+ WordUtil.GenerateWordByTemplate(templateFilePath, tempFile, dictionary);
|
|
|
+ WordUtil.SaveWordToPdf(tempFile, destinationFile);
|
|
|
+
|
|
|
+ //删除临时文件
|
|
|
+ File.Delete(tempFile);
|
|
|
|
|
|
+ MessageBox.Show("文档已生成!");
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -337,5 +363,62 @@ namespace UniformMaterialManagementSystem.ViewModels
|
|
|
model.EditUser = sampleRegistration.EditUser;
|
|
|
model.Telephone = sampleRegistration.Telephone;
|
|
|
}
|
|
|
+
|
|
|
+ private Dictionary<string, string> CreateDictionary(SampleRegistrationModel sampleRegistration)
|
|
|
+ {
|
|
|
+ Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
|
|
+ dictionary.Add("SampleNo", sampleRegistration.SampleNo);
|
|
|
+ dictionary.Add("Department", sampleRegistration.Department);
|
|
|
+ dictionary.Add("EditTime", sampleRegistration.EditTime.ToString("yyyy年MM月dd日"));
|
|
|
+ //检验类别
|
|
|
+ switch (sampleRegistration.InspectApply.InspCategory)
|
|
|
+ {
|
|
|
+ case "首批检验":
|
|
|
+ dictionary.Add("FirstSelected", "\u25a0");//选中框
|
|
|
+ break;
|
|
|
+ case "出厂检验":
|
|
|
+ dictionary.Add("SecondSelected", "\u25a0");//选中框
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ dictionary.Add("ProductName", sampleRegistration.InspectApply.ProductName);
|
|
|
+ dictionary.Add("Company", sampleRegistration.InspectApply.Company);
|
|
|
+ dictionary.Add("ProductDate", sampleRegistration.ProductDate.ToString("yyyy-MM-dd"));
|
|
|
+ dictionary.Add("BatchNo", sampleRegistration.BatchNo);
|
|
|
+ dictionary.Add("PacketNo", sampleRegistration.PacketNo);
|
|
|
+ dictionary.Add("Quantity", sampleRegistration.Quantity + "\u00d7" + "3");
|
|
|
+ dictionary.Add("TestProductDate", sampleRegistration.ProductDate.ToString("yyyy-MM-dd"));
|
|
|
+ dictionary.Add("TestBatchNo", sampleRegistration.BatchNo);
|
|
|
+ dictionary.Add("TestPacketNo", sampleRegistration.PacketNo);
|
|
|
+ dictionary.Add("TestQuantity", sampleRegistration.Quantity + "");
|
|
|
+ switch (sampleRegistration.TestingItem)
|
|
|
+ {
|
|
|
+ case "全检":
|
|
|
+ dictionary.Add("TestAll", "\u25a0");
|
|
|
+ break;
|
|
|
+ case "强制性指标":
|
|
|
+ dictionary.Add("MandatoryTest", "\u25a0");
|
|
|
+ break;
|
|
|
+ case "色牢度":
|
|
|
+ dictionary.Add("ColorFastness", "\u25a0");
|
|
|
+ break;
|
|
|
+ case "光谱":
|
|
|
+ dictionary.Add("Spectrum", "\u25a0");
|
|
|
+ break;
|
|
|
+ case "参考性指标":
|
|
|
+ dictionary.Add("Reference", "\u25a0");
|
|
|
+ break;
|
|
|
+ case "单项指标":
|
|
|
+ dictionary.Add("Single", "\u25a0");
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ dictionary.Add("SingleIndexItem", sampleRegistration.SingleIndexItem == null ? "" : sampleRegistration.SingleIndexItem);
|
|
|
+ dictionary.Add("InspectionOrganization", sampleRegistration.InspectionOrganization);
|
|
|
+ dictionary.Add("ProductUsers", sampleRegistration.ProductUsers == null ? "" : sampleRegistration.ProductUsers);
|
|
|
+ dictionary.Add("EditUser", sampleRegistration.EditUser);
|
|
|
+ dictionary.Add("Telephone", sampleRegistration.Telephone == null ? "" : sampleRegistration.Telephone);
|
|
|
+
|
|
|
+ return dictionary;
|
|
|
+ }
|
|
|
}
|
|
|
}
|