ConfigVM.cs
3.18 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
using HandyControl.Controls;
using HHECS.Application.Enums;
using HHECS.BllModel;
using HHECS.Model.Entities;
using HHECS.WinCommon.ViewModel;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using MessageBox = HandyControl.Controls.MessageBox;
namespace HHECS.WinClient.View.SystemInfo
{
public class ConfigVM : VMBase
{
public string Code { get; set; }
public string Name { get; set; }
public List<Config> Configs { get; set; }
public PageInfo PageInfo { get; set; } = new PageInfo();
public void Query()
{
Expression<Func<Config, bool>> filter = t => true;
if (!string.IsNullOrWhiteSpace(Code))
{
filter = filter.And(t => t.Code.Contains(Code));
}
if (!string.IsNullOrWhiteSpace(Name))
{
filter = filter.And(t => t.Name.Contains(Name));
}
var result = App.SystemService.GetConfigs(filter, PageInfo.PageIndex, PageInfo.PageSize, out long totalCount);
if (result.Success)
{
PageInfo.TotalCount = totalCount;
Configs = result.Data;
}
else
{
MessageBox.Show($"查询失败:{result.Msg}");
}
}
internal void Delete(List<Config> configs)
{
if (configs == null || configs.Count == 0)
{
MessageBox.Show("未选中数据");
return;
}
if (MessageBox.Show("是否确认删除?", "警告", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
{
return;
}
BllResult bllResult = App.SystemService.DeleteConfigs(configs);
if (bllResult.Success)
{
App.LogService.LogOperation(Title.ConfigDelete, ModuleConst.Config, $"配置删除成功.数据:{JsonConvert.SerializeObject(configs.Select(t => new { Id = t.Id, Code = t.Code, Name = t.Name, Value = t.Value }))}", bllResult.Code.ToString(), App.User.UserCode);
MessageBox.Show("删除成功");
}
else
{
App.LogService.LogOperation(Title.ConfigDelete, ModuleConst.Config, $"配置删除失败.数据:{JsonConvert.SerializeObject(configs.Select(t => new { Id = t.Id, Code = t.Code, Name = t.Name, Value = t.Value }))},详情:{bllResult.Msg}", bllResult.Code.ToString(), App.User.UserCode);
MessageBox.Error($"删除失败:{bllResult.Msg}");
}
Query();
}
internal void Edit(Config config)
{
if (config == null)
{
MessageBox.Show("请选中数据");
return;
}
WinConfigAddOrEdit win = new WinConfigAddOrEdit(config.Id);
win.ShowDialog();
Query();
}
internal void New()
{
WinConfigAddOrEdit win = new WinConfigAddOrEdit(0);
win.ShowDialog();
Query();
}
}
}