hytos / DTI_PID / ID2PSN / Form / ValveGroupingSetting.cs @ 7d6d1693
이력 | 보기 | 이력해설 | 다운로드 (17.9 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.ComponentModel; |
4 |
using System.Data; |
5 |
using System.Drawing; |
6 |
using System.Linq; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
using System.Windows.Forms; |
10 |
using System.IO; |
11 |
using DevExpress.XtraEditors.Repository; |
12 |
using DevExpress.XtraGrid.Columns; |
13 |
using DevExpress.XtraGrid; |
14 |
using DevExpress.XtraGrid.Views.Grid; |
15 |
using DevExpress.Utils.StructuredStorage.Internal.Reader; |
16 |
using DevExpress.XtraTreeList; |
17 |
using DevExpress.XtraTreeList.Columns; |
18 |
using DevExpress.XtraTreeList.Nodes; |
19 |
using DevExpress.Utils.Extensions; |
20 |
using DevExpress.Utils; |
21 |
using DevExpress.Utils.Drawing; |
22 |
|
23 |
namespace ID2PSN |
24 |
{ |
25 |
public partial class ValveGroupingSetting : DevExpress.XtraBars.Ribbon.RibbonForm |
26 |
{ |
27 |
ID2Info ID2Info = ID2Info.GetInstance(); |
28 |
List<ValveGroupInfo> ValveGroupInfos = new List<ValveGroupInfo>(); |
29 |
ValveGroupInfo currentValveGroupInfo = null; |
30 |
private RepositoryItemComboBox repositoryAttributeItem = new RepositoryItemComboBox(); |
31 |
private RepositoryItemComboBox repositoryGroupType = new RepositoryItemComboBox(); |
32 |
private DataTable SymbolList = new DataTable(); |
33 |
|
34 |
public ValveGroupingSetting() |
35 |
{ |
36 |
InitializeComponent(); |
37 |
|
38 |
InitGridValveGroupItems(); |
39 |
|
40 |
|
41 |
|
42 |
// gridViewValveGroup.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gridViewSymbol_CellValueChanged); |
43 |
gridViewValveGroup.CellValueChanging += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gridViewSymbol_CellValueChanged); |
44 |
ValveGroupInfos = new List<ValveGroupInfo>(); |
45 |
currentValveGroupInfo = new ValveGroupInfo(); |
46 |
|
47 |
InitData(); |
48 |
} |
49 |
|
50 |
public void InitGridValveGroupItems() |
51 |
{ |
52 |
RepositoryItemButtonEdit btnRemove = new RepositoryItemButtonEdit(); |
53 |
btnRemove.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor; |
54 |
btnRemove.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(removeSymbolButton_Click); |
55 |
btnRemove.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph; |
56 |
btnRemove.Buttons[0].ImageOptions.Image = ID2PSN.Properties.Resources.cancel_16x16; |
57 |
|
58 |
gridValveGroup.RepositoryItems.Add(btnRemove); |
59 |
|
60 |
DataTable dtType = new DataTable(); |
61 |
// dtType.Columns.Add("OID"); |
62 |
dtType.Columns.Add("GroupType"); |
63 |
dtType.Columns.Add("TagIdentifier"); |
64 |
dtType.Columns.Add("AttributeName"); |
65 |
dtType.Columns.Add("SppidSymbolName"); |
66 |
dtType.Columns.Add(" "); |
67 |
gridValveGroup.DataSource = dtType; |
68 |
|
69 |
GridColumn gridColumn = gridViewValveGroup.Columns[0]; |
70 |
//gridColumn.Name = "OID"; |
71 |
//gridColumn.Caption = "OID"; |
72 |
//gridColumn.OptionsColumn.AllowEdit = false; |
73 |
//gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False; |
74 |
//gridColumn.Visible = true; |
75 |
//gridColumn.VisibleIndex = 0; |
76 |
|
77 |
|
78 |
repositoryGroupType = new RepositoryItemComboBox(); |
79 |
repositoryGroupType.Items.AddRange(new string[] { "Valves (CV, PRV..)", "Traps (ST, DT..)", "Reliefs (PSV..)", "Scope Break" }); |
80 |
repositoryGroupType.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; |
81 |
//repositoryGroupType.EditValueChanging += RepositoryGroupType_EditValueChanging; |
82 |
// repositoryGroupType.SelectedIndexChanged += RepositoryGroupType_SelectedIndexChanged; |
83 |
|
84 |
gridValveGroup.RepositoryItems.Add(repositoryGroupType); |
85 |
//gridColumn = gridViewValveGroup.Columns[0]; |
86 |
gridColumn.Name = "GroupType"; |
87 |
gridColumn.Caption = "Group Type"; |
88 |
gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False; |
89 |
gridColumn.VisibleIndex = 0; |
90 |
|
91 |
gridViewValveGroup.Columns["GroupType"].ColumnEdit = repositoryGroupType; |
92 |
|
93 |
//gridColumn.AppearanceHeader.BackColor = Color.Red; |
94 |
|
95 |
gridColumn = gridViewValveGroup.Columns[1]; |
96 |
gridColumn.Name = "TagIdentifier"; |
97 |
gridColumn.Caption = "Prefix"; |
98 |
gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False; |
99 |
gridColumn.VisibleIndex = 1; |
100 |
|
101 |
|
102 |
SymbolList = DB.SelectAllSymbolAttribute(); |
103 |
|
104 |
repositoryAttributeItem.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; |
105 |
repositoryAttributeItem.AppearanceDropDown.Font = Font; |
106 |
gridValveGroup.RepositoryItems.Add(repositoryAttributeItem); |
107 |
|
108 |
gridColumn = gridViewValveGroup.Columns[2]; |
109 |
gridColumn.Name = "AttributeName"; |
110 |
gridColumn.Caption = "ID2 Attribute Name"; |
111 |
gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False; |
112 |
gridColumn.VisibleIndex = 2; |
113 |
gridViewValveGroup.Columns["AttributeName"].ColumnEdit = repositoryAttributeItem; |
114 |
|
115 |
gridColumn = gridViewValveGroup.Columns[3]; |
116 |
gridColumn.Name = "SppidSymbolName"; |
117 |
gridColumn.Caption = "ID2 Symbol Name"; |
118 |
gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False; |
119 |
gridColumn.VisibleIndex = 3; |
120 |
|
121 |
RepositoryItemTreeListLookUpEdit treeListLookUpEdit = new RepositoryItemTreeListLookUpEdit(); |
122 |
gridValveGroup.RepositoryItems.Add(treeListLookUpEdit); |
123 |
SetSymbol(treeListLookUpEdit); |
124 |
|
125 |
// gridColumn.ColumnEdit = treeListLookUpEdit; |
126 |
gridViewValveGroup.Columns["SppidSymbolName"].ColumnEdit = treeListLookUpEdit; |
127 |
|
128 |
gridColumn = gridViewValveGroup.Columns[4]; |
129 |
gridColumn.Name = "Remove"; |
130 |
gridColumn.Caption = ""; |
131 |
gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False; |
132 |
gridColumn.VisibleIndex = 4; |
133 |
gridColumn.MaxWidth = 16; |
134 |
|
135 |
gridColumn.ColumnEdit = btnRemove; |
136 |
gridColumn.ShowButtonMode = DevExpress.XtraGrid.Views.Base.ShowButtonModeEnum.ShowAlways; |
137 |
gridViewValveGroup.CustomRowCellEditForEditing += gridView1_CustomRowCellEditForEditing; |
138 |
//gridViewKeyword.CustomDrawColumnHeader += GridViewKeyword_CustomDrawColumnHeader; |
139 |
|
140 |
|
141 |
} |
142 |
|
143 |
private void gridView1_CustomRowCellEditForEditing(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e) |
144 |
{ |
145 |
if (e.Column == (sender as GridView).Columns["AttributeName"]) |
146 |
{ |
147 |
DevExpress.XtraGrid.Views.Base.ColumnView columnView = sender as DevExpress.XtraGrid.Views.Base.ColumnView; |
148 |
DataTable dt = gridValveGroup.DataSource as DataTable; |
149 |
string SppidSymbolName = dt.Rows[columnView.FocusedRowHandle]["SppidSymbolName"].ToString(); |
150 |
|
151 |
if(string.IsNullOrEmpty(SppidSymbolName)) |
152 |
{ |
153 |
MessageBox.Show("Choose a symbol !", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
154 |
return; |
155 |
} |
156 |
|
157 |
repositoryAttributeItem.Items.Clear(); |
158 |
repositoryAttributeItem.Items.Add(""); |
159 |
foreach (DataRow dr in SymbolList.Rows) |
160 |
{ |
161 |
if(dr["SymbolName"].ToString().ToUpper().Equals(SppidSymbolName.ToUpper())) |
162 |
{ |
163 |
repositoryAttributeItem.Items.Add(dr["SymbolAttribute"].ToString()); |
164 |
} |
165 |
} |
166 |
} |
167 |
} |
168 |
|
169 |
private void GridViewKeyword_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e) |
170 |
{ |
171 |
if (e.Column == null || (e.Column.AppearanceHeader.BackColor == Color.Empty && !e.Column.AppearanceHeader.Options.UseBackColor)) |
172 |
|
173 |
return; |
174 |
|
175 |
Rectangle rect = e.Bounds; |
176 |
|
177 |
rect.Inflate(-1, -1); |
178 |
|
179 |
// Fill the title color. |
180 |
|
181 |
e.Graphics.FillRectangle(new SolidBrush(e.Column.AppearanceHeader.BackColor), rect); |
182 |
|
183 |
e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect); |
184 |
|
185 |
// Draw filter and sort buttons. |
186 |
|
187 |
foreach (DrawElementInfo info in e.Info.InnerElements) |
188 |
|
189 |
{ |
190 |
|
191 |
if (!info.Visible) continue; |
192 |
|
193 |
ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo); |
194 |
|
195 |
} |
196 |
|
197 |
e.Handled = true; |
198 |
} |
199 |
|
200 |
public void InitData() |
201 |
{ |
202 |
DataTable dt = DB.SelectValveGroupItemsSetting(); |
203 |
DataTable typeDT = gridValveGroup.DataSource as DataTable; |
204 |
foreach (DataRow row in dt.Rows) |
205 |
{ |
206 |
//int index = row["OID"]; |
207 |
string GroupType = row["GroupType"].ToString(); |
208 |
string TagIdentifier = row["TagIdentifier"].ToString(); |
209 |
string AttributeName = row["AttributeName"].ToString(); |
210 |
string SppidSymbolName = row["SppidSymbolName"].ToString(); |
211 |
|
212 |
typeDT.Rows.Add(GroupType, TagIdentifier, AttributeName, SppidSymbolName, null); |
213 |
} |
214 |
|
215 |
} |
216 |
|
217 |
private void removeSymbolButton_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) |
218 |
{ |
219 |
DataTable dt = gridValveGroup.DataSource as DataTable; |
220 |
DataRow rows = dt.Rows[gridViewValveGroup.FocusedRowHandle]; |
221 |
if (rows != null) |
222 |
dt.Rows.Remove(rows); |
223 |
} |
224 |
|
225 |
public void SetSymbol(RepositoryItemTreeListLookUpEdit treeListLookUpEdit) |
226 |
{ |
227 |
string imgPath = ID2Info.ImageDirPath; |
228 |
string[] filesPath = Directory.GetFiles(imgPath, "*.png", SearchOption.AllDirectories); |
229 |
|
230 |
DataTable dt = new DataTable(); |
231 |
dt.Columns.Add("ID", typeof(int)); |
232 |
dt.Columns.Add("ParentID", typeof(int)); |
233 |
dt.Columns.Add("Name", typeof(string)); |
234 |
dt.Columns.Add("Level", typeof(int)); |
235 |
dt.Columns.Add("Image", typeof(Image)); |
236 |
dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] }; |
237 |
|
238 |
treeListLookUpEdit.DataSource = dt; |
239 |
treeListLookUpEdit.ValueMember = "Name"; |
240 |
treeListLookUpEdit.DisplayMember = "Name"; |
241 |
treeListLookUpEdit.TreeList.Columns["Level"].Visible = false; |
242 |
treeListLookUpEdit.NullText = ""; |
243 |
|
244 |
treeListLookUpEdit.EditValueChanging += new DevExpress.XtraEditors.Controls.ChangingEventHandler(TreeList_BeforeCheckNode); |
245 |
|
246 |
treeListLookUpEdit.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup; |
247 |
|
248 |
bool bLine = true; |
249 |
List<string> level1Index = new List<string>(); |
250 |
foreach (var path in filesPath) |
251 |
{ |
252 |
if (Path.GetFileNameWithoutExtension(path).Contains("_display")) |
253 |
continue; |
254 |
|
255 |
string root = path.Remove(0, imgPath.Length); |
256 |
string[] split = root.Split(new string[] { @"\" }, StringSplitOptions.None); |
257 |
string level1 = split[0]; |
258 |
if (!level1Index.Contains(level1)) |
259 |
{ |
260 |
level1Index.Add(level1); |
261 |
dt.Rows.Add(level1Index.IndexOf(level1) + 1, 0, level1, 0); |
262 |
} |
263 |
|
264 |
int parentId = level1Index.IndexOf(level1) + 1; |
265 |
string level2 = split[1]; |
266 |
//combobox image size 변경 |
267 |
Image image = Image.FromFile(Path.Combine(imgPath, root)); |
268 |
Bitmap imgbitmap = new Bitmap(image); |
269 |
Image resizedImage = resizeImage(imgbitmap, new Size(200, 200)); |
270 |
|
271 |
dt.Rows.Add(filesPath.ToList().IndexOf(path) + 10000, parentId, Path.GetFileNameWithoutExtension(path), 1, resizedImage); |
272 |
|
273 |
if (Path.GetFileNameWithoutExtension(path) == "Connect To Process" && bLine) |
274 |
{ |
275 |
bLine = false; |
276 |
dt.Rows.Add(filesPath.ToList().IndexOf(path) + 20000, parentId, "Primary", 1, resizedImage); |
277 |
dt.Rows.Add(filesPath.ToList().IndexOf(path) + 30000, parentId, "Secondary", 1, resizedImage); |
278 |
} |
279 |
} |
280 |
} |
281 |
|
282 |
public static Image resizeImage(Image imgToResize, Size size) |
283 |
{ |
284 |
return (Image)(new Bitmap(imgToResize, size)); |
285 |
} |
286 |
|
287 |
private void btnAddSymbol_Click(object sender, EventArgs e) |
288 |
{ |
289 |
if (currentValveGroupInfo == null) |
290 |
{ |
291 |
currentValveGroupInfo = new ValveGroupInfo(); |
292 |
} |
293 |
|
294 |
DataTable dt = gridValveGroup.DataSource as DataTable; |
295 |
dt.Rows.Add(null, null, null, null, null); |
296 |
gridViewValveGroup.Columns["GroupType"].BestFit(); |
297 |
} |
298 |
|
299 |
|
300 |
|
301 |
public void ReNumbering(ValveGroupInfo valveGroupInfo) |
302 |
{ |
303 |
DataTable dt = gridValveGroup.DataSource as DataTable; |
304 |
valveGroupInfo.ValveGroupItems.Clear(); |
305 |
for (int i = 0; i < dt.Rows.Count; i++) |
306 |
{ |
307 |
DataRow row = dt.Rows[i]; |
308 |
// row["Index"] = i + 1; |
309 |
valveGroupInfo.ValveGroupItems.Add(new ValveGroupItem() |
310 |
{ |
311 |
OID = Guid.NewGuid().ToString(), |
312 |
GroupType = row["GroupType"].ToString(), |
313 |
TagIdentifier = row["TagIdentifier"].ToString(), |
314 |
AttributeName = row["AttributeName"].ToString(), |
315 |
SppidSymbolName = row["SppidSymbolName"].ToString() |
316 |
}); |
317 |
} |
318 |
} |
319 |
|
320 |
private void gridViewType_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e) |
321 |
{ |
322 |
ReNumbering(currentValveGroupInfo); |
323 |
} |
324 |
private void gridViewSymbol_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) |
325 |
{ |
326 |
//Valves (CV, PRV..)", "Traps (ST, DT..)", "Reliefs (PSV..) |
327 |
if (e.Column.FieldName == "GroupType") |
328 |
{ |
329 |
DevExpress.XtraGrid.Views.Base.ColumnView columnView = sender as DevExpress.XtraGrid.Views.Base.ColumnView; |
330 |
if (!string.IsNullOrEmpty(e.Value.ToString())) |
331 |
{ |
332 |
string selectItem = e.Value.ToString(); |
333 |
DataTable dt = gridValveGroup.DataSource as DataTable; |
334 |
if (selectItem.Contains("Valves")) |
335 |
{ |
336 |
gridViewValveGroup.SetRowCellValue(columnView.FocusedRowHandle, "TagIdentifier", "CV"); |
337 |
//dt.Rows[columnView.FocusedRowHandle]["TagIdentifier"] = "CV"; |
338 |
} |
339 |
else if (selectItem.Contains("Traps")) |
340 |
{ |
341 |
gridViewValveGroup.SetRowCellValue(columnView.FocusedRowHandle, "TagIdentifier", "ST"); |
342 |
// dt.Rows[columnView.FocusedRowHandle]["TagIdentifier"] = "ST"; |
343 |
} |
344 |
else if (selectItem.Contains("Reliefs")) |
345 |
{ |
346 |
gridViewValveGroup.SetRowCellValue(columnView.FocusedRowHandle, "TagIdentifier", "PSV"); |
347 |
// dt.Rows[columnView.FocusedRowHandle]["TagIdentifier"] = "PSV"; |
348 |
} |
349 |
else |
350 |
{ |
351 |
gridViewValveGroup.SetRowCellValue(columnView.FocusedRowHandle, "TagIdentifier", string.Empty); |
352 |
} |
353 |
} |
354 |
} |
355 |
|
356 |
//ReNumbering(currentValveGroupInfo); |
357 |
} |
358 |
private void TreeList_BeforeCheckNode(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e) |
359 |
{ |
360 |
DevExpress.XtraEditors.TreeListLookUpEdit treeListLookUpEdit = sender as DevExpress.XtraEditors.TreeListLookUpEdit; |
361 |
if (treeListLookUpEdit.Properties.TreeList.FocusedNode == null) |
362 |
return; |
363 |
|
364 |
if (treeListLookUpEdit.Properties.TreeList.FocusedNode.Level == 0) |
365 |
e.Cancel = true; |
366 |
|
367 |
|
368 |
} |
369 |
|
370 |
private void btnSave_Click(object sender, EventArgs e) |
371 |
{ |
372 |
if (currentValveGroupInfo == null) |
373 |
{ |
374 |
currentValveGroupInfo = new ValveGroupInfo(); |
375 |
} |
376 |
|
377 |
ReNumbering(currentValveGroupInfo); |
378 |
if(currentValveGroupInfo.ValveGroupItems.Find(x => x.TagIdentifier == string.Empty || x.AttributeName == string.Empty || x.SppidSymbolName == string.Empty) != null) |
379 |
{ |
380 |
IEnumerable<ValveGroupItem> lstvalue = currentValveGroupInfo.ValveGroupItems.Where(x => x.TagIdentifier == string.Empty || x.SppidSymbolName == string.Empty); |
381 |
//Scope Break |
382 |
foreach(ValveGroupItem vg in lstvalue) |
383 |
{ |
384 |
if(vg.GroupType != "Scope Break" ) |
385 |
{ |
386 |
MessageBox.Show("Please save after entering data.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
387 |
return; |
388 |
} |
389 |
else |
390 |
{ |
391 |
if(vg.SppidSymbolName == string.Empty) |
392 |
{ |
393 |
MessageBox.Show("Please save after entering data.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
394 |
return; |
395 |
} |
396 |
} |
397 |
} |
398 |
|
399 |
} |
400 |
|
401 |
if (DB.SaveValveGroupItemsSetting(currentValveGroupInfo.ValveGroupItems)) |
402 |
MessageBox.Show("Save was successful", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
403 |
else |
404 |
MessageBox.Show("Failed to save", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
405 |
} |
406 |
|
407 |
private void btnClose_Click(object sender, EventArgs e) |
408 |
{ |
409 |
DialogResult = DialogResult.Cancel; |
410 |
} |
411 |
} |
412 |
} |