프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / APIDConverter / Form / APIDConverter.cs @ 5e0ecbf8

이력 | 보기 | 이력해설 | 다운로드 (11.8 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 d327a608 gaqhf
                ID2SymbolTypeTable = Project_DB.SelectSymbolType();
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 c7db500b gaqhf
            DataTable tDrawing = Project_DB.SelectDrawings();
200
            Documents.Clear();
201
            foreach (int rowHandle in gridViewConverter.GetSelectedRows())
202
            {
203
                string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath");
204 e49e1de9 gaqhf
                string _ID = gridViewConverter.GetRowCellValue(rowHandle, "colTemplate").ToString();
205
                string _TemplateName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
206
                string _DrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber");
207
                string _SheetNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colSheetNumber");
208 c7db500b gaqhf
209
                DataRow[] rows = tDrawing.Select(string.Format("NAME = '{0}'", Path.GetFileNameWithoutExtension(_FilePath) + ".png"));
210
                if (rows.Length != 1)
211
                    continue;
212
213
                Document document = _DicDocuments[_FilePath];
214
                document.UID = rows[0]["UID"].ToString();
215 e49e1de9 gaqhf
                document.AvevaDrawingNumber = _DrawingNumber;
216
                document.AvevaSheetNumber = _SheetNumber;
217
                document.AvevaTemplateID = _ID;
218
                document.AvevaTemplateName = _TemplateName;
219 a999464f gaqhf
                // validation check
220 b90890eb gaqhf
                if (document.SetAvevaInfo(symbolMappingTable, lineMappingTable))
221 a999464f gaqhf
                    Documents.Add(document);
222 c7db500b gaqhf
            }
223
224 b90890eb gaqhf
            symbolMappingTable.Dispose();
225 a999464f gaqhf
            lineMappingTable.Dispose();
226
227
            if (Documents.Count > 0)
228
            {
229
                DialogResult = DialogResult.OK;
230
            }
231
            else
232
            {
233
234
            }
235 c7db500b gaqhf
        }
236
237
        private void btnRefresh_Click(object sender, EventArgs e)
238
        {
239
            foreach (DataRow row in _ConverterDT.Rows)
240
            {
241
                string fileName = row["colDrawingFilePath"].ToString();
242
                Document document = new Document(fileName, ID2SymbolTypeTable);
243
244
                if (document.Enable)
245
                    row["colStatus"] = "Ready";
246
                else
247
                    row["colStatus"] = "Error";
248
249
                if (!_DicDocuments.ContainsKey(fileName))
250
                    _DicDocuments.Add(fileName, null);
251
252
                _DicDocuments[fileName] = document;
253
254
                if (document.Enable)
255
                    gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
256
            }
257
        }
258 e4ad75cb gaqhf
259
        private void btnID2DB_Click(object sender, EventArgs e)
260
        {
261
            ProjectForm form = new ProjectForm();
262
            if (form.ShowDialog() == DialogResult.OK)
263
            {
264
                Project_Info _ProjectInfo = Project_Info.GetInstance();
265
                _ProjectInfo.DefaultPath = Settings.Default.ProjectPath;
266
                _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType;
267
                _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP;
268
                _ProjectInfo.Port = Settings.Default.ProjectPort;
269
                _ProjectInfo.DBUser = Settings.Default.ProjectDBUser;
270
                _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword;
271
272
                if (Project_DB.ConnTestAndCreateTable())
273
                {
274
                    _ProjectInfo.Enable = true;
275
                    MessageBox.Show("Success project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Information);
276
                }
277
                else
278
                {
279
                    _ProjectInfo.Enable = false;
280
                    MessageBox.Show("Fail project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
281
                }
282
            }
283
        }
284
285
        private void btnItemMapping_Click(object sender, EventArgs e)
286
        {
287
            MappingForm form = new MappingForm();
288
            if (form.ShowDialog() == DialogResult.OK)
289
            {
290
291
            }
292
        }
293 74a0c9d6 gaqhf
    }
294
}
클립보드 이미지 추가 (최대 크기: 500 MB)