浏览代码

修改方案

ltwork 1 年之前
父节点
当前提交
a91e30ea47

+ 1 - 1
BlankApp1/BlankApp1/App.xaml.cs

@@ -69,7 +69,7 @@ namespace BlankApp1
             containerRegistry.RegisterForNavigation<DeviceTestView, DeviceTestViewModel>();
             containerRegistry.RegisterForNavigation<ResultQueryView, ResultQueryViewModel>();
             containerRegistry.RegisterForNavigation<RetryTestView, RetryTestViewModel>();
-            containerRegistry.RegisterDialog<AddOrEditSchView, AddOrEditSchViewModel>();
+            containerRegistry.RegisterForNavigation<AddOrEditSchView, AddOrEditSchViewModel>();
             containerRegistry.RegisterDialog<AddDetailView, AddDetailViewModel>();
             containerRegistry.RegisterDialog<AutoTestView, AutoTestViewModel>();
             containerRegistry.RegisterDialog<ManualTestView, ManualTestViewModel>();

+ 124 - 82
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/AddOrEditSchViewModel.cs

@@ -1,5 +1,7 @@
 using AutoMapper;
 using BizService;
+using BlankApp1.Events;
+using DryIoc;
 using Microsoft.Extensions.Logging;
 using Model.Dto;
 using Model.Entities;
@@ -9,6 +11,7 @@ using PLCTool.Models;
 using Prism.Commands;
 using Prism.Events;
 using Prism.Mvvm;
+using Prism.Regions;
 using Prism.Services.Dialogs;
 using System;
 using System.Collections.Generic;
@@ -21,10 +24,11 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
 
 namespace PLCTool.ViewModels.BasicConfigViewModel
 {
-    public class AddOrEditSchViewModel  : BindableBase, IDialogAware
+    public class AddOrEditSchViewModel  : BindableBase, INavigationAware
     {
         private readonly IDialogService _dialog;
         private readonly IEventAggregator _aggregator;
+        private readonly IRegionManager _regionManager;
         private readonly IOptionConfigService _optionConfigService;
         private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
         private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
@@ -34,10 +38,12 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         private List<OptionConfigDto> _optionConfigs;
         private bas_plc_test_scheme bas_Plc_Test_Scheme;//测试方案
         private int schDtlMainId = 0;//测试方案明细主键id
-        public AddOrEditSchViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBasicDeviceKindService iBasicDeviceKindService, IMapper mapper,ILogger logger)
+        public event Action<NavigationResult> RequestClose;
+        public AddOrEditSchViewModel(IDialogService dialog, IEventAggregator aggregator, IRegionManager regionManager,IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBasicDeviceKindService iBasicDeviceKindService, IMapper mapper,ILogger logger)
         {
             _dialog = dialog;
             _aggregator = aggregator;
+            _regionManager= regionManager;
             _optionConfigService = optionConfigService;
             _basicPlcTestSchemeService = basicPlcTestSchemeService;
             _basicPlcTestSchemeDtlService = basicPlcTestSchemeDtlService;
@@ -61,86 +67,64 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             DownCommand = new DelegateCommand<object>(DataDown);
             SaveAllSchCommand = new DelegateCommand<object>(SaveAllSch);
            // EditDetailCommand = new DelegateCommand<object>(DataGridSelectChange);
-
             DgSelectChangeCommand = new DelegateCommand<object>(DataGridSelectChange);
-            DisAnoCommand = new DelegateCommand<object>(DisAnomation);
-
-             BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
+            CancelCommand= new DelegateCommand<object>(Cancel);
+            DetailCommand = new DelegateCommand<object>(CheckDetail);
+            DeleteCommand = new DelegateCommand<object>(Delete);
+            BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
             InConList = new ObservableCollection<BasPlcItemConfigDto>();
             OutConList = new ObservableCollection<BasPlcItemConfigDto>();
-           
             //获取设备类型
             DeviceKindNameList = _iBasicDeviceKindService.FindAllDeviceKind();
             GetConfigOption();
         }
 
-       
+        private void Delete(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            bool isResult=_basicPlcTestSchemeDtlService.Delete(id);
+            if(isResult)
+            {
+                MessageBox.Show("删除成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+                //更新已有的测试项
+                GetExistSchs();
+            }
+           
+        }
+
+        private void CheckDetail(object obj)
+        {
+     
+        }
+
+
+
 
 
 
         #region idialog接口实现
         public string Title { set; get; } = "新增方案";
 
-        public event Action<IDialogResult> RequestClose;
 
-        public bool CanCloseDialog()
-        {
-            return true;
-        }
 
-        public void OnDialogClosed()
-        {
 
-        }
 
-        public void OnDialogOpened(IDialogParameters parameters)
-        {
-            //编辑
-            var getMsg = parameters.GetValues<string>("Key");
-            ///值不为空,表示修改,为空表示新增
-            if (getMsg != null)
-            {
-                foreach (var item in getMsg)
-                {
-                    try
-                    {
+        #endregion
 
-                        Title = "编辑方案";
-                        ScheduleName= item.ToString();
-                        //获取已经有的测试项
-                        GetExistSchs();
-                        //展示第一个测试项详情
-                        var findSch=_basicPlcTestSchemeService.FindByNameAndType(ScheduleName, DeviceKindName);
-                        if(findSch != null)
-                        {
-                            long schID = findSch.scheme_id;
-                            int schDtlId=(int)_basicPlcTestSchemeDtlService.FindAllBySchId(schID)?.OrderBy(x => x.scheme_dtl_id)?.First()?.scheme_dtl_id;
-                       
-                            schDtlMainId = schDtlId;//全局变量赋值,测试方案明细id
-                            GetDetaiMsg(schDtlId);
-                        }
-                       
-                    }
-                    catch (Exception ex)
-                    {
-                        _logger.LogError(ex.ToString());
-                    }
 
 
-                }
 
-        }
 
-            var getMsg2 = parameters.GetValues<string>("Key2");
-            if(getMsg2 != null )
-            {
-                foreach (var item in getMsg2)
-                {
-                    DeviceKindName = item;
-                }
-            }
-        }
 
+        #region 私有方法
+        /// <summary>
+        /// 取消返回列表界面
+        /// </summary>
+        /// <param name="obj"></param>
+        private void Cancel(object obj)
+        {
+            _regionManager.Regions["ContentRegion"].RequestNavigate("BaseConfigView");
+        }
         /// <summary>
         ///  测试方案明细主键ID 查找测试方案id 及方案名
         /// </summary>
@@ -232,9 +216,6 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
 
             }
         }
-
-        #endregion
-        #region 私有方法
         /// <summary>
         /// 选中datadagridView某一行
         /// </summary>
@@ -242,19 +223,16 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         private void DataGridSelectChange(object obj)
         {
             SelectItemModel selectItemModel = (SelectItemModel)obj;
-            int schDtlId = Convert.ToInt32(selectItemModel.SchDtlId);
-            schDtlMainId = schDtlId;//全局变量赋值,测试方案明细id
-            GetDetaiMsg(schDtlId);
-        }
-        /// <summary>
-        /// 显示侧边栏
-        /// </summary>
-        /// <param name="obj"></param>
-        /// <exception cref="NotImplementedException"></exception>
-        private void DisAnomation(object obj)
-        {
+            if(selectItemModel!=null)
+            {
+                int schDtlId = Convert.ToInt32(selectItemModel.SchDtlId);
+                schDtlMainId = schDtlId;//全局变量赋值,测试方案明细id
+                GetDetaiMsg(schDtlId);
+
+            }
             
         }
+       
 
         /// <summary>
         /// 保存所有测试项
@@ -263,6 +241,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         /// <exception cref="NotImplementedException"></exception>
         private void SaveAllSch(object obj)
         {
+            //先保存一下当前测试项
+            Sure(string.Empty);
             //可能调整了测试项的顺序,所以先删除所有测试项
             var findSche = _basicPlcTestSchemeService.FindByName(ScheduleName);
             if (findSche != null)
@@ -296,7 +276,9 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                   
                 }
                 MessageBox.Show("保存成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
-                RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
+                //发布消息
+                _aggregator.GetEvent<ChangeEvent>().Publish("Change");
+                _regionManager.Regions["ContentRegion"].RequestNavigate("BaseConfigView");
             }
         }
         /// <summary>
@@ -371,7 +353,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                         SchDtlId = unit.scheme_dtl_id,
                         ItemName = unit.item_name,
                         ItemType = itemType,
-                    }); ;
+                    }); 
 
                 }
             }
@@ -609,7 +591,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         /// </summary>
         private void Close()
         {
-            RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
+            //RequestClose?.Invoke(new NavigationResult(new NavigationContext(),true);
         }
         /// <summary>
         /// 确认
@@ -738,10 +720,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                 //更新已有的测试项
                 GetExistSchs();
                 //清空已填写的内容
-           
-    
-                TestName = string.Empty;
-      
+         
                 BeforeConList =new ObservableCollection<BasPlcItemConfigDto>();
                 InConList = new ObservableCollection<BasPlcItemConfigDto>();
                 OutConList = new ObservableCollection<BasPlcItemConfigDto>();
@@ -818,11 +797,11 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                             if (isSucc)
                             {
                                 _logger.LogInformation($"更新方案成功。方案名{ScheduleName},测试项{TestName}");
-                                MessageBoxResult boxResult = MessageBox.Show("更新成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                                MessageBoxResult boxResult = MessageBox.Show("保存成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                             }
                             else
                             {
-                                MessageBoxResult boxResult = MessageBox.Show("更新失败", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                                MessageBoxResult boxResult = MessageBox.Show("保存失败", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                                 return;
                             }
 
@@ -902,6 +881,65 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             DeviceKindName = string.Empty;
             TestName = string.Empty;
         }
+
+        public void OnNavigatedTo(NavigationContext navigationContext)
+        {
+            //编辑
+            var getMsg = navigationContext.Parameters.GetValues<string>("Key");
+            ///值不为空,表示修改,为空表示新增
+            if (getMsg != null)
+            {
+                foreach (var item in getMsg)
+                {
+                    try
+                    {
+
+                        Title = "编辑方案";
+                        ScheduleName = item.ToString();
+                        //获取已经有的测试项
+                        GetExistSchs();
+                        //展示第一个测试项详情
+                        var findSch = _basicPlcTestSchemeService.FindByNameAndType(ScheduleName, DeviceKindName);
+                        if (findSch != null)
+                        {
+                            long schID = findSch.scheme_id;
+                            int schDtlId = (int)_basicPlcTestSchemeDtlService.FindAllBySchId(schID)?.OrderBy(x => x.scheme_dtl_id)?.First()?.scheme_dtl_id;
+
+                            schDtlMainId = schDtlId;//全局变量赋值,测试方案明细id
+                            GetDetaiMsg(schDtlId);
+                        }
+
+                    }
+                    catch (Exception ex)
+                    {
+                        _logger.LogError(ex.ToString());
+                    }
+
+
+                }
+            }
+
+            var getMsg2 = navigationContext.Parameters.GetValues<string>("Key2");
+            if (getMsg2 != null)
+            {
+                foreach (var item in getMsg2)
+                {
+                    DeviceKindName = item;
+                }
+            }
+        }
+
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            return true;
+        }
+
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+            
+        }
+
+     
         #endregion
 
 
@@ -946,7 +984,11 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         public DelegateCommand<object> EditDetailCommand { set; get; }
         public DelegateCommand<object> DgSelectChangeCommand { set; get; }
         public DelegateCommand<object> DisAnoCommand { set; get; }
-        
+        public DelegateCommand<object> CancelCommand { set; get; }
+
+        public DelegateCommand<object> DetailCommand { set; get; }
+        public DelegateCommand<object> DeleteCommand { set; get; }
+
         #endregion
         #region 变量绑定
         /// <summary>

+ 28 - 16
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/BaseConfigViewModel.cs

@@ -1,12 +1,13 @@
 using AutoMapper;
 using BizService;
-
+using BlankApp1.Events;
 using Microsoft.Extensions.Logging;
 using MiniExcelLibs;
 using Model;
 using Model.Dto;
 using Model.Entities;
 using Prism.Commands;
+using Prism.Events;
 using Prism.Mvvm;
 using Prism.Regions;
 using Prism.Services.Dialogs;
@@ -25,6 +26,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
     public class BaseConfigViewModel : BindableBase
     {
         private readonly IDialogService _dialog;
+        private readonly IEventAggregator _aggregator;
+        private readonly IRegionManager _regionManager;
         private readonly IOptionConfigService _optionConfigService;
         private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
         private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
@@ -37,9 +40,11 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         private List<BasicPlcTestSchemeDto> conditionConfig = new List<BasicPlcTestSchemeDto>();//符合条件的方案
 
         private const int PageCount = 1; //每一页显示个数
-        public BaseConfigViewModel(IDialogService dialog, IMenuService menuService, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService , IBasicDeviceKindService iBasicDeviceKindService, IMapper mapper, ILogger logger)
+        public BaseConfigViewModel(IDialogService dialog, IEventAggregator aggregator, IRegionManager regionManager, IMenuService menuService, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService , IBasicDeviceKindService iBasicDeviceKindService, IMapper mapper, ILogger logger)
         {
             _dialog = dialog;
+            _aggregator = aggregator;
+            _regionManager= regionManager;
             _optionConfigService = optionConfigService;
             _basicPlcTestSchemeService = basicPlcTestSchemeService;
             _basicPlcTestSchemeDtlService = basicPlcTestSchemeDtlService;
@@ -58,6 +63,11 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             OnLoadCommand = new DelegateCommand(OnLoad);
             GetConfigOption();
             GetContent();
+            //添加或修改方案后重新读取
+            _aggregator.GetEvent<ChangeEvent>().Subscribe((s) =>
+            {
+                GetContent();
+            });
         }
 
        
@@ -161,19 +171,21 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             //测试方案名称和设备类型
             string schemeName = (string)multiObj[0];
             string deviceKindName = (string)multiObj[1];
-            DialogParameters parm = new DialogParameters();
+            NavigationParameters parm = new NavigationParameters();
             parm.Add("Key", schemeName);
             parm.Add("Key2", deviceKindName);
-            //弹出详情对话框
-            _dialog.ShowDialog("AddOrEditSchView", parm, async callback =>
+
+            _regionManager.Regions["ContentRegion"].RequestNavigate("AddOrEditSchView", async callback =>
             {
-                if (callback.Result == ButtonResult.OK)
+                if (callback.Result == true)
                 {
                     //更新表格,重新获取
                     GetContent();
                 }
 
-            });
+            },parm);
+            //弹出详情对话框
+         
         }
         /// <summary>
         /// 删除操作
@@ -225,17 +237,17 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         /// <param name="obj"></param>
         private void AddPlan(string obj)
         {
-
+            _regionManager.Regions["ContentRegion"].RequestNavigate("AddOrEditSchView");
             //弹出详情对话框
-            _dialog.ShowDialog("AddOrEditSchView", async callback =>
-            {
-                if (callback.Result == ButtonResult.OK)
-                {
-                    //更新表格,重新获取
-                    GetContent();
-                }
+            //_dialog.ShowDialog("AddOrEditSchView", async callback =>
+            //{
+            //    if (callback.Result == ButtonResult.OK)
+            //    {
+            //        //更新表格,重新获取
+            //        GetContent();
+            //    }
 
-            });
+            //});
         }
         /// <summary>
         /// excel导出

+ 17 - 5
BlankApp1/BlankApp1/Views/BasicConfigView/AddOrEditSchView.xaml

@@ -99,7 +99,7 @@
                         </Grid.RowDefinitions>
                         <StackPanel Grid.Row="0" Orientation="Horizontal">
                             <StackPanel Orientation="Horizontal" >
-                                <TextBlock Text="|"  TextAlignment="Center" VerticalAlignment="Center" Foreground="#409EFF" Margin="5,0,5,0"/>
+                                <TextBlock Text=""  TextAlignment="Center" VerticalAlignment="Center" Foreground="#409EFF" Margin="5,0,5,0"/>
                                 <TextBlock Text="测试方案明细"  Style="{StaticResource NormalTextBlockStyle}" Margin="0,0,5,0"/>
                             </StackPanel>
                         </StackPanel>
@@ -107,11 +107,11 @@
 
                             <StackPanel Orientation="Horizontal" >
                                 <TextBlock Text="测试项类型:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
-                                <ComboBox  Height="28" Width="120" ItemsSource="{Binding TestKinds}" SelectedItem="{Binding SelectTest}" />
+                                <ComboBox  Height="28" Width="160" ItemsSource="{Binding TestKinds}" SelectedItem="{Binding SelectTest}" />
                             </StackPanel>
                             <StackPanel Orientation="Horizontal">
                                 <TextBlock Text="测试项名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
-                                <TextBox  Height="28" Width="120"  Text="{Binding TestName}"/>
+                                <TextBox  Height="28" Width="160"  Text="{Binding TestName}"/>
                             </StackPanel>
                         </StackPanel>
 
@@ -385,7 +385,7 @@ Command="{Binding DataContext.DeleteOutCommand, RelativeSource={RelativeSource M
                 <Border Grid.Row="2" BorderBrush="#409EFF"  BorderThickness="1" Margin="5">
                     <StackPanel Orientation="Vertical">
                         <StackPanel Orientation="Horizontal" >
-                            <TextBlock Text="|"  TextAlignment="Center" VerticalAlignment="Center" Foreground="#409EFF" Margin="5,0,5,0"/>
+                            <TextBlock Text=""  TextAlignment="Center" VerticalAlignment="Center" Foreground="#409EFF" Margin="5,0,5,0"/>
                             <TextBlock Text="已添加测试项列表"  Style="{StaticResource NormalTextBlockStyle}" Margin="0,0,5,0"/>
                         </StackPanel>
                         <DataGrid    ColumnWidth="*" AutoGenerateColumns="False" HeadersVisibility="All" CanUserAddRows="False"  SelectionUnit="FullRow" SelectionMode="Single"   RowHeaderWidth="0"
@@ -400,11 +400,23 @@ ItemsSource="{Binding SchProjectList}" IsReadOnly="True" Margin="5" Padding="0"
                             <DataGrid.Columns >
                                 <DataGridTextColumn Header="测试项" Binding="{Binding ItemName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                                 <DataGridTextColumn Header="测试项类型" Binding="{Binding ItemType}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                                <DataGridTemplateColumn Header="操作" Width="120" CellStyle="{StaticResource MyDataGridCellStyle}">
+                                <DataGridTemplateColumn Header="操作" Width="240" CellStyle="{StaticResource MyDataGridCellStyle}">
                                     <DataGridTemplateColumn.CellTemplate>
                                         <DataTemplate>
                                             <StackPanel Orientation="Horizontal">
                                                 <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
+        Command="{Binding DataContext.DetailCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchDtlId}" Cursor="Hand" Margin="0,0,10,0" >
+                                                    <StackPanel Orientation="Horizontal">
+                                                        <TextBlock  Text="查看详情" VerticalAlignment="Center" Foreground="Blue"/>
+                                                    </StackPanel>
+                                                </Button>
+                                                <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
+Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchDtlId}" Cursor="Hand" Margin="0,0,10,0" >
+                                                    <StackPanel Orientation="Horizontal">
+                                                        <TextBlock  Text="删除" VerticalAlignment="Center" Foreground="Blue"/>
+                                                    </StackPanel>
+                                                </Button>
+                                                <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
       Command="{Binding DataContext.UpCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchDtlId}" Cursor="Hand" Margin="0,0,10,0" >
 
                                                     <StackPanel Orientation="Horizontal">