UC_LedConfig.cs
6.4 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
using OnlineStore;
using DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TheMachine.UC
{
using crc = OnlineStore.CodeResourceControl;
public partial class UC_LedConfig : UserControl
{
public UC_LedConfig()
{
InitializeComponent();
this.Tag = "not";
crc.LanguageChangeEvent += Crc_LanguageChangeEvent;
}
private void Crc_LanguageChangeEvent(object sender, EventArgs e)
{
if (Config == null)
return;
LoadLedList();
}
private DeviceConfig _Config;
public DeviceConfig Config
{
get { return _Config; }
set
{
if (value == null)
return;
_Config = value;
LoadLedList();
}
}
void LoadLedList()
{
//if (!this.Created)
// return;
if (this.InvokeRequired)
{
this.Invoke((EventHandler)delegate
{
try
{
LoadLedList();
}
catch (Exception ee)
{
MessageBox.Show("LoadLedList:" + ee.ToString());
}
});
return;
}
tableLayoutPanel1.SuspendLayout();
tableLayoutPanel1.Controls.Clear();
this.tableLayoutPanel1.RowStyles.Clear();
var statenames = Enum.GetNames(typeof(MachineLedStateE));
Label label_s = new Label()
{
Size = new Size(200, 34),
Text = crc.GetString("Res0212","状态,优先级从大到小"),
TextAlign = ContentAlignment.MiddleLeft
};
tableLayoutPanel1.Controls.Add(label_s, 0, 0);
Label label_g = new Label()
{
Size = new Size(120, 34),
Text = crc.GetString("Res0213","绿灯"),
TextAlign = ContentAlignment.MiddleCenter
};
tableLayoutPanel1.Controls.Add(label_g, 1, 0);
Label label_y = new Label()
{
Size = new Size(120, 34),
Text = crc.GetString("Res0214","黄灯"),
TextAlign = ContentAlignment.MiddleCenter
};
tableLayoutPanel1.Controls.Add(label_y, 2, 0);
Label label_r = new Label()
{
Size = new Size(120, 34),
Text = crc.GetString("Res0215","红灯"),
TextAlign = ContentAlignment.MiddleCenter
};
tableLayoutPanel1.Controls.Add(label_r, 3, 0);
int r = 1;
var ledkeys = RobotManage.mainMachine.MachineLedStateName.Keys;
foreach (var key in ledkeys)
{
//if (r == 3)
// return;
Label button = new Label();
button.Anchor = (AnchorStyles)(AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom);
button.Name = key.ToString();
button.Text = crc.GetString("ledstate_"+ key, RobotManage.mainMachine.MachineLedStateName[key]);
button.AutoSize = false;
button.Size = new System.Drawing.Size(200, 34);
button.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
tableLayoutPanel1.Controls.Add(button, 0, r);
int c = 1;
foreach (var led in Led.LedColors.Keys)
{
List<lightitem> lightitems = new List<lightitem>();
lightitems.Add(new lightitem(crc.GetString("Res0216","无动作"), LedState.none));
lightitems.Add(new lightitem(crc.GetString("Res0217","关"), LedState.off));
lightitems.Add(new lightitem(crc.GetString("Res0218","开"), LedState.on));
lightitems.Add(new lightitem(crc.GetString("Res0219","闪烁"), LedState.blink));
var selit = lightitems.FindIndex(x => x.value == RobotManage.mainMachine.MachineLedState[key][led]);
ComboBox comboBox = new ComboBox();
comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox.FormattingEnabled = true;
//comboBox.Items.AddRange(new object[] { "none", "on", "off", "blink" });
comboBox.Items.AddRange(lightitems.ToArray());
comboBox.Name = key.ToString();
comboBox.Tag = led;
//comboBox.SelectedItem = selit;
comboBox.SelectedIndex= selit;
tableLayoutPanel1.Controls.Add(comboBox, c, r);
c++;
}
r++;
}
tableLayoutPanel1.ResumeLayout(true);
}
class lightitem {
public string Text;
public LedState value;
public lightitem(string t, LedState v) {
Text = t;
value = v;
}
public override string ToString()
{
return Text;
}
}
private void button_reset_Click(object sender, EventArgs e)
{
RobotManage.mainMachine.DefaultLedCfg();
LoadLedList();
}
private void button_save_Click(object sender, EventArgs e)
{
for (int i = 0; i < tableLayoutPanel1.Controls.Count; i++) {
var cc = tableLayoutPanel1.Controls[i];
if (!(cc is ComboBox))
continue;
Enum.TryParse<MachineLedStateE>(cc.Name, out MachineLedStateE key);
LedColor led = (LedColor)cc.Tag;
RobotManage.mainMachine.MachineLedState[key][led] = ((lightitem)(cc as ComboBox).SelectedItem).value;
}
if (RobotManage.mainMachine.SaveLedCfg())
MessageBox.Show(crc.GetString("Res0220","保存成功!"));
else
MessageBox.Show(crc.GetString("Res0221","保存失败!"));
}
}
}