프로젝트

일반

사용자정보

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

hytos / DTI_PID / APIDConverter / Form / APIDConverter.cs @ b90890eb

이력 | 보기 | 이력해설 | 다운로드 (10.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
                foreach (var fileName in dia.FileNames)
106
                {
107 465c8b6e gaqhf
                    Document document = new Document(fileName, ID2SymbolTypeTable);
108 c7db500b gaqhf
109
                    DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName));
110
                    if (rows.Length == 0)
111 d327a608 gaqhf
                    {
112 c7db500b gaqhf
                        DataRow row = _ConverterDT.NewRow();
113
                        row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName);
114
                        row["colDrawingFilePath"] = fileName;
115
                        if (document.Enable)
116
                            row["colStatus"] = "Ready";
117
                        else
118
                            row["colStatus"] = "Error";
119
                        row["colUID"] = "";
120
121
                        _ConverterDT.Rows.Add(row);
122
123
                        if (document.Enable)
124
                            gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
125 d327a608 gaqhf
                    }
126 c7db500b gaqhf
                    else
127
                    {
128
                        foreach (DataRow row in rows)
129
                        {
130
                            if (document.Enable)
131
                                row["colStatus"] = "Ready";
132
                            else
133
                                row["colStatus"] = "Error";
134
                           
135
                            if (document.Enable)
136
                                gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
137
                        }
138
                    }
139
140
                    if (!_DicDocuments.ContainsKey(fileName))
141
                        _DicDocuments.Add(fileName, null);
142
143
                    _DicDocuments[fileName] = document;
144 fdb1367e gaqhf
                }
145
            }
146 74a0c9d6 gaqhf
        }
147 8562d7dc gaqhf
148
        private void APIDConverter_Load(object sender, EventArgs e)
149
        {
150
            Project_Info project = Project_Info.GetInstance();
151
            if (!project.Enable)
152
            {
153
                MessageBox.Show("Check Project Setting!", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning);
154 d327a608 gaqhf
                DialogResult = DialogResult.Cancel;
155 8562d7dc gaqhf
            }
156 465c8b6e gaqhf
            else
157
            {
158 d327a608 gaqhf
                ID2SymbolTypeTable = Project_DB.SelectSymbolType();
159 465c8b6e gaqhf
            }
160 8562d7dc gaqhf
        }
161 c7db500b gaqhf
162
        private void btnRun_Click(object sender, EventArgs e)
163
        {
164
            if (gridViewConverter.GetSelectedRows().Length == 0)
165
            {
166
                MessageBox.Show("Select Document", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning);
167
                return;
168
            }
169
170 b90890eb gaqhf
            DataTable symbolMappingTable = Project_DB.GetSymbolMappingTable();
171 a999464f gaqhf
            DataTable lineMappingTable = Project_DB.GetLineMappingTable();
172 c7db500b gaqhf
            DataTable tDrawing = Project_DB.SelectDrawings();
173
            Documents.Clear();
174
            foreach (int rowHandle in gridViewConverter.GetSelectedRows())
175
            {
176
                string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath");
177 e49e1de9 gaqhf
                string _ID = gridViewConverter.GetRowCellValue(rowHandle, "colTemplate").ToString();
178
                string _TemplateName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
179
                string _DrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber");
180
                string _SheetNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colSheetNumber");
181 c7db500b gaqhf
182
                DataRow[] rows = tDrawing.Select(string.Format("NAME = '{0}'", Path.GetFileNameWithoutExtension(_FilePath) + ".png"));
183
                if (rows.Length != 1)
184
                    continue;
185
186
                Document document = _DicDocuments[_FilePath];
187
                document.UID = rows[0]["UID"].ToString();
188 e49e1de9 gaqhf
                document.AvevaDrawingNumber = _DrawingNumber;
189
                document.AvevaSheetNumber = _SheetNumber;
190
                document.AvevaTemplateID = _ID;
191
                document.AvevaTemplateName = _TemplateName;
192 a999464f gaqhf
                // validation check
193 b90890eb gaqhf
                if (document.SetAvevaInfo(symbolMappingTable, lineMappingTable))
194 a999464f gaqhf
                    Documents.Add(document);
195 c7db500b gaqhf
            }
196
197 b90890eb gaqhf
            symbolMappingTable.Dispose();
198 a999464f gaqhf
            lineMappingTable.Dispose();
199
200
            if (Documents.Count > 0)
201
            {
202
                DialogResult = DialogResult.OK;
203
            }
204
            else
205
            {
206
207
            }
208 c7db500b gaqhf
        }
209
210
        private void btnRefresh_Click(object sender, EventArgs e)
211
        {
212
            foreach (DataRow row in _ConverterDT.Rows)
213
            {
214
                string fileName = row["colDrawingFilePath"].ToString();
215
                Document document = new Document(fileName, ID2SymbolTypeTable);
216
217
                if (document.Enable)
218
                    row["colStatus"] = "Ready";
219
                else
220
                    row["colStatus"] = "Error";
221
222
                if (!_DicDocuments.ContainsKey(fileName))
223
                    _DicDocuments.Add(fileName, null);
224
225
                _DicDocuments[fileName] = document;
226
227
                if (document.Enable)
228
                    gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
229
            }
230
        }
231 e4ad75cb gaqhf
232
        private void btnID2DB_Click(object sender, EventArgs e)
233
        {
234
            ProjectForm form = new ProjectForm();
235
            if (form.ShowDialog() == DialogResult.OK)
236
            {
237
                Project_Info _ProjectInfo = Project_Info.GetInstance();
238
                _ProjectInfo.DefaultPath = Settings.Default.ProjectPath;
239
                _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType;
240
                _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP;
241
                _ProjectInfo.Port = Settings.Default.ProjectPort;
242
                _ProjectInfo.DBUser = Settings.Default.ProjectDBUser;
243
                _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword;
244
245
                if (Project_DB.ConnTestAndCreateTable())
246
                {
247
                    _ProjectInfo.Enable = true;
248
                    MessageBox.Show("Success project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Information);
249
                }
250
                else
251
                {
252
                    _ProjectInfo.Enable = false;
253
                    MessageBox.Show("Fail project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
254
                }
255
            }
256
        }
257
258
        private void btnItemMapping_Click(object sender, EventArgs e)
259
        {
260
            MappingForm form = new MappingForm();
261
            if (form.ShowDialog() == DialogResult.OK)
262
            {
263
264
            }
265
        }
266 74a0c9d6 gaqhf
    }
267
}
클립보드 이미지 추가 (최대 크기: 500 MB)