Browse Source

修改测试记录查询

user_lt 1 năm trước cách đây
mục cha
commit
0e23f952f6

+ 389 - 2
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/QueryViewModel.cs

@@ -1,12 +1,399 @@
-using System;
+using AutoMapper;
+using BizService;
+using Microsoft.Extensions.Logging;
+using MiniExcelLibs;
+using Model.Dto;
+using Model.Entities;
+using Prism.Commands;
+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;
 
 namespace PLCTool.ViewModels.BusinessManageViewModel
 {
-    internal class QueryViewModel
+    internal class QueryViewModel : BindableBase
     {
+        private readonly IDialogService _dialog;
+        private readonly IOptionConfigService _optionConfigService;
+        private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
+        private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
+        private readonly ILogger _logger;
+        private readonly IMapper _mapper;
+        private readonly IMenuService _menuService;
+
+        private List<BasicPlcTestSchemeDto> allConfigList = new List<BasicPlcTestSchemeDto>();//所有方案
+        private List<BasicPlcTestSchemeDto> conditionConfig = new List<BasicPlcTestSchemeDto>();//所有方案
+
+        private const int PageCount = 1; //每一页显示个数
+        public QueryViewModel(IDialogService dialog, IMenuService menuService, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IMapper mapper, ILogger logger)
+        {
+            _dialog = dialog;
+            _optionConfigService = optionConfigService;
+            _basicPlcTestSchemeService = basicPlcTestSchemeService;
+            _basicPlcTestSchemeDtlService = basicPlcTestSchemeDtlService;
+            _logger = logger;
+            _mapper = mapper;
+            _menuService = menuService;
+            QueryCommand = new DelegateCommand<object>(Query);
+            ResetCommand = new DelegateCommand<object>(Reset);
+            ExportCommand = new DelegateCommand<string>(Export);
+            AddPlanCommand = new DelegateCommand<string>(AddPlan);
+            EditCommand = new DelegateCommand<object>(Edit);
+            DeleteCommand = new DelegateCommand<object>(Delete);
+
+            GetConfigOption();
+            GetContent();
+        }
+
+
+
+
+        #region 私有方法
+
+        private void Reset(object obj)
+        {
+            ScheduleName = string.Empty;
+            DeviceName = string.Empty;
+            TestName = string.Empty;
+            SelectTest = string.Empty;
+        }
+
+        private void Query(object obj)
+        {
+            if ((!string.IsNullOrEmpty(StartTime)) && (!string.IsNullOrEmpty(EndTime)))
+            {
+                if (Convert.ToDateTime(StartTime) > Convert.ToDateTime(EndTime))
+                {
+                    MessageBox.Show("起始时间大于结束时间,请重新输入", "确认", MessageBoxButton.OK, MessageBoxImage.Warning);
+                    return;
+                }
+                if (Convert.ToDateTime(StartTime).AddDays(2) < Convert.ToDateTime(EndTime))
+                {
+                    MessageBox.Show("起始时间和结束时间间隔不能大于2天,请重新输入", "确认", MessageBoxButton.OK, MessageBoxImage.Warning);
+                    return;
+                }
+            }
+
+            conditionConfig = (from a in allConfigList
+                               where (EndTime == string.Empty ? true : (a.CreateTime < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < a.CreateTime))
+                                && (string.IsNullOrEmpty(ScheduleName) ? true : (a.SchemeName == ScheduleName))
+                                 && (string.IsNullOrEmpty(TestName) ? true : (a.ItemName == TestName))
+                                  && (string.IsNullOrEmpty(DeviceName) ? true : (a.DeviceName == DeviceName))
+                                    && (string.IsNullOrEmpty(SelectTest) ? true : (a.ItemType == SelectTest))
+                               select a).ToList();
+            //默认显示的第一页
+            Getpage();
+            //BaseConfigList = new ObservableCollection<BasicPlcTestSchemeDto>(conditionConfig);
+        }
+        /// <summary>
+        /// 获取配置
+        /// </summary>
+        private void GetConfigOption()
+        {
+            var configList = _optionConfigService.QueryList();
+            var _optionConfigs = _mapper.Map<List<OptionConfig>, List<OptionConfigDto>>(configList);
+            var tests = _optionConfigs.FindAll(x => x.TypeID == 1);
+            TestKinds = new List<string>();
+            foreach (var test in tests)
+            {
+                TestKinds.Add(test.ContentOption);
+            }
+        }
+        /// <summary>
+        /// 编辑
+        /// </summary>
+        /// <param name="obj"></param>
+        private void Edit(object obj)
+        {
+            //测试方案明细主键ID
+            long id = Convert.ToInt64(obj);
+            DialogParameters parm = new DialogParameters();
+            parm.Add("Key", id);
+            //弹出详情对话框
+            _dialog.ShowDialog("AddOrEditSchView", parm, async callback =>
+            {
+                if (callback.Result == ButtonResult.OK)
+                {
+                    //更新表格,重新获取
+                    GetContent();
+                }
+
+            });
+        }
+        /// <summary>
+        /// 删除操作
+        /// </summary>
+        /// <param name="obj"></param>
+        private void Delete(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            MessageBoxResult boxResult = MessageBox.Show("确认删除此条数据?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
+            if (boxResult == MessageBoxResult.OK)
+            {
+
+                _basicPlcTestSchemeDtlService.Delete(id);
+                //更新表格,重新获取
+                GetContent();
+            }
+        }
+        /// <summary>
+        /// 新增按钮
+        /// </summary>
+        /// <param name="obj"></param>
+        private void AddPlan(string obj)
+        {
+
+            //弹出详情对话框
+            _dialog.ShowDialog("AddOrEditSchView", async callback =>
+            {
+                if (callback.Result == ButtonResult.OK)
+                {
+                    //更新表格,重新获取
+                    GetContent();
+                }
+
+            });
+        }
+        /// <summary>
+        /// excel导出
+        /// </summary>
+        /// <param name="obj"></param>
+        private void Export(object obj)
+        {
+
+
+            using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog()
+            {
+                //设置文件类型
+                //书写规则例如:txt files(*.txt)|*.txt
+                Filter = "Excel files(*.xlsx)|*.xlsx|All files(*.*)|*.*",
+                //设置默认文件名(可以不设置)
+                FileName = "配置导出",
+
+                //获取或设置一个值,该值指示如果用户省略扩展名,文件对话框是否自动在文件名中添加扩展名。(可以不设置)
+                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, BaseConfigList);
+                    }
+                    catch (Exception ex)
+                    {
+
+                    }
+
+
+                }
+
+            }
+        }
+        /// <summary>
+        /// 获取解决方案
+        /// </summary>
+        private void GetContent()
+        {
+            //所有测试方案
+            var schlist = _basicPlcTestSchemeService.QueryList();
+            var configList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
+            //清空集合
+            BaseConfigList.Clear();
+            allConfigList.Clear();
+            conditionConfig.Clear();
+            //查找测试项名称
+            foreach (var sch in configList)
+            {
+                long schId = sch.SchemeId;
+                //在解决方案详细表中查找所有的测试项
+                var items = _basicPlcTestSchemeDtlService.FindAllBySchId(schId);
+                foreach (var item in items)
+                {
+                    BasicPlcTestSchemeDto basicPlcTestSchemeDto = new BasicPlcTestSchemeDto();
+                    basicPlcTestSchemeDto.SchemeId = item.scheme_dtl_id;
+                    basicPlcTestSchemeDto.SchemeName = sch.SchemeName;
+                    basicPlcTestSchemeDto.DeviceName = sch.DeviceName;
+                    switch (item.item_type)
+                    {
+                        case 0:
+                            basicPlcTestSchemeDto.ItemType = "前置项";
+                            break;
+                        case 1:
+                            basicPlcTestSchemeDto.ItemType = "PLC点位测试项";
+                            break;
+                        case 2:
+                            basicPlcTestSchemeDto.ItemType = "Robot动作测试";
+                            break;
+                    }
+
+                    basicPlcTestSchemeDto.ItemName = item.item_name;
+                    basicPlcTestSchemeDto.CreateBy = sch.CreateBy;
+                    basicPlcTestSchemeDto.CreateTime = sch.CreateTime;
+
+                    allConfigList.Add(basicPlcTestSchemeDto);
+                    conditionConfig.Add(basicPlcTestSchemeDto);
+
+                }
+                //默认显示的第一页
+                Getpage();
+            }
+
+        }
+
+        /// <summary>
+        /// 获取页面
+        /// </summary>
+        private void Getpage()
+        {
+            CurrentPage = 1;
+            TotalCount = conditionConfig.Count;
+            CurrentPageChanged();
+
+
+        }
+        /// <summary>
+        /// 页面变化
+        /// </summary>
+        private void CurrentPageChanged()
+        {
+
+            BaseConfigList.Clear();
+
+            foreach (var i in conditionConfig.Skip((CurrentPage - 1) * CountPerPage).Take(CountPerPage))
+            {
+                BaseConfigList.Add(i);
+            }
+        }
+        #endregion
+        #region 命令绑定
+
+        public DelegateCommand<object> EditCommand { set; get; }
+        public DelegateCommand<string> AddPlanCommand { set; get; }
+        public DelegateCommand<object> QueryCommand { set; get; }
+        public DelegateCommand<object> ResetCommand { set; get; }
+        public DelegateCommand<object> DeleteCommand { set; get; }
+        public DelegateCommand<string> ExportCommand { set; get; }
+
+        public DelegateCommand PageUpdatedCmd { 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(); }
+        }
+        /// <summary>
+        /// 测试项名称
+        /// </summary>
+        private string testName;
+        public string TestName
+        {
+            get { return testName; }
+            set { testName = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 测试项类型
+        /// </summary>
+
+
+        private List<string> testKinds = new List<string>();
+        public List<string> TestKinds
+        {
+            get { return testKinds; }
+            set { testKinds = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 
+        /// </summary>
+        private string selectTest;
+        public string SelectTest
+        {
+            get { return selectTest; }
+            set { selectTest = value; RaisePropertyChanged(); }
+        }
+
+        private string startTime = string.Empty;
+        public string StartTime
+        {
+            get { return startTime; }
+            set { startTime = value; RaisePropertyChanged(); }
+        }
+        private string endTime = string.Empty;
+        public string EndTime
+        {
+            get { return endTime; }
+            set { endTime = value; RaisePropertyChanged(); }
+        }
+
+        /// <summary>
+        /// 总条数
+        /// </summary>
+        private int totalCount;
+        public int TotalCount
+        {
+            get { return totalCount; }
+            set { totalCount = value; RaisePropertyChanged(); CurrentPageChanged(); }
+        }
+        /// <summary>
+        /// 每页数量
+        /// </summary>
+        private int countPerPage = 1;
+        public int CountPerPage
+        {
+            get { return countPerPage; }
+            set { countPerPage = value; RaisePropertyChanged(); CurrentPageChanged(); }
+        }
+        /// <summary>
+        /// 单前页
+        /// </summary>
+        private int currentPage = 1;
+        public int CurrentPage
+        {
+            get { return currentPage; }
+            set { currentPage = value; RaisePropertyChanged(); CurrentPageChanged(); }
+        }
+
+        private ObservableCollection<BasicPlcTestSchemeDto> baseConfigList = new ObservableCollection<BasicPlcTestSchemeDto>();
+        public ObservableCollection<BasicPlcTestSchemeDto> BaseConfigList
+        {
+            get { return baseConfigList; }
+            set { SetProperty(ref baseConfigList, value); }
+        }
+
+        #endregion
+
     }
 }
+

+ 27 - 31
BlankApp1/BlankApp1/Views/BusinessManageView/QueryView.xaml

@@ -6,6 +6,7 @@
              xmlns:local="clr-namespace:BlankApp1.Views"
              xmlns:myContr="clr-namespace:BlankApp1.Controls"
              xmlns:hc="https://handyorg.github.io/handycontrol"
+             xmlns:wpfdev="https://github.com/WPFDevelopersOrg/WPFDevelopers"
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
     <Grid >
@@ -18,20 +19,20 @@
         </Grid.RowDefinitions>
         <UniformGrid Grid.Row="0" Columns="4">
             <StackPanel Orientation="Horizontal">
-                <TextBlock Text="测试方案编码:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
-                <TextBox  Height="28" Width="120" />
+                <TextBlock Text="测试方案名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                <TextBox  Height="28" Width="120" Text="{Binding ScheduleName}" />
             </StackPanel>
             <StackPanel Orientation="Horizontal">
                 <TextBlock Text="设备名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
-                <TextBox  Height="28" Width="120" />
-            </StackPanel>
-            <StackPanel Orientation="Horizontal">
-                <TextBlock Text="测试项名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
-                <TextBox  Height="28" Width="120" />
+                <TextBox  Height="28" Width="120" Text="{Binding DeviceName}"/>
             </StackPanel>
             <StackPanel Orientation="Horizontal" >
                 <TextBlock Text="测试项类型:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
-                <ComboBox  Height="28" Width="120" />
+                <ComboBox  Height="28" Width="120" 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}"/>
             </StackPanel>
 
 
@@ -44,7 +45,7 @@
             <StackPanel Grid.Column="0" Orientation="Horizontal">
                 <StackPanel Orientation="Horizontal">
                     <TextBlock Text="创建时间:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
-                    <myContr:MyDateTimePicker ></myContr:MyDateTimePicker>
+                    <myContr:MyDateTimePicker  ></myContr:MyDateTimePicker>
                 </StackPanel>
                 <StackPanel Orientation="Horizontal">
                     <TextBlock Text="至:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
@@ -54,37 +55,32 @@
             <StackPanel Grid.Column="1" Orientation="Horizontal">
 
                 <Button  Content="查询" Width="80"  Margin="5,0"  Command="{Binding QueryCommand}" Style="{StaticResource NormalButtonStyle}" />
-                <Button  Content="重置" Width="80"  Margin="5,0"  Command="{Binding QueryCommand}" Style="{StaticResource NormalButtonStyle}" />
-               
-                <Button Content="导出Excel" Width="80"  Margin="5,0"  Command="{Binding ExportCommand}" Style="{StaticResource NormalButtonStyle}" />
+                <Button  Content="重置" Width="80"  Margin="5,0"  Command="{Binding ResetCommand}" Style="{StaticResource NormalButtonStyle}" />
+                <Button  Content="导出Excel" Width="80"  Margin="5,0"  Command="{Binding ResetCommand}" Style="{StaticResource NormalButtonStyle}" />
             </StackPanel>
         </Grid>
         <DataGrid  Grid.Row="2"  ColumnWidth="*" AutoGenerateColumns="False" HeadersVisibility="All" CanUserAddRows="False"  SelectionUnit="FullRow" SelectionMode="Single"   RowHeaderWidth="0"
-               ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}" x:Name="DeviceDataGrid" RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
-              ItemsSource="{Binding BaseConfigList}" IsReadOnly="True"  >
+                ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"  RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
+               ItemsSource="{Binding BaseConfigList}" IsReadOnly="True"  >
             <DataGrid.Columns >
-                <DataGridTextColumn Header="序号" Binding="{Binding Id}" CellStyle="{StaticResource MyDataGridCellStyle}" />
-                <DataGridTextColumn Header="测试方案名称" Binding="{Binding Name}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                <DataGridTextColumn Header="设备名称" Binding="{Binding Name}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                <DataGridTextColumn Header="测试项类型" Binding="{Binding Name}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-
-                <DataGridTextColumn Header="测试项名称" Binding="{Binding Name}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                <DataGridTextColumn Header="测试结果" Binding="{Binding Name}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                <DataGridTextColumn Header="状态" Binding="{Binding Name}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                <DataGridTextColumn Header="创建者" Binding="{Binding Name}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-
+                <DataGridTextColumn Header="序号" 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 ItemName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="状态" Binding="{Binding ItemName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="创建者" Binding="{Binding CreateBy}" 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>