프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / APIDConverter / Form / APIDConverter.cs @ 04c6def2

이력 | 보기 | 이력해설 | 다운로드 (9.63 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

    
176
                DataRow[] rows = tDrawing.Select(string.Format("NAME = '{0}'", Path.GetFileNameWithoutExtension(_FilePath) + ".png"));
177
                if (rows.Length != 1)
178
                    continue;
179

    
180
                Document document = _DicDocuments[_FilePath];
181
                document.UID = rows[0]["UID"].ToString();
182
                Documents.Add(document);
183
            }
184

    
185
            DialogResult = DialogResult.OK;
186
        }
187

    
188
        private void btnRefresh_Click(object sender, EventArgs e)
189
        {
190
            foreach (DataRow row in _ConverterDT.Rows)
191
            {
192
                string fileName = row["colDrawingFilePath"].ToString();
193
                Document document = new Document(fileName, ID2SymbolTypeTable);
194

    
195
                if (document.Enable)
196
                    row["colStatus"] = "Ready";
197
                else
198
                    row["colStatus"] = "Error";
199

    
200
                if (!_DicDocuments.ContainsKey(fileName))
201
                    _DicDocuments.Add(fileName, null);
202

    
203
                _DicDocuments[fileName] = document;
204

    
205
                if (document.Enable)
206
                    gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
207
            }
208
        }
209

    
210
        private void btnID2DB_Click(object sender, EventArgs e)
211
        {
212
            ProjectForm form = new ProjectForm();
213
            if (form.ShowDialog() == DialogResult.OK)
214
            {
215
                Project_Info _ProjectInfo = Project_Info.GetInstance();
216
                _ProjectInfo.DefaultPath = Settings.Default.ProjectPath;
217
                _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType;
218
                _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP;
219
                _ProjectInfo.Port = Settings.Default.ProjectPort;
220
                _ProjectInfo.DBUser = Settings.Default.ProjectDBUser;
221
                _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword;
222

    
223
                if (Project_DB.ConnTestAndCreateTable())
224
                {
225
                    _ProjectInfo.Enable = true;
226
                    MessageBox.Show("Success project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Information);
227
                }
228
                else
229
                {
230
                    _ProjectInfo.Enable = false;
231
                    MessageBox.Show("Fail project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
232
                }
233
            }
234
        }
235

    
236
        private void btnItemMapping_Click(object sender, EventArgs e)
237
        {
238
            MappingForm form = new MappingForm();
239
            if (form.ShowDialog() == DialogResult.OK)
240
            {
241

    
242
            }
243
        }
244
    }
245
}
클립보드 이미지 추가 (최대 크기: 500 MB)