프로젝트

일반

사용자정보

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

hytos / DTI_PID / APIDConverter / Form / APIDConverter.cs @ 128c844f

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