MetroSetting.cs
12.8 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dal;
using Comm;
using MachineDll;
namespace App
{
public partial class MetroSetting : FrmBase
{
private float beforeWidth;//宽
private float beforeHeight;//长
private bool flag = false;//用来标识界面是否已经加载完成
private Dictionary<Control, Rectangle> controlsSize = new Dictionary<Control, Rectangle>();
private LoginManager _loginManager;
private readonly TheMachine theMachine;
public MetroSetting(LoginManager loginManager)
{
theMachine = GetMachineFromMe.GetMachine;
InitializeComponent();
this.showDataPanel.Location = new Point((this.Width - this.showDataPanel.Width) / 2, 2);
this.WindowState = FormWindowState.Maximized;
this.SetLanguage(this);
this._loginManager = loginManager;
init();
showSetting();
}
private void init()
{
this.Text = getMsg("systemSetting");
this.groupBox1.Text = getMsg("FrmMDIcms_PortsSettings");
this.lengthUnitPanel.Text = getMsg("FrmMDIrb_LengthUnit");
this.resultUnitPanel.Text = getMsg("FrmMDIrb_TestResultUnit");
this.tempatureUnitPanel.Text = getMsg("FrmMDIrb_TemplateUnit");
this.timeUnitPanel.Text = getMsg("FrmMDIrb_TimeUnit");
this.chooseLanguagePanel.Text = getMsg("FrmMDIrb_Language.InfoTitle");
this.chooseLanguageComboBox.Items.Clear();
this.chooseLanguageComboBox.Items.Add(getMsg("FrmMDItsmi_ch"));
this.chooseLanguageComboBox.Items.Add(getMsg("FrmMDItsmi_en"));
this.chooseLanguageComboBox.Items.Add(getMsg("FrmMDItsmi_jp"));
//this.portComboBox.Items.Clear();
//this.portComboBox.Items.Add(getMsg("FrmMDItsmi_Port1"));
//this.portComboBox.Items.Add(getMsg("FrmMDItsmi_Port2"));
//this.portComboBox.Items.Add(getMsg("FrmMDItsmi_Port3"));
//this.portComboBox.Items.Add(getMsg("FrmMDItsmi_Port4"));
//this.portComboBox.Items.Add(getMsg("FrmMDItsmi_Port5"));
//this.portComboBox.Items.Add(getMsg("FrmMDItsmi_Port6"));
this.cmUint.Text = getMsg("FrmMDItsmi_cm");
this.inUint.Text = getMsg("FrmMDItsmi_in");
this.squareCnUnit.Text = getMsg("FrmMDItsmi_EqNaClcm");
this.squareInUnit.Text = getMsg("FrmMDItsmi_EqNaClin");
this.celsiusUnit.Text = getMsg("FrmMDItsmi_C");
this.FahrenheitUnit.Text = getMsg("FrmMDItsmi_F");
this.minUnit.Text = getMsg("FrmMDItmsi_min");
this.secondUnit.Text = getMsg("FrmMDItsmi_s");
this.saveButton.Text = getMsg("FrmMDIrb_Save");
this.cancelButton.Text = getMsg("back");
}
private void MetroSetting_Load(object sender, EventArgs e)
{
//获取屏幕的长宽、得到一个比例,将里面控件的长宽乘以该比例
//窗体原本大小为620,417
float scaleHeight = (float)Screen.PrimaryScreen.WorkingArea.Height / 417;
float scaleWidth = (float)Screen.PrimaryScreen.WorkingArea.Width / 620;
foreach (Control ctl in settingPanel.Controls)
{
if (ctl is MetroFramework.Controls.MetroPanel)
{
ctl.Top = (int)(ctl.Top * scaleWidth);
ctl.Left = (int)(ctl.Left * scaleHeight);
ctl.Width = (int)(ctl.Width * scaleHeight);
ctl.Height = (int)(ctl.Height * scaleWidth);
}
}
}
private void showSetting()
{
//判断它的语言
switch(Fuction.m_Language)
{
case Const.LANGUAGE_CHINESE:
this.chooseLanguageComboBox.SelectedIndex = 0;break;
case Const.LANGUAGE_ENGLISH:
this.chooseLanguageComboBox.SelectedIndex = 1;break;
case Const.LANGUAGE_JAPANESE:
this.chooseLanguageComboBox.SelectedIndex = 2;break;
default: break;
}
//显示长度设置
if (Fuction.m_UserLengthUnit == Const.LENGTHUNIT_CM)
{
this.cmUint.Checked = true;
this.inUint.Checked = false;
}
else
{
this.cmUint.Checked = false;
this.inUint.Checked = true;
}
//显示结果设置
if (Fuction.m_UserResult == Const.RESULT_CM)
{
this.squareCnUnit.Checked = true;
this.squareInUnit.Checked = false;
}
else
{
this.squareCnUnit.Checked = false;
this.squareInUnit.Checked = true;
}
//显示温度设置
if (Fuction.m_UserTempUnit == Const.TEMPUNIT_C)
{
this.celsiusUnit.Checked = true;
this.FahrenheitUnit.Checked = false;
}
else
{
this.celsiusUnit.Checked = false;
this.FahrenheitUnit.Checked = true;
}
//显示时间设置
if (Fuction.m_UserTimeUnit == Const.TIMEUNIT_MIN)
{
this.minUnit.Checked = true;
this.secondUnit.Checked = false;
}
else
{
this.minUnit.Checked = false;
this.secondUnit.Checked = true;
}
this.portComboBox.SelectedItem = fuction.GetParameterByParaName(Const.PARA_PORT, "currency");
//显示端口
//switch (fuction.GetParameterByParaName(Const.PARA_PORT, "currency"))
//{
// case Const.PORT_1:
// this.portComboBox.SelectedIndex = 0;
// break;
// case Const.PORT_2:
// this.portComboBox.SelectedIndex = 1;
// break;
// case Const.PORT_3:
// this.portComboBox.SelectedIndex = 2;
// break;
// case Const.PORT_4:
// this.portComboBox.SelectedIndex = 3;
// break;
// case Const.PORT_5:
// this.portComboBox.SelectedIndex = 4;
// break;
// case Const.PORT_6:
// this.portComboBox.SelectedIndex = 5;
// break;
// default:
// break;
//}
}
/**
* 点击测试端口按钮
*/
private void testPortButton_Click(object sender, EventArgs e)
{
this.testPortButton.Enabled = false;
string port = theMachine.TestConnection();
if (port != "")
{
MessageBox.Show(port + getMsg("PortIsAvailable"));
}
else
{
MessageBox.Show(getMsg("ConfirmPort"));
}
this.testPortButton.Enabled = true;
}
private void testPortButton_MouseHover(object sender, EventArgs e)
{
ToolTip tt = new ToolTip();
tt.SetToolTip(this.testPortButton, getMsg("FrmMDIrb_TestPort"));
}
/**
* 保存所有设置
*/
private void saveButton_Click(object sender, EventArgs e)
{
//判断端口
string m_port = this.portComboBox.SelectedItem.ToString();
//switch (this.portComboBox.SelectedIndex)
//{
// case 0:
// m_port = Const.PORT_1;
// break;
// case 1:
// m_port = Const.PORT_2;
// break;
// case 2:
// m_port = Const.PORT_3;
// break;
// case 3:
// m_port = Const.PORT_4;
// break;
// case 4:
// m_port = Const.PORT_5;
// break;
// case 5:
// m_port = Const.PORT_6;
// break;
// default:
// break;
//}
//判断长度
if (this.cmUint.Checked)
{
Fuction.m_UserLengthUnit = Const.LENGTHUNIT_CM;
}
else
{
Fuction.m_UserLengthUnit = Const.LENGTHUNIT_IN;
}
//判断结果
if(this.squareCnUnit.Checked)
{
Fuction.m_UserResult = Const.RESULT_CM;
}
else
{
Fuction.m_UserResult = Const.RESULT_IN;
}
//判断温度
if(this.celsiusUnit.Checked)
{
Fuction.m_UserTempUnit = Const.TEMPUNIT_C;
}
else
{
Fuction.m_UserTempUnit = Const.TEMPUNIT_F;
}
//判断时间
if(this.minUnit.Checked)
{
Fuction.m_UserTimeUnit = Const.TIMEUNIT_MIN;
}
else
{
Fuction.m_UserTimeUnit = Const.TIMEUNIT_S;
}
fuction.CreateParaConfig("", "currency", Const.USER_TIMEUNIT, Fuction.m_UserTimeUnit);
//判断语言
switch (this.chooseLanguageComboBox.SelectedIndex)
{
case 0: Fuction.m_Language = Const.LANGUAGE_CHINESE; break;
case 1: Fuction.m_Language = Const.LANGUAGE_ENGLISH; break;
case 2: Fuction.m_Language = Const.LANGUAGE_JAPANESE; break;
default: break;
}
if (fuction.CreateParaConfig("", "currency", Const.PARA_PORT, m_port) &&
fuction.CreateParaConfig("", "currency", Const.USER_LENGTHUNIT, Fuction.m_UserLengthUnit) &&
fuction.CreateParaConfig("", "currency", Const.USER_RESULT, Fuction.m_UserResult) &&
fuction.CreateParaConfig("", "currency", Const.USER_TEMPUNIT, Fuction.m_UserTempUnit) &&
fuction.CreateParaConfig("", "currency", Const.USER_LANGUAGE, Fuction.m_Language))
{
ShowMessageBox.ShowInfo(Const.MESSAGEBOX_TITLE_NOTE, Const.SUCCESS_OPERATION);
}
else
{
ShowMessageBox.ShowError(Const.MESSAGEBOX_TITLE_NOTE, "", Const.ERROR_OPERATION);
}
this.Close();
}
/**
* 取消更改设置
*/
private void cancelButton_Click(object sender, EventArgs e)
{
this.Close();
//MetroMDI mm = new MetroMDI(_loginManager);
//mm.Show();
}
/**
* 长度单位:厘米是否选中
*/
private void cmUint_CheckedChanged(object sender, EventArgs e)
{
if (cmUint.Checked)
{
cmIsChecked();
}
}
/**
* 长度单位:英寸是否选中
*/
private void inUint_CheckedChanged(object sender, EventArgs e)
{
if (this.inUint.Checked)
{
inIsChecked();
}
}
/**
* 结果单位:厘米是否选中
*/
private void squareCnUnit_CheckedChanged(object sender, EventArgs e)
{
if (this.squareCnUnit.Checked)
{
cmIsChecked();
}
}
/**
* 结果单位:英寸是否选中
*/
private void squareInUnit_CheckedChanged(object sender, EventArgs e)
{
if (this.squareInUnit.Checked)
{
inIsChecked();
}
}
private void cmIsChecked()
{
this.cmUint.Checked = true;
this.squareCnUnit.Checked = true;
this.inUint.Checked = false;
this.squareInUnit.Checked = false;
}
private void inIsChecked()
{
this.cmUint.Checked = false;
this.squareCnUnit.Checked = false;
this.inUint.Checked = true;
this.squareInUnit.Checked = true;
}
private void MetroSetting_FormClosed(object sender, EventArgs e)
{
try
{
MetroMDI mm = new MetroMDI(_loginManager);
mm.ShowInTaskbar = true;
mm.Show();
}
catch (Exception ex)
{
LOGGER.Warn(ex.StackTrace);
}
}
}
}