|
@@ -0,0 +1,326 @@
|
|
|
+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;
|
|
|
+
|
|
|
+namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ public class ResultQueryViewModel : BindableBase
|
|
|
+ {
|
|
|
+ private readonly IBasicDeviceService _iBasicDeviceService;
|
|
|
+ private readonly IBasicDeviceKindService _iBasicDeviceKindService;
|
|
|
+ private readonly IBasicProjectService _iBasicProjectService;
|
|
|
+ private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
|
|
|
+ private readonly IBizTestRecordDtlService _iBizTestRecordDtlService;
|
|
|
+ private readonly IBizTestRecordService _iBizTestRecordService;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ private readonly IDialogService _dialog;
|
|
|
+ private readonly ILogger _logger;
|
|
|
+ private List<DeviceDtlWithResultModel> allDeviceList = new List<DeviceDtlWithResultModel>();//所有方案
|
|
|
+ private List<DeviceDtlWithResultModel> conditionDevices = new List<DeviceDtlWithResultModel>();//符合条件的方案
|
|
|
+ public ResultQueryViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBizTestRecordDtlService iBizTestRecordDtlService, IBizTestRecordService iBizTestRecordService, IMapper mapper, IDialogService dialog, ILogger logger)
|
|
|
+ {
|
|
|
+ _iBasicDeviceService = iBasicDeviceService;
|
|
|
+ _iBasicDeviceKindService = iBasicDeviceKindService;
|
|
|
+ _iBasicProjectService = iBasicProjectService;
|
|
|
+ _basicPlcTestSchemeService = basicPlcTestSchemeService;
|
|
|
+ _iBizTestRecordService= iBizTestRecordService;
|
|
|
+ _iBizTestRecordDtlService= iBizTestRecordDtlService;
|
|
|
+ _mapper = mapper;
|
|
|
+ _dialog = dialog;
|
|
|
+ _logger = logger;
|
|
|
+ QueryCommand = new DelegateCommand<object>(Query);
|
|
|
+
|
|
|
+ ExportCommand = new DelegateCommand<string>(Export);
|
|
|
+ ;
|
|
|
+ ResetCommand = new DelegateCommand<object>(Reset);
|
|
|
+ OnLoadCommand = new DelegateCommand(OnLoad);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #region 私有方法
|
|
|
+ /// <summary>
|
|
|
+ /// 加载页面
|
|
|
+ /// </summary>
|
|
|
+ private void OnLoad()
|
|
|
+ {
|
|
|
+ DeviceKindNameList = _iBasicDeviceKindService.FindAllDeviceKind();
|
|
|
+ ProjectNameList = _iBasicProjectService.FindAllProject();
|
|
|
+ GetProjectConfig();
|
|
|
+ }
|
|
|
+ private void Reset(object obj)
|
|
|
+ {
|
|
|
+ DeviceNo = string.Empty;
|
|
|
+ DeviceName = string.Empty;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
+ private void Query(object obj)
|
|
|
+ {
|
|
|
+ conditionDevices = (from a in allDeviceList
|
|
|
+ where (string.IsNullOrEmpty(DeviceName) ? true : (a.DeviceName == DeviceName))
|
|
|
+ && (string.IsNullOrEmpty(DeviceNo) ? true : (a.DeviceNo == DeviceNo))
|
|
|
+ //&& (string.IsNullOrEmpty(DeviceKindName) ? true : (a.DeviceKindId == DeviceKindName))
|
|
|
+ // && (string.IsNullOrEmpty(ProjectName) ? true : (a.ProjectId == ProjectName))
|
|
|
+ select a).ToList();
|
|
|
+ //默认显示的第一页
|
|
|
+ conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
|
|
|
+ Getpage();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Export(string 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();
|
|
|
+
|
|
|
+ //获取文件内容
|
|
|
+ MiniExcel.SaveAs(localFilePath, DeviceResultItemList);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.LogError(ex.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取所有项目
|
|
|
+ /// </summary>
|
|
|
+ private void GetProjectConfig()
|
|
|
+ {
|
|
|
+ allDeviceList.Clear();
|
|
|
+ conditionDevices.Clear();
|
|
|
+ //所有测试方案
|
|
|
+ var schlist = _basicPlcTestSchemeService.QueryList();
|
|
|
+ var schDtoList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
|
|
|
+ //测试记录中的所有设备
|
|
|
+ var deviceIds=_iBizTestRecordService.QueryList().Select(X => X.device_id).Distinct();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ foreach (var deviceId in deviceIds)
|
|
|
+ {
|
|
|
+ var deviceMsg = _iBasicDeviceService.Find(((int)deviceId));
|
|
|
+ if(deviceMsg != null)
|
|
|
+ {
|
|
|
+ //查找哦记录有的方案
|
|
|
+
|
|
|
+ var recordMsgs=_iBizTestRecordService.FindRecordByDeviceId(deviceId);
|
|
|
+ foreach ( var sch in recordMsgs)
|
|
|
+ {
|
|
|
+ allDeviceList.Add(new DeviceDtlWithResultModel()
|
|
|
+ {
|
|
|
+ DeviceId = deviceMsg.device_id,
|
|
|
+ DeviceNo = deviceMsg.device_no,
|
|
|
+ DeviceName = deviceMsg.device_name,
|
|
|
+ DeviceKindName = _iBasicDeviceKindService.Find((int)deviceMsg.device_kind_id)?.devicekind_name,
|
|
|
+ ProjectName = _iBasicProjectService.Find((int)deviceMsg.project_id)?.project_name,
|
|
|
+ SchemeName = sch.scheme_name,
|
|
|
+ StartTestTime = sch.start_test_time.Value,
|
|
|
+ }); ;
|
|
|
+ conditionDevices.Add(new DeviceDtlWithResultModel()
|
|
|
+ {
|
|
|
+ DeviceId = deviceMsg.device_id,
|
|
|
+ DeviceNo = deviceMsg.device_no,
|
|
|
+ DeviceName = deviceMsg.device_name,
|
|
|
+ DeviceKindName =_iBasicDeviceKindService.Find((int) deviceMsg.device_kind_id)?.devicekind_name,
|
|
|
+ ProjectName = _iBasicProjectService.Find((int)deviceMsg.project_id)?.project_name,
|
|
|
+ SchemeName = sch.scheme_name,
|
|
|
+ StartTestTime = sch.start_test_time.Value,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
|
|
|
+ Getpage();
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 获取页面
|
|
|
+ /// </summary>
|
|
|
+ private void Getpage()
|
|
|
+ {
|
|
|
+ CurrentPage = 1;
|
|
|
+ TotalCount = conditionDevices.Count;
|
|
|
+ CurrentPageChanged();
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 页面变化
|
|
|
+ /// </summary>
|
|
|
+ private void CurrentPageChanged()
|
|
|
+ {
|
|
|
+
|
|
|
+ DeviceResultItemList.Clear();
|
|
|
+
|
|
|
+ foreach (var i in conditionDevices.Skip((CurrentPage - 1) * CountPerPage).Take(CountPerPage))
|
|
|
+ {
|
|
|
+ DeviceResultItemList.Add(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ #region 命令绑定
|
|
|
+
|
|
|
+ public DelegateCommand<object> QueryCommand { set; get; }
|
|
|
+
|
|
|
+ public DelegateCommand<string> ExportCommand { set; get; }
|
|
|
+
|
|
|
+
|
|
|
+ public DelegateCommand<object> ResetCommand { set; get; }
|
|
|
+
|
|
|
+ public DelegateCommand OnLoadCommand { set; get; }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 数据绑定
|
|
|
+ private ObservableCollection<DeviceDtlWithResultModel> deviceResultItemList = new ObservableCollection<DeviceDtlWithResultModel>();
|
|
|
+ public ObservableCollection<DeviceDtlWithResultModel> DeviceResultItemList
|
|
|
+ {
|
|
|
+ get { return deviceResultItemList; }
|
|
|
+ set { deviceResultItemList = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 设备编号
|
|
|
+ /// </summary>
|
|
|
+ private string devicedNo;
|
|
|
+ public string DeviceNo
|
|
|
+ {
|
|
|
+ get { return devicedNo; }
|
|
|
+ set { devicedNo = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 设备类型名称
|
|
|
+ /// </summary>
|
|
|
+ private string deviceName;
|
|
|
+ public string DeviceName
|
|
|
+ {
|
|
|
+ get { return deviceName; }
|
|
|
+ set { deviceName = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string projectName;
|
|
|
+ public string ProjectName
|
|
|
+ {
|
|
|
+ get { return projectName; }
|
|
|
+ set { projectName = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string deviceKindName;
|
|
|
+ public string DeviceKindName
|
|
|
+ {
|
|
|
+ get { return deviceKindName; }
|
|
|
+ set { deviceKindName = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 项目名称
|
|
|
+ /// </summary>
|
|
|
+ private List<string> projectNameList;
|
|
|
+ public List<string> ProjectNameList
|
|
|
+ {
|
|
|
+ get { return projectNameList; }
|
|
|
+ set { projectNameList = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 设备类型
|
|
|
+ /// </summary>
|
|
|
+ private List<string> deviceKindNameList;
|
|
|
+ public List<string> DeviceKindNameList
|
|
|
+ {
|
|
|
+ get { return deviceKindNameList; }
|
|
|
+ set { deviceKindNameList = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 总条数
|
|
|
+ /// </summary>
|
|
|
+ private int totalCount;
|
|
|
+ public int TotalCount
|
|
|
+ {
|
|
|
+ get { return totalCount; }
|
|
|
+ set { totalCount = value; RaisePropertyChanged(); CurrentPageChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 每页数量
|
|
|
+ /// </summary>
|
|
|
+ private int countPerPage = 15;
|
|
|
+ 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(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+}
|