WinParameter.xaml.cs
5.54 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
135
136
137
138
139
140
141
142
143
144
145
146
147
using RCS.Dal;
using RCS.Model.Entity;
using RCS.WinClient.Common;
using System.Windows;
using System.Windows.Input;
namespace RCS.WinClient.Views.Pages
{
/// <summary>
/// WinTest.xaml 的交互逻辑
/// </summary>
public partial class WinParameter : Window
{
public WinParameter()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Init.DownKeyValue();
DGrid_KeyValue.ItemsSource = App.Config_KeyValueDic.Values.ToList();
}
private void BtnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
//重写Closing方法
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
this.Hide();
e.Cancel = true;
}
private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void Btn_OK_Click(object sender, RoutedEventArgs e)
{
try
{
foreach (var keyValue in App.Config_KeyValueDic.Values)
{
if (!float.TryParse(keyValue.Value, out float doubleValue))
{
ComnMethod.Message($"参数变量【{keyValue}】的值必须是 数值类型 !");
return;
}
keyValue.DoubleValue = doubleValue;
}
BaseDal<Config_KeyValue> _configDb = new BaseDal<Config_KeyValue>();
//除了流水号不更新,其他都更新
var keyValues = App.Config_KeyValueDic.Values.Where(t => t.KeyVariable != "Tno").ToArray();
var updateResult = _configDb.Update(keyValues);
if (updateResult.IsSuccess)
{
ComnMethod.Message("保存参数成功!");
}
else
{
ComnMethod.Message($"保存参数失败!原因:{updateResult.Message}");
}
//if (!float.TryParse(Tbox_FullCharge.Text, out float fullCharge))
//{
// ComnMethod.Message("满电量必须是 数值类型 !");
// return;
//}
//if (!float.TryParse(Tbox_SafeCharge.Text, out float safeCharge))
//{
// ComnMethod.Message("安全电量必须是 数值类型 !");
// return;
//}
//if (!float.TryParse(Tbox_DangerCharge.Text, out float dangerCharge))
//{
// ComnMethod.Message("危险电量必须是 数值类型 !");
// return;
//}
//if (!float.TryParse(Tbox_MinCharges.Text, out float minCharges))
//{
// ComnMethod.Message("最少充电量必须是 数值类型 !");
// return;
//}
//if (!float.TryParse(Tbox_MinTime.Text, out float minTime))
//{
// ComnMethod.Message("最少充电时间必须是 数值类型 !");
// return;
//}
//App.FullCharge = fullCharge;
//App.SafeCharge = safeCharge;
//App.DangerCharge = dangerCharge;
//App.MinCharges = minCharges;
//App.MinTime = minTime;
//var updateresult1 = _configDb.Update(it => it.KeyVariable == "Cfull", it => new Config_KeyValue()
//{
// Value = Tbox_FullCharge.Text,
//});
//var updateresult2 = _configDb.Update(it => it.KeyVariable == "Savety", it => new Config_KeyValue()
//{
// Value = Tbox_SafeCharge.Text,
//});
//var updateresult3 = _configDb.Update(it => it.KeyVariable == "Danger", it => new Config_KeyValue()
//{
// Value = Tbox_DangerCharge.Text,
//});
//var updateresult4 = _configDb.Update(it => it.KeyVariable == "MinCharges", it => new Config_KeyValue()
//{
// Value = Tbox_MinCharges.Text,
//});
//var updateresult5 = _configDb.Update(it => it.KeyVariable == "MinTime", it => new Config_KeyValue()
//{
// Value = Tbox_MinTime.Text,
//});
//if (updateresult1.Success && updateresult2.Success && updateresult3.Success && updateresult4.Success && updateresult5.Success)
//{
// ComnMethod.Message("保存参数成功!");
//}
//else
//{
// var msg = "保存参数失败!原因:";
// if (!updateresult1.Success) msg += " " + updateresult1.Msg;
// if (!updateresult2.Success) msg += " " + updateresult2.Msg;
// if (!updateresult3.Success) msg += " " + updateresult3.Msg;
// if (!updateresult4.Success) msg += " " + updateresult4.Msg;
// if (!updateresult5.Success) msg += " " + updateresult5.Msg;
// ComnMethod.Message(msg);
//}
}
catch (Exception Ex)
{
ComnMethod.Message(Ex.ToString());
}
}
}
}