|
@@ -1,5 +1,6 @@
|
|
using AutoMapper;
|
|
using AutoMapper;
|
|
using BizService;
|
|
using BizService;
|
|
|
|
+using MiniExcelLibs;
|
|
using Model.Dto;
|
|
using Model.Dto;
|
|
using Model.Entities;
|
|
using Model.Entities;
|
|
using Prism.Commands;
|
|
using Prism.Commands;
|
|
@@ -31,10 +32,13 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
_dialog = dialog;
|
|
_dialog = dialog;
|
|
QueryCommand = new DelegateCommand<object>(Query);
|
|
QueryCommand = new DelegateCommand<object>(Query);
|
|
AddCommand= new DelegateCommand<object>(Add);
|
|
AddCommand= new DelegateCommand<object>(Add);
|
|
|
|
+ ExportCommand = new DelegateCommand<string>(Export);
|
|
GetPLCConfig();
|
|
GetPLCConfig();
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
#region 私有方法
|
|
#region 私有方法
|
|
@@ -51,6 +55,49 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
//默认显示的第一页
|
|
//默认显示的第一页
|
|
Getpage();
|
|
Getpage();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void Export(string obj)
|
|
|
|
+ {
|
|
|
|
+ using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog()
|
|
|
|
+ {
|
|
|
|
+ //设置文件类型
|
|
|
|
+ //书写规则例如:txt files(*.txt)|*.txt
|
|
|
|
+ Filter = "Excel files(*.xlsx)|*.xlsx|All files(*.*)|*.*",
|
|
|
|
+ //设置默认文件名(可以不设置)
|
|
|
|
+ FileName = "PLC配置表",
|
|
|
|
+
|
|
|
|
+ //获取或设置一个值,该值指示如果用户省略扩展名,文件对话框是否自动在文件名中添加扩展名。(可以不设置)
|
|
|
|
+ AddExtension = true,
|
|
|
|
+
|
|
|
|
+ //保存对话框是否记忆上次打开的目录
|
|
|
|
+ RestoreDirectory = true
|
|
|
|
+ })
|
|
|
|
+ {
|
|
|
|
+ // Show save file dialog box
|
|
|
|
+
|
|
|
|
+ //点了保存按钮进入
|
|
|
|
+ if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ //获得文件路径
|
|
|
|
+ string localFilePath = saveFileDialog.FileName.ToString();
|
|
|
|
+
|
|
|
|
+ //string filePathWithName = localFilePath + ".xlsx";
|
|
|
|
+
|
|
|
|
+ //获取文件内容
|
|
|
|
+ MiniExcel.SaveAs(localFilePath, PLCItemList);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 添加PLC变量
|
|
/// 添加PLC变量
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -72,7 +119,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
var findPlc=allPLCConfigList.FirstOrDefault(x=>(x.PlcAddress==returnValue.PlcAddress)||(x.PlcItem==returnValue.PlcAddress));
|
|
var findPlc=allPLCConfigList.FirstOrDefault(x=>(x.PlcAddress==returnValue.PlcAddress)||(x.PlcItem==returnValue.PlcAddress));
|
|
if(findPlc != null)
|
|
if(findPlc != null)
|
|
{
|
|
{
|
|
- MessageBox.Show("已有次PLC变量地址或名称,请更改名称!", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
|
|
|
|
|
|
+ MessageBox.Show("已有此PLC变量地址或名称,请更改名称!", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
bool isSucc=_iBasPlcItemConfigService.Add(plcCon);
|
|
bool isSucc=_iBasPlcItemConfigService.Add(plcCon);
|
|
@@ -133,6 +180,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
|
|
|
public DelegateCommand<object> QueryCommand { set; get; }
|
|
public DelegateCommand<object> QueryCommand { set; get; }
|
|
public DelegateCommand<object> AddCommand { set; get; }
|
|
public DelegateCommand<object> AddCommand { set; get; }
|
|
|
|
+ public DelegateCommand<string> ExportCommand { set; get; }
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
#region 数据绑定
|
|
#region 数据绑定
|