hytos / DTI_PID / SPPIDConverter / ConverterForm.cs @ af63e77a
이력 | 보기 | 이력해설 | 다운로드 (18.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 Converter.BaseModel; |
12 |
using DevExpress.XtraEditors.Repository; |
13 |
using DevExpress.XtraEditors.Controls; |
14 |
using DevExpress.XtraEditors; |
15 |
using System.Globalization; |
16 |
using System.Threading; |
17 |
using System.IO; |
18 |
using Converter.SPPID.Properties; |
19 |
using Converter.SPPID.DB; |
20 |
using Converter.SPPID.Util; |
21 |
using Converter.SPPID.Form; |
22 |
using Converter.SPPID.Model; |
23 |
|
24 |
namespace Converter.SPPID |
25 |
{ |
26 |
public partial class ConverterForm : DevExpress.XtraBars.Ribbon.RibbonForm |
27 |
{ |
28 |
private Dictionary<string, SPPID_Document> _DicDocuments = new Dictionary<string, SPPID_Document>(); |
29 |
public List< SPPID_Document> Documents { get { return _DicDocuments.Select(x => x.Value).ToList(); } } |
30 |
private DataTable _ConverterDT = new DataTable(); |
31 |
private DataTable _SPPIDSymbolPathDT = new DataTable(); |
32 |
private DataTable _SPPIDUnitDT = new DataTable(); |
33 |
private RepositoryItemComboBox templateComboBox; |
34 |
|
35 |
|
36 |
private DataTable _ID2SymbolDT = new DataTable(); |
37 |
private DataTable _ID2LineDT = new DataTable(); |
38 |
private DataTable _ID2AssociationDT = new DataTable(); |
39 |
private DataTable _ID2LinePropertyDT = new DataTable(); |
40 |
|
41 |
private List<SymbolMapping> symbolMappings = new List<SymbolMapping>(); |
42 |
private List<LineMapping> lineMappings = new List<LineMapping>(); |
43 |
private List<LineNumberMapping> lineNumberMappings = new List<LineNumberMapping>(); |
44 |
private List<AssociationMapping> associationMappings = new List<AssociationMapping>(); |
45 |
|
46 |
public ConverterForm() |
47 |
{ |
48 |
InitializeComponent(); |
49 |
|
50 |
CultureInfo culture = CultureInfo.GetCultureInfo("ko"); |
51 |
Msg.Culture = culture; |
52 |
|
53 |
InitUsedDataTable(); |
54 |
InitGridControl(); |
55 |
InitID2Project(); |
56 |
} |
57 |
|
58 |
private void InitUsedDataTable() |
59 |
{ |
60 |
// Converter Table |
61 |
DataColumn col = _ConverterDT.Columns.Add("colDrawingFileName"); |
62 |
col.Caption = "Drawing File Name"; |
63 |
col = _ConverterDT.Columns.Add("colDrawingFilePath"); |
64 |
col.Caption = "DrawingFilePath"; |
65 |
col = _ConverterDT.Columns.Add("colUnit"); |
66 |
col.Caption = "Unit"; |
67 |
col = _ConverterDT.Columns.Add("colTemplate"); |
68 |
col.Caption = "Template"; |
69 |
col = _ConverterDT.Columns.Add("colDrawingNumber"); |
70 |
col.Caption = "Drawing Number"; |
71 |
col = _ConverterDT.Columns.Add("colDrawingName"); |
72 |
col.Caption = "Drawing Name"; |
73 |
col = _ConverterDT.Columns.Add("colStatus"); |
74 |
col.Caption = "Status"; |
75 |
col = _ConverterDT.Columns.Add("colUID"); |
76 |
|
77 |
col = _ID2LineDT.Columns.Add("UID"); |
78 |
col = _ID2LineDT.Columns.Add("Name"); |
79 |
col.Caption = "Name"; |
80 |
col = _ID2LineDT.Columns.Add("Type"); |
81 |
col.Caption = "Type"; |
82 |
col = _ID2LineDT.Columns.Add("SPPID_SYMBOL_PATH"); |
83 |
col.Caption = "SPPID Symbol Path"; |
84 |
col = _ID2LineDT.Columns.Add("Clear"); |
85 |
col.Caption = ""; |
86 |
} |
87 |
|
88 |
private void InitGridControl() |
89 |
{ |
90 |
#region Converter Page |
91 |
gridViewConverter.OptionsSelection.MultiSelect = true; |
92 |
gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect; |
93 |
|
94 |
gridControlConverter.DataSource = _ConverterDT; |
95 |
|
96 |
templateComboBox = new RepositoryItemComboBox(); |
97 |
templateComboBox.TextEditStyle = TextEditStyles.DisableTextEditor; |
98 |
templateComboBox.EditValueChanged += templateComboBox_EditValueChanged; |
99 |
gridControlConverter.RepositoryItems.Add(templateComboBox); |
100 |
gridViewConverter.Columns["colTemplate"].ColumnEdit = templateComboBox; |
101 |
|
102 |
gridViewConverter.Columns["colUnit"].OptionsColumn.AllowEdit = false; |
103 |
gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false; |
104 |
gridViewConverter.Columns["colUnit"].OptionsColumn.ReadOnly = true; |
105 |
gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false; |
106 |
gridViewConverter.Columns["colDrawingFilePath"].Visible = false; |
107 |
gridViewConverter.Columns["colUID"].Visible = false; |
108 |
|
109 |
gridViewConverter.BestFitColumns(); |
110 |
#endregion |
111 |
} |
112 |
private void templateComboBox_EditValueChanged(object sender, EventArgs e) |
113 |
{ |
114 |
gridViewConverter.CloseEditor(); |
115 |
gridViewConverter.UpdateCurrentRow(); |
116 |
} |
117 |
|
118 |
private void gridViewConverter_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e) |
119 |
{ |
120 |
if (e.Column.Name == "colcolTemplate") |
121 |
{ |
122 |
gridViewConverter.ShowEditor(); |
123 |
(gridViewConverter.ActiveEditor as ComboBoxEdit).ShowPopup(); |
124 |
} |
125 |
else if (e.Column.Name == "colcolUnit") |
126 |
{ |
127 |
UnitForm unitForm = new UnitForm(_SPPIDUnitDT); |
128 |
if (unitForm.ShowDialog() == DialogResult.OK) |
129 |
{ |
130 |
gridViewConverter.SetRowCellValue(e.RowHandle, e.Column, unitForm.SelectedUnit); |
131 |
gridViewConverter.CloseEditor(); |
132 |
gridViewConverter.UpdateCurrentRow(); |
133 |
} |
134 |
} |
135 |
} |
136 |
|
137 |
private void btnID2Project_ButtonClick(object sender, ButtonPressedEventArgs e) |
138 |
{ |
139 |
xtraFolderBrowserDialog.SelectedPath = btnID2Project.Text; |
140 |
|
141 |
if (xtraFolderBrowserDialog.ShowDialog() == DialogResult.OK) |
142 |
{ |
143 |
if (xtraFolderBrowserDialog.SelectedPath[xtraFolderBrowserDialog.SelectedPath.Length - 1] == '\\') |
144 |
xtraFolderBrowserDialog.SelectedPath = xtraFolderBrowserDialog.SelectedPath.Remove(xtraFolderBrowserDialog.SelectedPath.Length - 1); |
145 |
Settings.Default.LatestProjectPath = xtraFolderBrowserDialog.SelectedPath; |
146 |
Settings.Default.Save(); |
147 |
if (InitID2Project()) |
148 |
{ |
149 |
MessageBox.Show(Msg.SuccessProjectSelect, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information); |
150 |
} |
151 |
else |
152 |
MessageBox.Show(Msg.FailProjectSelect, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
153 |
} |
154 |
} |
155 |
|
156 |
private bool InitID2Project() |
157 |
{ |
158 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
159 |
_ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath; |
160 |
if (Project_DB.ConnTestAndCreateTable()) |
161 |
{ |
162 |
_ProjectInfo.Enable = true; |
163 |
btnID2Project.Text = _ProjectInfo.DefaultPath; |
164 |
labelID2ProjectName.Text = _ProjectInfo.Name; |
165 |
labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Blue; |
166 |
labelID2ProjectStatus.Text = Msg.ConnectionSuccessful; |
167 |
labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Blue; |
168 |
layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
169 |
layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; |
170 |
} |
171 |
else |
172 |
{ |
173 |
_ProjectInfo.Enable = false; |
174 |
btnID2Project.Text = ""; |
175 |
labelID2ProjectName.Text = " "; |
176 |
labelID2ProjectName.AppearanceItemCaption.ForeColor = Color.Red; |
177 |
labelID2ProjectStatus.Text = Msg.ConnectionFail; |
178 |
labelID2ProjectStatus.AppearanceItemCaption.ForeColor = Color.Red; |
179 |
layoutControlGroupSPPIDDB.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
180 |
layoutControlGroupItemMapping.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; |
181 |
} |
182 |
|
183 |
InitMapping(); |
184 |
InitSPPIDDB(); |
185 |
|
186 |
return _ProjectInfo.Enable; |
187 |
} |
188 |
|
189 |
private void InitMapping() |
190 |
{ |
191 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
192 |
if (_ProjectInfo.Enable) |
193 |
{ |
194 |
InitID2Symbol(); |
195 |
InitID2Line(); |
196 |
InitID2LineNumber(); |
197 |
InitID2Association(); |
198 |
|
199 |
InitETCSetting(); |
200 |
} |
201 |
} |
202 |
private void InitETCSetting() |
203 |
{ |
204 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
205 |
if (_ProjectInfo.Enable) |
206 |
{ |
207 |
DataTable dt = Project_DB.SelectETCSetting(); |
208 |
if (dt.Columns.Count > 0 && dt.Rows.Count > 0) |
209 |
SPPIDUtil.ConvertToETCSetting(dt.Rows[0][0].ToString()); |
210 |
else |
211 |
SPPID_DBInfo.Clear(); |
212 |
} |
213 |
} |
214 |
|
215 |
private void InitID2Symbol() |
216 |
{ |
217 |
using (DataTable symbolDT = Project_DB.SelectProjectSymbol()) |
218 |
{ |
219 |
symbolMappings.Clear(); |
220 |
_ID2SymbolDT = symbolDT; |
221 |
_ID2SymbolDT.Columns.Add("Clear"); |
222 |
_ID2SymbolDT.Columns["Clear"].Caption = ""; |
223 |
foreach (DataRow row in symbolDT.Rows) |
224 |
{ |
225 |
symbolMappings.Add(new SymbolMapping() |
226 |
{ |
227 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
228 |
SYMBOLNAME = row["Name"] == null ? "" : row["Name"].ToString(), |
229 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(), |
230 |
}); |
231 |
} |
232 |
} |
233 |
} |
234 |
|
235 |
private void InitID2Line() |
236 |
{ |
237 |
using (DataTable lineTypes = Project_DB.SelectProjectLine()) |
238 |
{ |
239 |
lineMappings.Clear(); |
240 |
_ID2LineDT.Rows.Clear(); |
241 |
foreach (DataRow row in lineTypes.Rows) |
242 |
{ |
243 |
DataRow newRow = _ID2LineDT.NewRow(); |
244 |
newRow["UID"] = row["UID"] == null ? "" : row["UID"].ToString(); |
245 |
newRow["Name"] = row["Name"] == null ? "" : row["Name"].ToString(); |
246 |
newRow["Type"] = "Line"; |
247 |
newRow["SPPID_SYMBOL_PATH"] = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(); |
248 |
_ID2LineDT.Rows.Add(newRow); |
249 |
|
250 |
lineMappings.Add(new LineMapping() |
251 |
{ |
252 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
253 |
LINENAME = row["Name"] == null ? "" : row["Name"].ToString(), |
254 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString(), |
255 |
}); |
256 |
} |
257 |
} |
258 |
} |
259 |
|
260 |
private void InitID2LineNumber() |
261 |
{ |
262 |
using (DataTable linePropertiesDT = Project_DB.SelectProjectLineProperties()) |
263 |
{ |
264 |
lineNumberMappings.Clear(); |
265 |
_ID2LinePropertyDT = linePropertiesDT; |
266 |
_ID2LinePropertyDT.Columns.Add("Type"); |
267 |
foreach (DataRow row in linePropertiesDT.Rows) |
268 |
{ |
269 |
row["Type"] = "Line Property"; |
270 |
lineNumberMappings.Add(new LineNumberMapping() |
271 |
{ |
272 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
273 |
DisplayName = row["DisplayName"] == null ? "" : row["DisplayName"].ToString(), |
274 |
SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(), |
275 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString() |
276 |
}); |
277 |
} |
278 |
} |
279 |
} |
280 |
|
281 |
private void InitID2Association() |
282 |
{ |
283 |
using (DataTable associationDT = Project_DB.SelectProjectAssociation()) |
284 |
{ |
285 |
associationMappings.Clear(); |
286 |
_ID2AssociationDT = associationDT; |
287 |
_ID2AssociationDT.Columns.Add("Clear"); |
288 |
_ID2AssociationDT.Columns["Clear"].Caption = ""; |
289 |
foreach (DataRow row in associationDT.Rows) |
290 |
{ |
291 |
associationMappings.Add(new AssociationMapping() |
292 |
{ |
293 |
UID = row["UID"] == null ? "" : row["UID"].ToString(), |
294 |
DisplayAttribute = row["DisplayAttribute"] == null ? "" : row["DisplayAttribute"].ToString(), |
295 |
Type = row["Type"] == null ? "" : row["Type"].ToString(), |
296 |
SPPIDATTRIBUTENAME = row["SPPID_ATTRIBUTE"] == null ? "" : row["SPPID_ATTRIBUTE"].ToString(), |
297 |
SPPIDSYMBOLNAME = row["SPPID_SYMBOL_PATH"] == null ? "" : row["SPPID_SYMBOL_PATH"].ToString() |
298 |
}); |
299 |
} |
300 |
} |
301 |
} |
302 |
|
303 |
private void InitSPPIDDB() |
304 |
{ |
305 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
306 |
if (_ProjectInfo.Enable) |
307 |
{ |
308 |
DataTable dt = Project_DB.SelectSPPID_DB_INFO(); |
309 |
if (dt.Columns.Count > 0 && dt.Rows.Count > 0) |
310 |
SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString()); |
311 |
else |
312 |
SPPID_DBInfo.Clear(); |
313 |
} |
314 |
|
315 |
templateComboBox.Items.Clear(); |
316 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
317 |
if (_SPPIDInfo.Enable) |
318 |
{ |
319 |
labelSPPIDPlantName.Text = _SPPIDInfo.SelectedPlant; |
320 |
labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Blue; |
321 |
labelSPPIDDBStatus.Text = Msg.ConnectionSuccessful; |
322 |
labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Blue; |
323 |
|
324 |
string TemplatePath = SPPID_DB.GetPlantPID_T_OPTIONSETTING_Value("PID Template Path"); |
325 |
if (!string.IsNullOrEmpty(TemplatePath)) |
326 |
templateComboBox.Items.AddRange(Directory.GetFiles(TemplatePath, "*.pid").ToList().Select(filePath => Path.GetFileName(filePath)).ToList()); |
327 |
|
328 |
_SPPIDUnitDT = SPPID_DB.GetUnitTree(); |
329 |
|
330 |
layoutControlGroupAutoConverter.Enabled = true; |
331 |
} |
332 |
else |
333 |
{ |
334 |
labelSPPIDPlantName.Text = " "; |
335 |
labelSPPIDPlantName.AppearanceItemCaption.ForeColor = Color.Red; |
336 |
labelSPPIDDBStatus.Text = Msg.ConnectionFail; |
337 |
labelSPPIDDBStatus.AppearanceItemCaption.ForeColor = Color.Red; |
338 |
|
339 |
layoutControlGroupAutoConverter.Enabled = false; |
340 |
} |
341 |
|
342 |
_DicDocuments.Clear(); |
343 |
_ConverterDT.Rows.Clear(); |
344 |
InitSPPIDSymbolTreeTable(); |
345 |
} |
346 |
|
347 |
private void InitSPPIDSymbolTreeTable() |
348 |
{ |
349 |
SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
350 |
|
351 |
_SPPIDSymbolPathDT = new DataTable(); |
352 |
_SPPIDSymbolPathDT.Columns.Add("ID"); |
353 |
_SPPIDSymbolPathDT.Columns.Add("Parent"); |
354 |
_SPPIDSymbolPathDT.Columns.Add("Name"); |
355 |
_SPPIDSymbolPathDT.Columns.Add("FullPath"); |
356 |
|
357 |
if (_SPPIDInfo.Enable) |
358 |
{ |
359 |
string symbolPath = SPPID_DB.GetPlantPID_T_OPTIONSETTING_Value("Catalog Explorer root path"); |
360 |
DirectoryInfo info = new DirectoryInfo(symbolPath); |
361 |
_SPPIDSymbolPathDT.Rows.Add(new object[] { "0", "-1", info.Name }); |
362 |
loop(info, "0", symbolPath); |
363 |
} |
364 |
} |
365 |
|
366 |
private void loop(DirectoryInfo parentInfo, string parentUID, string defaultPath) |
367 |
{ |
368 |
DirectoryInfo[] infos = parentInfo.GetDirectories(); |
369 |
foreach (DirectoryInfo info in infos) |
370 |
{ |
371 |
string uid = Guid.NewGuid().ToString(); |
372 |
_SPPIDSymbolPathDT.Rows.Add(new object[] { uid, parentUID, info.Name }); |
373 |
loop(info, uid, defaultPath); |
374 |
|
375 |
FileInfo[] files = info.GetFiles("*.sym"); |
376 |
foreach (FileInfo fileInfo in files) |
377 |
{ |
378 |
_SPPIDSymbolPathDT.Rows.Add(new object[] { Guid.NewGuid().ToString(), uid, fileInfo.Name, fileInfo.FullName.Replace(defaultPath, "") }); |
379 |
} |
380 |
} |
381 |
} |
382 |
|
383 |
private void btnLoadFile_Click(object sender, EventArgs e) |
384 |
{ |
385 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
386 |
if (!_ProjectInfo.Enable) |
387 |
{ |
388 |
MessageBox.Show(Msg.PleaseSetID2ProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
389 |
return; |
390 |
} |
391 |
|
392 |
xtraOpenFileDialog.InitialDirectory = _ProjectInfo.TempDirPath; |
393 |
if (xtraOpenFileDialog.ShowDialog() == DialogResult.OK) |
394 |
{ |
395 |
foreach (string fileName in xtraOpenFileDialog.FileNames) |
396 |
{ |
397 |
SPPID_Document document = new SPPID_Document(fileName); |
398 |
document.SymbolMappings = symbolMappings; |
399 |
DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName)); |
400 |
DataRow row; |
401 |
if (rows.Length == 0) |
402 |
{ |
403 |
row = _ConverterDT.NewRow(); |
404 |
row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName); |
405 |
row["colDrawingFilePath"] = fileName; |
406 |
row["colDrawingNumber"] = document.DWGNAME; |
407 |
row["colDrawingName"] = document.DWGNAME; |
408 |
if (document.Enable) |
409 |
row["colStatus"] = "Ready"; |
410 |
else |
411 |
row["colStatus"] = "Error"; |
412 |
row["colUID"] = ""; |
413 |
_ConverterDT.Rows.Add(row); |
414 |
} |
415 |
if (!_DicDocuments.ContainsKey(fileName)) |
416 |
_DicDocuments.Add(fileName, null); |
417 |
|
418 |
_DicDocuments[fileName] = document; |
419 |
} |
420 |
} |
421 |
} |
422 |
|
423 |
private void btnRun_Click(object sender, EventArgs e) |
424 |
{ |
425 |
DialogResult = DialogResult.OK; |
426 |
} |
427 |
|
428 |
private void btnSPPIDDB_Click(object sender, EventArgs e) |
429 |
{ |
430 |
SPPID_DB_SettingForm form = new SPPID_DB_SettingForm(); |
431 |
if (form.ShowDialog() == DialogResult.OK) |
432 |
InitSPPIDDB(); |
433 |
} |
434 |
|
435 |
private void btnItemMapping_Click(object sender, EventArgs e) |
436 |
{ |
437 |
Project_Info _ProjectInfo = Project_Info.GetInstance(); |
438 |
if (!_ProjectInfo.Enable) |
439 |
{ |
440 |
MessageBox.Show(Msg.PleaseSetID2ProjectInfo, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
441 |
return; |
442 |
} |
443 |
|
444 |
MappingForm form = new MappingForm(_ID2SymbolDT,_SPPIDSymbolPathDT, _ID2LineDT, _ID2LinePropertyDT, _ID2AssociationDT); |
445 |
form.ShowDialog(); |
446 |
InitMapping(); |
447 |
} |
448 |
|
449 |
} |
450 |
} |