DictAddOrEditVM.cs
2.34 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
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.Text;
using System.Threading.Tasks;
using MessageBox = HandyControl.Controls.MessageBox;
namespace HHECS.WinClient.View.SystemInfo
{
public class DictAddOrEditVM : VMBase
{
public Dict Dict { get; set; }
public string Title { get; set; } = "test";
public bool Enable { get; set; } = true;
public DictAddOrEditVM(int id)
{
if (id == 0)
{
this.Title = "新增";
Dict = new Dict();
}
else
{
this.Title = "更新";
var bllResult = App.SystemService.GetDicts(t => t.Id == id);
if (bllResult.Success && bllResult.Data.Count > 0)
{
Dict = bllResult.Data[0];
}
else
{
MessageBox.Show("未查询到指定字典数据");
Enable = false;
}
}
}
public void Save()
{
if (Dict.Created == null)
{
Dict.Created = DateTime.Now;
Dict.CreatedBy = App.User.UserCode;
}
Dict.Updated = DateTime.Now;
Dict.UpdatedBy = App.User.UserCode;
var title = Dict.Id == 0 ? Application.Enums.Title.DictAdd : Application.Enums.Title.DictEdit;
var a = new
{
Code = Dict.Code,
Name = Dict.Name,
};
var result = App.SystemService.SaveDict(Dict);
if (result.Success)
{
App.LogService.LogOperation(title, ModuleConst.Dict, $"字典保存成功.数据:{JsonConvert.SerializeObject(a)}", result.Code.ToString(), App.User.UserCode);
MessageBox.Show("保存成功");
}
else
{
App.LogService.LogOperation(title, ModuleConst.Dict, $"字典保存失败.数据:{JsonConvert.SerializeObject(a)},详情:{result.Msg}", result.Code.ToString(), App.User.UserCode);
MessageBox.Error($"保存失败:{result.Msg}");
}
}
}
}