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