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