프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / APIDConverter / Form / APIDConverter.cs @ 69b97ac0

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