WinConfigAddOrEdit.xaml.cs
3.02 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
using HHECS.Bll;
using HHECS.Model.BllModel;
using HHECS.Model.Entities;
using HHECS.View.Win;
using System;
using System.Collections.Generic;
using System.Windows;
namespace HHECS.View.SystemInfo
{
/// <summary>
/// WinConfigAddOrEdit.xaml 的交互逻辑
/// </summary>
public partial class WinConfigAddOrEdit : BaseWindow
{
public int? Id { get; set; }
public Config CurrentConfig { get; set; } = new Config();
public WinConfigAddOrEdit(int? id)
{
this.Id = id;
this.Title = id == null ? "新增" : "编辑";
InitializeComponent();
Init();
this.GridMain.DataContext = CurrentConfig;
}
private void Init()
{
if (Id != null)
{
BllResult<List<Config>> result = AppSession.Bll.GetCommonModelByCondition<Config>($"where id = {Id}");
if (result.Success)
{
var temp = result.Data[0];
CurrentConfig.Id = temp.Id;
CurrentConfig.Code = temp.Code;
CurrentConfig.Name = temp.Name;
CurrentConfig.Value = temp.Value;
CurrentConfig.Remark = temp.Remark;
CurrentConfig.Created = temp.Created;
CurrentConfig.CreatedBy = temp.CreatedBy;
CurrentConfig.Updated = temp.Updated;
CurrentConfig.UpdatedBy = temp.UpdatedBy;
}
else
{
MessageBox.Show($"未查询到Id为{Id}的参数");
}
//编辑模式下,设置code不能更改
TxtConfigCode.IsReadOnly = true;
}
}
private void BtnSave_Click(object sender, RoutedEventArgs e)
{
if (CurrentConfig.Id == null)
{
//新增
CurrentConfig.Created = DateTime.Now;
CurrentConfig.CreatedBy = AppSession.User.UserCode;
BllResult<int?> result = AppSession.Bll.SaveCommonModel<Config>(CurrentConfig);
if (result.Success)
{
MessageBox.Show("新增成功");
TxtConfigCode.IsReadOnly = true;
CurrentConfig.Id = result.Data;
}
else
{
MessageBox.Show($"新增失败:{result.Msg}");
}
}
else
{
//更新
BllResult result = AppSession.Bll.UpdateCommonModel<Config>(CurrentConfig);
if (result.Success)
{
MessageBox.Show("更新成功");
}
else
{
MessageBox.Show($"更新失败:{result.Msg}");
}
}
}
private void BtnCancel_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}