浏览代码

增加勾选功能

user_lt 1 年之前
父节点
当前提交
c10efd6a27

+ 6 - 0
BlankApp1/BlankApp1/Models/SelectItemModel.cs

@@ -9,6 +9,12 @@ namespace PLCTool.Models
 {
 {
     public class SelectItemModel:BaseDto
     public class SelectItemModel:BaseDto
     {
     {
+        private long id { get; set; }
+        public long Id
+        {
+            get { return id; }
+            set { id = value; OnPropertyChanged(); }
+        }
         /// <summary>
         /// <summary>
         /// Desc:测试项名称
         /// Desc:测试项名称
         /// Default:
         /// Default:

+ 112 - 22
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/CopySchViewModel.cs

@@ -1,5 +1,6 @@
 using AutoMapper;
 using AutoMapper;
 using BizService;
 using BizService;
+using ImTools;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Logging;
 using Model.Dto;
 using Model.Dto;
 using Model.Entities;
 using Model.Entities;
@@ -13,6 +14,8 @@ using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Collections.ObjectModel;
 using System.Linq;
 using System.Linq;
+using System.Net.NetworkInformation;
+using System.Security.Cryptography.Xml;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
@@ -28,6 +31,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
         private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
         private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
         private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
         private string schNameAgo = String.Empty;
         private string schNameAgo = String.Empty;
+ 
+
         public CopySchViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IMapper mapper, ILogger logger)
         public CopySchViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IMapper mapper, ILogger logger)
         {
         {
             
             
@@ -36,6 +41,70 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             _mapper = mapper;
             _mapper = mapper;
             _logger = logger;
             _logger = logger;
             SureCommand = new DelegateCommand<string>(Sure);
             SureCommand = new DelegateCommand<string>(Sure);
+            UpCommand = new DelegateCommand<object>(DataUp);
+            DownCommand = new DelegateCommand<object>(DataDown);
+            SelectAllCommand = new DelegateCommand<object>(SelectAll);
+            UnSelectAllCommand = new DelegateCommand<object>(UnSelecttAll);
+        }
+
+        private void UnSelecttAll(object obj)
+        {
+            SchProjectList.ToList().FindAll(p => p.IsSelected = false);
+        }
+
+        private void SelectAll(object obj)
+        {
+            SchProjectList.ToList().FindAll(p => p.IsSelected = true);
+        }
+
+        /// <summary>
+        /// 下移
+        /// </summary>
+        /// <param name="obj"></param>
+        private void DataDown(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            var findScheExist = SchProjectList.FirstOrDefault(x => x.Id == id);
+            if (findScheExist != null)
+            {
+
+                int index = SchProjectList.IndexOf(findScheExist);
+                if(index!=-1)
+                {
+                    if (index == SchProjectList.Count - 1)
+                        return;
+                    SchProjectList.RemoveAt(index);
+                    index = index + 1;
+                    SchProjectList.Insert(index, findScheExist);
+                }
+        
+
+            }
+        }
+        /// <summary>
+        /// 上移
+        /// </summary>
+        /// <param name="obj"></param>
+        private void DataUp(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            var findScheExist = SchProjectList.FirstOrDefault(x=>x.Id==id);
+            if (findScheExist != null)
+            {
+
+                int index = SchProjectList.IndexOf(findScheExist);
+                if(index!=-1)
+                {
+                    if (index == 0)
+                        return;
+                    SchProjectList.RemoveAt(index);
+                    index = index - 1;
+                    SchProjectList.Insert(index, findScheExist);
+                }
+               
+
+            }
+
         }
         }
 
 
         private void Sure(string obj)
         private void Sure(string obj)
@@ -64,28 +133,38 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                 long schID = finsSche.scheme_id;
                 long schID = finsSche.scheme_id;
                 //查找此方案下的所有的测试项,并增加到测试项详细表中
                 //查找此方案下的所有的测试项,并增加到测试项详细表中
                 long? schINewID = _basicPlcTestSchemeService.FindByName(ScheduleName)?.scheme_id;
                 long? schINewID = _basicPlcTestSchemeService.FindByName(ScheduleName)?.scheme_id;
-                var schDtls = _basicPlcTestSchemeDtlService.QueryList()?.FindAll(x => x.scheme_id == schID);
-                foreach (var unit in schDtls)
+                //这里要注意顺序,所以用了SchProjectList循环
+                foreach (var sch in SchProjectList)
                 {
                 {
-                    bas_plc_test_scheme_dtl schDtlDto = new bas_plc_test_scheme_dtl();
-                    schDtlDto.scheme_id = schINewID;
-                    schDtlDto.item_name = unit.item_name;
-
-                    schDtlDto.item_type = unit.item_type;
-                    schDtlDto.precondition = unit.precondition;
-                    schDtlDto.precondition_describe = unit.precondition_describe;
-                    schDtlDto.action = unit.action;
-                    schDtlDto.action_describe = unit.action_describe;
-                    schDtlDto.judgement_result = unit.judgement_result;
-                    schDtlDto.judgement_result_describe = unit.judgement_result_describe;
-                    schDtlDto.create_by = Appsession.UserName;
-                    schDtlDto.create_time = DateTime.Now;
-                    schDtlDto.update_time = DateTime.Now;
-                    schDtlDto.update_by = Appsession.UserName;
-                    bool isAddSucc = _basicPlcTestSchemeDtlService.Add(schDtlDto);
-                    _logger.LogInformation($"复制方案成功。方案名{ScheduleName}");
+                    if(sch.IsSelected)
+                    {
+                        int dtlId = Convert.ToInt32(sch.Id);
+                        var unit = _basicPlcTestSchemeDtlService.Find(dtlId);
+                        if (unit != null)
+                        {
+                            bas_plc_test_scheme_dtl schDtlDto = new bas_plc_test_scheme_dtl();
+                            schDtlDto.scheme_id = schINewID;
+                            schDtlDto.item_name = unit.item_name;
+
+                            schDtlDto.item_type = unit.item_type;
+                            schDtlDto.precondition = unit.precondition;
+                            schDtlDto.precondition_describe = unit.precondition_describe;
+                            schDtlDto.action = unit.action;
+                            schDtlDto.action_describe = unit.action_describe;
+                            schDtlDto.judgement_result = unit.judgement_result;
+                            schDtlDto.judgement_result_describe = unit.judgement_result_describe;
+                            schDtlDto.create_by = Appsession.UserName;
+                            schDtlDto.create_time = DateTime.Now;
+                            schDtlDto.update_time = DateTime.Now;
+                            schDtlDto.update_by = Appsession.UserName;
+                            bool isAddSucc = _basicPlcTestSchemeDtlService.Add(schDtlDto);
 
 
+                        }
+                    }
+                    
+                  
                 }
                 }
+                _logger.LogInformation($"复制方案成功。方案名{ScheduleName}");
             }
             }
             RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
             RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
         }
         }
@@ -140,10 +219,10 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                             }
                             }
                             SchProjectList.Add(new SelectItemModel
                             SchProjectList.Add(new SelectItemModel
                             {
                             {
+                                Id = unit.scheme_dtl_id,
                                 ItemName = unit.item_name,
                                 ItemName = unit.item_name,
-
-                                ItemType= itemType,
-                            }) ;
+                                ItemType = itemType,
+                            }); ;
 
 
                         }
                         }
                     }
                     }
@@ -152,6 +231,13 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         }
         }
         #region 命令绑定
         #region 命令绑定
         public DelegateCommand<string> SureCommand { set; get; }
         public DelegateCommand<string> SureCommand { set; get; }
+        
+               
+        public DelegateCommand<object> DownCommand { set; get; }
+        public DelegateCommand<object> UpCommand { set; get; }
+        public DelegateCommand<object> SelectAllCommand { set; get; }
+        public DelegateCommand<object> UnSelectAllCommand { set; get; }
+
         #endregion
         #endregion
         #region 数据绑定
         #region 数据绑定
         /// <summary>
         /// <summary>
@@ -172,12 +258,16 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             get { return deviceName; }
             get { return deviceName; }
             set { deviceName = value; RaisePropertyChanged(); }
             set { deviceName = value; RaisePropertyChanged(); }
         }
         }
+
+
         private ObservableCollection<SelectItemModel> schProjectList = new ObservableCollection<SelectItemModel>();
         private ObservableCollection<SelectItemModel> schProjectList = new ObservableCollection<SelectItemModel>();
         public ObservableCollection<SelectItemModel> SchProjectList
         public ObservableCollection<SelectItemModel> SchProjectList
         {
         {
             get { return schProjectList; }
             get { return schProjectList; }
             set { SetProperty(ref schProjectList, value); }
             set { SetProperty(ref schProjectList, value); }
         }
         }
+
+    
         #endregion
         #endregion
 
 
     }
     }

+ 3 - 1
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ManualTestViewModel.cs

@@ -438,6 +438,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 if (globalSchDetailId == maxDtlId)
                 if (globalSchDetailId == maxDtlId)
                 {
                 {
                     MessageBox.Show("已是此测试方案最后一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
                     MessageBox.Show("已是此测试方案最后一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+                    break;
                 }
                 }
 
 
             }
             }
@@ -447,7 +448,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         {
         {
             StepIndex = 0;
             StepIndex = 0;
             ///查找方案下的所有方案明细,并排序,
             ///查找方案下的所有方案明细,并排序,
-            var basicSchDtls = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.OrderBy(x => x.scheme_dtl_id);
+            var basicSchDtls = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.OrderByDescending(x => x.scheme_dtl_id);
             foreach (var item in basicSchDtls)
             foreach (var item in basicSchDtls)
             {
             {
                 //在测试结果明细中查看
                 //在测试结果明细中查看
@@ -468,6 +469,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             if (globalSchDetailId == maxDtlId)
             if (globalSchDetailId == maxDtlId)
             {
             {
                 MessageBox.Show("已是此测试方案的第一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
                 MessageBox.Show("已是此测试方案的第一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+               
             }
             }
         }
         }
         /// <summary>
         /// <summary>

+ 46 - 7
BlankApp1/BlankApp1/Views/BasicConfigView/CopySchView.xaml

@@ -4,6 +4,7 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:PLCTool.Views.BasicConfigView"
              xmlns:local="clr-namespace:PLCTool.Views.BasicConfigView"
+             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
              mc:Ignorable="d" 
              mc:Ignorable="d" 
              Height="600" Width="800">
              Height="600" Width="800">
     <Grid>
     <Grid>
@@ -24,17 +25,55 @@
             <DataGrid  Grid.Row="2"  ColumnWidth="*" AutoGenerateColumns="False" HeadersVisibility="All" CanUserAddRows="False"  SelectionUnit="FullRow" SelectionMode="Single"   RowHeaderWidth="0"
             <DataGrid  Grid.Row="2"  ColumnWidth="*" AutoGenerateColumns="False" HeadersVisibility="All" CanUserAddRows="False"  SelectionUnit="FullRow" SelectionMode="Single"   RowHeaderWidth="0"
              ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"  RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
              ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"  RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
             ItemsSource="{Binding SchProjectList}" IsReadOnly="True" Padding="0"  >
             ItemsSource="{Binding SchProjectList}" IsReadOnly="True" Padding="0"  >
-                <DataGrid.RowHeaderTemplate>
-                    <DataTemplate>
-                        <CheckBox Content="全选" Background="Red" IsChecked="{Binding IsSelected,RelativeSource={RelativeSource AncestorType=DataGridRow}}"/>
-                    </DataTemplate>
-                </DataGrid.RowHeaderTemplate>
+               
                 <DataGrid.Columns >
                 <DataGrid.Columns >
-
+                    <DataGridTemplateColumn CanUserResize="False" Width="60">
+                        <DataGridTemplateColumn.HeaderTemplate>
+                            <DataTemplate>
+                                <CheckBox Content="全选" IsChecked="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=AllSelected}" Foreground="White" >
+                                    <i:Interaction.Triggers>
+                                        <i:EventTrigger EventName="Checked">
+                                            <i:InvokeCommandAction  Command="{Binding DataContext.SelectAllCommand, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding IsSelectAll, ElementName=qx}"/>
+                                        </i:EventTrigger>
+                                        <i:EventTrigger EventName="Unchecked">
+                                            <i:InvokeCommandAction   Command="{Binding DataContext.UnSelectAllCommand,  RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding IsSelectAll, ElementName=qx}"/>
+                                        </i:EventTrigger>
+                                    </i:Interaction.Triggers>
+                                </CheckBox>
+                            </DataTemplate>
+                        </DataGridTemplateColumn.HeaderTemplate>
+                        <DataGridTemplateColumn.CellTemplate>
+                            <DataTemplate>
+                                <CheckBox IsChecked="{Binding IsSelected}"  HorizontalAlignment="Center" />
+                            </DataTemplate>
+                        </DataGridTemplateColumn.CellTemplate>
+                    </DataGridTemplateColumn>
                     <DataGridTextColumn Header="测试项" Binding="{Binding ItemName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                     <DataGridTextColumn Header="测试项" Binding="{Binding ItemName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
 
 
                     <DataGridTextColumn Header="测试项类型" Binding="{Binding ItemType}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                     <DataGridTextColumn Header="测试项类型" Binding="{Binding ItemType}" 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.UpCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding Id}" 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.DownCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding Id}" Cursor="Hand" Margin="0,0,10,0">
+
+                                        <StackPanel Orientation="Horizontal">
+                                            <TextBlock  Text="下移↓" VerticalAlignment="Center" Foreground="Blue"/>
+                                        </StackPanel>
+                                    </Button>
+
+                                </StackPanel>
+                            </DataTemplate>
+                        </DataGridTemplateColumn.CellTemplate>
+                    </DataGridTemplateColumn>
                 </DataGrid.Columns>
                 </DataGrid.Columns>
 
 
             </DataGrid>
             </DataGrid>