Browse Source

添加复制功能

user_lt 1 year ago
parent
commit
ed5d31ac52

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

@@ -71,6 +71,7 @@ namespace BlankApp1
             containerRegistry.RegisterDialog<ManualTestView, ManualTestViewModel>();
             containerRegistry.RegisterDialog<TestResultDetailView, TestResultDetailViewModel>();
             containerRegistry.RegisterDialog<WritePLCView, WritePLCViewModel>();
+            containerRegistry.RegisterDialog<CopySchView, CopySchViewModel>();
         }
 
         private IMapper GetMapper(IContainerProvider container)

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

@@ -0,0 +1,42 @@
+using Model.Dto;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PLCTool.Models
+{
+    public class SelectItemModel:BaseDto
+    {
+        /// <summary>
+        /// Desc:测试项名称
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        private string itemName { get; set; }
+        public string ItemName
+        {
+            get { return itemName; }
+            set { itemName = value; OnPropertyChanged(); }
+        }
+        /// <summary>
+        /// Desc:测试项类型。0:代表测试方案的前置项,需要首先进行测试。1:PLC点位测试项。2:Robot动作测试
+        /// Default:
+        /// Nullable:True
+        /// </summary>           
+        private string item_type { get; set; }
+        public string ItemType
+        {
+            get { return item_type; }
+            set { item_type = value; OnPropertyChanged(); }
+        }
+
+        private bool isSelected { get; set; }
+        public bool IsSelected
+        {
+            get { return isSelected; }
+            set { isSelected = value; OnPropertyChanged(); }
+        }
+    }
+}

+ 30 - 3
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/BaseConfigViewModel.cs

@@ -51,16 +51,18 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             AddPlanCommand = new DelegateCommand<string>(AddPlan);
             EditCommand = new DelegateCommand<object>(Edit);
             DeleteCommand = new DelegateCommand<object>(Delete);
-           
+            CopyCommand = new DelegateCommand<object>(Copy);
             GetConfigOption();
             GetContent();
         }
 
+      
+
 
 
 
         #region 私有方法
-     
+
         private void Reset(object obj)
         {
             ScheduleName = string.Empty;
@@ -68,7 +70,10 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             TestName = string.Empty;
             SelectTest = string.Empty;
         }
-
+        /// <summary>
+        /// 查询
+        /// </summary>
+        /// <param name="obj"></param>
         private void Query(object obj)
         {
             if((!string.IsNullOrEmpty(StartTime))&&(!string.IsNullOrEmpty(EndTime)))
@@ -148,6 +153,27 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             }
         }
         /// <summary>
+        /// 复制方案
+        /// </summary>
+        /// <param name="obj"></param>
+        private void Copy(object obj)
+        {
+            //测试方案名称
+            string  schName = obj.ToString();
+            DialogParameters parm = new DialogParameters();
+            parm.Add("Key", schName);
+            //弹出详情对话框
+            _dialog.ShowDialog("CopySchView", parm, async callback =>
+            {
+                if (callback.Result == ButtonResult.OK)
+                {
+                    //更新表格,重新获取
+                    GetContent();
+                }
+
+            });
+        }
+        /// <summary>
         /// 新增按钮
         /// </summary>
         /// <param name="obj"></param>
@@ -296,6 +322,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         public DelegateCommand<object> QueryCommand { set; get; }
         public DelegateCommand<object> ResetCommand { set; get; }
         public DelegateCommand<object> DeleteCommand { set; get; }
+        public DelegateCommand<object> CopyCommand { set; get; }
         public DelegateCommand<string> ExportCommand { set; get; }
 
   

+ 183 - 0
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/CopySchViewModel.cs

@@ -0,0 +1,183 @@
+using AutoMapper;
+using BizService;
+using Microsoft.Extensions.Logging;
+using Model.Dto;
+using Model.Entities;
+using PLCTool.Common;
+using PLCTool.Models;
+using Prism.Commands;
+using Prism.Events;
+using Prism.Mvvm;
+using Prism.Services.Dialogs;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Automation;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
+
+namespace PLCTool.ViewModels.BasicConfigViewModel
+{
+    internal class CopySchViewModel : BindableBase, IDialogAware
+    {
+        private readonly IMapper _mapper;
+        private readonly ILogger _logger;
+        private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
+        private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
+        private string schNameAgo = String.Empty;
+        public CopySchViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IMapper mapper, ILogger logger)
+        {
+            
+            _basicPlcTestSchemeService = basicPlcTestSchemeService;
+            _basicPlcTestSchemeDtlService = basicPlcTestSchemeDtlService;
+            _mapper = mapper;
+            _logger = logger;
+            SureCommand = new DelegateCommand<string>(Sure);
+        }
+
+        private void Sure(string obj)
+        {
+            //查找是否有这个测试方案
+            var findExist = _basicPlcTestSchemeService.FindByName(ScheduleName);
+            if (findExist != null)
+            {
+                MessageBoxResult boxResult = MessageBox.Show("已有次测试方案,请填写其他方案名!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            //查找以前测试方案的信息
+            var finsSche = _basicPlcTestSchemeService.FindByName(schNameAgo);
+            if (finsSche != null)
+            {
+                //增加测试方案到数据库
+                bas_plc_test_scheme schDto = new bas_plc_test_scheme();
+                schDto.scheme_name = ScheduleName;
+                schDto.device_name = DeviceName;
+                schDto.create_by = Appsession.UserName;
+                schDto.create_time = DateTime.Now;
+                schDto.update_time = DateTime.Now;
+                schDto.update_by = Appsession.UserName;
+                _basicPlcTestSchemeService.Add(schDto);
+                //以前复制的schID
+                long schID = finsSche.scheme_id;
+                //查找此方案下的所有的测试项,并增加到测试项详细表中
+                long? schINewID = _basicPlcTestSchemeService.FindByName(ScheduleName)?.scheme_id;
+                var schDtls = _basicPlcTestSchemeDtlService.QueryList()?.FindAll(x => x.scheme_id == schID);
+                foreach (var unit in schDtls)
+                {
+                    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);
+
+                }
+            }
+            RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
+        }
+
+        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)
+                {
+                    schNameAgo = item.ToString();
+                    ScheduleName = schNameAgo + "_copy";
+
+                    var findSche = _basicPlcTestSchemeService.FindByName(schNameAgo);
+                    if (findSche != null)
+                    {
+                       //显示设备名称
+                       DeviceName= findSche.device_name;
+                        long schID = findSche.scheme_id;
+                        //查找此方案下的所有的测试项,并增加到表格
+                        var schDtls = _basicPlcTestSchemeDtlService.QueryList()?.FindAll(x => x.scheme_id == schID);
+                        foreach (var unit in schDtls)
+                        {
+                            string itemType = string.Empty;
+                            switch (unit.item_type)
+                            {
+                                case 0:
+                                    itemType = "前置项";
+                                    break;
+                                case 1:
+                                    itemType = "PLC点位测试项";
+                                    break;
+                                case 2:
+                                    itemType = "Robot动作测试";
+                                    break;
+                            }
+                            SchProjectList.Add(new SelectItemModel
+                            {
+                                ItemName = unit.item_name,
+
+                                ItemType= itemType,
+                            }) ;
+
+                        }
+                    }
+                }
+            }
+        }
+        #region 命令绑定
+        public DelegateCommand<string> SureCommand { set; get; }
+        #endregion
+        #region 数据绑定
+        /// <summary>
+        /// 测试方案编码
+        /// </summary>
+        private string scheduleName;
+        public string ScheduleName
+        {
+            get { return scheduleName; }
+            set { scheduleName = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 设备名称
+        /// </summary>
+        private string deviceName;
+        public string DeviceName
+        {
+            get { return deviceName; }
+            set { deviceName = value; RaisePropertyChanged(); }
+        }
+        private ObservableCollection<SelectItemModel> schProjectList = new ObservableCollection<SelectItemModel>();
+        public ObservableCollection<SelectItemModel> SchProjectList
+        {
+            get { return schProjectList; }
+            set { SetProperty(ref schProjectList, value); }
+        }
+        #endregion
+
+    }
+}

+ 12 - 6
BlankApp1/BlankApp1/Views/BasicConfigView/BaseConfigView.xaml

@@ -65,33 +65,39 @@
                   ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"  RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
                  ItemsSource="{Binding BaseConfigList}" IsReadOnly="True" Padding="0"  >
             <DataGrid.Columns >
-                <DataGridTextColumn Header="序号" Binding="{Binding SchemeId}" CellStyle="{StaticResource MyDataGridCellStyle}" />
+                <DataGridTextColumn Header="序号" Width="50" Binding="{Binding SchemeId}" CellStyle="{StaticResource MyDataGridCellStyle}" />
                 <DataGridTextColumn Header="测试方案名称" Binding="{Binding SchemeName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                 <DataGridTextColumn Header="设备名称" Binding="{Binding DeviceName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                 <DataGridTextColumn Header="测试项类型" Binding="{Binding ItemType}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                 <DataGridTextColumn Header="测试项名称" Binding="{Binding ItemName}" 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="操作"  CellStyle="{StaticResource MyDataGridCellStyle}">
+                <DataGridTemplateColumn Header="操作" Width="180" CellStyle="{StaticResource MyDataGridCellStyle}">
                         <DataGridTemplateColumn.CellTemplate>
                             <DataTemplate>
-                                <UniformGrid Columns="2">
+                                <StackPanel Orientation="Horizontal">
                                     <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
-                                        Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchemeId}" Cursor="Hand" Margin="0,0,10,0" >
+                                        Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchemeId}" Cursor="Hand" Margin="0,0,20,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 SchemeId}" Cursor="Hand" >
+                                        Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchemeId}" Cursor="Hand" Margin="0,0,20,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.CopyCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchemeName}" Cursor="Hand" >
 
-                                </UniformGrid>
+                                    <StackPanel Orientation="Horizontal">
+                                        <TextBlock  Text="复制方案" VerticalAlignment="Center" Foreground="Blue"/>
+                                    </StackPanel>
+                                </Button>
+                            </StackPanel>
                             </DataTemplate>
                         </DataGridTemplateColumn.CellTemplate>
                     </DataGridTemplateColumn>

+ 43 - 0
BlankApp1/BlankApp1/Views/BasicConfigView/CopySchView.xaml

@@ -0,0 +1,43 @@
+<UserControl x:Class="PLCTool.Views.BasicConfigView.CopySchView"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:PLCTool.Views.BasicConfigView"
+             mc:Ignorable="d" 
+             Height="600" Width="800">
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="60" />
+            <RowDefinition />
+        </Grid.RowDefinitions>
+        <StackPanel Grid.Row="0" Orientation="Horizontal">
+            <TextBlock Text="测试方案名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+            <TextBox  Height="28" Width="120" Text="{Binding ScheduleName}" />
+            <StackPanel Orientation="Horizontal">
+                <TextBlock Text="设备名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                <TextBox  Height="28" Width="120" Text="{Binding DeviceName}"/>
+            </StackPanel>
+            <Button  Content="确认" Width="80"  Margin="5,0"  Command="{Binding SureCommand}" Style="{StaticResource NormalButtonStyle}" />
+        </StackPanel>
+        <Grid Grid.Row="1">
+            <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"
+            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 >
+
+                    <DataGridTextColumn Header="测试项" Binding="{Binding ItemName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+
+                    <DataGridTextColumn Header="测试项类型" Binding="{Binding ItemType}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                   
+                </DataGrid.Columns>
+
+            </DataGrid>
+        </Grid>
+    </Grid>
+</UserControl>

+ 28 - 0
BlankApp1/BlankApp1/Views/BasicConfigView/CopySchView.xaml.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PLCTool.Views.BasicConfigView
+{
+    /// <summary>
+    /// CopySchView.xaml 的交互逻辑
+    /// </summary>
+    public partial class CopySchView : UserControl
+    {
+        public CopySchView()
+        {
+            InitializeComponent();
+        }
+    }
+}