프로젝트

일반

사용자정보

통계
| 개정판:

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

이력 | 보기 | 이력해설 | 다운로드 (10.3 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 tDrawing = Project_DB.SelectDrawings();
171
            Documents.Clear();
172
            foreach (int rowHandle in gridViewConverter.GetSelectedRows())
173
            {
174
                string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath");
175
                string _ID = gridViewConverter.GetRowCellValue(rowHandle, "colTemplate").ToString();
176
                string _TemplateName = gridViewConverter.GetRowCellDisplayText(rowHandle, "colTemplate");
177
                string _DrawingNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingNumber");
178
                string _SheetNumber = gridViewConverter.GetRowCellDisplayText(rowHandle, "colSheetNumber");
179

    
180
                DataRow[] rows = tDrawing.Select(string.Format("NAME = '{0}'", Path.GetFileNameWithoutExtension(_FilePath) + ".png"));
181
                if (rows.Length != 1)
182
                    continue;
183

    
184
                Document document = _DicDocuments[_FilePath];
185
                document.UID = rows[0]["UID"].ToString();
186
                document.AvevaDrawingNumber = _DrawingNumber;
187
                document.AvevaSheetNumber = _SheetNumber;
188
                document.AvevaTemplateID = _ID;
189
                document.AvevaTemplateName = _TemplateName;
190
                Documents.Add(document);
191
            }
192

    
193
            DialogResult = DialogResult.OK;
194
        }
195

    
196
        private void btnRefresh_Click(object sender, EventArgs e)
197
        {
198
            foreach (DataRow row in _ConverterDT.Rows)
199
            {
200
                string fileName = row["colDrawingFilePath"].ToString();
201
                Document document = new Document(fileName, ID2SymbolTypeTable);
202

    
203
                if (document.Enable)
204
                    row["colStatus"] = "Ready";
205
                else
206
                    row["colStatus"] = "Error";
207

    
208
                if (!_DicDocuments.ContainsKey(fileName))
209
                    _DicDocuments.Add(fileName, null);
210

    
211
                _DicDocuments[fileName] = document;
212

    
213
                if (document.Enable)
214
                    gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
215
            }
216
        }
217

    
218
        private void btnID2DB_Click(object sender, EventArgs e)
219
        {
220
            ProjectForm form = new ProjectForm();
221
            if (form.ShowDialog() == DialogResult.OK)
222
            {
223
                Project_Info _ProjectInfo = Project_Info.GetInstance();
224
                _ProjectInfo.DefaultPath = Settings.Default.ProjectPath;
225
                _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType;
226
                _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP;
227
                _ProjectInfo.Port = Settings.Default.ProjectPort;
228
                _ProjectInfo.DBUser = Settings.Default.ProjectDBUser;
229
                _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword;
230

    
231
                if (Project_DB.ConnTestAndCreateTable())
232
                {
233
                    _ProjectInfo.Enable = true;
234
                    MessageBox.Show("Success project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Information);
235
                }
236
                else
237
                {
238
                    _ProjectInfo.Enable = false;
239
                    MessageBox.Show("Fail project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
240
                }
241
            }
242
        }
243

    
244
        private void btnItemMapping_Click(object sender, EventArgs e)
245
        {
246
            MappingForm form = new MappingForm();
247
            if (form.ShowDialog() == DialogResult.OK)
248
            {
249

    
250
            }
251
        }
252
    }
253
}
클립보드 이미지 추가 (최대 크기: 500 MB)