user_lt пре 1 година
родитељ
комит
fb81f3bb31

+ 11 - 0
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/AddDetailViewModel.cs

@@ -11,6 +11,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
 
 namespace PLCTool.ViewModels.BasicConfigViewModel
 {
@@ -110,6 +111,16 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         /// <param name="obj"></param>
         private void Sure(string obj)
         {
+            if(string.IsNullOrEmpty(PLCItem)|| string.IsNullOrEmpty(PLCAddress))
+            {
+                MessageBox.Show("请填写PLC变量名或地址!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+            if (string.IsNullOrEmpty(SelectPLCType) )
+            {
+                MessageBox.Show("请选择PLC类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
             BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto()
             {
                 Id = id,

+ 1 - 1
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/AddOrEditSchViewModel.cs

@@ -74,7 +74,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         {
             //编辑
             var getMsg = parameters.GetValues<long>("Key");
-            ///值不为空,表示修改
+            ///值不为空,表示修改,为空表示新增
             if (getMsg != null)
             {
                 foreach (var item in getMsg)

+ 50 - 2
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/PLCConfigViewModel.cs

@@ -1,5 +1,6 @@
 using AutoMapper;
 using BizService;
+using MiniExcelLibs;
 using Model.Dto;
 using Model.Entities;
 using Prism.Commands;
@@ -31,10 +32,13 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             _dialog = dialog;
             QueryCommand = new DelegateCommand<object>(Query);
             AddCommand= new DelegateCommand<object>(Add);
+            ExportCommand = new DelegateCommand<string>(Export);
             GetPLCConfig();
         }
 
-       
+      
+
+
 
 
         #region 私有方法
@@ -51,6 +55,49 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             //默认显示的第一页
             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>
         /// 添加PLC变量
         /// </summary>
@@ -72,7 +119,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                         var findPlc=allPLCConfigList.FirstOrDefault(x=>(x.PlcAddress==returnValue.PlcAddress)||(x.PlcItem==returnValue.PlcAddress));
                         if(findPlc != null)
                         {
-                            MessageBox.Show("已有PLC变量地址或名称,请更改名称!", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
+                            MessageBox.Show("已有PLC变量地址或名称,请更改名称!", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
                             return;
                         }
                         bool isSucc=_iBasPlcItemConfigService.Add(plcCon);
@@ -133,6 +180,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
 
         public DelegateCommand<object> QueryCommand { set; get; }
         public DelegateCommand<object> AddCommand { set; get; }
+        public DelegateCommand<string> ExportCommand { set; get; }
         #endregion
 
         #region 数据绑定

+ 1 - 1
BlankApp1/BlankApp1/Views/BasicConfigView/PLCConfigView.xaml

@@ -52,7 +52,7 @@ ItemsSource="{Binding PLCItemList}" IsReadOnly="True"  Padding="0">
                 <DataGridTextColumn Header="PLC地址" Binding="{Binding PlcAddress}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                 <DataGridTextColumn Header="描述" Binding="{Binding Remark}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                 <DataGridTextColumn Header="数据类型" Binding="{Binding PlcAddType}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                <DataGridTextColumn Header="当前值" Binding="{Binding RealValue}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+               
             </DataGrid.Columns>
 
         </DataGrid>