ltwork 1 год назад
Родитель
Сommit
81d0e0cfd1

+ 13 - 1
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/DeviceTestCardViewModel.cs

@@ -7,13 +7,16 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Controls;
 using System.Windows;
+using Prism.Regions;
 
 namespace PLCTool.ViewModels.BusinessManageViewModel
 {
     public  class DeviceTestCardViewModel : BindableBase
     {
-        public DeviceTestCardViewModel()
+        private readonly IRegionManager _regionManager;
+        public DeviceTestCardViewModel(IRegionManager regionManager)
         {
+            this._regionManager=regionManager;
             DoubleClickCommand = new DelegateCommand<object>(DoubleClickCard);
         }
 
@@ -31,6 +34,15 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
                 //参数转换
                 TextBlock txtbl = obj as TextBlock;
+                string projectName=txtbl.Text;
+                NavigationParameters parm = new NavigationParameters();
+                parm.Add("Key", projectName);
+               
+                _regionManager.Regions["ContentRegion"].RequestNavigate("DeviceTestView", async callback =>
+                {
+                  
+
+                }, parm);
             }
             catch
             {

+ 62 - 14
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/DeviceTestViewModel.cs

@@ -7,6 +7,7 @@ using Model.Entities;
 using PLCTool.Common;
 using Prism.Commands;
 using Prism.Mvvm;
+using Prism.Regions;
 using Prism.Services.Dialogs;
 using System;
 using System.Collections.Generic;
@@ -21,7 +22,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 {
     
 
-    public class DeviceTestViewModel : BindableBase
+    public class DeviceTestViewModel : BindableBase, INavigationAware
     {
         private readonly IBasicDeviceService _iBasicDeviceService;
         private readonly IBasicDeviceKindService _iBasicDeviceKindService;
@@ -30,8 +31,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private readonly IMapper _mapper;
         private readonly IDialogService _dialog;
         private readonly ILogger _logger;
-        private List<BasDeviceWithSchModel> allDeviceList = new List<BasDeviceWithSchModel>();//所有方案
+        private List<BasDeviceWithSchModel> allDeviceAndSchList = new List<BasDeviceWithSchModel>();//所有设备,并带有测试方案
+        private List<BasDeviceWithSchModel> allDeviceList = new List<BasDeviceWithSchModel>();//所有设备
         private List<BasDeviceWithSchModel> conditionDevices = new List<BasDeviceWithSchModel>();//符合条件的方案
+        private string selectProjectName;
         public DeviceTestViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IMapper mapper, IDialogService dialog, ILogger logger)
         {
             _iBasicDeviceService = iBasicDeviceService;
@@ -219,6 +222,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         {
             allDeviceList.Clear();
             conditionDevices.Clear();
+            allDeviceAndSchList.Clear();
             var devicelist = _iBasicDeviceService.QueryList();
             var allDeviceKinds = _mapper.Map<List<bas_device>, List<BasDeviceDto>>(devicelist);
             //所有测试方案
@@ -228,34 +232,54 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
             foreach (var item in allDeviceKinds)
             {
-                string deviceKind =_iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
+             
+
+                string projectName = _iBasicProjectService.Find((int)item.ProjectId)?.project_name;
+                string deviceKindName = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
+
+
+                string deviceKind = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
                 //在测试方案中查找此设备类型的所有方案
-                var schs= schDtoList.FindAll(x => x.DeviceKindName == deviceKind);
+                var schs = schDtoList.FindAll(x => x.DeviceKindName == deviceKind);
                 //设备方案
                 foreach (var sch in schs)
                 {
-                    allDeviceList.Add(new BasDeviceWithSchModel()
+                    allDeviceAndSchList.Add(new BasDeviceWithSchModel()
                     {
                         DeviceId = item.DeviceId,
                         DeviceNo = item.DeviceNo,
                         DeviceName = item.DeviceName,
-                        DeviceKindName = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name,
-                        ProjectName = _iBasicProjectService.Find((int)item.ProjectId)?.project_name,
+                        DeviceKindName = deviceKindName,
+                        ProjectName = projectName,
                         SchemeName = sch.SchemeName,
-                        SchemeId=sch.SchemeId,
-                    }) ;
+                        SchemeId = sch.SchemeId,
+                    });
+                 
+                }
+                //只添加选择的项目
+                if (projectName == selectProjectName)
+                {
+                    allDeviceList.Add(new BasDeviceWithSchModel()
+                    {
+                        DeviceId = item.DeviceId,
+                        DeviceNo = item.DeviceNo,
+                        DeviceName = item.DeviceName,
+                        DeviceKindName = deviceKindName,
+                        ProjectName = projectName,
+                
+                    });
                     conditionDevices.Add(new BasDeviceWithSchModel()
                     {
                         DeviceId = item.DeviceId,
                         DeviceNo = item.DeviceNo,
                         DeviceName = item.DeviceName,
-                        DeviceKindName = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name,
-                        ProjectName = _iBasicProjectService.Find((int)item.ProjectId)?.project_name,
-                        SchemeName = sch.SchemeName,
-                        SchemeId = sch.SchemeId,
+                        DeviceKindName = deviceKindName,
+                        ProjectName = projectName,
+                        
                     });
                 }
-             
+
+          
             }
             conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
             Getpage();
@@ -285,6 +309,30 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             }
         }
 
+        public void OnNavigatedTo(NavigationContext navigationContext)
+        {
+            //编辑
+            var getMsg = navigationContext.Parameters.GetValues<string>("Key");
+            ///值不为空,表示修改,为空表示新增
+            if (getMsg != null)
+            {
+                foreach (var item in getMsg)
+                {
+                    selectProjectName= item;
+                }
+            }
+        }
+
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            return true;
+        }
+
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+           
+        }
+
         #endregion
         #region 命令绑定
 

+ 2 - 2
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ProjectTestViewModel.cs

@@ -94,7 +94,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 ProjectePicList.Add(deviceCard);
             }
             //计算行数
-            if(projectNames.Count% 4==0)
+            if (projectNames.Count % 4 == 0)
             {
                 RowsCount = projectNames.Count / 4;
             }
@@ -102,7 +102,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             {
                 RowsCount = projectNames.Count / 4 + 1;
             }
-            if(RowsCount<2)
+            if (RowsCount < 2)
             {
                 RowsCount = 2;
             }

+ 3 - 2
BlankApp1/BlankApp1/Views/BusinessManageView/DeviceTestCardView.xaml

@@ -4,12 +4,13 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:PLCTool.Views.BusinessManageView"
-             
+              xmlns:prism="http://prismlibrary.com/"
+              prism:ViewModelLocator.AutoWireViewModel="True"
              Height="240" Width="280">
     <Grid>
       
             <Grid.InputBindings>
-                <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding DoubleClickCommand}" CommandParameter="{Binding ElementName=txtName}">
+            <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding DoubleClickCommand}" CommandParameter="{Binding ElementName=txtName}">
                 </MouseBinding>
             </Grid.InputBindings>
             <Grid.RowDefinitions>

+ 34 - 20
BlankApp1/BlankApp1/Views/BusinessManageView/DeviceTestView.xaml

@@ -25,7 +25,7 @@
             <RowDefinition Height="40"/>
             <RowDefinition/>
             <RowDefinition Height="40"/>
-
+            <RowDefinition/>
         </Grid.RowDefinitions>
         <UniformGrid Grid.Row="0" Columns="4">
             <StackPanel Orientation="Horizontal">
@@ -79,18 +79,46 @@
                 <DataGridTextColumn Header="序号" Width="50" Binding="{Binding DeviceId}" CellStyle="{StaticResource MyDataGridCellStyle}" />
                 <DataGridTextColumn Header="设备编号" Binding="{Binding DeviceNo}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                 <DataGridTextColumn Header="设备名称" Binding="{Binding DeviceName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="设备类型" Binding="{Binding DeviceKindName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                 <DataGridTextColumn Header="项目名称" Binding="{Binding ProjectName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="描述" Binding="{Binding Remark}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="测试状态" Binding="{Binding Remark}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="创建者" Binding="{Binding CreateBy}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="创建时间" Binding="{Binding CreateTime,StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                
+            </DataGrid.Columns>
+
+        </DataGrid>
+        <Grid Grid.Row="3" HorizontalAlignment="Center" VerticalAlignment="Center">
+            <wpfdev:Pagination IsLite="False"    Margin="0"  Width="auto" Height="30" HorizontalAlignment="Center"  
+                       Count="{Binding TotalCount,Mode=TwoWay}" 
+                       CountPerPage="{Binding CountPerPage,Mode=TwoWay}"
+                       Current="{Binding CurrentPage,Mode=TwoWay}"/>
+            <!--<hc:Pagination MaxPageCount="10" PageIndex="{Binding PageIndex}" IsJumpEnabled="True">
+                <hc:Interaction.Triggers>
+                    <hc:EventTrigger EventName="PageUpdated">
+                        <hc:EventToCommand Command="{Binding PageUpdatedCmd}" PassEventArgsToCommand="True" />
+                    </hc:EventTrigger>
+                </hc:Interaction.Triggers>
+            </hc:Pagination>-->
+        </Grid>
+        <DataGrid  Grid.Row="4"  ColumnWidth="*" AutoGenerateColumns="False" HeadersVisibility="All" CanUserAddRows="False"  SelectionUnit="FullRow" SelectionMode="Single"   RowHeaderWidth="0"
+           ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"  RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
+          ItemsSource="{Binding SchItemList}" IsReadOnly="True" Padding="0"  >
+            <DataGrid.Columns >
+                <DataGridTextColumn Header="序号" Width="50" Binding="{Binding DeviceId}" CellStyle="{StaticResource MyDataGridCellStyle}" />
+              
                 <DataGridTextColumn Header="设备类型" Binding="{Binding DeviceKindName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                 <DataGridTextColumn Header="测试方案名称" Binding="{Binding SchemeName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                <DataGridTextColumn Header="描述" Binding="{Binding Remark}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                <!--<DataGridTextColumn Header="创建者" Binding="{Binding CreateBy}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                <DataGridTextColumn Header="创建时间" Binding="{Binding CreateTime,StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" CellStyle="{StaticResource MyDataGridCellStyle}"/>-->
+                <DataGridTextColumn Header="测试状态" Binding="{Binding Remark}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="创建者" Binding="{Binding CreateBy}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                 <DataGridTextColumn Header="创建时间" Binding="{Binding CreateTime,StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                 <DataGridTemplateColumn Header="操作" Width="180" 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.ManualTestCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" Cursor="Hand" Margin="0,0,10,0" >
+                                 Command="{Binding DataContext.ManualTestCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" Cursor="Hand" Margin="0,0,10,0" >
 
                                     <StackPanel Orientation="Horizontal">
                                         <TextBlock  Text="手动测试" VerticalAlignment="Center" Foreground="Blue"/>
@@ -103,7 +131,7 @@
                                     </Button.CommandParameter>
                                 </Button>
                                 <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
-                                        Command="{Binding DataContext.AutoTestCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}"  Cursor="Hand" Margin="0,0,10,0">
+                                 Command="{Binding DataContext.AutoTestCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}"  Cursor="Hand" Margin="0,0,10,0">
 
                                     <StackPanel Orientation="Horizontal">
                                         <TextBlock  Text="自动测试" VerticalAlignment="Center" Foreground="Blue"/>
@@ -124,20 +152,6 @@
             </DataGrid.Columns>
 
         </DataGrid>
-        <Grid Grid.Row="3" HorizontalAlignment="Center" VerticalAlignment="Center">
-            <wpfdev:Pagination IsLite="False"    Margin="0"  Width="auto" Height="30" HorizontalAlignment="Center"  
-                       Count="{Binding TotalCount,Mode=TwoWay}" 
-                       CountPerPage="{Binding CountPerPage,Mode=TwoWay}"
-                       Current="{Binding CurrentPage,Mode=TwoWay}"/>
-            <!--<hc:Pagination MaxPageCount="10" PageIndex="{Binding PageIndex}" IsJumpEnabled="True">
-                <hc:Interaction.Triggers>
-                    <hc:EventTrigger EventName="PageUpdated">
-                        <hc:EventToCommand Command="{Binding PageUpdatedCmd}" PassEventArgsToCommand="True" />
-                    </hc:EventTrigger>
-                </hc:Interaction.Triggers>
-            </hc:Pagination>-->
-        </Grid>
-
 
     </Grid>
 </UserControl>