프로젝트

일반

사용자정보

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

hytos / DTI_PID / APIDConverter / Form / APIDConverter.cs @ 0169b3c7

이력 | 보기 | 이력해설 | 다운로드 (6.72 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("colStatus");
44
            col.Caption = "Status";
45
            col = _ConverterDT.Columns.Add("colUID");
46
        }
47

    
48
        private void InitGridControl()
49
        {
50
            #region Converter Page
51
            gridViewConverter.OptionsSelection.MultiSelect = true;
52
            gridViewConverter.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
53

    
54
            gridControlConverter.DataSource = _ConverterDT;
55

    
56
            gridViewConverter.Columns["colDrawingFileName"].OptionsColumn.AllowEdit = false;
57
            gridViewConverter.Columns["colStatus"].OptionsColumn.AllowEdit = false;
58
            gridViewConverter.Columns["colDrawingFilePath"].Visible = false;
59
            gridViewConverter.Columns["colUID"].Visible = false;
60

    
61
            gridViewConverter.BestFitColumns();
62
            #endregion
63
        }
64

    
65

    
66
        private void btnLoadFile_Click(object sender, EventArgs e)
67
        {
68
            Project_Info _ProjectInfo = Project_Info.GetInstance();
69

    
70
            OpenFileDialog dia = new OpenFileDialog();
71
            dia.Filter = "Xml Files(*.xml)|*.xml";
72
            dia.InitialDirectory = _ProjectInfo.TempDirPath;
73
            dia.Multiselect = true;
74

    
75
            if (dia.ShowDialog() == DialogResult.OK)
76
            {
77
                foreach (var fileName in dia.FileNames)
78
                {
79
                    Document document = new Document(fileName, ID2SymbolTypeTable);
80

    
81
                    DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName));
82
                    if (rows.Length == 0)
83
                    {
84
                        DataRow row = _ConverterDT.NewRow();
85
                        row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName);
86
                        row["colDrawingFilePath"] = fileName;
87
                        if (document.Enable)
88
                            row["colStatus"] = "Ready";
89
                        else
90
                            row["colStatus"] = "Error";
91
                        row["colUID"] = "";
92

    
93
                        _ConverterDT.Rows.Add(row);
94

    
95
                        if (document.Enable)
96
                            gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
97
                    }
98
                    else
99
                    {
100
                        foreach (DataRow row in rows)
101
                        {
102
                            if (document.Enable)
103
                                row["colStatus"] = "Ready";
104
                            else
105
                                row["colStatus"] = "Error";
106
                           
107
                            if (document.Enable)
108
                                gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
109
                        }
110
                    }
111

    
112
                    if (!_DicDocuments.ContainsKey(fileName))
113
                        _DicDocuments.Add(fileName, null);
114

    
115
                    _DicDocuments[fileName] = document;
116
                }
117
            }
118
        }
119

    
120
        private void APIDConverter_Load(object sender, EventArgs e)
121
        {
122
            Project_Info project = Project_Info.GetInstance();
123
            if (!project.Enable)
124
            {
125
                MessageBox.Show("Check Project Setting!", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning);
126
                DialogResult = DialogResult.Cancel;
127
            }
128
            else
129
            {
130
                ID2SymbolTypeTable = Project_DB.SelectSymbolType();
131
            }
132
        }
133

    
134
        private void btnRun_Click(object sender, EventArgs e)
135
        {
136
            if (gridViewConverter.GetSelectedRows().Length == 0)
137
            {
138
                MessageBox.Show("Select Document", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning);
139
                return;
140
            }
141

    
142
            DataTable tDrawing = Project_DB.SelectDrawings();
143
            Documents.Clear();
144
            foreach (int rowHandle in gridViewConverter.GetSelectedRows())
145
            {
146
                string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath");
147

    
148
                DataRow[] rows = tDrawing.Select(string.Format("NAME = '{0}'", Path.GetFileNameWithoutExtension(_FilePath) + ".png"));
149
                if (rows.Length != 1)
150
                    continue;
151

    
152
                Document document = _DicDocuments[_FilePath];
153
                document.UID = rows[0]["UID"].ToString();
154
                Documents.Add(document);
155
            }
156

    
157
            DialogResult = DialogResult.OK;
158
        }
159

    
160
        private void btnRefresh_Click(object sender, EventArgs e)
161
        {
162
            foreach (DataRow row in _ConverterDT.Rows)
163
            {
164
                string fileName = row["colDrawingFilePath"].ToString();
165
                Document document = new Document(fileName, ID2SymbolTypeTable);
166

    
167
                if (document.Enable)
168
                    row["colStatus"] = "Ready";
169
                else
170
                    row["colStatus"] = "Error";
171

    
172
                if (!_DicDocuments.ContainsKey(fileName))
173
                    _DicDocuments.Add(fileName, null);
174

    
175
                _DicDocuments[fileName] = document;
176

    
177
                if (document.Enable)
178
                    gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row)));
179
            }
180
        }
181
    }
182
}
클립보드 이미지 추가 (최대 크기: 500 MB)