hytos / DTI_PID / SPPIDConverter_AutoModeling / MainControl.cs @ ccb722a4
이력 | 보기 | 이력해설 | 다운로드 (25.2 KB)
1 | f2151e28 | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.ComponentModel; |
||
4 | using System.Drawing; |
||
5 | using System.Data; |
||
6 | using System.Linq; |
||
7 | using System.Text; |
||
8 | using System.Threading.Tasks; |
||
9 | using System.Windows.Forms; |
||
10 | 2cae7d1f | gaqhf | using Microsoft.Win32; |
11 | using Telerik.WinControls.UI; |
||
12 | using System.IO; |
||
13 | using System.Threading; |
||
14 | using SPPID.Modeling; |
||
15 | using SPPID.Model; |
||
16 | using SPPID.Utill; |
||
17 | 3823b4ab | gaqhf | using SPPID.DB; |
18 | e9718eec | gaqhf | using Microsoft.VisualBasic; |
19 | 3823b4ab | gaqhf | using Newtonsoft.Json; |
20 | f2151e28 | gaqhf | |
21 | namespace SPPIDConverter_AutoModeling |
||
22 | { |
||
23 | public partial class MainControl : UserControl |
||
24 | { |
||
25 | 3823b4ab | gaqhf | Thread autoModelingThread; |
26 | |||
27 | 2cae7d1f | gaqhf | private Dictionary<string, string> symbolMapping = new Dictionary<string, string>(); |
28 | private Dictionary<string, string> attributeMapping = new Dictionary<string, string>(); |
||
29 | 3823b4ab | gaqhf | private DataTable dUnit = new DataTable(); |
30 | private string TemplatePath; |
||
31 | private string SymbolPath; |
||
32 | 2cae7d1f | gaqhf | |
33 | f2151e28 | gaqhf | public MainControl() |
34 | { |
||
35 | InitializeComponent(); |
||
36 | 3823b4ab | gaqhf | |
37 | if (SetPath()) |
||
38 | { |
||
39 | if (SPPIDUtill.LoadDB()) |
||
40 | InitDBInformation(); |
||
41 | else |
||
42 | MessageBox.Show("Please Check DB Setting", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
43 | InitGridViewDB(); |
||
44 | } |
||
45 | else |
||
46 | 2cae7d1f | gaqhf | { |
47 | |||
48 | } |
||
49 | } |
||
50 | |||
51 | 3823b4ab | gaqhf | private bool SetPath() |
52 | 2cae7d1f | gaqhf | { |
53 | try |
||
54 | { |
||
55 | RegistryKey key = Registry.LocalMachine; |
||
56 | RegistryKey software = key.OpenSubKey("SOFTWARE"); |
||
57 | RegistryKey DOFTECH = software.OpenSubKey("DOFTECH"); |
||
58 | if (DOFTECH != null) |
||
59 | { |
||
60 | RegistryKey ID2 = DOFTECH.OpenSubKey("ID2"); |
||
61 | if (ID2 != null) |
||
62 | { |
||
63 | SPPIDUtill.defaultPath = ID2.GetValue("Path").ToString(); |
||
64 | Log.logPath = SPPIDUtill.defaultPath + @"Converter\SPPID Converter.log"; |
||
65 | SPPIDUtill.mappingFilePath = SPPIDUtill.defaultPath + @"Converter\mapping.xml"; |
||
66 | 3823b4ab | gaqhf | SPPIDUtill.dbFilePath = SPPIDUtill.defaultPath + @"Converter\DB.config"; |
67 | |||
68 | return true; |
||
69 | 2cae7d1f | gaqhf | } |
70 | } |
||
71 | } |
||
72 | catch (Exception ex) |
||
73 | { |
||
74 | 3823b4ab | gaqhf | |
75 | } |
||
76 | |||
77 | return false; |
||
78 | } |
||
79 | |||
80 | #region Init Data Setting |
||
81 | |||
82 | public void InitDBInformation() |
||
83 | { |
||
84 | // Unit DataTable |
||
85 | dUnit = DB.GetUnitTree(); |
||
86 | |||
87 | // Template List |
||
88 | TemplatePath = DB.GetPlantPID_T_OPTIONSETTING_Value("PID Template Path"); |
||
89 | GridViewComboBoxColumn colTemplate = gridViewDrawingList.Columns["colTemplate"] as GridViewComboBoxColumn; |
||
90 | colTemplate.DataSource = Directory.GetFiles(TemplatePath, "*.pid").ToList().Select(filePath => Path.GetFileName(filePath)); |
||
91 | |||
92 | // Load Mapping |
||
93 | SPPIDUtill.LoadMapping(symbolMapping, attributeMapping); |
||
94 | |||
95 | // Symbol Path |
||
96 | SymbolPath = DB.GetPlantPID_T_OPTIONSETTING_Value("Catalog Explorer root path"); |
||
97 | GridViewComboBoxColumn colSPPIDName = gridViewItemMapping.Columns["colSPPIDName"] as GridViewComboBoxColumn; |
||
98 | colSPPIDName.DataSource = Directory.GetFiles(SymbolPath, "*.sym", SearchOption.AllDirectories).ToList().Select(symbol => symbol.Remove(0, SymbolPath.Length)); |
||
99 | |||
100 | // Load Mapping |
||
101 | SPPIDUtill.LoadMapping(symbolMapping, attributeMapping); |
||
102 | gridViewItemMapping.BeginUpdate(); |
||
103 | foreach (var item in symbolMapping) |
||
104 | gridViewItemMapping.Rows.Add(new object[] {item.Key,item.Value, "View" }); |
||
105 | gridViewItemMapping.BestFitColumns(); |
||
106 | gridViewItemMapping.EndUpdate(); |
||
107 | |||
108 | |||
109 | // Attribute |
||
110 | GridViewComboBoxColumn colSPPIDAttribute = gridViewAttribute.Columns["colSPPIDAttribute"] as GridViewComboBoxColumn; |
||
111 | colSPPIDAttribute.DataSource = DB.GetSPPIDAttribute(); |
||
112 | |||
113 | // Load Attribute |
||
114 | gridViewAttribute.BeginUpdate(); |
||
115 | foreach (var item in attributeMapping) |
||
116 | gridViewAttribute.Rows.Add(new object[] { item.Key, item.Value, "View" }); |
||
117 | gridViewAttribute.BestFitColumns(); |
||
118 | gridViewAttribute.EndUpdate(); |
||
119 | } |
||
120 | |||
121 | #endregion |
||
122 | |||
123 | |||
124 | #region Setting Page |
||
125 | private const string _DBType = "DB Type"; |
||
126 | private const string _ServiceName = "Service Name"; |
||
127 | private const string _SiteName = "Site Name"; |
||
128 | private const string _ServerIP = "Server IP"; |
||
129 | private const string _Port = "Port"; |
||
130 | private const string _DBUser = "DB User"; |
||
131 | private const string _DBPassword = "DB Password"; |
||
132 | |||
133 | private void InitGridViewDB() |
||
134 | { |
||
135 | DBInformation dbInfo = DBInformation.GetInstance(); |
||
136 | |||
137 | gridViewDB.Rows.Add(new object[] { _DBType , dbInfo.DBType}); |
||
138 | gridViewDB.Rows.Add(new object[] { _ServiceName, dbInfo.Service }); |
||
139 | gridViewDB.Rows.Add(new object[] { _SiteName, dbInfo.Site}); |
||
140 | gridViewDB.Rows.Add(new object[] { _ServerIP, dbInfo.ServerIP}); |
||
141 | gridViewDB.Rows.Add(new object[] { _Port, dbInfo.Port}); |
||
142 | gridViewDB.Rows.Add(new object[] { _DBUser, dbInfo.DBUser}); |
||
143 | gridViewDB.Rows.Add(new object[] { _DBPassword, dbInfo.DBPassword}); |
||
144 | gridViewDB.BestFitColumns(); |
||
145 | |||
146 | this.gridViewDB.RowFormatting += new Telerik.WinControls.UI.RowFormattingEventHandler(this.gridViewDB_RowFormatting); |
||
147 | this.gridViewDB.CellBeginEdit += new Telerik.WinControls.UI.GridViewCellCancelEventHandler(this.gridViewDB_CellBeginEdit); |
||
148 | this.gridViewDB.CellValueChanged += new Telerik.WinControls.UI.GridViewCellEventHandler(this.gridViewDB_CellValueChanged); |
||
149 | } |
||
150 | |||
151 | private void gridViewDB_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) |
||
152 | { |
||
153 | string sKey = (string)e.Row.Cells["colKey"].Value; |
||
154 | if (sKey == _DBType || |
||
155 | sKey == _ServiceName || |
||
156 | sKey == _SiteName) |
||
157 | { |
||
158 | e.Cancel = true; |
||
159 | } |
||
160 | else |
||
161 | { |
||
162 | |||
163 | } |
||
164 | } |
||
165 | 2cae7d1f | gaqhf | |
166 | 3823b4ab | gaqhf | private void gridViewDB_RowFormatting(object sender, RowFormattingEventArgs e) |
167 | { |
||
168 | string sKey = (string)e.RowElement.RowInfo.Cells["colKey"].Value; |
||
169 | if (sKey == _DBType || |
||
170 | sKey == _ServiceName || |
||
171 | sKey == _SiteName) |
||
172 | { |
||
173 | e.RowElement.DrawFill = true; |
||
174 | e.RowElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid; |
||
175 | e.RowElement.BackColor = Color.Aquamarine; |
||
176 | } |
||
177 | } |
||
178 | |||
179 | private void gridViewDB_CellValueChanged(object sender, GridViewCellEventArgs e) |
||
180 | { |
||
181 | btnSave.Enabled = false; |
||
182 | } |
||
183 | |||
184 | private void btnLoadiniFile_Click(object sender, EventArgs e) |
||
185 | { |
||
186 | try |
||
187 | { |
||
188 | OpenFileDialog dialog = new OpenFileDialog(); |
||
189 | dialog.Multiselect = false; |
||
190 | dialog.Filter = "ini File(*.ini)|*.ini"; |
||
191 | if (dialog.ShowDialog() == DialogResult.OK) |
||
192 | { |
||
193 | string sDBTYPE = string.Empty; |
||
194 | string sSERVICENAME = string.Empty; |
||
195 | string sUID = string.Empty; |
||
196 | |||
197 | string[] texts = File.ReadAllLines(dialog.FileName); |
||
198 | |||
199 | bool find = false; |
||
200 | for (int i = 0; i < texts.Length; i++) |
||
201 | { |
||
202 | string text = texts[i]; |
||
203 | |||
204 | if (text.Trim() == "[SITESCHEMA]") |
||
205 | find = true; |
||
206 | |||
207 | if (find) |
||
208 | { |
||
209 | if (text.StartsWith("DBTYPE=") && string.IsNullOrEmpty(sDBTYPE)) |
||
210 | sDBTYPE = text.Remove(0, "DBTYPE=".Length); |
||
211 | else if (text.StartsWith("DBSERVER=") && string.IsNullOrEmpty(sSERVICENAME)) |
||
212 | sSERVICENAME = text.Remove(0, "DBSERVER=".Length); |
||
213 | else if (text.StartsWith("UID=") && string.IsNullOrEmpty(sUID)) |
||
214 | sUID = text.Remove(0, "UID=".Length); |
||
215 | } |
||
216 | } |
||
217 | |||
218 | if (string.IsNullOrEmpty(sDBTYPE) || string.IsNullOrEmpty(sSERVICENAME) || string.IsNullOrEmpty(sUID)) |
||
219 | MessageBox.Show("Unavailable ini file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
220 | else |
||
221 | { |
||
222 | foreach (GridViewRowInfo rowInfo in gridViewDB.Rows) |
||
223 | { |
||
224 | string sKey = (string)rowInfo.Cells["colKey"].Value; |
||
225 | if (sKey == _DBType) |
||
226 | rowInfo.Cells["colValue"].Value = sDBTYPE; |
||
227 | else if (sKey == _ServiceName) |
||
228 | rowInfo.Cells["colValue"].Value = sSERVICENAME; |
||
229 | else if (sKey == _SiteName) |
||
230 | rowInfo.Cells["colValue"].Value = sUID; |
||
231 | } |
||
232 | } |
||
233 | } |
||
234 | } |
||
235 | catch (Exception ex) |
||
236 | { |
||
237 | MessageBox.Show("Unavailable ini file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
238 | } |
||
239 | } |
||
240 | |||
241 | private void btnSPPIDDBTest_Click(object sender, EventArgs e) |
||
242 | { |
||
243 | DBInformation dbInfo = DBInformation.GetInstance(); |
||
244 | dbInfo.Status = false; |
||
245 | foreach (GridViewRowInfo rowInfo in gridViewDB.Rows) |
||
246 | { |
||
247 | string sKey = (string)rowInfo.Cells["colKey"].Value; |
||
248 | string sValue = (string)rowInfo.Cells["colValue"].Value; |
||
249 | |||
250 | switch (sKey) |
||
251 | { |
||
252 | case _DBType: |
||
253 | dbInfo.DBType = sValue; |
||
254 | break; |
||
255 | case _ServiceName: |
||
256 | dbInfo.Service = sValue; |
||
257 | break; |
||
258 | case _SiteName: |
||
259 | dbInfo.Site = sValue; |
||
260 | break; |
||
261 | case _ServerIP: |
||
262 | dbInfo.ServerIP = sValue; |
||
263 | break; |
||
264 | case _Port: |
||
265 | dbInfo.Port = sValue; |
||
266 | break; |
||
267 | case _DBUser: |
||
268 | dbInfo.DBUser = sValue; |
||
269 | break; |
||
270 | case _DBPassword: |
||
271 | dbInfo.DBPassword = sValue; |
||
272 | break; |
||
273 | default: |
||
274 | break; |
||
275 | } |
||
276 | } |
||
277 | |||
278 | if (DB.CheckAndSetDBInformation()) |
||
279 | { |
||
280 | btnSave.Enabled = true; |
||
281 | MessageBox.Show("Test Connection Success!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
282 | } |
||
283 | else |
||
284 | { |
||
285 | MessageBox.Show("Check DB Information!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
286 | } |
||
287 | } |
||
288 | |||
289 | private void gridViewDB_CellFormatting(object sender, CellFormattingEventArgs e) |
||
290 | { |
||
291 | if (e.Column.Name == "colValue" && (string)e.Row.Cells["colKey"].Value == _DBPassword) |
||
292 | { |
||
293 | object value = e.CellElement.RowInfo.Cells["colValue"].Value; |
||
294 | string text = string.Empty; |
||
295 | if (value != null) |
||
296 | { |
||
297 | int passwordLen = Convert.ToString(value).Length + 1; |
||
298 | text = string.Join("*", new string[passwordLen]); |
||
299 | } |
||
300 | |||
301 | e.CellElement.Text = text; |
||
302 | } |
||
303 | } |
||
304 | |||
305 | private void btnSave_Click(object sender, EventArgs e) |
||
306 | { |
||
307 | DBInformation dbInfo = DBInformation.GetInstance(); |
||
308 | if (dbInfo != null) |
||
309 | { |
||
310 | dbInfo.Status = true; |
||
311 | string sJson = JsonConvert.SerializeObject(dbInfo); |
||
312 | SPPIDUtill.SaveDB(sJson); |
||
313 | |||
314 | MessageBox.Show("Save Success!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
315 | } |
||
316 | else |
||
317 | { |
||
318 | |||
319 | } |
||
320 | } |
||
321 | |||
322 | #endregion |
||
323 | |||
324 | #region Convert Page |
||
325 | const string _Ready = "Ready"; |
||
326 | const string _LoadFail = "Can't Load"; |
||
327 | const string _NeedMapping = "Need Mapping"; |
||
328 | const string _NeedUnit = "Select Unit"; |
||
329 | const string _NeedTemplate = "Select Template"; |
||
330 | b33b0d0a | gaqhf | const string _Error = "Error"; |
331 | const string _EndProcess = "End Process"; |
||
332 | const string _Processing = "Processing"; |
||
333 | 3823b4ab | gaqhf | |
334 | private void btnLoadFiles_Click(object sender, EventArgs e) |
||
335 | { |
||
336 | OpenFileDialog dia = new OpenFileDialog(); |
||
337 | dia.Multiselect = true; |
||
338 | dia.Filter = "Xml Files(*.xml)|*.xml"; |
||
339 | if (dia.ShowDialog() == DialogResult.OK) |
||
340 | { |
||
341 | gridViewDrawingList.CellValueChanged -= new GridViewCellEventHandler(this.gridViewDrawingList_CellValueChanged); |
||
342 | foreach (string fileName in dia.FileNames) |
||
343 | { |
||
344 | try |
||
345 | { |
||
346 | GridViewDataRowInfo row = new GridViewDataRowInfo(gridViewDrawingList.MasterView); |
||
347 | Document document = Document.Load(fileName, symbolMapping, attributeMapping); |
||
348 | row.Tag = document; |
||
349 | |||
350 | if (document == null) |
||
351 | { |
||
352 | row.Cells["colDrawingFileName"].Value = fileName; |
||
353 | row.Cells["colStatus"].Value = _LoadFail; |
||
354 | row.Cells["colDrawingFullName"].Value = fileName; |
||
355 | } |
||
356 | else |
||
357 | { |
||
358 | row.Cells["colCheckBox"].Value = false; |
||
359 | row.Cells["colDrawingFileName"].Value = document.DWGNAME; |
||
360 | row.Cells["colDrawingNumber"].Value = document.DWGNAME; |
||
361 | row.Cells["colDrawingName"].Value = document.DWGNAME; |
||
362 | row.Cells["colDrawingFullName"].Value = fileName; |
||
363 | } |
||
364 | |||
365 | gridViewDrawingList.Rows.Add(row); |
||
366 | CheckValidateDrawing(row); |
||
367 | } |
||
368 | catch (Exception ex) |
||
369 | { |
||
370 | |||
371 | } |
||
372 | } |
||
373 | gridViewDrawingList.CellValueChanged += new GridViewCellEventHandler(this.gridViewDrawingList_CellValueChanged); |
||
374 | 2cae7d1f | gaqhf | } |
375 | f2151e28 | gaqhf | } |
376 | e9718eec | gaqhf | |
377 | private void btnRun_Click(object sender, EventArgs e) |
||
378 | { |
||
379 | try |
||
380 | { |
||
381 | b33b0d0a | gaqhf | ProgressForm.stop = false; |
382 | 3823b4ab | gaqhf | foreach (GridViewRowInfo rowInfo in gridViewDrawingList.Rows) |
383 | ec0ff05a | gaqhf | { |
384 | 3823b4ab | gaqhf | try |
385 | { |
||
386 | bool bChecked = (bool)rowInfo.Cells["colCheckBox"].Value; |
||
387 | string sStatus = rowInfo.Cells["colStatus"].Value.ToString(); |
||
388 | ec0ff05a | gaqhf | |
389 | b33b0d0a | gaqhf | if (bChecked && sStatus == _Ready && !ProgressForm.stop) |
390 | 3823b4ab | gaqhf | { |
391 | b33b0d0a | gaqhf | rowInfo.Cells["colStatus"].Value = _Processing; |
392 | RefreshGridViewDrawingList(); |
||
393 | |||
394 | 3823b4ab | gaqhf | string sUnit = rowInfo.Cells["colUnit"].Value.ToString(); |
395 | string sTemplate = TemplatePath + @"\" + rowInfo.Cells["colTemplate"].Value.ToString(); |
||
396 | string sDrawingNumber = rowInfo.Cells["colDrawingNumber"].Value.ToString(); |
||
397 | string sDrawingName = rowInfo.Cells["colDrawingName"].Value.ToString(); |
||
398 | ec0ff05a | gaqhf | |
399 | 3823b4ab | gaqhf | // |
400 | b33b0d0a | gaqhf | dynamic application = Interaction.GetObject("", "PIDAutomation.Application"); |
401 | 3823b4ab | gaqhf | dynamic newDrawing = application.Drawings.Add(sUnit, sTemplate, sDrawingNumber, sDrawingName); |
402 | application.ActiveWindow.Fit(); |
||
403 | b33b0d0a | gaqhf | Thread.Sleep(100); |
404 | 3823b4ab | gaqhf | application.ActiveWindow.Zoom = 2000; |
405 | b33b0d0a | gaqhf | Thread.Sleep(100); |
406 | 3823b4ab | gaqhf | // |
407 | ec0ff05a | gaqhf | |
408 | 3823b4ab | gaqhf | Document document = rowInfo.Tag as Document; |
409 | b33b0d0a | gaqhf | autoModelingThread = new Thread(Func => |
410 | { |
||
411 | try |
||
412 | { |
||
413 | Thread.Sleep(500); |
||
414 | ProgressForm.UpdateDocument(document.DWGNAME); |
||
415 | AutoModeling auto = new AutoModeling(document); |
||
416 | auto.Run(); |
||
417 | ProgressForm.End(); |
||
418 | } |
||
419 | catch (Exception ex) |
||
420 | { |
||
421 | Log.WriteLine(ex); |
||
422 | } |
||
423 | }); |
||
424 | ProgressForm.Start(autoModelingThread); |
||
425 | |||
426 | rowInfo.Cells["colStatus"].Value = _EndProcess; |
||
427 | RefreshGridViewDrawingList(); |
||
428 | 3823b4ab | gaqhf | application.ActiveWindow.Fit(); |
429 | b33b0d0a | gaqhf | Thread.Sleep(100); |
430 | newDrawing.CloseDrawing(true); |
||
431 | Thread.Sleep(100); |
||
432 | 3823b4ab | gaqhf | } |
433 | } |
||
434 | catch (Exception ex) |
||
435 | { |
||
436 | b33b0d0a | gaqhf | rowInfo.Cells["colStatus"].Value = _Error; |
437 | 3823b4ab | gaqhf | } |
438 | } |
||
439 | e9718eec | gaqhf | } |
440 | catch (Exception ex) |
||
441 | { |
||
442 | MessageBox.Show(ex.Message); |
||
443 | } |
||
444 | } |
||
445 | 3823b4ab | gaqhf | |
446 | b33b0d0a | gaqhf | private void RefreshGridViewDrawingList() |
447 | { |
||
448 | if (gridViewDrawingList.InvokeRequired) |
||
449 | { |
||
450 | gridViewDrawingList.BeginInvoke(new Action(() => gridViewDrawingList.Refresh())); |
||
451 | Thread.Sleep(1); |
||
452 | } |
||
453 | else |
||
454 | { |
||
455 | gridViewDrawingList.Refresh(); |
||
456 | } |
||
457 | } |
||
458 | |||
459 | 3823b4ab | gaqhf | private void gridViewDrawingList_CellValueChanged(object sender, GridViewCellEventArgs e) |
460 | { |
||
461 | CheckValidateDrawing(e.Row); |
||
462 | } |
||
463 | |||
464 | private void CheckValidateDrawing(GridViewRowInfo rowInfo) |
||
465 | { |
||
466 | b33b0d0a | gaqhf | string statusValue = (string)rowInfo.Cells["colStatus"].Value; |
467 | if (statusValue != _LoadFail && statusValue != _EndProcess && statusValue != _Error && statusValue != _Processing) |
||
468 | 3823b4ab | gaqhf | { |
469 | StringBuilder sStatus = new StringBuilder(); |
||
470 | // Unit Check |
||
471 | if (string.IsNullOrEmpty((string)rowInfo.Cells["colUnit"].Value)) |
||
472 | sStatus.AppendLine(_NeedUnit); |
||
473 | // Template Check |
||
474 | if (string.IsNullOrEmpty((string)rowInfo.Cells["colTemplate"].Value)) |
||
475 | sStatus.AppendLine(_NeedTemplate); |
||
476 | // ReMapping |
||
477 | Document document = rowInfo.Tag as Document; |
||
478 | if (!document.ReMapping(new List<string>(), new List<string>())) |
||
479 | sStatus.AppendLine(_NeedMapping); |
||
480 | |||
481 | // IF READY |
||
482 | if (sStatus.Length == 0) |
||
483 | sStatus.Append(_Ready); |
||
484 | |||
485 | rowInfo.Cells["colStatus"].Value = sStatus.ToString().Trim(); |
||
486 | } |
||
487 | |||
488 | if ((string)rowInfo.Cells["colStatus"].Value != _Ready) |
||
489 | rowInfo.Cells["colCheckBox"].Value = false; |
||
490 | } |
||
491 | |||
492 | private void gridViewDrawingList_CellClick(object sender, GridViewCellEventArgs e) |
||
493 | { |
||
494 | try |
||
495 | { |
||
496 | if (e.RowIndex == -1) |
||
497 | return; |
||
498 | |||
499 | if (e.Column.Name == "colUnit") |
||
500 | { |
||
501 | SelectUnitForm form = new SelectUnitForm(dUnit); |
||
502 | if (form.ShowDialog() == DialogResult.OK) |
||
503 | { |
||
504 | gridViewDrawingList.Rows[e.RowIndex].Cells["colUnit"].Value = form.SelectedUnit; |
||
505 | } |
||
506 | } |
||
507 | } |
||
508 | catch (Exception ex) |
||
509 | { |
||
510 | |||
511 | } |
||
512 | } |
||
513 | |||
514 | private void gridViewDrawingList_CellFormatting(object sender, CellFormattingEventArgs e) |
||
515 | { |
||
516 | try |
||
517 | { |
||
518 | GridCommandCellElement cmdCell = e.CellElement as GridCommandCellElement; |
||
519 | if (cmdCell != null) |
||
520 | { |
||
521 | cmdCell.CommandButton.TextAlignment = ContentAlignment.MiddleCenter; |
||
522 | } |
||
523 | } |
||
524 | catch (Exception ex) |
||
525 | { |
||
526 | |||
527 | } |
||
528 | } |
||
529 | |||
530 | #endregion |
||
531 | |||
532 | #region Mapping Page |
||
533 | |||
534 | private void gridViewItemMapping_CellFormatting(object sender, CellFormattingEventArgs e) |
||
535 | { |
||
536 | try |
||
537 | { |
||
538 | GridCommandCellElement cmdCell = e.CellElement as GridCommandCellElement; |
||
539 | if (cmdCell != null) |
||
540 | { |
||
541 | cmdCell.CommandButton.TextAlignment = ContentAlignment.MiddleCenter; |
||
542 | } |
||
543 | } |
||
544 | catch (Exception ex) |
||
545 | { |
||
546 | |||
547 | } |
||
548 | } |
||
549 | |||
550 | private void gridViewAttribute_CellFormatting(object sender, CellFormattingEventArgs e) |
||
551 | { |
||
552 | try |
||
553 | { |
||
554 | GridCommandCellElement cmdCell = e.CellElement as GridCommandCellElement; |
||
555 | if (cmdCell != null) |
||
556 | { |
||
557 | cmdCell.CommandButton.TextAlignment = ContentAlignment.MiddleCenter; |
||
558 | } |
||
559 | } |
||
560 | catch (Exception ex) |
||
561 | { |
||
562 | |||
563 | } |
||
564 | } |
||
565 | |||
566 | private void btnMappingSave_Click(object sender, EventArgs e) |
||
567 | { |
||
568 | symbolMapping.Clear(); |
||
569 | foreach (GridViewRowInfo row in gridViewItemMapping.Rows) |
||
570 | { |
||
571 | if (row.Cells["colItemName"].Value != null && row.Cells["colSPPIDName"].Value != null) |
||
572 | { |
||
573 | string key = row.Cells["colItemName"].Value.ToString(); |
||
574 | string value = row.Cells["colSPPIDName"].Value.ToString(); |
||
575 | |||
576 | if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) |
||
577 | { |
||
578 | if (symbolMapping.ContainsKey(key)) |
||
579 | symbolMapping[key] = value; |
||
580 | else |
||
581 | symbolMapping.Add(key, value); |
||
582 | } |
||
583 | |||
584 | } |
||
585 | } |
||
586 | |||
587 | attributeMapping.Clear(); |
||
588 | foreach (GridViewRowInfo row in gridViewAttribute.Rows) |
||
589 | { |
||
590 | if (row.Cells["colAttribute"].Value != null && row.Cells["colSPPIDAttribute"].Value != null) |
||
591 | { |
||
592 | string key = row.Cells["colAttribute"].Value.ToString(); |
||
593 | string value = row.Cells["colSPPIDAttribute"].Value.ToString(); |
||
594 | |||
595 | if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) |
||
596 | { |
||
597 | if (attributeMapping.ContainsKey(key)) |
||
598 | attributeMapping[key] = value; |
||
599 | else |
||
600 | attributeMapping.Add(key, value); |
||
601 | } |
||
602 | |||
603 | } |
||
604 | } |
||
605 | |||
606 | SPPIDUtill.SaveMapping(symbolMapping, attributeMapping); |
||
607 | |||
608 | foreach (GridViewRowInfo rowInfo in gridViewDrawingList.Rows) |
||
609 | CheckValidateDrawing(rowInfo); |
||
610 | b33b0d0a | gaqhf | |
611 | MessageBox.Show("Save success!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
612 | 3823b4ab | gaqhf | } |
613 | |||
614 | #endregion |
||
615 | |||
616 | private void pageView_SelectedPageChanged(object sender, EventArgs e) |
||
617 | { |
||
618 | if (pageView.SelectedPage.Name == "pageItemMapping") |
||
619 | { |
||
620 | // Load Item Mapping |
||
621 | gridViewItemMapping.BeginUpdate(); |
||
622 | gridViewItemMapping.Rows.Clear(); |
||
623 | foreach (var item in symbolMapping) |
||
624 | gridViewItemMapping.Rows.Add(new object[] { item.Key, item.Value, "View" }); |
||
625 | |||
626 | // Load Attribute |
||
627 | gridViewAttribute.BeginUpdate(); |
||
628 | gridViewAttribute.Rows.Clear(); |
||
629 | foreach (var item in attributeMapping) |
||
630 | gridViewAttribute.Rows.Add(new object[] { item.Key, item.Value, "View" }); |
||
631 | |||
632 | List<string> needSymbolMapping = new List<string>(); |
||
633 | List<string> needAttributeMapping = new List<string>(); |
||
634 | foreach (GridViewRowInfo rowInfo in gridViewDrawingList.Rows) |
||
635 | { |
||
636 | Document document = rowInfo.Tag as Document; |
||
637 | if (document != null) |
||
638 | document.ReMapping(needSymbolMapping, needAttributeMapping); |
||
639 | } |
||
640 | |||
641 | needSymbolMapping = needSymbolMapping.Distinct().ToList(); |
||
642 | needAttributeMapping = needAttributeMapping.Distinct().ToList(); |
||
643 | |||
644 | foreach (string item in needSymbolMapping) |
||
645 | gridViewItemMapping.Rows.Add(new object[] { item, "", "View" }); |
||
646 | |||
647 | foreach (string item in needAttributeMapping) |
||
648 | gridViewAttribute.Rows.Add(new object[] { item, "", "View" }); |
||
649 | |||
650 | gridViewItemMapping.BestFitColumns(); |
||
651 | gridViewItemMapping.EndUpdate(); |
||
652 | |||
653 | gridViewAttribute.BestFitColumns(); |
||
654 | gridViewAttribute.EndUpdate(); |
||
655 | } |
||
656 | } |
||
657 | f2151e28 | gaqhf | } |
658 | } |