hytos / DTI_PID / APIDConverter / Form / APIDConverter.cs @ 0169b3c7
이력 | 보기 | 이력해설 | 다운로드 (6.72 KB)
1 | 74a0c9d6 | gaqhf | 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 | d327a608 | gaqhf | using DevExpress.XtraEditors.Repository; |
11 | using DevExpress.XtraEditors.Controls; |
||
12 | using DevExpress.XtraEditors; |
||
13 | using System.Globalization; |
||
14 | using System.Threading; |
||
15 | using System.IO; |
||
16 | fdb1367e | gaqhf | using AVEVA.PID.CustomizationUtility.DB; |
17 | using AVEVA.PID.CustomizationUtility.Model; |
||
18 | using AVEVA.PID.CustomizationUtility.Properties; |
||
19 | 74a0c9d6 | gaqhf | |
20 | namespace AVEVA.PID.CustomizationUtility |
||
21 | { |
||
22 | e3ced1c9 | gaqhf | public partial class APIDConverter : DevExpress.XtraBars.Ribbon.RibbonForm |
23 | 74a0c9d6 | gaqhf | { |
24 | public APIDConverter() |
||
25 | { |
||
26 | InitializeComponent(); |
||
27 | d327a608 | gaqhf | InitUsedDataTable(); |
28 | InitGridControl(); |
||
29 | 74a0c9d6 | gaqhf | } |
30 | |||
31 | 465c8b6e | gaqhf | DataTable ID2SymbolTypeTable = null; |
32 | d327a608 | gaqhf | private DataTable _ConverterDT = new DataTable(); |
33 | public List<Document> Documents = new List<Document>(); |
||
34 | c7db500b | gaqhf | private Dictionary<string, Document> _DicDocuments = new Dictionary<string, Document>(); |
35 | d327a608 | gaqhf | |
36 | private void InitUsedDataTable() |
||
37 | { |
||
38 | // Converter Table |
||
39 | DataColumn col = _ConverterDT.Columns.Add("colDrawingFileName"); |
||
40 | col.Caption = "Drawing File Name"; |
||
41 | col = _ConverterDT.Columns.Add("colDrawingFilePath"); |
||
42 | col.Caption = "DrawingFilePath"; |
||
43 | col = _ConverterDT.Columns.Add("colStatus"); |
||
44 | col.Caption = "Status"; |
||
45 | col = _ConverterDT.Columns.Add("colUID"); |
||
46 | } |
||
47 | |||
48 | private void InitGridControl() |
||
49 | { |
||
50 | #region Converter Page |
||
51 | gridViewConverter.OptionsSelection.MultiSelect = true; |
||
52 | gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect; |
||
53 | |||
54 | gridControlConverter.DataSource = _ConverterDT; |
||
55 | |||
56 | gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false; |
||
57 | gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false; |
||
58 | gridViewConverter.Columns["colDrawingFilePath"].Visible = false; |
||
59 | gridViewConverter.Columns["colUID"].Visible = false; |
||
60 | |||
61 | gridViewConverter.BestFitColumns(); |
||
62 | #endregion |
||
63 | } |
||
64 | |||
65 | 465c8b6e | gaqhf | |
66 | fdb1367e | gaqhf | private void btnLoadFile_Click(object sender, EventArgs e) |
67 | 74a0c9d6 | gaqhf | { |
68 | fdb1367e | gaqhf | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
69 | |||
70 | OpenFileDialog dia = new OpenFileDialog(); |
||
71 | dia.Filter = "Xml Files(*.xml)|*.xml"; |
||
72 | dia.InitialDirectory = _ProjectInfo.TempDirPath; |
||
73 | dia.Multiselect = true; |
||
74 | |||
75 | if (dia.ShowDialog() == DialogResult.OK) |
||
76 | { |
||
77 | foreach (var fileName in dia.FileNames) |
||
78 | { |
||
79 | 465c8b6e | gaqhf | Document document = new Document(fileName, ID2SymbolTypeTable); |
80 | c7db500b | gaqhf | |
81 | DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName)); |
||
82 | if (rows.Length == 0) |
||
83 | d327a608 | gaqhf | { |
84 | c7db500b | gaqhf | DataRow row = _ConverterDT.NewRow(); |
85 | row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName); |
||
86 | row["colDrawingFilePath"] = fileName; |
||
87 | if (document.Enable) |
||
88 | row["colStatus"] = "Ready"; |
||
89 | else |
||
90 | row["colStatus"] = "Error"; |
||
91 | row["colUID"] = ""; |
||
92 | |||
93 | _ConverterDT.Rows.Add(row); |
||
94 | |||
95 | if (document.Enable) |
||
96 | gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
||
97 | d327a608 | gaqhf | } |
98 | c7db500b | gaqhf | else |
99 | { |
||
100 | foreach (DataRow row in rows) |
||
101 | { |
||
102 | if (document.Enable) |
||
103 | row["colStatus"] = "Ready"; |
||
104 | else |
||
105 | row["colStatus"] = "Error"; |
||
106 | |||
107 | if (document.Enable) |
||
108 | gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | if (!_DicDocuments.ContainsKey(fileName)) |
||
113 | _DicDocuments.Add(fileName, null); |
||
114 | |||
115 | _DicDocuments[fileName] = document; |
||
116 | fdb1367e | gaqhf | } |
117 | } |
||
118 | 74a0c9d6 | gaqhf | } |
119 | 8562d7dc | gaqhf | |
120 | private void APIDConverter_Load(object sender, EventArgs e) |
||
121 | { |
||
122 | Project_Info project = Project_Info.GetInstance(); |
||
123 | if (!project.Enable) |
||
124 | { |
||
125 | MessageBox.Show("Check Project Setting!", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
126 | d327a608 | gaqhf | DialogResult = DialogResult.Cancel; |
127 | 8562d7dc | gaqhf | } |
128 | 465c8b6e | gaqhf | else |
129 | { |
||
130 | d327a608 | gaqhf | ID2SymbolTypeTable = Project_DB.SelectSymbolType(); |
131 | 465c8b6e | gaqhf | } |
132 | 8562d7dc | gaqhf | } |
133 | c7db500b | gaqhf | |
134 | private void btnRun_Click(object sender, EventArgs e) |
||
135 | { |
||
136 | if (gridViewConverter.GetSelectedRows().Length == 0) |
||
137 | { |
||
138 | MessageBox.Show("Select Document", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
139 | return; |
||
140 | } |
||
141 | |||
142 | DataTable tDrawing = Project_DB.SelectDrawings(); |
||
143 | Documents.Clear(); |
||
144 | foreach (int rowHandle in gridViewConverter.GetSelectedRows()) |
||
145 | { |
||
146 | string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath"); |
||
147 | |||
148 | DataRow[] rows = tDrawing.Select(string.Format("NAME = '{0}'", Path.GetFileNameWithoutExtension(_FilePath) + ".png")); |
||
149 | if (rows.Length != 1) |
||
150 | continue; |
||
151 | |||
152 | Document document = _DicDocuments[_FilePath]; |
||
153 | document.UID = rows[0]["UID"].ToString(); |
||
154 | Documents.Add(document); |
||
155 | } |
||
156 | |||
157 | DialogResult = DialogResult.OK; |
||
158 | } |
||
159 | |||
160 | private void btnRefresh_Click(object sender, EventArgs e) |
||
161 | { |
||
162 | foreach (DataRow row in _ConverterDT.Rows) |
||
163 | { |
||
164 | string fileName = row["colDrawingFilePath"].ToString(); |
||
165 | Document document = new Document(fileName, ID2SymbolTypeTable); |
||
166 | |||
167 | if (document.Enable) |
||
168 | row["colStatus"] = "Ready"; |
||
169 | else |
||
170 | row["colStatus"] = "Error"; |
||
171 | |||
172 | if (!_DicDocuments.ContainsKey(fileName)) |
||
173 | _DicDocuments.Add(fileName, null); |
||
174 | |||
175 | _DicDocuments[fileName] = document; |
||
176 | |||
177 | if (document.Enable) |
||
178 | gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
||
179 | } |
||
180 | } |
||
181 | 74a0c9d6 | gaqhf | } |
182 | } |