|
@@ -0,0 +1,137 @@
|
|
|
+using AutoMapper;
|
|
|
+using BizService;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
+using Model.Dto;
|
|
|
+using Model.Entities;
|
|
|
+using PLCTool.Views.BusinessManageView;
|
|
|
+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 ProjectTestViewModel:BindableBase
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ private readonly IBasicDeviceService _iBasicDeviceService;
|
|
|
+ private readonly IBasicDeviceKindService _iBasicDeviceKindService;
|
|
|
+ private readonly IBasicProjectService _iBasicProjectService;
|
|
|
+ private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ private readonly IDialogService _dialog;
|
|
|
+ private readonly ILogger _logger;
|
|
|
+ private List<BasDeviceWithSchModel> allDeviceList = new List<BasDeviceWithSchModel>();//所有方案
|
|
|
+
|
|
|
+ public ProjectTestViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IMapper mapper, IDialogService dialog, ILogger logger)
|
|
|
+ {
|
|
|
+ _iBasicDeviceService = iBasicDeviceService;
|
|
|
+ _iBasicDeviceKindService = iBasicDeviceKindService;
|
|
|
+ _iBasicProjectService = iBasicProjectService;
|
|
|
+ _basicPlcTestSchemeService = basicPlcTestSchemeService;
|
|
|
+ _mapper = mapper;
|
|
|
+ _dialog = dialog;
|
|
|
+ _logger = logger;
|
|
|
+ OnLoadCommand = new DelegateCommand(OnLoad);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OnLoad()
|
|
|
+ {
|
|
|
+ GetProjectConfig();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取所有项目
|
|
|
+ /// </summary>
|
|
|
+ private void GetProjectConfig()
|
|
|
+ {
|
|
|
+ allDeviceList.Clear();
|
|
|
+
|
|
|
+ var devicelist = _iBasicDeviceService.QueryList();
|
|
|
+ var allDeviceKinds = _mapper.Map<List<bas_device>, List<BasDeviceDto>>(devicelist);
|
|
|
+ //所有测试方案
|
|
|
+ var schlist = _basicPlcTestSchemeService.QueryList();
|
|
|
+ var schDtoList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
|
|
|
+
|
|
|
+
|
|
|
+ foreach (var item in allDeviceKinds)
|
|
|
+ {
|
|
|
+ string deviceKind = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
|
|
|
+ //在测试方案中查找此设备类型的所有方案
|
|
|
+ var schs = schDtoList.FindAll(x => x.DeviceKindName == deviceKind);
|
|
|
+ //设备方案
|
|
|
+ foreach (var sch in schs)
|
|
|
+ {
|
|
|
+ allDeviceList.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,
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //所有新项目
|
|
|
+ List<string> projectNames = allDeviceList.Select(x => x.ProjectName).ToList();
|
|
|
+ foreach (var project in projectNames)
|
|
|
+ {
|
|
|
+ DeviceTestCardView deviceCard = new DeviceTestCardView();
|
|
|
+ deviceCard.txtName.Text = project;
|
|
|
+ deviceCard.txtProjectNo.Text = _iBasicProjectService.FindByProjectName(project)?.project_no;
|
|
|
+ deviceCard.txtPProjectLeader.Text = _iBasicProjectService.FindByProjectName(project)?.project_leader;
|
|
|
+ //赋值
|
|
|
+ ProjectePicList.Add(deviceCard);
|
|
|
+ }
|
|
|
+ //计算行数
|
|
|
+ if(projectNames.Count% 4==0)
|
|
|
+ {
|
|
|
+ RowsCount = projectNames.Count / 4;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ RowsCount = projectNames.Count / 4 + 1;
|
|
|
+ }
|
|
|
+ if(RowsCount<2)
|
|
|
+ {
|
|
|
+ RowsCount = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ #region 命令绑定
|
|
|
+ public DelegateCommand OnLoadCommand { set; get; }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 数据绑定
|
|
|
+ /// <summary>
|
|
|
+ /// 设备卡片
|
|
|
+ /// </summary>
|
|
|
+
|
|
|
+ private ObservableCollection<DeviceTestCardView> projectPicList=new ObservableCollection<DeviceTestCardView>();
|
|
|
+ public ObservableCollection<DeviceTestCardView> ProjectePicList
|
|
|
+ {
|
|
|
+ get { return projectPicList; }
|
|
|
+ set { projectPicList = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private int rowsCount =2;
|
|
|
+ public int RowsCount
|
|
|
+ {
|
|
|
+ get { return rowsCount; }
|
|
|
+ set { rowsCount = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+ }
|
|
|
+}
|