프로젝트

일반

사용자정보

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

hytos / DTI_PID / ID2PSN / Form / EquipmentSetting.cs @ c3b48db0

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

1
using DevExpress.Utils.Drawing;
2
using DevExpress.XtraEditors.Controls;
3
using DevExpress.XtraEditors.Repository;
4
using DevExpress.XtraGrid.Columns;
5
using DevExpress.XtraGrid.Views.Grid;
6
using System;
7
using System.Collections.Generic;
8
using System.ComponentModel;
9
using System.Data;
10
using System.Drawing;
11
using System.IO;
12
using System.Linq;
13
using System.Text;
14
using System.Threading.Tasks;
15
using System.Windows.Forms;
16

    
17
namespace ID2PSN
18
{
19
    public partial class EquipmentSetting : DevExpress.XtraBars.Ribbon.RibbonForm
20
    {
21
        ID2Info ID2Info = ID2Info.GetInstance();
22
        List<EquipmentNoPocketInfo> EquipmentNoPocketInfos = new List<EquipmentNoPocketInfo>();
23
        EquipmentNoPocketInfo currentEquipmentNoPocketInfo = null;
24
        private RepositoryItemComboBox repositoryGroupType = new RepositoryItemComboBox();
25

    
26
        List<EquipmentAirFinCoolerInfo> EquipmentAirFinCoolerInfos = new List<EquipmentAirFinCoolerInfo>();
27
        EquipmentAirFinCoolerInfo currentEquipmentAirFinCoolerInfo = null;
28
        private RepositoryItemComboBox repositoryGroupType2 = new RepositoryItemComboBox();
29

    
30
        public EquipmentSetting()
31
        {
32
            InitializeComponent();
33

    
34
            InitGridEquipmentNoPocket();
35
            InitGridEquipmentAirFinCooler();
36

    
37
            EquipmentNoPocketInfos = new List<EquipmentNoPocketInfo>();
38
            currentEquipmentNoPocketInfo = new EquipmentNoPocketInfo();
39

    
40
            EquipmentAirFinCoolerInfos = new List<EquipmentAirFinCoolerInfo>();
41
            currentEquipmentAirFinCoolerInfo = new EquipmentAirFinCoolerInfo();
42

    
43
            InitData();
44
            InitAirFinCoolerData();
45
        }
46

    
47
        //const string FluidPriorityType = "FLUIDCODE";
48
        //const string PipingMaterialsPriorityType = "PIPINGMATERIALSCLASS";
49
        public void InitGridEquipmentNoPocket()
50
        {
51
            RepositoryItemButtonEdit btnRemove = new RepositoryItemButtonEdit();
52
            btnRemove.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
53
            btnRemove.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(removeSymbolButton_Click);
54
            btnRemove.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
55
            btnRemove.Buttons[0].ImageOptions.Image = ID2PSN.Properties.Resources.cancel_16x16;
56

    
57
            gridEquipment.RepositoryItems.Add(btnRemove);
58

    
59
            DataTable dtType = new DataTable();
60
            dtType.Columns.Add("Index");
61
            dtType.Columns.Add("Type");
62
            dtType.Columns.Add("SppidSymbolName");
63
            dtType.Columns.Add(" ");
64
            gridEquipment.DataSource = dtType;
65

    
66
            GridColumn gridColumn = gridViewEquipment.Columns[0];
67

    
68

    
69
            gridColumn.Name = "Index";
70
            gridColumn.Caption = "Index";
71
            gridColumn.OptionsColumn.AllowEdit = false;
72
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
73
            gridColumn.VisibleIndex = 0;
74

    
75
            repositoryGroupType = new RepositoryItemComboBox();
76
            repositoryGroupType.Items.AddRange(new string[] { "Pump", "Vertical Vessel" });
77
            repositoryGroupType.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
78

    
79
            gridEquipment.RepositoryItems.Add(repositoryGroupType);
80
            gridColumn = gridViewEquipment.Columns[1];
81
            gridColumn.Name = "Type";
82
            gridColumn.Caption = "Equipment Type";
83
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
84
            gridColumn.VisibleIndex = 1;
85
            gridViewEquipment.Columns["Type"].ColumnEdit = repositoryGroupType;
86

    
87
            gridColumn = gridViewEquipment.Columns[2];
88
            gridColumn.Name = "SppidSymbolName";
89
            gridColumn.Caption = "ID2 Symbol Name";
90
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
91
            gridColumn.VisibleIndex = 2;
92

    
93
            RepositoryItemTreeListLookUpEdit treeListLookUpEdit = new RepositoryItemTreeListLookUpEdit();
94
            gridEquipment.RepositoryItems.Add(treeListLookUpEdit);
95
            SetSymbol(treeListLookUpEdit);
96

    
97
            gridViewEquipment.Columns["SppidSymbolName"].ColumnEdit = treeListLookUpEdit;
98

    
99
            gridColumn = gridViewEquipment.Columns[3];
100
            gridColumn.Name = "Remove";
101
            gridColumn.Caption = "";
102
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
103
            gridColumn.VisibleIndex = 3;
104
            gridColumn.MaxWidth = 16;
105

    
106
            gridColumn.ColumnEdit = btnRemove;
107
            gridColumn.ShowButtonMode = DevExpress.XtraGrid.Views.Base.ShowButtonModeEnum.ShowAlways;
108
        }
109

    
110
        public void InitGridEquipmentAirFinCooler()
111
        {
112
            RepositoryItemButtonEdit btnRemove = new RepositoryItemButtonEdit();
113
            btnRemove.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
114
            btnRemove.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(removeAirSymbolButton_Click);
115
            btnRemove.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
116
            btnRemove.Buttons[0].ImageOptions.Image = ID2PSN.Properties.Resources.cancel_16x16;
117

    
118
            gridControlAirFinCooler.RepositoryItems.Add(btnRemove);
119

    
120
            DataTable dtType = new DataTable();
121
            dtType.Columns.Add("Index");
122
            dtType.Columns.Add("Type");
123
            dtType.Columns.Add("SppidSymbolName");
124
            dtType.Columns.Add(" ");
125
            gridControlAirFinCooler.DataSource = dtType;
126

    
127
            GridColumn gridColumn = gridViewAirFinCooler.Columns[0];
128

    
129

    
130
            gridColumn.Name = "Index";
131
            gridColumn.Caption = "Index";
132
            gridColumn.OptionsColumn.AllowEdit = false;
133
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
134
            gridColumn.VisibleIndex = 0;
135

    
136
            repositoryGroupType2 = new RepositoryItemComboBox();
137
            repositoryGroupType2.Items.AddRange(new string[] { "Air Fin Cooler", "Pump" });
138
            repositoryGroupType2.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
139

    
140
            gridControlAirFinCooler.RepositoryItems.Add(repositoryGroupType2);
141
            gridColumn = gridViewAirFinCooler.Columns[1];
142
            gridColumn.Name = "Type";
143
            gridColumn.Caption = "Equipment Type";
144
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
145
            gridColumn.VisibleIndex = 1;
146
            gridViewAirFinCooler.Columns["Type"].ColumnEdit = repositoryGroupType2;
147

    
148
            gridColumn = gridViewAirFinCooler.Columns[2];
149
            gridColumn.Name = "SppidSymbolName";
150
            gridColumn.Caption = "ID2 Symbol Name";
151
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
152
            gridColumn.VisibleIndex = 2;
153

    
154
            RepositoryItemTreeListLookUpEdit treeListLookUpEdit = new RepositoryItemTreeListLookUpEdit();
155
            gridControlAirFinCooler.RepositoryItems.Add(treeListLookUpEdit);
156
            SetSymbol(treeListLookUpEdit);
157

    
158
            gridViewAirFinCooler.Columns["SppidSymbolName"].ColumnEdit = treeListLookUpEdit;
159

    
160
            gridColumn = gridViewAirFinCooler.Columns[3];
161
            gridColumn.Name = "Remove";
162
            gridColumn.Caption = "";
163
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
164
            gridColumn.VisibleIndex = 3;
165
            gridColumn.MaxWidth = 16;
166

    
167
            gridColumn.ColumnEdit = btnRemove;
168
            gridColumn.ShowButtonMode = DevExpress.XtraGrid.Views.Base.ShowButtonModeEnum.ShowAlways;
169
        }
170

    
171
        private void GridViewKeyword_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
172
        {
173
            if (e.Column == null || (e.Column.AppearanceHeader.BackColor == Color.Empty && !e.Column.AppearanceHeader.Options.UseBackColor))
174

    
175
                return;
176

    
177
            Rectangle rect = e.Bounds;
178

    
179
            rect.Inflate(-1, -1);
180

    
181
            // Fill the title color.
182

    
183
            e.Graphics.FillRectangle(new SolidBrush(e.Column.AppearanceHeader.BackColor), rect);
184

    
185
            e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect);
186

    
187
            // Draw filter and sort buttons.
188

    
189
            foreach (DrawElementInfo info in e.Info.InnerElements)
190

    
191
            {
192

    
193
                if (!info.Visible) continue;
194

    
195
                ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo);
196

    
197
            }
198

    
199
            e.Handled = true;
200
        }
201

    
202
        public void InitData()
203
        {
204
            DataTable dt = DB.SelectEquipmentNoPocketSetting();
205
            DataTable typeDT = gridEquipment.DataSource as DataTable;
206
            foreach (DataRow row in dt.Rows)
207
            {
208
                int index = Convert.ToInt32(row["INDEX"]);
209
                string Type = row["TYPE"].ToString();
210
                string SppidSymbolName = row["NAME"].ToString();
211

    
212
                typeDT.Rows.Add(index, Type, SppidSymbolName, null);
213
            }
214

    
215
        }
216

    
217
        public void InitAirFinCoolerData()
218
        {
219
            DataTable dt = DB.SelectAirFinCoolerSetting();
220
            DataTable typeDT = gridControlAirFinCooler.DataSource as DataTable;
221
            foreach (DataRow row in dt.Rows)
222
            {
223
                int index = Convert.ToInt32(row["INDEX"]);
224
                string Type = row["TYPE"].ToString();
225
                string SppidSymbolName = row["NAME"].ToString();
226

    
227
                typeDT.Rows.Add(index, Type, SppidSymbolName, null);
228
            }
229

    
230
        }
231

    
232
        private void removeSymbolButton_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
233
        {
234
            DataTable dt = gridEquipment.DataSource as DataTable;
235
            DataRow rows = dt.Rows[gridViewEquipment.FocusedRowHandle];
236
            if (rows != null)
237
                dt.Rows.Remove(rows);
238
        }
239

    
240
        private void removeAirSymbolButton_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
241
        {
242
            DataTable dt = gridControlAirFinCooler.DataSource as DataTable;
243
            DataRow rows = dt.Rows[gridViewAirFinCooler.FocusedRowHandle];
244
            if (rows != null)
245
                dt.Rows.Remove(rows);
246
        }
247

    
248
        public void SetSymbol(RepositoryItemTreeListLookUpEdit treeListLookUpEdit)
249
        {
250
            string imgPath = ID2Info.ImageDirPath;
251
            string[] filesPath = Directory.GetFiles(imgPath, "*.png", SearchOption.AllDirectories);
252

    
253
            DataTable dt = new DataTable();
254
            dt.Columns.Add("ID", typeof(int));
255
            dt.Columns.Add("ParentID", typeof(int));
256
            dt.Columns.Add("Name", typeof(string));
257
            dt.Columns.Add("Level", typeof(int));
258
            dt.Columns.Add("Image", typeof(Image));
259
            dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] };
260

    
261
            treeListLookUpEdit.DataSource = dt;
262
            treeListLookUpEdit.ValueMember = "Name";
263
            treeListLookUpEdit.DisplayMember = "Name";
264
            treeListLookUpEdit.TreeList.Columns["Level"].Visible = false;
265
            treeListLookUpEdit.NullText = "";
266

    
267
            treeListLookUpEdit.EditValueChanging += new DevExpress.XtraEditors.Controls.ChangingEventHandler(TreeList_BeforeCheckNode);
268

    
269
            treeListLookUpEdit.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
270

    
271
            bool bLine = true;
272
            List<string> level1Index = new List<string>();
273
            foreach (var path in filesPath)
274
            {
275
                if (Path.GetFileNameWithoutExtension(path).Contains("_display"))
276
                    continue;
277

    
278
                string root = path.Remove(0, imgPath.Length);
279
                string[] split = root.Split(new string[] { @"\" }, StringSplitOptions.None);
280
                string level1 = split[0];
281
                if (!level1Index.Contains(level1))
282
                {
283
                    level1Index.Add(level1);
284
                    dt.Rows.Add(level1Index.IndexOf(level1) + 1, 0, level1, 0);
285
                }
286

    
287
                int parentId = level1Index.IndexOf(level1) + 1;
288
                string level2 = split[1];
289
                //combobox image size 변경
290
                Image image = Image.FromFile(Path.Combine(imgPath, root));
291
                Bitmap imgbitmap = new Bitmap(image);
292
                Image resizedImage = resizeImage(imgbitmap, new Size(200, 200));
293

    
294
                dt.Rows.Add(filesPath.ToList().IndexOf(path) + 10000, parentId, Path.GetFileNameWithoutExtension(path), 1, resizedImage);
295

    
296
                if (Path.GetFileNameWithoutExtension(path) == "Connect To Process" && bLine)
297
                {
298
                    bLine = false;
299
                    dt.Rows.Add(filesPath.ToList().IndexOf(path) + 20000, parentId, "Primary", 1, resizedImage);
300
                    dt.Rows.Add(filesPath.ToList().IndexOf(path) + 30000, parentId, "Secondary", 1, resizedImage);
301
                }
302
            }
303
        }
304

    
305
        public static Image resizeImage(Image imgToResize, Size size)
306
        {
307
            return (Image)(new Bitmap(imgToResize, size));
308
        }
309

    
310
        private void btnAddSymbol_Click(object sender, EventArgs e)
311
        {
312
            if (currentEquipmentNoPocketInfo == null)
313
            {
314
                currentEquipmentNoPocketInfo = new EquipmentNoPocketInfo();
315
            }
316

    
317
            DataTable dt = gridEquipment.DataSource as DataTable;
318
            dt.Rows.Add(dt.Rows.Count + 1, null, null, null);
319
            gridViewEquipment.Columns["Index"].BestFit();
320
        }
321

    
322
        private void btnAddAirSymbol_Click(object sender, EventArgs e)
323
        {
324
            if (currentEquipmentAirFinCoolerInfo == null)
325
            {
326
                currentEquipmentAirFinCoolerInfo = new EquipmentAirFinCoolerInfo();
327
            }
328

    
329
            DataTable dt = gridControlAirFinCooler.DataSource as DataTable;
330
            dt.Rows.Add(dt.Rows.Count + 1, null, null, null);
331
            gridViewAirFinCooler.Columns["Index"].BestFit();
332
        }
333

    
334
        public void ReNumbering(EquipmentNoPocketInfo equipmentNoPocketInfo)
335
        {
336
            DataTable dt = gridEquipment.DataSource as DataTable;
337
            equipmentNoPocketInfo.EquipmentNoPocketItem.Clear();
338
            for (int i = 0; i < dt.Rows.Count; i++)
339
            {
340
                DataRow row = dt.Rows[i];
341
                row["Index"] = i + 1;
342
                equipmentNoPocketInfo.EquipmentNoPocketItem.Add(new EquipmentNoPocketItem()
343
                {
344
                    Index = i + 1,
345
                    Type = row["Type"].ToString(),
346
                    Name = row["SppidSymbolName"].ToString()
347
                });
348
            }
349
        }
350

    
351
        public void ReNumberingAir(EquipmentAirFinCoolerInfo equipmentAirFinCoolerInfo)
352
        {
353
            DataTable dt = gridControlAirFinCooler.DataSource as DataTable;
354
            equipmentAirFinCoolerInfo.EquipmentAirFinCoolerItem.Clear();
355
            for (int i = 0; i < dt.Rows.Count; i++)
356
            {
357
                DataRow row = dt.Rows[i];
358
                row["Index"] = i + 1;
359
                equipmentAirFinCoolerInfo.EquipmentAirFinCoolerItem.Add(new EquipmentAirFinCoolerItem()
360
                {
361
                    Index = i + 1,
362
                    Type = row["Type"].ToString(),
363
                    Name = row["SppidSymbolName"].ToString()
364
                });
365
            }
366
        }
367

    
368

    
369

    
370
        private void TreeList_BeforeCheckNode(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
371
        {
372
            DevExpress.XtraEditors.TreeListLookUpEdit treeListLookUpEdit = sender as DevExpress.XtraEditors.TreeListLookUpEdit;
373
            if (treeListLookUpEdit.Properties.TreeList.FocusedNode == null)
374
                return;
375

    
376
            if (treeListLookUpEdit.Properties.TreeList.FocusedNode.Level == 0)
377
                e.Cancel = true;
378

    
379

    
380
        }
381

    
382
        private void btnSave_Click(object sender, EventArgs e)
383
        {
384
            if (currentEquipmentNoPocketInfo == null)
385
            {
386
                currentEquipmentNoPocketInfo = new EquipmentNoPocketInfo();
387
            }
388

    
389
            if (currentEquipmentAirFinCoolerInfo == null)
390
            {
391
                currentEquipmentAirFinCoolerInfo = new EquipmentAirFinCoolerInfo();
392
            }
393

    
394
            ReNumbering(currentEquipmentNoPocketInfo);
395
            ReNumberingAir(currentEquipmentAirFinCoolerInfo);
396
            if (currentEquipmentNoPocketInfo.EquipmentNoPocketItem.Find(x => x.Type == string.Empty || x.Name == string.Empty) != null)
397
            {
398
                MessageBox.Show("Please save after entering data.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
399
                return;
400
            }
401

    
402
            if (DB.SaveEquipmentNopocketSetting(currentEquipmentNoPocketInfo.EquipmentNoPocketItem) &&
403
                DB.SaveAirFinCoolerSetting(currentEquipmentAirFinCoolerInfo.EquipmentAirFinCoolerItem))
404
                MessageBox.Show("Save was successful", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
405
            else
406
                MessageBox.Show("Failed to save", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
407

    
408

    
409
        }
410

    
411
        private void btnClose_Click(object sender, EventArgs e)
412
        {
413
            DialogResult = DialogResult.Cancel;
414
        }
415
    }
416
}
클립보드 이미지 추가 (최대 크기: 500 MB)