hytos / DTI_PID / ID2PSN / Form / ValveGroupingSetting.cs @ 1621e1e9
이력 | 보기 | 이력해설 | 다운로드 (15.9 KB)
1 | 3610fd3f | LJIYEON | 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 | b267209c | LJIYEON | private DataTable SymbolList = new DataTable(); |
33 | 3610fd3f | LJIYEON | |
34 | public ValveGroupingSetting() |
||
35 | { |
||
36 | InitializeComponent(); |
||
37 | |||
38 | InitGridValveGroupItems(); |
||
39 | |||
40 | b267209c | LJIYEON | |
41 | 3610fd3f | LJIYEON | |
42 | b267209c | LJIYEON | // gridViewValveGroup.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gridViewSymbol_CellValueChanged); |
43 | gridViewValveGroup.CellValueChanging += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gridViewSymbol_CellValueChanged); |
||
44 | 3610fd3f | LJIYEON | 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..)" }); |
||
80 | repositoryGroupType.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; |
||
81 | b267209c | LJIYEON | //repositoryGroupType.EditValueChanging += RepositoryGroupType_EditValueChanging; |
82 | // repositoryGroupType.SelectedIndexChanged += RepositoryGroupType_SelectedIndexChanged; |
||
83 | |||
84 | 3610fd3f | LJIYEON | 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 | b267209c | LJIYEON | |
101 | |||
102 | SymbolList = DB.SelectAllSymbolAttribute(); |
||
103 | 3610fd3f | LJIYEON | |
104 | b267209c | LJIYEON | //선택 Symbol에 따라 Combobox값 변경해줘야함 (어려우니 그냥 넣는걸로..) |
105 | 3610fd3f | LJIYEON | repositoryAttributeItem.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; |
106 | repositoryAttributeItem.AppearanceDropDown.Font = Font; |
||
107 | repositoryAttributeItem.Items.Add("NoSelection"); |
||
108 | b267209c | LJIYEON | foreach(DataRow dr in SymbolList.Rows) |
109 | { |
||
110 | repositoryAttributeItem.Items.Add(dr["SymbolAttribute"].ToString()); |
||
111 | |||
112 | } |
||
113 | //repositoryAttributeItem.Items.Add(""); |
||
114 | 3610fd3f | LJIYEON | gridValveGroup.RepositoryItems.Add(repositoryAttributeItem); |
115 | |||
116 | gridColumn = gridViewValveGroup.Columns[2]; |
||
117 | gridColumn.Name = "AttributeName"; |
||
118 | gridColumn.Caption = "ID2 Attribute Name"; |
||
119 | gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False; |
||
120 | gridColumn.VisibleIndex = 2; |
||
121 | gridViewValveGroup.Columns["AttributeName"].ColumnEdit = repositoryAttributeItem; |
||
122 | |||
123 | gridColumn = gridViewValveGroup.Columns[3]; |
||
124 | gridColumn.Name = "SppidSymbolName"; |
||
125 | gridColumn.Caption = "ID2 Symbol Name"; |
||
126 | gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False; |
||
127 | gridColumn.VisibleIndex = 3; |
||
128 | |||
129 | RepositoryItemTreeListLookUpEdit treeListLookUpEdit = new RepositoryItemTreeListLookUpEdit(); |
||
130 | gridValveGroup.RepositoryItems.Add(treeListLookUpEdit); |
||
131 | SetSymbol(treeListLookUpEdit); |
||
132 | b267209c | LJIYEON | // gridColumn.ColumnEdit = treeListLookUpEdit; |
133 | gridViewValveGroup.Columns["SppidSymbolName"].ColumnEdit = treeListLookUpEdit; |
||
134 | 3610fd3f | LJIYEON | |
135 | gridColumn = gridViewValveGroup.Columns[4]; |
||
136 | gridColumn.Name = "Remove"; |
||
137 | gridColumn.Caption = ""; |
||
138 | gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False; |
||
139 | gridColumn.VisibleIndex = 4; |
||
140 | gridColumn.MaxWidth = 16; |
||
141 | |||
142 | gridColumn.ColumnEdit = btnRemove; |
||
143 | gridColumn.ShowButtonMode = DevExpress.XtraGrid.Views.Base.ShowButtonModeEnum.ShowAlways; |
||
144 | //gridViewKeyword.CustomDrawColumnHeader += GridViewKeyword_CustomDrawColumnHeader; |
||
145 | b267209c | LJIYEON | |
146 | } |
||
147 | 3610fd3f | LJIYEON | |
148 | private void GridViewKeyword_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e) |
||
149 | { |
||
150 | if (e.Column == null || (e.Column.AppearanceHeader.BackColor == Color.Empty && !e.Column.AppearanceHeader.Options.UseBackColor)) |
||
151 | |||
152 | return; |
||
153 | |||
154 | Rectangle rect = e.Bounds; |
||
155 | |||
156 | rect.Inflate(-1, -1); |
||
157 | |||
158 | // Fill the title color. |
||
159 | |||
160 | e.Graphics.FillRectangle(new SolidBrush(e.Column.AppearanceHeader.BackColor), rect); |
||
161 | |||
162 | e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect); |
||
163 | |||
164 | // Draw filter and sort buttons. |
||
165 | |||
166 | foreach (DrawElementInfo info in e.Info.InnerElements) |
||
167 | |||
168 | { |
||
169 | |||
170 | if (!info.Visible) continue; |
||
171 | |||
172 | ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo); |
||
173 | |||
174 | } |
||
175 | |||
176 | e.Handled = true; |
||
177 | } |
||
178 | |||
179 | public void InitData() |
||
180 | { |
||
181 | DataTable dt = DB.SelectValveGroupItemsSetting(); |
||
182 | DataTable typeDT = gridValveGroup.DataSource as DataTable; |
||
183 | foreach (DataRow row in dt.Rows) |
||
184 | { |
||
185 | //int index = row["OID"]; |
||
186 | string GroupType = row["GroupType"].ToString(); |
||
187 | string TagIdentifier = row["TagIdentifier"].ToString(); |
||
188 | string AttributeName = row["AttributeName"].ToString(); |
||
189 | string SppidSymbolName = row["SppidSymbolName"].ToString(); |
||
190 | |||
191 | typeDT.Rows.Add(GroupType, TagIdentifier, AttributeName, SppidSymbolName, null); |
||
192 | } |
||
193 | b267209c | LJIYEON | |
194 | 3610fd3f | LJIYEON | } |
195 | b267209c | LJIYEON | |
196 | 3610fd3f | LJIYEON | |
197 | private void removeSymbolButton_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) |
||
198 | { |
||
199 | b267209c | LJIYEON | // string value = gridViewValveGroup.GetFocusedRowCellValue("OID").ToString(); |
200 | 3610fd3f | LJIYEON | DataTable dt = gridValveGroup.DataSource as DataTable; |
201 | b267209c | LJIYEON | |
202 | //DevExpress.XtraGrid.Views.Base.ColumnView columnView = sender as DevExpress.XtraGrid.Views.Base.ColumnView; |
||
203 | |||
204 | |||
205 | // DataRow[] rows = dt. |
||
206 | //if (rows.Length.Equals(1)) |
||
207 | // dt.Rows.Remove(rows.First()); |
||
208 | //ReNumbering(currentValveGroupInfo); |
||
209 | 3610fd3f | LJIYEON | } |
210 | |||
211 | public void SetSymbol(RepositoryItemTreeListLookUpEdit treeListLookUpEdit) |
||
212 | { |
||
213 | string imgPath = ID2Info.ImageDirPath; |
||
214 | string[] filesPath = Directory.GetFiles(imgPath, "*.png", SearchOption.AllDirectories); |
||
215 | |||
216 | DataTable dt = new DataTable(); |
||
217 | dt.Columns.Add("ID", typeof(int)); |
||
218 | dt.Columns.Add("ParentID", typeof(int)); |
||
219 | dt.Columns.Add("Name", typeof(string)); |
||
220 | dt.Columns.Add("Level", typeof(int)); |
||
221 | dt.Columns.Add("Image", typeof(Image)); |
||
222 | dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] }; |
||
223 | |||
224 | treeListLookUpEdit.DataSource = dt; |
||
225 | treeListLookUpEdit.ValueMember = "Name"; |
||
226 | treeListLookUpEdit.DisplayMember = "Name"; |
||
227 | treeListLookUpEdit.TreeList.Columns["Level"].Visible = false; |
||
228 | treeListLookUpEdit.NullText = ""; |
||
229 | |||
230 | b267209c | LJIYEON | treeListLookUpEdit.EditValueChanging += new DevExpress.XtraEditors.Controls.ChangingEventHandler(TreeList_BeforeCheckNode); |
231 | |||
232 | 3610fd3f | LJIYEON | treeListLookUpEdit.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup; |
233 | |||
234 | bool bLine = true; |
||
235 | List<string> level1Index = new List<string>(); |
||
236 | foreach (var path in filesPath) |
||
237 | { |
||
238 | if (Path.GetFileNameWithoutExtension(path).Contains("_display")) |
||
239 | continue; |
||
240 | |||
241 | string root = path.Remove(0, imgPath.Length); |
||
242 | string[] split = root.Split(new string[] { @"\" }, StringSplitOptions.None); |
||
243 | string level1 = split[0]; |
||
244 | if (!level1Index.Contains(level1)) |
||
245 | { |
||
246 | level1Index.Add(level1); |
||
247 | dt.Rows.Add(level1Index.IndexOf(level1) + 1, 0, level1, 0); |
||
248 | } |
||
249 | |||
250 | int parentId = level1Index.IndexOf(level1) + 1; |
||
251 | string level2 = split[1]; |
||
252 | //combobox image size 변경 |
||
253 | Image image = Image.FromFile(Path.Combine(imgPath, root)); |
||
254 | Bitmap imgbitmap = new Bitmap(image); |
||
255 | Image resizedImage = resizeImage(imgbitmap, new Size(200, 200)); |
||
256 | |||
257 | dt.Rows.Add(filesPath.ToList().IndexOf(path) + 10000, parentId, Path.GetFileNameWithoutExtension(path), 1, resizedImage); |
||
258 | |||
259 | if (Path.GetFileNameWithoutExtension(path) == "Connect To Process" && bLine) |
||
260 | { |
||
261 | bLine = false; |
||
262 | dt.Rows.Add(filesPath.ToList().IndexOf(path) + 20000, parentId, "Primary", 1, resizedImage); |
||
263 | dt.Rows.Add(filesPath.ToList().IndexOf(path) + 30000, parentId, "Secondary", 1, resizedImage); |
||
264 | } |
||
265 | } |
||
266 | } |
||
267 | b267209c | LJIYEON | |
268 | 3610fd3f | LJIYEON | public static Image resizeImage(Image imgToResize, Size size) |
269 | { |
||
270 | return (Image)(new Bitmap(imgToResize, size)); |
||
271 | } |
||
272 | |||
273 | private void btnAddSymbol_Click(object sender, EventArgs e) |
||
274 | { |
||
275 | if (currentValveGroupInfo == null) |
||
276 | { |
||
277 | currentValveGroupInfo = new ValveGroupInfo(); |
||
278 | } |
||
279 | |||
280 | DataTable dt = gridValveGroup.DataSource as DataTable; |
||
281 | dt.Rows.Add(null, null, null, null, null); |
||
282 | gridViewValveGroup.Columns["GroupType"].BestFit(); |
||
283 | } |
||
284 | |||
285 | |||
286 | |||
287 | public void ReNumbering(ValveGroupInfo valveGroupInfo) |
||
288 | { |
||
289 | DataTable dt = gridValveGroup.DataSource as DataTable; |
||
290 | valveGroupInfo.ValveGroupItems.Clear(); |
||
291 | for (int i = 0; i < dt.Rows.Count; i++) |
||
292 | { |
||
293 | DataRow row = dt.Rows[i]; |
||
294 | // row["Index"] = i + 1; |
||
295 | valveGroupInfo.ValveGroupItems.Add(new ValveGroupItem() |
||
296 | { |
||
297 | OID = Guid.NewGuid().ToString(), |
||
298 | GroupType = row["GroupType"].ToString(), |
||
299 | TagIdentifier = row["TagIdentifier"].ToString(), |
||
300 | AttributeName = row["AttributeName"].ToString(), |
||
301 | SppidSymbolName = row["SppidSymbolName"].ToString() |
||
302 | }); |
||
303 | } |
||
304 | } |
||
305 | |||
306 | private void gridViewType_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e) |
||
307 | { |
||
308 | ReNumbering(currentValveGroupInfo); |
||
309 | } |
||
310 | private void gridViewSymbol_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) |
||
311 | { |
||
312 | b267209c | LJIYEON | //Valves (CV, PRV..)", "Traps (ST, DT..)", "Reliefs (PSV..) |
313 | if (e.Column.FieldName == "GroupType") |
||
314 | { |
||
315 | DevExpress.XtraGrid.Views.Base.ColumnView columnView = sender as DevExpress.XtraGrid.Views.Base.ColumnView; |
||
316 | if (!string.IsNullOrEmpty(e.Value.ToString())) |
||
317 | { |
||
318 | string selectItem = e.Value.ToString(); |
||
319 | DataTable dt = gridValveGroup.DataSource as DataTable; |
||
320 | if (selectItem.Contains("Valves")) |
||
321 | { |
||
322 | dt.Rows[columnView.FocusedRowHandle]["TagIdentifier"] = "CV"; |
||
323 | } |
||
324 | else if (selectItem.Contains("Traps")) |
||
325 | { |
||
326 | dt.Rows[columnView.FocusedRowHandle]["TagIdentifier"] = "ST"; |
||
327 | } |
||
328 | else if (selectItem.Contains("Reliefs")) |
||
329 | { |
||
330 | dt.Rows[columnView.FocusedRowHandle]["TagIdentifier"] = "PSV"; |
||
331 | } |
||
332 | } |
||
333 | } |
||
334 | |||
335 | //ReNumbering(currentValveGroupInfo); |
||
336 | 3610fd3f | LJIYEON | } |
337 | private void TreeList_BeforeCheckNode(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e) |
||
338 | { |
||
339 | DevExpress.XtraEditors.TreeListLookUpEdit treeListLookUpEdit = sender as DevExpress.XtraEditors.TreeListLookUpEdit; |
||
340 | if (treeListLookUpEdit.Properties.TreeList.FocusedNode == null) |
||
341 | return; |
||
342 | |||
343 | if (treeListLookUpEdit.Properties.TreeList.FocusedNode.Level == 0) |
||
344 | e.Cancel = true; |
||
345 | |||
346 | b267209c | LJIYEON | |
347 | 3610fd3f | LJIYEON | } |
348 | b267209c | LJIYEON | |
349 | 3610fd3f | LJIYEON | private void btnSave_Click(object sender, EventArgs e) |
350 | { |
||
351 | if (currentValveGroupInfo == null) |
||
352 | { |
||
353 | currentValveGroupInfo = new ValveGroupInfo(); |
||
354 | } |
||
355 | |||
356 | ReNumbering(currentValveGroupInfo); |
||
357 | if(currentValveGroupInfo.ValveGroupItems.Find(x => x.TagIdentifier == string.Empty || x.AttributeName == string.Empty || x.SppidSymbolName == string.Empty) != null) |
||
358 | { |
||
359 | MessageBox.Show("Please save after entering data.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
360 | return; |
||
361 | } |
||
362 | |||
363 | if (DB.SaveValveGroupItemsSetting(currentValveGroupInfo.ValveGroupItems)) |
||
364 | MessageBox.Show("Save was successful", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
365 | else |
||
366 | MessageBox.Show("Failed to save", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
367 | } |
||
368 | |||
369 | private void btnClose_Click(object sender, EventArgs e) |
||
370 | { |
||
371 | DialogResult = DialogResult.Cancel; |
||
372 | } |
||
373 | } |
||
374 | } |