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