hytos / DTI_PID / APIDConverter / Form / APIDConverter.cs @ 4622d687
이력 | 보기 | 이력해설 | 다운로드 (11.9 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 | 04c6def2 | gaqhf | col = _ConverterDT.Columns.Add("colTemplate"); |
44 | col.Caption = "Template"; |
||
45 | col = _ConverterDT.Columns.Add("colDrawingNumber"); |
||
46 | col.Caption = "Drawing Number"; |
||
47 | col = _ConverterDT.Columns.Add("colSheetNumber"); |
||
48 | col.Caption = "Sheet Number"; |
||
49 | d327a608 | gaqhf | col = _ConverterDT.Columns.Add("colStatus"); |
50 | col.Caption = "Status"; |
||
51 | col = _ConverterDT.Columns.Add("colUID"); |
||
52 | } |
||
53 | |||
54 | private void InitGridControl() |
||
55 | { |
||
56 | #region Converter Page |
||
57 | gridViewConverter.OptionsSelection.MultiSelect = true; |
||
58 | gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect; |
||
59 | |||
60 | gridControlConverter.DataSource = _ConverterDT; |
||
61 | |||
62 | gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false; |
||
63 | gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false; |
||
64 | gridViewConverter.Columns["colDrawingFilePath"].Visible = false; |
||
65 | gridViewConverter.Columns["colUID"].Visible = false; |
||
66 | |||
67 | gridViewConverter.BestFitColumns(); |
||
68 | #endregion |
||
69 | 04c6def2 | gaqhf | |
70 | #region set lookUpEdit |
||
71 | DataTable templateTable = Project_DB.GetDrawingTemplate(); |
||
72 | RepositoryItemGridLookUpEdit lookUpEdit = new RepositoryItemGridLookUpEdit(); |
||
73 | lookUpEdit.BeginInit(); |
||
74 | lookUpEdit.DataSource = templateTable; |
||
75 | lookUpEdit.DisplayMember = "Name"; |
||
76 | lookUpEdit.ValueMember = "ID"; |
||
77 | lookUpEdit.NullText = ""; |
||
78 | lookUpEdit.BestFitMode = BestFitMode.BestFitResizePopup; |
||
79 | lookUpEdit.EndInit(); |
||
80 | |||
81 | lookUpEdit.View.OptionsBehavior.AutoPopulateColumns = false; |
||
82 | DevExpress.XtraGrid.Columns.GridColumn colName = lookUpEdit.View.Columns.AddField("Name"); |
||
83 | colName.VisibleIndex = 0; |
||
84 | DevExpress.XtraGrid.Columns.GridColumn colDate = lookUpEdit.View.Columns.AddField("DateCreation"); |
||
85 | colDate.VisibleIndex = 1; |
||
86 | DevExpress.XtraGrid.Columns.GridColumn colMachineName = lookUpEdit.View.Columns.AddField("MachineName"); |
||
87 | colMachineName.VisibleIndex = 2; |
||
88 | |||
89 | gridControlConverter.RepositoryItems.Add(lookUpEdit); |
||
90 | gridViewConverter.Columns["colTemplate"].ColumnEdit = lookUpEdit; |
||
91 | #endregion |
||
92 | d327a608 | gaqhf | } |
93 | |||
94 | fdb1367e | gaqhf | private void btnLoadFile_Click(object sender, EventArgs e) |
95 | 74a0c9d6 | gaqhf | { |
96 | fdb1367e | gaqhf | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
97 | |||
98 | OpenFileDialog dia = new OpenFileDialog(); |
||
99 | dia.Filter = "Xml Files(*.xml)|*.xml"; |
||
100 | dia.InitialDirectory = _ProjectInfo.TempDirPath; |
||
101 | dia.Multiselect = true; |
||
102 | |||
103 | if (dia.ShowDialog() == DialogResult.OK) |
||
104 | { |
||
105 | 128c844f | gaqhf | DataTable drawingTable = Project_DB.SelectDrawingTable(); |
106 | |||
107 | fdb1367e | gaqhf | foreach (var fileName in dia.FileNames) |
108 | { |
||
109 | 465c8b6e | gaqhf | Document document = new Document(fileName, ID2SymbolTypeTable); |
110 | c7db500b | gaqhf | |
111 | DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName)); |
||
112 | if (rows.Length == 0) |
||
113 | d327a608 | gaqhf | { |
114 | c7db500b | gaqhf | DataRow row = _ConverterDT.NewRow(); |
115 | 128c844f | gaqhf | string drawingName = Path.GetFileNameWithoutExtension(fileName); |
116 | row["colDrawingFileName"] = drawingName; |
||
117 | c7db500b | gaqhf | row["colDrawingFilePath"] = fileName; |
118 | if (document.Enable) |
||
119 | row["colStatus"] = "Ready"; |
||
120 | else |
||
121 | row["colStatus"] = "Error"; |
||
122 | row["colUID"] = ""; |
||
123 | |||
124 | 128c844f | gaqhf | row["colDrawingNumber"] = drawingName; |
125 | row["colSheetNumber"] = GetSheetNumber(drawingTable, drawingName); |
||
126 | |||
127 | c7db500b | gaqhf | _ConverterDT.Rows.Add(row); |
128 | |||
129 | if (document.Enable) |
||
130 | gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
||
131 | d327a608 | gaqhf | } |
132 | c7db500b | gaqhf | else |
133 | { |
||
134 | foreach (DataRow row in rows) |
||
135 | { |
||
136 | if (document.Enable) |
||
137 | row["colStatus"] = "Ready"; |
||
138 | else |
||
139 | row["colStatus"] = "Error"; |
||
140 | |||
141 | if (document.Enable) |
||
142 | gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
||
143 | } |
||
144 | } |
||
145 | |||
146 | if (!_DicDocuments.ContainsKey(fileName)) |
||
147 | _DicDocuments.Add(fileName, null); |
||
148 | |||
149 | _DicDocuments[fileName] = document; |
||
150 | fdb1367e | gaqhf | } |
151 | } |
||
152 | 74a0c9d6 | gaqhf | } |
153 | 8562d7dc | gaqhf | |
154 | 128c844f | gaqhf | private string GetSheetNumber(DataTable drawingTable, string drawingName) |
155 | { |
||
156 | string result = string.Empty; |
||
157 | List<DataRow> rows = drawingTable.Select(string.Format("XDNLABEL = '{0}'", drawingName)).ToList(); |
||
158 | if (rows.Count != 0) |
||
159 | { |
||
160 | int index = 1; |
||
161 | while (true) |
||
162 | { |
||
163 | DataRow row = rows.Find(x => !DBNull.Value.Equals(x["XDSLABEL"]) && x["XDSLABEL"].ToString() == index.ToString()); |
||
164 | if (row == null) |
||
165 | { |
||
166 | result = index.ToString(); |
||
167 | break; |
||
168 | } |
||
169 | 5e0ecbf8 | gaqhf | index++; |
170 | 128c844f | gaqhf | } |
171 | } |
||
172 | return result; |
||
173 | } |
||
174 | |||
175 | 8562d7dc | gaqhf | private void APIDConverter_Load(object sender, EventArgs e) |
176 | { |
||
177 | Project_Info project = Project_Info.GetInstance(); |
||
178 | if (!project.Enable) |
||
179 | { |
||
180 | MessageBox.Show("Check Project Setting!", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
181 | d327a608 | gaqhf | DialogResult = DialogResult.Cancel; |
182 | 8562d7dc | gaqhf | } |
183 | 465c8b6e | gaqhf | else |
184 | { |
||
185 | 4622d687 | gaqhf | ID2SymbolTypeTable = Project_DB.GetSymbolType(); |
186 | 465c8b6e | gaqhf | } |
187 | 8562d7dc | gaqhf | } |
188 | c7db500b | gaqhf | |
189 | private void btnRun_Click(object sender, EventArgs e) |
||
190 | { |
||
191 | if (gridViewConverter.GetSelectedRows().Length == 0) |
||
192 | { |
||
193 | MessageBox.Show("Select Document", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
194 | return; |
||
195 | } |
||
196 | |||
197 | b90890eb | gaqhf | DataTable symbolMappingTable = Project_DB.GetSymbolMappingTable(); |
198 | a999464f | gaqhf | DataTable lineMappingTable = Project_DB.GetLineMappingTable(); |
199 | ff4941b2 | gaqhf | DataTable opcMappingTable = Project_DB.GetOPCMappingTable(); |
200 | 4622d687 | gaqhf | DataTable tDrawing = Project_DB.GetDrawings(); |
201 | c7db500b | gaqhf | Documents.Clear(); |
202 | foreach (int rowHandle in gridViewConverter.GetSelectedRows()) |
||
203 | { |
||
204 | string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath"); |
||
205 | e49e1de9 | gaqhf | string _ID = gridViewConverter.GetRowCellValue(rowHandle, "colTemplate").ToString(); |
206 | string _TemplateName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate"); |
||
207 | string _DrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber"); |
||
208 | string _SheetNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colSheetNumber"); |
||
209 | c7db500b | gaqhf | |
210 | DataRow[] rows = tDrawing.Select(string.Format("NAME = '{0}'", Path.GetFileNameWithoutExtension(_FilePath) + ".png")); |
||
211 | if (rows.Length != 1) |
||
212 | continue; |
||
213 | |||
214 | Document document = _DicDocuments[_FilePath]; |
||
215 | document.UID = rows[0]["UID"].ToString(); |
||
216 | e49e1de9 | gaqhf | document.AvevaDrawingNumber = _DrawingNumber; |
217 | document.AvevaSheetNumber = _SheetNumber; |
||
218 | document.AvevaTemplateID = _ID; |
||
219 | document.AvevaTemplateName = _TemplateName; |
||
220 | a999464f | gaqhf | // validation check |
221 | ff4941b2 | gaqhf | if (document.SetAvevaInfo(symbolMappingTable, lineMappingTable, opcMappingTable)) |
222 | a999464f | gaqhf | Documents.Add(document); |
223 | c7db500b | gaqhf | } |
224 | |||
225 | b90890eb | gaqhf | symbolMappingTable.Dispose(); |
226 | a999464f | gaqhf | lineMappingTable.Dispose(); |
227 | ff4941b2 | gaqhf | opcMappingTable.Dispose(); |
228 | a999464f | gaqhf | |
229 | if (Documents.Count > 0) |
||
230 | { |
||
231 | DialogResult = DialogResult.OK; |
||
232 | } |
||
233 | else |
||
234 | { |
||
235 | |||
236 | } |
||
237 | c7db500b | gaqhf | } |
238 | |||
239 | private void btnRefresh_Click(object sender, EventArgs e) |
||
240 | { |
||
241 | foreach (DataRow row in _ConverterDT.Rows) |
||
242 | { |
||
243 | string fileName = row["colDrawingFilePath"].ToString(); |
||
244 | Document document = new Document(fileName, ID2SymbolTypeTable); |
||
245 | |||
246 | if (document.Enable) |
||
247 | row["colStatus"] = "Ready"; |
||
248 | else |
||
249 | row["colStatus"] = "Error"; |
||
250 | |||
251 | if (!_DicDocuments.ContainsKey(fileName)) |
||
252 | _DicDocuments.Add(fileName, null); |
||
253 | |||
254 | _DicDocuments[fileName] = document; |
||
255 | |||
256 | if (document.Enable) |
||
257 | gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
||
258 | } |
||
259 | } |
||
260 | e4ad75cb | gaqhf | |
261 | private void btnID2DB_Click(object sender, EventArgs e) |
||
262 | { |
||
263 | ProjectForm form = new ProjectForm(); |
||
264 | if (form.ShowDialog() == DialogResult.OK) |
||
265 | { |
||
266 | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
||
267 | _ProjectInfo.DefaultPath = Settings.Default.ProjectPath; |
||
268 | _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType; |
||
269 | _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP; |
||
270 | _ProjectInfo.Port = Settings.Default.ProjectPort; |
||
271 | _ProjectInfo.DBUser = Settings.Default.ProjectDBUser; |
||
272 | _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword; |
||
273 | |||
274 | if (Project_DB.ConnTestAndCreateTable()) |
||
275 | { |
||
276 | _ProjectInfo.Enable = true; |
||
277 | MessageBox.Show("Success project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
278 | } |
||
279 | else |
||
280 | { |
||
281 | _ProjectInfo.Enable = false; |
||
282 | MessageBox.Show("Fail project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error); |
||
283 | } |
||
284 | } |
||
285 | } |
||
286 | |||
287 | private void btnItemMapping_Click(object sender, EventArgs e) |
||
288 | { |
||
289 | MappingForm form = new MappingForm(); |
||
290 | if (form.ShowDialog() == DialogResult.OK) |
||
291 | { |
||
292 | |||
293 | } |
||
294 | } |
||
295 | 74a0c9d6 | gaqhf | } |
296 | } |