-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestForm1.cs
More file actions
193 lines (161 loc) · 6.14 KB
/
Copy pathTestForm1.cs
File metadata and controls
193 lines (161 loc) · 6.14 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
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 BaseCommon;
namespace ModbusSample
{
public partial class TestForm1 : Form
{
public Vendor V = null;
public List<ChannelInfo> Channels_A = new List<ChannelInfo>();
List<ChannelInfo> Channels_B = new List<ChannelInfo>();
public TestForm1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (V == null) return;
int index = -1;
if (!Program.GetIndex("A", ref index))
{
return;
}
V.OutputGoods(index, (flag) =>
{
MessageBox.Show("出货A:{0},货道:{1}".ExtFormat(flag ? "成功" : "失败", ""));
});
}
private void button2_Click(object sender, EventArgs e)
{
if (V == null) return;
int index = -1;
if (!Program.GetIndex("B", ref index))
{
return;
}
V.OutputGoods(index, (flag) =>
{
MessageBox.Show("出货B:{0},货道:{1}".ExtFormat(flag ? "成功" : "失败", ""));
});
}
private void button3_Click(object sender, EventArgs e)
{
VEMConfigHelper config = VEMConfigHelper.Create();
config.SetProductAChannels(this.Channels_A);
config.SetProductBChannels(this.Channels_B);
config.ACurrent = (int)this.numericUpDown_A.Value;
config.BCurrent = (int)this.numericUpDown_B.Value;
config.Port = port.Text;
config.Save();
MessageBox.Show("保存成功!");
}
private void TestForm1_Load(object sender, EventArgs e)
{
VEMConfigHelper config = VEMConfigHelper.Create();
this.Channels_A = config.GetProductAChannels();
this.Channels_B = config.GetProductBChannels();
this.dataGridView_A.AutoGenerateColumns = false;
this.dataGridView_B.AutoGenerateColumns = false;
this.dataGridView_A.DataSource = this.Channels_A;
this.dataGridView_B.DataSource = this.Channels_B;
this.numericUpDown_A.Value = config.ACurrent;
this.numericUpDown_B.Value = config.BCurrent;
this.port.Text = config.Port;
}
private void toolStripMenuItem1_Click_Add(object sender, EventArgs e)
{
try
{
var viewer = this.contextMenuStrip1.SourceControl as DataGridView;
if (viewer != null)
{
var name = viewer.Name;
if (name == "dataGridView_A")
{
this.dataGridView_A.DataSource = null;
this.Channels_A.Add(new ChannelInfo());
this.dataGridView_A.DataSource = this.Channels_A;
}
else
{
this.dataGridView_B.DataSource = null;
this.Channels_B.Add(new ChannelInfo());
this.dataGridView_B.DataSource = this.Channels_B;
}
}
}
catch (Exception ex)
{
Log.log.Error(ex.Message, ex);
}
}
private void toolStripMenuItem2_Click_Remove(object sender, EventArgs e)
{
try
{
var viewer = this.contextMenuStrip1.SourceControl as DataGridView;
var item = viewer.SelectedRows;
var name = viewer.Name;
if (viewer != null && item != null && item.Count > 0)
{
ChannelInfo info = item[0].DataBoundItem as ChannelInfo;
if (info != null)
{
if (name == "dataGridView_A")
{
if (this.Channels_A.Contains(info))
{
this.dataGridView_A.DataSource = null;
this.Channels_A.Remove(info);
this.dataGridView_A.DataSource = this.Channels_A;
}
}
else
{
if (this.Channels_B.Contains(info))
{
//this.dataGridView_B.Rows.RemoveAt(item[0].Index);
this.dataGridView_B.DataSource = null;
this.Channels_B.Remove(info);
//this.dataGridView_B.AllowUserToDeleteRows = true;
//(item[0].DataBoundItem as DataRowView).Delete();
// ResetView(this.dataGridView_B);
this.dataGridView_B.DataSource = this.Channels_B;
}
}
}
}
}
catch (Exception ex)
{
Log.log.Error(ex.Message, ex);
}
}
private void ResetView(DataGridView dview)
{
//
// Column_ID
//
this.Column_ID.DataPropertyName = "ID";
this.Column_ID.HeaderText = "编号(从0开始)";
this.Column_ID.Name = "Column_ID";
this.Column_ID.Width = 200;
dview.Columns.Add(this.Column_ID.Clone() as DataGridViewTextBoxColumn);
//
// Column_Count
//
this.Column_Count.DataPropertyName = "Count";
this.Column_Count.HeaderText = "数量";
this.Column_Count.Name = "Column_Count";
this.Column_Count.Width = 200;
dview.Columns.Add(this.Column_Count.Clone() as DataGridViewTextBoxColumn);
dview.AutoGenerateColumns = false;
}
}
}