EquipmentTypeAddOrEditVM.cs
2.68 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
using HHECS.Application.Enums;
using HHECS.Model.Entities;
using HHECS.WinCommon.ViewModel;
using Newtonsoft.Json;
using System;
using System.Windows;
using MessageBox = HandyControl.Controls.MessageBox;
namespace HHECS.WinClient.View.EquipmentInfo
{
public class EquipmentTypeAddOrEditVM : VMBase
{
public EquipmentType EquipmentType { get; set; }
public string Title { get; set; } = "test";
public bool Enable { get; set; } = true;
public Visibility Visibility { get; set; } = Visibility.Hidden;
public EquipmentTypeAddOrEditVM(int id)
{
if (id == 0)
{
this.Title = "新增";
EquipmentType = new EquipmentType();
Visibility = Visibility.Visible;
}
else
{
this.Title = "更新";
var bllResult = App.EquipmentService.GetEquipmentTypes(t => t.Id == id);
if (bllResult.Success && bllResult.Data.Count > 0)
{
EquipmentType = bllResult.Data[0];
}
else
{
MessageBox.Show("未查询到指定字典数据");
Enable = false;
}
}
}
public void Save()
{
if (EquipmentType.CreateTime == null)
{
EquipmentType.CreateTime = DateTime.Now;
EquipmentType.CreateBy = App.User.UserCode;
}
EquipmentType.UpdateTime = DateTime.Now;
EquipmentType.UpdateBy = App.User.UserCode;
var title = EquipmentType.Id == 0 ? Application.Enums.Title.EquipmentTypeAdd : Application.Enums.Title.EquipmentTypeEdit;
var a = new
{
Code = EquipmentType.Code,
Name = EquipmentType.Name,
};
var result = App.EquipmentService.SaveEquipmentType(EquipmentType);
if (result.Success)
{
App.LogService.LogOperation(title, ModuleConst.EquipmentType, $"设备类型保存成功.数据:{JsonConvert.SerializeObject(a)}", result.Code.ToString(), App.User.UserCode);
MessageBox.Show("保存成功");
}
else
{
App.LogService.LogOperation(title, ModuleConst.EquipmentType, $"设备类型保存失败.数据:{JsonConvert.SerializeObject(a)},详情:{result.Msg}", result.Code.ToString(), App.User.UserCode);
MessageBox.Error($"保存失败:{result.Msg}");
}
}
public void Clear()
{
EquipmentType = new EquipmentType();
}
}
}