FrmBoardList.cs
10.1 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
using log4net;
using URSoldering.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace URSoldering.Client
{
public partial class FrmBoardList : FrmBase
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public FrmBoardList()
{
InitializeComponent();
}
private void FrmBoard_Load(object sender, EventArgs e)
{
LoadCom();
}
private void LoadCom()
{
List<BoardInfo> newList = (from m in BoardManager.boardList orderby m.PartNumber ascending, m.boardName ascending select m).ToList<BoardInfo>();
cmbBoardList.DataSource = null;
cmbBoardList.DataSource = newList;
cmbBoardList.DisplayMember = "boardName";
cmbBoardList.ValueMember = "boardId";
if (newList.Count > 0)
{
cmbBoardList.SelectedIndex = 0;
}
this.listPoint.Columns.Clear();
ColumnHeader chName = new ColumnHeader();
chName.Text = "焊点名称"; //设置列标题
chName.Width = 150; //设置列宽度
chName.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
this.listPoint.Columns.Add(chName); //将列头添加到ListView控件。
//ColumnHeader chValue = new ColumnHeader();
//chValue.Text = "预热温度"; //设置列标题
//chValue.Width = 80; //设置列宽度
//chValue.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
//this.listPoint.Columns.Add(chValue); //将列头添加到ListView控件。
ColumnHeader chStatus = new ColumnHeader();
chStatus.Text = "焊接温度"; //设置列标题
chStatus.Width = 80; //设置列宽度
chStatus.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
this.listPoint.Columns.Add(chStatus); //将列头添加到ListView控件。
ColumnHeader preSendwire = new ColumnHeader();
preSendwire.Text = "初始送丝"; //设置列标题
preSendwire.Width = 80; //设置列宽度
preSendwire.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
this.listPoint.Columns.Add(preSendwire); //将列头添加到ListView控件。
ColumnHeader sendWire = new ColumnHeader();
sendWire.Text = "送丝量"; //设置列标题
sendWire.Width = 60; //设置列宽度
sendWire.TextAlign = HorizontalAlignment.Left; //设置列的对齐方式
this.listPoint.Columns.Add(sendWire); //将列头添加到ListView控件。
}
private void btnSave_Click(object sender, EventArgs e)
{
if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
FrmBoardInfo frm = new FrmBoardInfo(board);
this.Visible = false;
frm.ShowDialog();
this.Visible = true;
LoadCom();
preId = -1;
}
else
{
MessageBox.Show("请选择程序!");
}
}
private int pointHight = 14;
private void btnLook_Click(object sender, EventArgs e)
{
LoadBoard();
this.panel1.Refresh();
}
private void LoadBoard()
{
if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
txtBoardName.Text = board.boardName;
txtLength.Text = board.boardLength.ToString();
txtWidth.Text = board.boardWidth.ToString();
txtPointCount.Text = board.pointList.Count.ToString();
txtMianji.Text = (board.boardLength * board.boardWidth).ToString();
txtCode.Text = board.WareCode;
loadPictureBoxSize(board);
LoadPoint(board);
}
}
int preId = -1;
private void LoadPoint(BoardInfo board)
{
if (preId >= 0 && preId.Equals(board.boardId))
{
return;
}
preId = board.boardId;
this.listPoint.Items.Clear();
int i = 0;
foreach (WeldPointInfo point in board.pointList)
{
ListViewItem lvi = new ListViewItem();
lvi.ImageIndex = i;
lvi.Text = point.pointName;
lvi.SubItems.Add(point.weldTemperature.ToString());
lvi.SubItems.Add((point.startSendWireSpeed * point.startSendWireTime).ToString());
lvi.SubItems.Add((point.sendWireTime * point.sendWireSpeed).ToString());
this.listPoint.Items.Add(lvi);
i++;
}
}
private void btnNew_Click(object sender, EventArgs e)
{
FrmBoardInfo info = new FrmBoardInfo(null);
this.Visible = false;
info.ShowDialog();
this.Visible = true;
LoadCom();
preId = -1;
}
private void cmbBoardList_SelectedIndexChanged(object sender, EventArgs e)
{
LoadBoard();
}
private void btnDel_Click(object sender, EventArgs e)
{
if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
if (MessageBox.Show("确认要删除程序【" + board.boardName + "】吗?", "删除确认",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question).Equals(DialogResult.OK))
{
BoardManager.Delete(board);
MessageBox.Show("删除程序【" + board.boardName + "】成功!");
LoadCom();
preId = -1;
}
}
else
{
MessageBox.Show("请选择程序!");
}
}
private void loadPictureBoxSize(BoardInfo board)
{
picBoard.SizeMode = PictureBoxSizeMode.StretchImage;
List<WeldPointInfo> pointList = board.pointList;
int width = board.boardWidth;
int height = board.boardLength;
int xishu = 10;
picBoard.Width = width * xishu;
picBoard.Height = height * xishu;
if (picBoard.Width > panBoard.Width)
{
picBoard.Height = height * xishu * panBoard.Width / (width * xishu);
picBoard.Width = panBoard.Width;
}
if (picBoard.Height > panBoard.Height)
{
picBoard.Width = width * xishu * panBoard.Height / (height * xishu);
picBoard.Height = panBoard.Height;
}
int locationX = picBoard.Location.X;
int locationY = picBoard.Location.Y;
locationX = (panBoard.Size.Width - picBoard.Width) / 2;
picBoard.Location = new Point(locationX, locationY);
//显示点
Graphics g = (picBoard).CreateGraphics();
picBoard.Image = board.GetImage();
picBoard.Refresh();
//int orgType = board.orgType;
//double orgX = board.getImageOrgX();
//double orgY = board.getImageOrgY();
//Graphics grfx = picBoard.CreateGraphics();
//float preX = 0;
//float preY = 0;
//int index = 0;
//foreach (WeldPointInfo weld in pointList)
//{
//float x = (float)Math.Abs(weld.PositionX - orgX) * picBoard.Width / width - pointHight / 2;
//float y = (float)Math.Abs(weld.PositionY - orgY) * picBoard.Width / width - pointHight / 2;
//g.FillEllipse(Brushes.Red, x - pointHight / 2, y - pointHight / 2, pointHight, pointHight);
//if (index > 0)
//{
// Pen p = new Pen(Color.Red, 2);
// //中间点
// float xCenter = (preX + x) / 2;
// float yCenter = (preY + y) / 2;
// System.Drawing.Drawing2D.AdjustableArrowCap lineCap = new System.Drawing.Drawing2D.AdjustableArrowCap(6, 8, true);
// Pen RedPen = new Pen(Color.Red, 2);
// RedPen.CustomEndCap = lineCap;
// grfx.DrawLine(RedPen, preX, preY, xCenter, yCenter);
// grfx.DrawLine(p, preX, preY, x, y);
//}
//preX = x;
//preY = y;
//index++;
//g.FillEllipse(Brushes.Red, x, y, pointHight, pointHight);
//}
//g.Dispose();
}
private void FrmBoardList_Shown(object sender, EventArgs e)
{
LoadBoard();
}
private void btnBack_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnCopy_Click(object sender, EventArgs e)
{
if (cmbBoardList.Text != "" && cmbBoardList.SelectedIndex >= 0)
{
BoardInfo board = (BoardInfo)cmbBoardList.SelectedItem;
DialogResult result = MessageBox.Show("复制后的程序料号不变,是否确定复制?", "确定", MessageBoxButtons.YesNo);
if (result.Equals(DialogResult.Yes))
{
FrmBoardCopy copy = new FrmBoardCopy(board);
DialogResult saveResult = copy.ShowDialog();
if (saveResult.Equals(DialogResult.OK))
{
LoadCom();
}
}
}
else
{
MessageBox.Show("请选择程序!");
}
}
}
}