프로젝트

일반

사용자정보

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

hytos / DTI_PID / ID2PSN / Form / ValveGroupingSetting.cs @ e3562345

이력 | 보기 | 이력해설 | 다운로드 (18.2 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 System.IO;
11
using DevExpress.XtraEditors.Repository;
12
using DevExpress.XtraGrid.Columns;
13
using DevExpress.XtraGrid;
14
using DevExpress.XtraGrid.Views.Grid;
15
using DevExpress.Utils.StructuredStorage.Internal.Reader;
16
using DevExpress.XtraTreeList;
17
using DevExpress.XtraTreeList.Columns;
18
using DevExpress.XtraTreeList.Nodes;
19
using DevExpress.Utils.Extensions;
20
using DevExpress.Utils;
21
using DevExpress.Utils.Drawing;
22

    
23
namespace ID2PSN
24
{
25
    public partial class ValveGroupingSetting : DevExpress.XtraBars.Ribbon.RibbonForm
26
    {
27
        ID2Info ID2Info = ID2Info.GetInstance();
28
        List<ValveGroupInfo> ValveGroupInfos = new List<ValveGroupInfo>();
29
        ValveGroupInfo currentValveGroupInfo = null;
30
        private RepositoryItemComboBox repositoryAttributeItem = new RepositoryItemComboBox();
31
        private RepositoryItemComboBox repositoryGroupType = new RepositoryItemComboBox();
32
        private DataTable SymbolList = new DataTable();
33

    
34
        public ValveGroupingSetting()
35
        {
36
            InitializeComponent();
37

    
38
            InitGridValveGroupItems();
39

    
40
            
41

    
42
           // gridViewValveGroup.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gridViewSymbol_CellValueChanged);
43
            gridViewValveGroup.CellValueChanging += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gridViewSymbol_CellValueChanged);
44
            ValveGroupInfos = new List<ValveGroupInfo>();
45
            currentValveGroupInfo = new ValveGroupInfo();
46

    
47
            InitData();            
48
        }
49
        
50
        public void InitGridValveGroupItems()
51
        {
52
            RepositoryItemButtonEdit btnRemove = new RepositoryItemButtonEdit();
53
            btnRemove.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
54
            btnRemove.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(removeSymbolButton_Click);
55
            btnRemove.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
56
            btnRemove.Buttons[0].ImageOptions.Image = ID2PSN.Properties.Resources.cancel_16x16;
57
            
58
            gridValveGroup.RepositoryItems.Add(btnRemove);
59

    
60
            DataTable dtType = new DataTable();
61
          //  dtType.Columns.Add("OID");
62
            dtType.Columns.Add("GroupType");
63
            dtType.Columns.Add("TagIdentifier");
64
            dtType.Columns.Add("AttributeName");
65
            dtType.Columns.Add("SppidSymbolName");
66
            dtType.Columns.Add(" ");
67
            gridValveGroup.DataSource = dtType;
68

    
69
            GridColumn gridColumn = gridViewValveGroup.Columns[0];
70
            //gridColumn.Name = "OID";
71
            //gridColumn.Caption = "OID";
72
            //gridColumn.OptionsColumn.AllowEdit = false;
73
            //gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
74
            //gridColumn.Visible = true;
75
            //gridColumn.VisibleIndex = 0;
76

    
77

    
78
            repositoryGroupType = new RepositoryItemComboBox();
79
            repositoryGroupType.Items.AddRange(new string[] { "Valves (CV, PRV..)", "Traps (ST, DT..)", "Reliefs (PSV..)", "Pumps", "Scope Break" });
80
            repositoryGroupType.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
81
            //repositoryGroupType.EditValueChanging += RepositoryGroupType_EditValueChanging;
82
           // repositoryGroupType.SelectedIndexChanged += RepositoryGroupType_SelectedIndexChanged;
83
            
84
            gridValveGroup.RepositoryItems.Add(repositoryGroupType);
85
            //gridColumn = gridViewValveGroup.Columns[0];
86
            gridColumn.Name = "GroupType";
87
            gridColumn.Caption = "Group Type";
88
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
89
            gridColumn.VisibleIndex = 0;
90

    
91
            gridViewValveGroup.Columns["GroupType"].ColumnEdit = repositoryGroupType;
92

    
93
            //gridColumn.AppearanceHeader.BackColor = Color.Red;
94

    
95
            gridColumn = gridViewValveGroup.Columns[1];
96
            gridColumn.Name = "TagIdentifier";
97
            gridColumn.Caption = "Prefix";
98
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
99
            gridColumn.VisibleIndex = 1;
100
        
101

    
102
            SymbolList = DB.SelectAllSymbolAttribute();
103

    
104
            //repositoryAttributeItem.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
105
            //repositoryAttributeItem.AppearanceDropDown.Font = Font;
106
            //repositoryAttributeItem.Items.Add("NoSelection");
107
            //foreach (DataRow dr in SymbolList.Rows)
108
            //{
109
            //    repositoryAttributeItem.Items.Add(dr["SymbolAttribute"].ToString());
110
            //}
111
            //repositoryAttributeItem.Items.Add("");
112

    
113
            repositoryAttributeItem.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
114
            repositoryAttributeItem.AppearanceDropDown.Font = Font;
115
            gridValveGroup.RepositoryItems.Add(repositoryAttributeItem);
116

    
117
            gridColumn = gridViewValveGroup.Columns[2];
118
            gridColumn.Name = "AttributeName";
119
            gridColumn.Caption = "ID2 Attribute Name";
120
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
121
            gridColumn.VisibleIndex = 2;
122
            gridViewValveGroup.Columns["AttributeName"].ColumnEdit = repositoryAttributeItem;
123

    
124
            gridColumn = gridViewValveGroup.Columns[3];
125
            gridColumn.Name = "SppidSymbolName";
126
            gridColumn.Caption = "ID2 Symbol Name";
127
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
128
            gridColumn.VisibleIndex = 3;
129

    
130
            RepositoryItemTreeListLookUpEdit treeListLookUpEdit = new RepositoryItemTreeListLookUpEdit();
131
            gridValveGroup.RepositoryItems.Add(treeListLookUpEdit);
132
            SetSymbol(treeListLookUpEdit);
133
            
134
           // gridColumn.ColumnEdit = treeListLookUpEdit;
135
            gridViewValveGroup.Columns["SppidSymbolName"].ColumnEdit = treeListLookUpEdit;
136

    
137
            gridColumn = gridViewValveGroup.Columns[4];
138
            gridColumn.Name = "Remove";
139
            gridColumn.Caption = "";
140
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
141
            gridColumn.VisibleIndex = 4;
142
            gridColumn.MaxWidth = 16;
143
           
144
            gridColumn.ColumnEdit = btnRemove;
145
            gridColumn.ShowButtonMode = DevExpress.XtraGrid.Views.Base.ShowButtonModeEnum.ShowAlways;
146
            gridViewValveGroup.CustomRowCellEditForEditing += gridView1_CustomRowCellEditForEditing;
147
            //gridViewKeyword.CustomDrawColumnHeader += GridViewKeyword_CustomDrawColumnHeader;
148

    
149

    
150
        }
151

    
152
        private void gridView1_CustomRowCellEditForEditing(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
153
        {
154
            if (e.Column == (sender as GridView).Columns["AttributeName"])
155
            {
156
                DevExpress.XtraGrid.Views.Base.ColumnView columnView = sender as DevExpress.XtraGrid.Views.Base.ColumnView;
157
                DataTable dt = gridValveGroup.DataSource as DataTable;
158
                string SppidSymbolName = dt.Rows[columnView.FocusedRowHandle]["SppidSymbolName"].ToString();
159
                
160
                if(string.IsNullOrEmpty(SppidSymbolName))
161
                {
162
                    MessageBox.Show("Choose a symbol !", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
163
                    return;
164
                }
165

    
166
                repositoryAttributeItem.Items.Clear();                
167
                repositoryAttributeItem.Items.Add("NoSelection");
168
                foreach (DataRow dr in SymbolList.Rows)
169
                {
170
                    if(dr["SymbolName"].ToString().ToUpper().Equals(SppidSymbolName.ToUpper()))
171
                    {
172
                        repositoryAttributeItem.Items.Add(dr["SymbolAttribute"].ToString());
173
                    }                    
174
                }
175
                //repositoryAttributeItem.Items.Add("");
176
            }
177
        }
178

    
179
        private void GridViewKeyword_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
180
        {
181
            if (e.Column == null || (e.Column.AppearanceHeader.BackColor == Color.Empty && !e.Column.AppearanceHeader.Options.UseBackColor))
182

    
183
                return;
184

    
185
            Rectangle rect = e.Bounds;
186

    
187
            rect.Inflate(-1, -1);
188

    
189
            // Fill the title color.
190

    
191
            e.Graphics.FillRectangle(new SolidBrush(e.Column.AppearanceHeader.BackColor), rect);
192

    
193
            e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect);
194

    
195
            // Draw filter and sort buttons.
196

    
197
            foreach (DrawElementInfo info in e.Info.InnerElements)
198

    
199
            {
200

    
201
                if (!info.Visible) continue;
202

    
203
                ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo);
204

    
205
            }
206

    
207
            e.Handled = true;
208
        }
209

    
210
        public void InitData()
211
        {
212
            DataTable dt = DB.SelectValveGroupItemsSetting();
213
            DataTable typeDT = gridValveGroup.DataSource as DataTable;
214
            foreach (DataRow row in dt.Rows)
215
            {
216
                //int index = row["OID"];
217
                string GroupType = row["GroupType"].ToString();
218
                string TagIdentifier = row["TagIdentifier"].ToString();
219
                string AttributeName = row["AttributeName"].ToString();
220
                string SppidSymbolName = row["SppidSymbolName"].ToString();
221

    
222
                typeDT.Rows.Add(GroupType, TagIdentifier, AttributeName, SppidSymbolName, null);
223
            }
224
            
225
        }
226
      
227
        private void removeSymbolButton_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
228
        {
229
            DataTable dt = gridValveGroup.DataSource as DataTable;
230
            DataRow rows = dt.Rows[gridViewValveGroup.FocusedRowHandle];
231
            if (rows != null)
232
                dt.Rows.Remove(rows);
233
        }
234

    
235
        public void SetSymbol(RepositoryItemTreeListLookUpEdit treeListLookUpEdit)
236
        {
237
            string imgPath = ID2Info.ImageDirPath;
238
            string[] filesPath = Directory.GetFiles(imgPath, "*.png", SearchOption.AllDirectories);            
239

    
240
            DataTable dt = new DataTable();
241
            dt.Columns.Add("ID", typeof(int));
242
            dt.Columns.Add("ParentID", typeof(int));
243
            dt.Columns.Add("Name", typeof(string));
244
            dt.Columns.Add("Level", typeof(int));
245
            dt.Columns.Add("Image", typeof(Image));
246
            dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] };
247

    
248
            treeListLookUpEdit.DataSource = dt;
249
            treeListLookUpEdit.ValueMember = "Name";
250
            treeListLookUpEdit.DisplayMember = "Name";
251
            treeListLookUpEdit.TreeList.Columns["Level"].Visible = false;
252
            treeListLookUpEdit.NullText = "";
253

    
254
            treeListLookUpEdit.EditValueChanging += new DevExpress.XtraEditors.Controls.ChangingEventHandler(TreeList_BeforeCheckNode);            
255
            
256
            treeListLookUpEdit.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
257

    
258
            bool bLine = true;
259
            List<string> level1Index = new List<string>();
260
            foreach (var path in filesPath)
261
            {
262
                if (Path.GetFileNameWithoutExtension(path).Contains("_display"))
263
                    continue;
264

    
265
                string root = path.Remove(0, imgPath.Length);
266
                string[] split = root.Split(new string[] { @"\" }, StringSplitOptions.None);
267
                string level1 = split[0];
268
                if (!level1Index.Contains(level1))
269
                {
270
                    level1Index.Add(level1);
271
                    dt.Rows.Add(level1Index.IndexOf(level1) + 1, 0, level1, 0);
272
                }
273

    
274
                int parentId = level1Index.IndexOf(level1) + 1;
275
                string level2 = split[1];
276
                //combobox image size 변경
277
                Image image = Image.FromFile(Path.Combine(imgPath, root));
278
                Bitmap imgbitmap = new Bitmap(image);
279
                Image resizedImage = resizeImage(imgbitmap, new Size(200, 200));
280

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

    
283
                if (Path.GetFileNameWithoutExtension(path) == "Connect To Process" && bLine)
284
                {
285
                    bLine = false;
286
                    dt.Rows.Add(filesPath.ToList().IndexOf(path) + 20000, parentId, "Primary", 1, resizedImage);
287
                    dt.Rows.Add(filesPath.ToList().IndexOf(path) + 30000, parentId, "Secondary", 1, resizedImage);
288
                }
289
            }
290
        }
291
              
292
        public static Image resizeImage(Image imgToResize, Size size)
293
        {
294
            return (Image)(new Bitmap(imgToResize, size));
295
        }
296

    
297
        private void btnAddSymbol_Click(object sender, EventArgs e)
298
        {
299
            if (currentValveGroupInfo == null)
300
            {
301
                currentValveGroupInfo = new ValveGroupInfo();
302
            }
303

    
304
            DataTable dt = gridValveGroup.DataSource as DataTable;
305
            dt.Rows.Add(null, null, null, null, null);
306
            gridViewValveGroup.Columns["GroupType"].BestFit();
307
        }
308

    
309
  
310

    
311
        public void ReNumbering(ValveGroupInfo valveGroupInfo)
312
        {
313
            DataTable dt = gridValveGroup.DataSource as DataTable;
314
            valveGroupInfo.ValveGroupItems.Clear();
315
            for (int i = 0; i < dt.Rows.Count; i++)
316
            {
317
                DataRow row = dt.Rows[i];
318
               // row["Index"] = i + 1;
319
                valveGroupInfo.ValveGroupItems.Add(new ValveGroupItem()
320
                {
321
                    OID = Guid.NewGuid().ToString(),
322
                    GroupType = row["GroupType"].ToString(),
323
                    TagIdentifier = row["TagIdentifier"].ToString(),
324
                    AttributeName = row["AttributeName"].ToString(),
325
                    SppidSymbolName = row["SppidSymbolName"].ToString()
326
                });
327
            }
328
        }
329

    
330
        private void gridViewType_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e)
331
        {
332
            ReNumbering(currentValveGroupInfo);
333
        }
334
        private void gridViewSymbol_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
335
        {
336
            //Valves (CV, PRV..)", "Traps (ST, DT..)", "Reliefs (PSV..)
337
            if (e.Column.FieldName == "GroupType")
338
            {
339
                DevExpress.XtraGrid.Views.Base.ColumnView columnView = sender as DevExpress.XtraGrid.Views.Base.ColumnView;
340
                if (!string.IsNullOrEmpty(e.Value.ToString()))
341
                {
342
                    string selectItem = e.Value.ToString();
343
                    DataTable dt = gridValveGroup.DataSource as DataTable;
344
                    if (selectItem.Contains("Valves"))
345
                    {
346
                        dt.Rows[columnView.FocusedRowHandle]["TagIdentifier"] = "CV";
347
                    }
348
                    else if (selectItem.Contains("Traps"))
349
                    {
350
                        dt.Rows[columnView.FocusedRowHandle]["TagIdentifier"] = "ST";
351
                    }
352
                    else if (selectItem.Contains("Reliefs"))
353
                    {
354
                        dt.Rows[columnView.FocusedRowHandle]["TagIdentifier"] = "PSV";
355
                    }
356
                    else if(selectItem.Contains("Pumps"))
357
                    {
358
                        dt.Rows[columnView.FocusedRowHandle]["TagIdentifier"] = "Pump";
359
                    }
360
                }
361
            }
362
           
363
            //ReNumbering(currentValveGroupInfo);
364
        }
365
        private void TreeList_BeforeCheckNode(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
366
        {
367
            DevExpress.XtraEditors.TreeListLookUpEdit treeListLookUpEdit = sender as DevExpress.XtraEditors.TreeListLookUpEdit;
368
            if (treeListLookUpEdit.Properties.TreeList.FocusedNode == null)
369
                return;
370

    
371
            if (treeListLookUpEdit.Properties.TreeList.FocusedNode.Level == 0)
372
                e.Cancel = true;
373

    
374
           
375
        }
376

    
377
        private void btnSave_Click(object sender, EventArgs e)
378
        {
379
            if (currentValveGroupInfo == null)
380
            {
381
                currentValveGroupInfo = new ValveGroupInfo();
382
            }
383

    
384
            ReNumbering(currentValveGroupInfo);
385
            if(currentValveGroupInfo.ValveGroupItems.Find(x => x.TagIdentifier == string.Empty || x.AttributeName == string.Empty || x.SppidSymbolName == string.Empty) != null)
386
            {
387
                IEnumerable<ValveGroupItem> lstvalue = currentValveGroupInfo.ValveGroupItems.Where(x => x.TagIdentifier == string.Empty || x.AttributeName == string.Empty || x.SppidSymbolName == string.Empty);
388
                //Scope Break
389
                foreach(ValveGroupItem vg in lstvalue)
390
                {
391
                    if(vg.GroupType != "Scope Break")
392
                    {
393
                        MessageBox.Show("Please save after entering data.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
394
                        return;
395
                    }
396
                    else
397
                    {
398
                        if(vg.SppidSymbolName == string.Empty)
399
                        {
400
                            MessageBox.Show("Please save after entering data.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
401
                            return;
402
                        }
403
                    }
404
                }
405
                
406
            }
407

    
408
            if (DB.SaveValveGroupItemsSetting(currentValveGroupInfo.ValveGroupItems))
409
                MessageBox.Show("Save was successful", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
410
            else
411
                MessageBox.Show("Failed to save", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
412
        }
413

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