EquipmentStatusRecordVM.cs
5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using AutoMapper;
using HHECS.Application.Enums;
using HHECS.Infrastructure.CommonHelper;
using HHECS.Infrastructure.Excel;
using HHECS.Model.Dtos;
using HHECS.Model.Entities;
using HHECS.Model.ExcelModels;
using HHECS.WinCommon.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Windows;
using MessageBox = HandyControl.Controls.MessageBox;
namespace HHECS.WinClient.View.EquipmentInfo
{
public class EquipmentStatusRecordVM : VMBase
{
public string EquipmentCode { get; set; }
public string EquipmentName { get; set; }
public string EquipmentStatus { get; set; }
public object RecordStatus { get; set; }
public DateTime? StartTime { get; set; } = DateTime.Now.Date.AddDays(-7);
public DateTime? EndTime { get; set; } = DateTime.Now.Date.AddDays(2).AddSeconds(-1);
public List<EquipmentStatusRecordDto> EquipmentStatusRecordDtos { get; set; }
public PageInfo PageInfo { get; set; } = new PageInfo();
public Dictionary<string, object> EquipmentStatuses { get; set; }
public Dictionary<string, object> RecordStatuses { get; set; }
public EquipmentStatusRecordVM()
{
var equipmentStatuses = EnumHelper.EnumListDicString<EquipmentStatusRecordStatus>("全部", "");
EquipmentStatuses = equipmentStatuses;
Dictionary<string, object> recordStatuses = new Dictionary<string, object>()
{
{ "全部", "" },
{ "未结束", false },
{ "已结束", true }
};
RecordStatuses = recordStatuses;
}
private Expression<Func<EquipmentStatusRecord, bool>> GetEquipmentStatusRecordExpression()
{
Expression<Func<EquipmentStatusRecord, bool>> filter = a => true;
if (!string.IsNullOrWhiteSpace(EquipmentCode))
{
filter = filter.And(a => a.EquipmentCode.Contains(EquipmentCode));
}
if (!string.IsNullOrWhiteSpace(EquipmentName))
{
filter = filter.And(a => a.EquipmentName.Contains(EquipmentName));
}
if (!string.IsNullOrWhiteSpace(EquipmentStatus))
{
filter = filter.And(a => a.EquipmentStatus == EquipmentStatus);
}
if (!string.IsNullOrWhiteSpace(RecordStatus.ToString()))
{
filter = filter.And(a => a.IsEnd == (bool)RecordStatus);
}
if (StartTime != null)
{
filter = filter.And(a => a.CreateTime >= StartTime);
}
if (EndTime != null)
{
filter = filter.And(a => a.CreateTime <= EndTime);
}
return filter;
}
public void Query()
{
Expression<Func<EquipmentStatusRecord, bool>> filter = GetEquipmentStatusRecordExpression();
var result = App.EquipmentService.GetEquipmentStatusRecordDtos(filter, PageInfo.PageIndex, PageInfo.PageSize, out long totalCount);
if (result.Success)
{
PageInfo.TotalCount = totalCount;
EquipmentStatusRecordDtos = result.Data;
}
else
{
MessageBox.Show($"查询失败:{result.Msg}");
}
}
public async void Export()
{
try
{
if (MessageBox.Show("是否确认导出?", "注意", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
{
return;
}
Expression<Func<EquipmentStatusRecord, bool>> filter = GetEquipmentStatusRecordExpression();
var result = App.EquipmentService.GetEquipmentStatusRecordDtos(filter);
if (result.Success)
{
var records = result.Data;
var config = new MapperConfiguration(cfg => cfg.CreateMap<EquipmentStatusRecordDto, EquipmentStatusRecordExcelModel>());
var mapper = config.CreateMapper();
List<EquipmentStatusRecordExcelModel> models = new List<EquipmentStatusRecordExcelModel>();
records.ForEach(t =>
{
var temp = mapper.Map<EquipmentStatusRecordExcelModel>(t);
models.Add(temp);
});
string TimeTxt = DateTime.Now.ToString("yyyy年MM月dd日HH点mm分ss秒");
await NPIOHelper.ExportDTtoExcelAsync<EquipmentStatusRecordExcelModel>(models, "设备状态记录", string.Format($"{App.ExportPath}设备状态记录{TimeTxt}.xlsx"), App.ExportPath);
MessageBox.Show($"设备状态记录导出成功");
}
else
{
MessageBox.Show($"导出失败:{result.Msg}");
}
}
catch (Exception ex)
{
MessageBox.Show($"导出异常:{ex.Message}");
}
}
}
}