From c598fd0fe98803e379fbc6a5937f67582f2890ea Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Tue, 11 Mar 2025 16:21:50 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E6=96=99=E7=AE=A1=E7=90=86=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=A8=A1=E6=9D=BF=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 货架标准上位机/LocalFile.cs | 2 + .../ViewModels/MatBaseInfoViewModel.cs | 44 +++++++++++++++++++ 货架标准上位机/Views/MatBaseInfoView.xaml | 10 ++++- 货架标准上位机/货架标准上位机.csproj | 4 +- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/货架标准上位机/LocalFile.cs b/货架标准上位机/LocalFile.cs index 7d04920..76d2d86 100644 --- a/货架标准上位机/LocalFile.cs +++ b/货架标准上位机/LocalFile.cs @@ -33,6 +33,8 @@ namespace 智慧物流软件系统 /// 资源目录 /// public static readonly string ResourcesDir = Path.Combine(AppDir, "Resources"); + + public static readonly string ExcelDir = Path.Combine(AppDir, "Excel"); /// /// 运行主程序 /// diff --git a/货架标准上位机/ViewModels/MatBaseInfoViewModel.cs b/货架标准上位机/ViewModels/MatBaseInfoViewModel.cs index b1fac1c..48e521a 100644 --- a/货架标准上位机/ViewModels/MatBaseInfoViewModel.cs +++ b/货架标准上位机/ViewModels/MatBaseInfoViewModel.cs @@ -26,6 +26,8 @@ using WCS.Model.ApiModel.MatBaseInfo; using System.Collections.ObjectModel; using HandyControl.Tools.Extension; using 智慧物流软件系统.Tool; +using Microsoft.Win32; +using System.IO; namespace 智慧物流软件系统.ViewModel { @@ -164,6 +166,48 @@ namespace 智慧物流软件系统.ViewModel #endregion } + + /// + /// 下载导入模板 + /// + public ICommand DownloadImportTemplateCommand { get => new DelegateCommand(DownloadImportTemplate); } + public void DownloadImportTemplate() + { + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Title = "选择保存导入模板路径";//窗口标题 + + saveFileDialog.Filter = "Excel 文件 (*.xlsx)|*.xlsx|All files (*.*)|*.*"; // 设置文件过滤器 + saveFileDialog.ValidateNames = true; + saveFileDialog.FileName = "物料管理导入模板.xlsx";// 设置默认文件名 + + if (saveFileDialog.ShowDialog() == true) + { + try + { + // 文件保存路径 + var destinationPath = saveFileDialog.FileName; + // 文件源路径 + var sourcePath = Path.Combine(LocalFile.ExcelDir, "物料管理导入模板.xlsx"); + + Folder.CopyFile(sourcePath, destinationPath); + + // 更新文件的最后修改时间(通常设置为当前时间) + File.SetLastWriteTime(destinationPath, DateTime.Now); + + if (File.Exists(destinationPath) && LocalFile.Config.IsLoadingDownloadPath) + { + LocalFile.Config.BatchBindImportTemplatePath = destinationPath; + LocalFile.SaveConfig(); + } + Growl.Success("下载成功!"); + } + catch (Exception ex) + { + Growl.Warning($"操作失败:{ex.Message}"); + } + } + } + /// /// 导出数据为Excel文件 /// diff --git a/货架标准上位机/Views/MatBaseInfoView.xaml b/货架标准上位机/Views/MatBaseInfoView.xaml index 72c9bd2..23da21e 100644 --- a/货架标准上位机/Views/MatBaseInfoView.xaml +++ b/货架标准上位机/Views/MatBaseInfoView.xaml @@ -105,7 +105,15 @@ Command="{Binding BtnDeleteCommand}" Style="{StaticResource ButtonDanger}"> - + + + + +