hytos / DTI_PID / SPPIDConverter / ConverterForm.cs @ 8847ea67
이력 | 보기 | 이력해설 | 다운로드 (33.8 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 Microsoft.VisualBasic; |
11 |
using DevExpress.XtraEditors.Repository; |
12 |
using DevExpress.XtraEditors.Controls; |
13 |
using DevExpress.XtraEditors; |
14 |
using System.Globalization; |
15 |
using System.Threading; |
16 |
using System.IO; |
17 |
using Ingr.RAD2D; |
18 |
using Converter.BaseModel; |
19 |
using Converter.SPPID.Properties; |
20 |
using Converter.SPPID.DB; |
21 |
using Converter.SPPID.Util; |
22 |
using Converter.SPPID.Form; |
23 |
using Converter.SPPID.Model; |
24 |
|
25 |
namespace Converter.SPPID |
26 |
{ |
27 |
public partial class ConverterForm : DevExpress.XtraBars.Ribbon.RibbonForm |
28 |
{ |
29 |
private Dictionary<string, SPPID_Document> _DicDocuments = new Dictionary<string, SPPID_Document>(); |
30 |
private List<SPPID_Document> _Documents = new List<SPPID_Document>(); |
31 |
public List<SPPID_Document> Documents { get { return _Documents; } } |
32 |
private DataTable _ConverterDT = new DataTable(); |
33 |
private DataTable _SPPIDSymbolPathDT = new DataTable(); |
34 |
private DataTable _SPPIDUnitDT = new DataTable(); |
35 |
private DataTable _SPPIDAttributeDT = new DataTable(); |
36 |
private RepositoryItemComboBox templateComboBox; |
37 |
|
38 |
|
39 |
private DataTable _ID2SymbolDT = new DataTable(); |
40 |
private DataTable _ID2ChildSymbolDT = new DataTable(); |
41 |
private DataTable _ID2LineDT = new DataTable(); |
42 |
private DataTable _ID2AttributeDT = new DataTable(); |
43 |
private DataTable _ID2LinePropertyDT = new DataTable(); |
44 |
private DataTable _ID2SymbolTypeDT = new DataTable(); |
45 |
private DataTable _ID2SymbolTable = new DataTable(); |
46 |
|
47 |
|
48 |
private List<SymbolMapping> symbolMappings = new List<SymbolMapping>(); |
49 |
private List<ChildSymbolMapping> childSymbolMappings = new List<ChildSymbolMapping>(); |
50 |
private List<LineMapping> lineMappings = new List<LineMapping>(); |
51 |
private List<LineNumberMapping> lineNumberMappings = new List<LineNumberMapping>(); |
52 |
private List<AttributeMapping> attributeMappings = new List<AttributeMapping>(); |
53 |
|
54 |
public ConverterForm() |
55 |
{ |
56 |
InitializeComponent(); |
57 |
|
58 |
CultureInfo culture = CultureInfo.GetCultureInfo("ko"); |
59 |
Msg.Culture = culture; |
60 |
|
61 |
InitUsedDataTable(); |
62 |
InitGridControl(); |
63 |
InitID2Project(); |
64 |
} |
65 |
|
66 |
private void InitUsedDataTable() |
67 |
{ |
68 |
// Converter Table |
69 |
DataColumn col = _ConverterDT.Columns.Add("colDrawingFileName"); |
70 |
col.Caption = "Drawing File Name"; |
71 |
col = _ConverterDT.Columns.Add("colDrawingFilePath"); |
72 |
col.Caption = "DrawingFilePath"; |
73 |
col = _ConverterDT.Columns.Add("colUnit"); |
74 |
col.Caption = "Unit"; |
75 |
col = _ConverterDT.Columns.Add("colTemplate"); |
76 |
col.Caption = "Template"; |
77 |
col = _ConverterDT.Columns.Add("colDrawingNumber"); |
78 |
col.Caption = "Drawing Number"; |
79 |
col = _ConverterDT.Columns.Add("colDrawingName"); |
80 |
col.Caption = "Drawing Name"; |
81 |
col = _ConverterDT.Columns.Add("colStatus"); |
82 |
col.Caption = "Status"; |
83 |
col = _ConverterDT.Columns.Add("colUID"); |
84 |
|
85 |
col = _ID2LineDT.Columns.Add("UID"); |
86 |
col = _ID2LineDT.Columns.Add("Name"); |
87 |
col.Caption = "Name"; |
88 |
col = _ID2LineDT.Columns.Add("Type"); |
89 |
col.Caption = "Type"; |
90 |
col = _ID2LineDT.Columns.Add("SPPID_SYMBOL_PATH"); |
91 |
col.Caption = "SPPID Symbol Path"; |
92 |
col = _ID2LineDT.Columns.Add("Clear"); |
93 |
col.Caption = ""; |
94 |
} |
95 |
|
96 |
private void InitGridControl() |
97 |
{ |
98 |
#region Converter Page |
99 |
gridViewConverter.OptionsSelection.MultiSelect = true; |
100 |
gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect; |
101 |
|
102 |
gridControlConverter.DataSource = _ConverterDT; |
103 |
|
104 |
templateComboBox = new RepositoryItemComboBox(); |
105 |
templateComboBox.TextEditStyle = TextEditStyles.DisableTextEditor; |
106 |
templateComboBox.EditValueChanged += templateComboBox_EditValueChanged; |
107 |
gridControlConverter.RepositoryItems.Add(templateComboBox); |
108 |
gridViewConverter.Columns["colTemplate"].ColumnEdit = templateComboBox; |
109 |
|
110 |
gridViewConverter.Columns["colUnit"].OptionsColumn.AllowEdit = false; |
111 |
gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false; |
112 |
gridViewConverter.Columns["colUnit"].OptionsColumn.ReadOnly = true; |
113 |
gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false; |
114 |
gridViewConverter.Columns["colDrawingFilePath"].Visible = false; |
115 |
gridViewConverter.Columns["colUID"].Visible = false; |
116 |
|
117 |
gridViewConverter.BestFitColumns(); |
118 |
#endregion |
119 |
} |
120 |
|
121 |
private void templateComboBox_EditValueChanged(object sender, EventArgs e) |
122 |
{ |
123 |
gridViewConverter.CloseEditor(); |
124 |
gridViewConverter.UpdateCurrentRow(); |
125 |
} |
126 |
|
127 |
private void gridViewConverter_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) |
128 |
{ |
129 |
if (e.Column.Name == "colcolTemplate") |
130 |
{ |
131 |
gridViewConverter.ShowEditor(); |
132 |
(gridViewConverter.ActiveEditor as ComboBoxEdit).ShowPopup(); |
133 |
} |
134 |
else if (e.Column.Name == "colcolUnit") |
135 |
{ |
136 |
UnitForm unitForm = new UnitForm(_SPPIDUnitDT); |
137 |
if (unitForm.ShowDialog() == DialogResult.OK) |
138 |
{ |
139 |
gridViewConverter.SetRowCellValue(e.RowHandle, e.Column, unitForm.SelectedUnit); |
140 |
gridViewConverter.CloseEditor(); |
141 |
gridViewConverter.UpdateCurrentRow(); |
142 |
} |
143 |
} |
144 |
} |
145 |
|
146 |
private void btnID2DB_Click(object sender, EventArgs e) |
147 |
{ |
148 |
ID2DBSetting form = new ID2DBSetting(); |
149 |
DialogResult = form.ShowDialog(); |
150 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
151 |
_ProjectInfo.DefaultPath = Settings.Default.ProjectPath; |
152 |
_ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType; |
153 |
_ProjectInfo.ServerIP = Settings.Default.ProjectServerIP; |
154 |
_ProjectInfo.Port = Settings.Default.ProjectPort; |
155 |
_ProjectInfo.DBUser = Settings.Default.ProjectDBUser; |
156 |
_ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword; |
157 |
|
158 |
if (DialogResult == DialogResult.OK) |
159 |
{ |
160 |
if (InitID2Project()) |
161 |
MessageBox.Show(Msg.SuccessProjectSelect, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
162 |
else |
163 |
MessageBox.Show(Msg.FailProjectSelect, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
164 |
} |
165 |
} |
166 |
|
167 |
private bool InitID2Project() |
168 |
{ |
169 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
170 |
if (Project_DB.ConnTestAndCreateTable()) |
171 |
{ |
172 |
_ProjectInfo.Enable = true; |
173 |
labelDBType.Text = _ProjectInfo.DBType.ToString(); |
174 |
labelDBType.AppearanceItemCaption.ForeColor = Color.Blue; |
175 |
labelID2ProjectName.Text = _ProjectInfo.Name; |
176 |
labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Blue; |
177 |
labelID2ProjectStatus.Text = Msg.ConnectionSuccessful; |
178 |
labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Blue; |
179 |
layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
180 |
layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
181 |
} |
182 |
else |
183 |
{ |
184 |
_ProjectInfo.Enable = false; |
185 |
labelDBType.Text = ""; |
186 |
labelID2ProjectName.Text = " "; |
187 |
labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Red; |
188 |
labelID2ProjectStatus.Text = Msg.ConnectionFail; |
189 |
labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Red; |
190 |
layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
191 |
layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
192 |
} |
193 |
|
194 |
InitMapping(); |
195 |
InitSPPIDDB(); |
196 |
|
197 |
return _ProjectInfo.Enable; |
198 |
} |
199 |
|
200 |
private void InitMapping() |
201 |
{ |
202 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
203 |
if (_ProjectInfo.Enable) |
204 |
{ |
205 |
if (_ID2SymbolTable != null) |
206 |
{ |
207 |
_ID2SymbolTable.Dispose(); |
208 |
_ID2SymbolTable = null; |
209 |
} |
210 |
_ID2SymbolTable = Project_DB.SelectID2SymbolTable(); |
211 |
|
212 |
if (_ID2SymbolTypeDT != null) |
213 |
{ |
214 |
_ID2SymbolTypeDT.Dispose(); |
215 |
_ID2SymbolTypeDT = null; |
216 |
} |
217 |
_ID2SymbolTypeDT = Project_DB.SelectSymbolType(); |
218 |
InitID2Symbol(); |
219 |
InitID2Line(); |
220 |
InitID2LineNumber(); |
221 |
InitID2Attribute(); |
222 |
|
223 |
InitETCSetting(); |
224 |
} |
225 |
} |
226 |
|
227 |
private void InitETCSetting() |
228 |
{ |
229 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
230 |
if (_ProjectInfo.Enable) |
231 |
{ |
232 |
DataTable dt = Project_DB.SelectSetting(); |
233 |
foreach (DataRow item in dt.Rows) |
234 |
{ |
235 |
string settingType = item["SettingType"].ToString(); |
236 |
if (settingType == "ETCSetting") |
237 |
SPPIDUtil.ConvertToETCSetting(item["JsonString"].ToString()); |
238 |
else if (settingType == "GridSetting") |
239 |
SPPIDUtil.ConvertToGridSetting(item["JsonString"].ToString()); |
240 |
} |
241 |
} |
242 |
} |
243 |
|
244 |
private void InitID2Symbol() |
245 |
{ |
246 |
using (DataTable symbolDT = Project_DB.SelectProjectSymbol()) |
247 |
{ |
248 |
symbolMappings.Clear(); |
249 |
_ID2SymbolDT = symbolDT; |
250 |
_ID2SymbolDT.Columns.Add("Clear"); |
251 |
_ID2SymbolDT.Columns["Clear"].Caption = ""; |
252 |
foreach (DataRow row in symbolDT.Rows) |
253 |
{ |
254 |
symbolMappings.Add(new SymbolMapping() |
255 |
{ |
256 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
257 |
SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(), |
258 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(), |
259 |
LEADERLINE = DBNull.Value.Equals(row["LEADERLINE"]) ? false : (bool)row["LEADERLINE"] |
260 |
}); |
261 |
} |
262 |
|
263 |
MergeID2ChildSymbol(); |
264 |
} |
265 |
} |
266 |
|
267 |
private void MergeID2ChildSymbol() |
268 |
{ |
269 |
using (DataTable childSymbolDT = Project_DB.SelectProjectChildSymbol()) |
270 |
{ |
271 |
childSymbolMappings.Clear(); |
272 |
_ID2ChildSymbolDT = childSymbolDT; |
273 |
_ID2ChildSymbolDT.Columns.Add("Clear"); |
274 |
_ID2ChildSymbolDT.Columns["Clear"].Caption = ""; |
275 |
foreach (DataRow row in childSymbolDT.Rows) |
276 |
{ |
277 |
childSymbolMappings.Add(new ChildSymbolMapping() |
278 |
{ |
279 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
280 |
SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(), |
281 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(), |
282 |
}); |
283 |
} |
284 |
|
285 |
_ID2SymbolDT.Merge(_ID2ChildSymbolDT); |
286 |
} |
287 |
} |
288 |
|
289 |
private void InitID2Line() |
290 |
{ |
291 |
using (DataTable lineTypes = Project_DB.SelectProjectLine()) |
292 |
{ |
293 |
lineMappings.Clear(); |
294 |
_ID2LineDT.Rows.Clear(); |
295 |
foreach (DataRow row in lineTypes.Rows) |
296 |
{ |
297 |
DataRow newRow = _ID2LineDT.NewRow(); |
298 |
newRow["UID"] = row["UID"] == null ? "" : row["UID"].ToString(); |
299 |
newRow["Name"] = row["Name"] == null ? "" : row["Name"].ToString(); |
300 |
newRow["Type"] = "Line"; |
301 |
newRow["SPPID_SYMBOL_PATH"] = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(); |
302 |
_ID2LineDT.Rows.Add(newRow); |
303 |
|
304 |
lineMappings.Add(new LineMapping() |
305 |
{ |
306 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
307 |
LINENAME = row["Name"] == null ? "" : row["Name"].ToString(), |
308 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(), |
309 |
}); |
310 |
} |
311 |
} |
312 |
} |
313 |
|
314 |
private void InitID2LineNumber() |
315 |
{ |
316 |
using (DataTable linePropertiesDT = Project_DB.SelectProjectLineProperties()) |
317 |
{ |
318 |
lineNumberMappings.Clear(); |
319 |
_ID2LinePropertyDT = linePropertiesDT; |
320 |
_ID2LinePropertyDT.Columns.Add("Type"); |
321 |
foreach (DataRow row in linePropertiesDT.Rows) |
322 |
{ |
323 |
row["Type"] = "Line Property"; |
324 |
lineNumberMappings.Add(new LineNumberMapping() |
325 |
{ |
326 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
327 |
DisplayName = row["DisplayName"] == null ? "" : row["DisplayName"].ToString(), |
328 |
SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(), |
329 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString() |
330 |
}); |
331 |
} |
332 |
} |
333 |
} |
334 |
|
335 |
private void InitID2Attribute() |
336 |
{ |
337 |
using (DataTable attributeDT = Project_DB.SelectProjectAttribute()) |
338 |
{ |
339 |
attributeMappings.Clear(); |
340 |
_ID2AttributeDT = attributeDT; |
341 |
_ID2AttributeDT.Columns.Add("Clear"); |
342 |
_ID2AttributeDT.Columns["Clear"].Caption = ""; |
343 |
foreach (DataRow row in attributeDT.Rows) |
344 |
{ |
345 |
attributeMappings.Add(new AttributeMapping() |
346 |
{ |
347 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
348 |
DisplayAttribute = row["DisplayAttribute"] == null ? "" : row["DisplayAttribute"].ToString(), |
349 |
Type = row["Type"] == null ? "" : row["Type"].ToString(), |
350 |
SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(), |
351 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(), |
352 |
Location = DBNull.Value.Equals(row["LOCATION"]) ? Model.Location.None : (Location)row["LOCATION"], |
353 |
LeaderLine = DBNull.Value.Equals(row["LEADERLINE"]) ? false : (bool)row["LEADERLINE"] |
354 |
}); |
355 |
} |
356 |
} |
357 |
} |
358 |
|
359 |
private void InitSPPIDDB() |
360 |
{ |
361 |
buttonEditDefaultUnit.TextChanged -= new EventHandler(buttonEditDefaultUnit_TextChanged); |
362 |
comboBoxEditDefaultTemplate.SelectedIndexChanged -= new EventHandler(comboBoxEditDefaultTemplate_SelectedIndexChanged); |
363 |
|
364 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
365 |
if (_ProjectInfo.Enable) |
366 |
{ |
367 |
DataTable dt = Project_DB.SelectSPPID_DB_INFO(); |
368 |
if (dt.Columns.Count > 0 && dt.Rows.Count > 0) |
369 |
SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString()); |
370 |
else |
371 |
SPPID_DBInfo.Clear(); |
372 |
} |
373 |
|
374 |
templateComboBox.Items.Clear(); |
375 |
comboBoxEditDefaultTemplate.SelectedIndex = -1; |
376 |
comboBoxEditDefaultTemplate.Properties.Items.Clear(); |
377 |
buttonEditDefaultUnit.Text = ""; |
378 |
|
379 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
380 |
if (_SPPIDInfo.Enable) |
381 |
{ |
382 |
labelSPPIDPlantName.Text = _SPPIDInfo.SelectedPlant; |
383 |
labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Blue; |
384 |
labelSPPIDDBStatus.Text = Msg.ConnectionSuccessful; |
385 |
labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Blue; |
386 |
|
387 |
string TemplatePath = SPPID_DB.GetPlantPID_T_OPTIONSETTING_Value("PID Template Path"); |
388 |
if (!string.IsNullOrEmpty(TemplatePath)) |
389 |
{ |
390 |
List<string> templateFiles = Directory.GetFiles(TemplatePath, "*.pid").ToList().Select(filePath => Path.GetFileName(filePath)).ToList(); |
391 |
templateComboBox.Items.AddRange(templateFiles); |
392 |
comboBoxEditDefaultTemplate.Properties.Items.AddRange(templateFiles); |
393 |
} |
394 |
|
395 |
|
396 |
if (_SPPIDUnitDT != null) |
397 |
{ |
398 |
_SPPIDUnitDT.Dispose(); |
399 |
_SPPIDUnitDT = null; |
400 |
} |
401 |
if (_SPPIDAttributeDT != null) |
402 |
{ |
403 |
_SPPIDAttributeDT.Dispose(); |
404 |
_SPPIDAttributeDT = null; |
405 |
} |
406 |
|
407 |
_SPPIDUnitDT = SPPID_DB.GetUnitTree(); |
408 |
_SPPIDAttributeDT = SPPID_DB.GetSPPIDAttribute(); |
409 |
if (_SPPIDAttributeDT != null) |
410 |
{ |
411 |
_SPPIDAttributeDT.Columns["DISPLAYNAME"].ColumnName = "DISPLAY NAME"; |
412 |
} |
413 |
|
414 |
if (!string.IsNullOrEmpty(Settings.Default.DefaultTemplate) && comboBoxEditDefaultTemplate.Properties.Items.Contains(Settings.Default.DefaultTemplate)) |
415 |
comboBoxEditDefaultTemplate.SelectedItem = Settings.Default.DefaultTemplate; |
416 |
|
417 |
// Unit 있는지 없는지 검사 필요 |
418 |
if (!string.IsNullOrEmpty(Settings.Default.DefaultUnit)) |
419 |
buttonEditDefaultUnit.Text = Settings.Default.DefaultUnit; |
420 |
} |
421 |
else |
422 |
{ |
423 |
labelSPPIDPlantName.Text = " "; |
424 |
labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Red; |
425 |
labelSPPIDDBStatus.Text = Msg.ConnectionFail; |
426 |
labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Red; |
427 |
} |
428 |
|
429 |
_DicDocuments.Clear(); |
430 |
_ConverterDT.Rows.Clear(); |
431 |
InitSPPIDSymbolTreeTable(); |
432 |
|
433 |
buttonEditDefaultUnit.TextChanged += new EventHandler(buttonEditDefaultUnit_TextChanged); |
434 |
comboBoxEditDefaultTemplate.SelectedIndexChanged += new EventHandler(comboBoxEditDefaultTemplate_SelectedIndexChanged); |
435 |
} |
436 |
|
437 |
private void InitSPPIDSymbolTreeTable() |
438 |
{ |
439 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
440 |
|
441 |
try |
442 |
{ |
443 |
_SPPIDSymbolPathDT = new DataTable(); |
444 |
_SPPIDSymbolPathDT.Columns.Add("ID"); |
445 |
_SPPIDSymbolPathDT.Columns.Add("Parent"); |
446 |
_SPPIDSymbolPathDT.Columns.Add("Name"); |
447 |
_SPPIDSymbolPathDT.Columns.Add("FullPath"); |
448 |
|
449 |
if (_SPPIDInfo.Enable) |
450 |
{ |
451 |
string symbolPath = SPPID_DB.GetPlantPID_T_OPTIONSETTING_Value("Catalog Explorer root path"); |
452 |
DirectoryInfo info = new DirectoryInfo(symbolPath); |
453 |
_SPPIDSymbolPathDT.Rows.Add(new object[] { "0", "-1", info.Name }); |
454 |
loop(info, "0", symbolPath); |
455 |
} |
456 |
} |
457 |
catch (Exception ex) |
458 |
{ |
459 |
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
460 |
} |
461 |
} |
462 |
|
463 |
private void loop(DirectoryInfo parentInfo, string parentUID, string defaultPath) |
464 |
{ |
465 |
DirectoryInfo[] infos = parentInfo.GetDirectories(); |
466 |
foreach (DirectoryInfo info in infos) |
467 |
{ |
468 |
string uid = Guid.NewGuid().ToString(); |
469 |
_SPPIDSymbolPathDT.Rows.Add(new object[] { uid, parentUID, info.Name }); |
470 |
loop(info, uid, defaultPath); |
471 |
|
472 |
FileInfo[] files = info.GetFiles("*.sym"); |
473 |
foreach (FileInfo fileInfo in files) |
474 |
{ |
475 |
_SPPIDSymbolPathDT.Rows.Add(new object[] { Guid.NewGuid().ToString(), uid, fileInfo.Name, fileInfo.FullName.Replace(defaultPath, "") }); |
476 |
} |
477 |
} |
478 |
} |
479 |
|
480 |
private void btnLoadFile_Click(object sender, EventArgs e) |
481 |
{ |
482 |
List< BaseModel.Document> validationFailDocs = new List<BaseModel.Document>(); |
483 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
484 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
485 |
if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable) |
486 |
{ |
487 |
MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
488 |
return; |
489 |
} |
490 |
|
491 |
xtraOpenFileDialog.InitialDirectory = _ProjectInfo.TempDirPath; |
492 |
if (xtraOpenFileDialog.ShowDialog() == DialogResult.OK) |
493 |
{ |
494 |
foreach (string fileName in xtraOpenFileDialog.FileNames) |
495 |
{ |
496 |
SPPID_Document document = new SPPID_Document(fileName, _ID2SymbolTypeDT); |
497 |
|
498 |
document.SymbolTable = _ID2SymbolTable; |
499 |
document.SymbolMappings = symbolMappings; |
500 |
document.ChildSymbolMappings = childSymbolMappings; |
501 |
document.LineMappings = lineMappings; |
502 |
document.LineNumberMappings = lineNumberMappings; |
503 |
document.AttributeMappings = attributeMappings; |
504 |
document.ETCSetting = ETCSetting.GetInstance(); |
505 |
document.SetSPPIDInfo(); |
506 |
|
507 |
|
508 |
if (!document.SetSPPIDMapping()) |
509 |
{ |
510 |
document.Enable = false; |
511 |
document.MappingValidation = false; |
512 |
} |
513 |
|
514 |
DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName)); |
515 |
if (rows.Length == 0) |
516 |
{ |
517 |
DataRow row = _ConverterDT.NewRow(); |
518 |
row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName); |
519 |
row["colDrawingFilePath"] = fileName; |
520 |
row["colDrawingNumber"] = document.DWGNAME; |
521 |
row["colDrawingName"] = document.DWGNAME; |
522 |
if (document.Enable) |
523 |
row["colStatus"] = "Ready"; |
524 |
else |
525 |
row["colStatus"] = "Error"; |
526 |
row["colUID"] = ""; |
527 |
if (comboBoxEditDefaultTemplate.SelectedIndex > -1) |
528 |
row["colTemplate"] = comboBoxEditDefaultTemplate.SelectedItem; |
529 |
if (!string.IsNullOrEmpty(buttonEditDefaultUnit.Text)) |
530 |
row["colUnit"] = buttonEditDefaultUnit.Text; |
531 |
|
532 |
_ConverterDT.Rows.Add(row); |
533 |
|
534 |
if (document.Enable && document.Validation && document.MappingValidation) |
535 |
gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
536 |
} |
537 |
else |
538 |
{ |
539 |
foreach (DataRow row in rows) |
540 |
{ |
541 |
if (document.Enable) |
542 |
row["colStatus"] = "Ready"; |
543 |
else |
544 |
row["colStatus"] = "Error"; |
545 |
|
546 |
if (comboBoxEditDefaultTemplate.SelectedIndex > -1) |
547 |
row["colTemplate"] = comboBoxEditDefaultTemplate.SelectedItem; |
548 |
if (!string.IsNullOrEmpty(buttonEditDefaultUnit.Text)) |
549 |
row["colUnit"] = buttonEditDefaultUnit.Text; |
550 |
|
551 |
if (document.Enable && document.Validation && document.MappingValidation) |
552 |
gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
553 |
} |
554 |
} |
555 |
if (!_DicDocuments.ContainsKey(fileName)) |
556 |
_DicDocuments.Add(fileName, null); |
557 |
|
558 |
if (!document.Validation || !document.MappingValidation) |
559 |
validationFailDocs.Add(document); |
560 |
|
561 |
_DicDocuments[fileName] = document; |
562 |
} |
563 |
if (validationFailDocs.Count > 0) |
564 |
{ |
565 |
MessageForm messageForm = new MessageForm(validationFailDocs); |
566 |
messageForm.ShowDialog(); |
567 |
} |
568 |
} |
569 |
} |
570 |
|
571 |
/// <summary> |
572 |
/// 선택한 도면의 정보를 로딩한다 |
573 |
/// </summary> |
574 |
/// <param name="sender"></param> |
575 |
/// <param name="e"></param> |
576 |
private void btnRun_Click(object sender, EventArgs e) |
577 |
{ |
578 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
579 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
580 |
if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable) |
581 |
{ |
582 |
MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
583 |
return; |
584 |
} |
585 |
|
586 |
if (gridViewConverter.GetSelectedRows().Length == 0) |
587 |
{ |
588 |
MessageBox.Show(Msg.SelectDocument, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
589 |
return; |
590 |
} |
591 |
DataTable tDrawing = Project_DB.SelectDrawings(); |
592 |
this._Documents.Clear(); |
593 |
foreach (int rowHandle in gridViewConverter.GetSelectedRows()) |
594 |
{ |
595 |
string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath"); |
596 |
string _Unit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit"); |
597 |
string _Template = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate"); |
598 |
string _DrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber"); |
599 |
string _DrawingName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingName"); |
600 |
|
601 |
DataRow[] rows = tDrawing.Select(string.Format("NAME = '{0}'", Path.GetFileNameWithoutExtension(_FilePath) + ".png")); |
602 |
if (rows.Length != 1) |
603 |
continue; |
604 |
|
605 |
SPPID_Document document = _DicDocuments[_FilePath]; |
606 |
document.Unit = _Unit; |
607 |
document.Template = _Template; |
608 |
document.DrawingNumber = _DrawingNumber; |
609 |
document.DrawingName = _DrawingName; |
610 |
document.UID = rows[0]["UID"].ToString(); |
611 |
|
612 |
document.SymbolTable = _ID2SymbolTable; |
613 |
document.SymbolMappings = symbolMappings; |
614 |
document.ChildSymbolMappings = childSymbolMappings; |
615 |
document.LineMappings = lineMappings; |
616 |
document.LineNumberMappings = lineNumberMappings; |
617 |
document.AttributeMappings = attributeMappings; |
618 |
document.ETCSetting = ETCSetting.GetInstance(); |
619 |
document.SetSPPIDInfo(); |
620 |
|
621 |
if (document.SetSPPIDMapping() && document.Enable) |
622 |
this._Documents.Add(document); |
623 |
} |
624 |
|
625 |
if (_Documents.Count > 50) |
626 |
checkEditCloseDocument.Checked = true; |
627 |
|
628 |
tDrawing.Dispose(); |
629 |
DialogResult = DialogResult.OK; |
630 |
} |
631 |
|
632 |
private void btnSPPIDDB_Click(object sender, EventArgs e) |
633 |
{ |
634 |
SPPID_DB_SettingForm form = new SPPID_DB_SettingForm(); |
635 |
if (form.ShowDialog() == DialogResult.OK) |
636 |
InitSPPIDDB(); |
637 |
} |
638 |
|
639 |
private void btnItemMapping_Click(object sender, EventArgs e) |
640 |
{ |
641 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
642 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
643 |
if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable) |
644 |
{ |
645 |
MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
646 |
return; |
647 |
} |
648 |
|
649 |
MappingForm form = new MappingForm(_ID2SymbolDT,_SPPIDSymbolPathDT, _ID2LineDT, _ID2LinePropertyDT, _ID2AttributeDT, _SPPIDAttributeDT); |
650 |
form.ShowDialog(); |
651 |
InitMapping(); |
652 |
} |
653 |
private List<int> prevSelectedList = new List<int>(); |
654 |
|
655 |
private void gridViewConverter_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e) |
656 |
{ |
657 |
if (e.Action == CollectionChangeAction.Add) |
658 |
{ |
659 |
string _Unit = gridViewConverter.GetRowCellDisplayText(e.ControllerRow, "colUnit"); |
660 |
string _Template = gridViewConverter.GetRowCellDisplayText(e.ControllerRow, "colTemplate"); |
661 |
|
662 |
if (string.IsNullOrEmpty(_Unit) || string.IsNullOrEmpty(_Template)) |
663 |
gridViewConverter.UnselectRow(e.ControllerRow); |
664 |
} |
665 |
else if (e.Action == CollectionChangeAction.Refresh) |
666 |
{ |
667 |
foreach (int rowHandle in gridViewConverter.GetSelectedRows()) |
668 |
{ |
669 |
string _Unit = gridViewConverter.GetRowCellDisplayText(rowHandle, "colUnit"); |
670 |
string _Template = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate"); |
671 |
|
672 |
if (string.IsNullOrEmpty(_Unit) || string.IsNullOrEmpty(_Template)) |
673 |
gridViewConverter.UnselectRow(rowHandle); |
674 |
} |
675 |
|
676 |
List<int> selectedRowHandleList = gridViewConverter.GetSelectedRows().ToList(); |
677 |
var firstNotSecond = prevSelectedList.Except(selectedRowHandleList).ToList(); |
678 |
var secondNotFirst = selectedRowHandleList.Except(prevSelectedList).ToList(); |
679 |
|
680 |
if (!firstNotSecond.Any() && !secondNotFirst.Any()) |
681 |
{ |
682 |
this.gridViewConverter.SelectionChanged -= new DevExpress.Data.SelectionChangedEventHandler(this.gridViewConverter_SelectionChanged); |
683 |
gridViewConverter.ClearSelection(); |
684 |
this.gridViewConverter.SelectionChanged += new DevExpress.Data.SelectionChangedEventHandler(this.gridViewConverter_SelectionChanged); |
685 |
} |
686 |
} |
687 |
|
688 |
prevSelectedList = gridViewConverter.GetSelectedRows().ToList(); |
689 |
} |
690 |
|
691 |
private void buttonEditDefaulUnit_ButtonClick(object sender, ButtonPressedEventArgs e) |
692 |
{ |
693 |
UnitForm unitForm = new UnitForm(_SPPIDUnitDT); |
694 |
if (unitForm.ShowDialog() == DialogResult.OK) |
695 |
{ |
696 |
buttonEditDefaultUnit.Text = unitForm.SelectedUnit; |
697 |
} |
698 |
} |
699 |
|
700 |
private void btnRefresh_Click(object sender, EventArgs e) |
701 |
{ |
702 |
List<BaseModel.Document> validationFailDocs = new List<BaseModel.Document>(); |
703 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
704 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
705 |
if (!_ProjectInfo.Enable || !_SPPIDInfo.Enable) |
706 |
{ |
707 |
MessageBox.Show(Msg.PleaseSetProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
708 |
return; |
709 |
} |
710 |
|
711 |
foreach (DataRow row in _ConverterDT.Rows) |
712 |
{ |
713 |
string fileName = row["colDrawingFilePath"].ToString(); |
714 |
SPPID_Document document = new SPPID_Document(fileName, _ID2SymbolTypeDT); |
715 |
document.SymbolTable = _ID2SymbolTable; |
716 |
document.SymbolMappings = symbolMappings; |
717 |
document.ChildSymbolMappings = childSymbolMappings; |
718 |
document.LineMappings = lineMappings; |
719 |
document.LineNumberMappings = lineNumberMappings; |
720 |
document.AttributeMappings = attributeMappings; |
721 |
document.ETCSetting = ETCSetting.GetInstance(); |
722 |
document.SetSPPIDInfo(); |
723 |
|
724 |
|
725 |
if (!document.SetSPPIDMapping()) |
726 |
{ |
727 |
document.Enable = false; |
728 |
document.MappingValidation = false; |
729 |
} |
730 |
|
731 |
row["colDrawingNumber"] = document.DWGNAME; |
732 |
row["colDrawingName"] = document.DWGNAME; |
733 |
if (document.Enable) |
734 |
row["colStatus"] = "Ready"; |
735 |
else |
736 |
row["colStatus"] = "Error"; |
737 |
|
738 |
if (!_DicDocuments.ContainsKey(fileName)) |
739 |
_DicDocuments.Add(fileName, null); |
740 |
|
741 |
if (!document.Validation || !document.MappingValidation) |
742 |
validationFailDocs.Add(document); |
743 |
|
744 |
_DicDocuments[fileName] = document; |
745 |
|
746 |
if (document.Enable && document.Validation && document.MappingValidation) |
747 |
gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
748 |
} |
749 |
|
750 |
|
751 |
if (validationFailDocs.Count > 0) |
752 |
{ |
753 |
MessageForm messageForm = new MessageForm(validationFailDocs); |
754 |
messageForm.ShowDialog(); |
755 |
} |
756 |
} |
757 |
|
758 |
private void buttonEditDefaultUnit_TextChanged(object sender, EventArgs e) |
759 |
{ |
760 |
Settings.Default.DefaultUnit = buttonEditDefaultUnit.Text; |
761 |
Settings.Default.Save(); |
762 |
} |
763 |
|
764 |
private void comboBoxEditDefaultTemplate_SelectedIndexChanged(object sender, EventArgs e) |
765 |
{ |
766 |
Settings.Default.DefaultTemplate = comboBoxEditDefaultTemplate.SelectedItem.ToString(); |
767 |
Settings.Default.Save(); |
768 |
} |
769 |
|
770 |
|
771 |
} |
772 |
} |