프로젝트

일반

사용자정보

통계
| 개정판:

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

이력 | 보기 | 이력해설 | 다운로드 (10.7 KB)

1
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
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
using AVEVA.PID.CustomizationUtility.DB;
17
using AVEVA.PID.CustomizationUtility.Model;
18
using AVEVA.PID.CustomizationUtility.Properties;
19

    
20
namespace AVEVA.PID.CustomizationUtility
21
{
22
    public partial class APIDConverter : DevExpress.XtraBars.Ribbon.RibbonForm
23
    {
24
        public APIDConverter()
25
        {
26
            InitializeComponent();
27
            InitUsedDataTable();
28
            InitGridControl();
29
        }
30

    
31
        DataTable ID2SymbolTypeTable = null;
32
        private DataTable _ConverterDT = new DataTable();
33
        public List<Document> Documents = new List<Document>();
34
        private Dictionary<string, Document> _DicDocuments = new Dictionary<string, Document>();
35

    
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
            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
            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

    
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
        }
93

    
94
        private void btnLoadFile_Click(object sender, EventArgs e)
95
        {
96
            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
                    Document document = new Document(fileName, ID2SymbolTypeTable);
108

    
109
                    DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName));
110
                    if (rows.Length == 0)
111
                    {
112
                        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
                    }
126
                    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
                }
145
            }
146
        }
147

    
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
                DialogResult = DialogResult.Cancel;
155
            }
156
            else
157
            {
158
                ID2SymbolTypeTable = Project_DB.SelectSymbolType();
159
            }
160
        }
161

    
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
            DataTable symbolMappingTable = Project_DB.GetSymbolMappingTable();
171
            DataTable lineMappingTable = Project_DB.GetLineMappingTable();
172
            DataTable tDrawing = Project_DB.SelectDrawings();
173
            Documents.Clear();
174
            foreach (int rowHandle in gridViewConverter.GetSelectedRows())
175
            {
176
                string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath");
177
                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

    
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
                document.AvevaDrawingNumber = _DrawingNumber;
189
                document.AvevaSheetNumber = _SheetNumber;
190
                document.AvevaTemplateID = _ID;
191
                document.AvevaTemplateName = _TemplateName;
192
                // validation check
193
                if (document.SetAvevaInfo(symbolMappingTable, lineMappingTable))
194
                    Documents.Add(document);
195
            }
196

    
197
            symbolMappingTable.Dispose();
198
            lineMappingTable.Dispose();
199

    
200
            if (Documents.Count > 0)
201
            {
202
                DialogResult = DialogResult.OK;
203
            }
204
            else
205
            {
206

    
207
            }
208
        }
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

    
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
    }
267
}
클립보드 이미지 추가 (최대 크기: 500 MB)