hytos / DTI_PID / APIDConverter / Form / APIDConverter.cs @ bc7a6ad1
이력 | 보기 | 이력해설 | 다운로드 (8.14 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 | 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 | fdb1367e | gaqhf | private void btnLoadFile_Click(object sender, EventArgs e) |
66 | 74a0c9d6 | gaqhf | { |
67 | fdb1367e | gaqhf | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
68 | |||
69 | OpenFileDialog dia = new OpenFileDialog(); |
||
70 | dia.Filter = "Xml Files(*.xml)|*.xml"; |
||
71 | dia.InitialDirectory = _ProjectInfo.TempDirPath; |
||
72 | dia.Multiselect = true; |
||
73 | |||
74 | if (dia.ShowDialog() == DialogResult.OK) |
||
75 | { |
||
76 | foreach (var fileName in dia.FileNames) |
||
77 | { |
||
78 | 465c8b6e | gaqhf | Document document = new Document(fileName, ID2SymbolTypeTable); |
79 | c7db500b | gaqhf | |
80 | DataRow[] rows = _ConverterDT.Select(string.Format("colDrawingFilePath = '{0}'", fileName)); |
||
81 | if (rows.Length == 0) |
||
82 | d327a608 | gaqhf | { |
83 | c7db500b | gaqhf | DataRow row = _ConverterDT.NewRow(); |
84 | row["colDrawingFileName"] = Path.GetFileNameWithoutExtension(fileName); |
||
85 | row["colDrawingFilePath"] = fileName; |
||
86 | if (document.Enable) |
||
87 | row["colStatus"] = "Ready"; |
||
88 | else |
||
89 | row["colStatus"] = "Error"; |
||
90 | row["colUID"] = ""; |
||
91 | |||
92 | _ConverterDT.Rows.Add(row); |
||
93 | |||
94 | if (document.Enable) |
||
95 | gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
||
96 | d327a608 | gaqhf | } |
97 | c7db500b | gaqhf | else |
98 | { |
||
99 | foreach (DataRow row in rows) |
||
100 | { |
||
101 | if (document.Enable) |
||
102 | row["colStatus"] = "Ready"; |
||
103 | else |
||
104 | row["colStatus"] = "Error"; |
||
105 | |||
106 | if (document.Enable) |
||
107 | gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | if (!_DicDocuments.ContainsKey(fileName)) |
||
112 | _DicDocuments.Add(fileName, null); |
||
113 | |||
114 | _DicDocuments[fileName] = document; |
||
115 | fdb1367e | gaqhf | } |
116 | } |
||
117 | 74a0c9d6 | gaqhf | } |
118 | 8562d7dc | gaqhf | |
119 | private void APIDConverter_Load(object sender, EventArgs e) |
||
120 | { |
||
121 | Project_Info project = Project_Info.GetInstance(); |
||
122 | if (!project.Enable) |
||
123 | { |
||
124 | MessageBox.Show("Check Project Setting!", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
125 | d327a608 | gaqhf | DialogResult = DialogResult.Cancel; |
126 | 8562d7dc | gaqhf | } |
127 | 465c8b6e | gaqhf | else |
128 | { |
||
129 | d327a608 | gaqhf | ID2SymbolTypeTable = Project_DB.SelectSymbolType(); |
130 | 465c8b6e | gaqhf | } |
131 | 8562d7dc | gaqhf | } |
132 | c7db500b | gaqhf | |
133 | private void btnRun_Click(object sender, EventArgs e) |
||
134 | { |
||
135 | if (gridViewConverter.GetSelectedRows().Length == 0) |
||
136 | { |
||
137 | MessageBox.Show("Select Document", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
138 | return; |
||
139 | } |
||
140 | |||
141 | DataTable tDrawing = Project_DB.SelectDrawings(); |
||
142 | Documents.Clear(); |
||
143 | foreach (int rowHandle in gridViewConverter.GetSelectedRows()) |
||
144 | { |
||
145 | string _FilePath = gridViewConverter.GetRowCellDisplayText(rowHandle, "colDrawingFilePath"); |
||
146 | |||
147 | DataRow[] rows = tDrawing.Select(string.Format("NAME = '{0}'", Path.GetFileNameWithoutExtension(_FilePath) + ".png")); |
||
148 | if (rows.Length != 1) |
||
149 | continue; |
||
150 | |||
151 | Document document = _DicDocuments[_FilePath]; |
||
152 | document.UID = rows[0]["UID"].ToString(); |
||
153 | Documents.Add(document); |
||
154 | } |
||
155 | |||
156 | DialogResult = DialogResult.OK; |
||
157 | } |
||
158 | |||
159 | private void btnRefresh_Click(object sender, EventArgs e) |
||
160 | { |
||
161 | foreach (DataRow row in _ConverterDT.Rows) |
||
162 | { |
||
163 | string fileName = row["colDrawingFilePath"].ToString(); |
||
164 | Document document = new Document(fileName, ID2SymbolTypeTable); |
||
165 | |||
166 | if (document.Enable) |
||
167 | row["colStatus"] = "Ready"; |
||
168 | else |
||
169 | row["colStatus"] = "Error"; |
||
170 | |||
171 | if (!_DicDocuments.ContainsKey(fileName)) |
||
172 | _DicDocuments.Add(fileName, null); |
||
173 | |||
174 | _DicDocuments[fileName] = document; |
||
175 | |||
176 | if (document.Enable) |
||
177 | gridViewConverter.SelectRow(gridViewConverter.GetRowHandle(_ConverterDT.Rows.IndexOf(row))); |
||
178 | } |
||
179 | } |
||
180 | e4ad75cb | gaqhf | |
181 | private void btnID2DB_Click(object sender, EventArgs e) |
||
182 | { |
||
183 | ProjectForm form = new ProjectForm(); |
||
184 | if (form.ShowDialog() == DialogResult.OK) |
||
185 | { |
||
186 | Project_Info _ProjectInfo = Project_Info.GetInstance(); |
||
187 | _ProjectInfo.DefaultPath = Settings.Default.ProjectPath; |
||
188 | _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType; |
||
189 | _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP; |
||
190 | _ProjectInfo.Port = Settings.Default.ProjectPort; |
||
191 | _ProjectInfo.DBUser = Settings.Default.ProjectDBUser; |
||
192 | _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword; |
||
193 | |||
194 | if (Project_DB.ConnTestAndCreateTable()) |
||
195 | { |
||
196 | _ProjectInfo.Enable = true; |
||
197 | MessageBox.Show("Success project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Information); |
||
198 | } |
||
199 | else |
||
200 | { |
||
201 | _ProjectInfo.Enable = false; |
||
202 | MessageBox.Show("Fail project setting", "APID Converter", MessageBoxButtons.OK, MessageBoxIcon.Error); |
||
203 | } |
||
204 | } |
||
205 | } |
||
206 | |||
207 | private void btnItemMapping_Click(object sender, EventArgs e) |
||
208 | { |
||
209 | MappingForm form = new MappingForm(); |
||
210 | if (form.ShowDialog() == DialogResult.OK) |
||
211 | { |
||
212 | |||
213 | } |
||
214 | } |
||
215 | 74a0c9d6 | gaqhf | } |
216 | } |