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