프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / ID2PSN / Form / EquipmentNoPocketSetting.cs @ 63ff8e26

이력 | 보기 | 이력해설 | 다운로드 (12.1 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 EquipmentNoPocketSetting : DevExpress.XtraBars.Ribbon.RibbonForm
26
    {
27
        ID2Info ID2Info = ID2Info.GetInstance();
28
        List<EquipmentNoPocketInfo> EquipmentNoPocketInfos = new List<EquipmentNoPocketInfo>();
29
        EquipmentNoPocketInfo currentEquipmentNoPocketInfo = null;
30
        private RepositoryItemComboBox repositoryGroupType = new RepositoryItemComboBox();
31

    
32
        public EquipmentNoPocketSetting()
33
        {
34
            InitializeComponent();
35

    
36
            InitGridEquipmentNoPocket();            
37

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

    
41
            InitData();            
42
        }
43
        
44
        public void InitGridEquipmentNoPocket()
45
        {
46
            RepositoryItemButtonEdit btnRemove = new RepositoryItemButtonEdit();
47
            btnRemove.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
48
            btnRemove.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(removeSymbolButton_Click);
49
            btnRemove.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
50
            btnRemove.Buttons[0].ImageOptions.Image = ID2PSN.Properties.Resources.cancel_16x16;
51
            
52
            gridEquipment.RepositoryItems.Add(btnRemove);
53

    
54
            DataTable dtType = new DataTable();
55
            dtType.Columns.Add("Index");
56
            dtType.Columns.Add("Type");
57
            dtType.Columns.Add("SppidSymbolName");
58
            dtType.Columns.Add(" ");
59
            gridEquipment.DataSource = dtType;
60

    
61
            GridColumn gridColumn = gridViewEquipment.Columns[0];
62

    
63
            
64
            gridColumn.Name = "Index";
65
            gridColumn.Caption = "Index";
66
            gridColumn.OptionsColumn.AllowEdit = false;
67
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
68
            gridColumn.VisibleIndex = 0;
69

    
70
            repositoryGroupType = new RepositoryItemComboBox();
71
            repositoryGroupType.Items.AddRange(new string[] { "Pump(To)", "Tower", "Vertical Vessel" });
72
            repositoryGroupType.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
73
            
74
            gridEquipment.RepositoryItems.Add(repositoryGroupType);
75
            gridColumn = gridViewEquipment.Columns[1];
76
            gridColumn.Name = "Type";
77
            gridColumn.Caption = "Type";
78
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
79
            gridColumn.VisibleIndex = 1;
80
            gridViewEquipment.Columns["Type"].ColumnEdit = repositoryGroupType;       
81

    
82
            gridColumn = gridViewEquipment.Columns[2];
83
            gridColumn.Name = "SppidSymbolName";
84
            gridColumn.Caption = "ID2 Symbol Name";
85
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
86
            gridColumn.VisibleIndex = 2;
87

    
88
            RepositoryItemTreeListLookUpEdit treeListLookUpEdit = new RepositoryItemTreeListLookUpEdit();
89
            gridEquipment.RepositoryItems.Add(treeListLookUpEdit);
90
            SetSymbol(treeListLookUpEdit);
91
            
92
            gridViewEquipment.Columns["SppidSymbolName"].ColumnEdit = treeListLookUpEdit;
93

    
94
            gridColumn = gridViewEquipment.Columns[3];
95
            gridColumn.Name = "Remove";
96
            gridColumn.Caption = "";
97
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
98
            gridColumn.VisibleIndex = 3;
99
            gridColumn.MaxWidth = 16;
100
           
101
            gridColumn.ColumnEdit = btnRemove;
102
            gridColumn.ShowButtonMode = DevExpress.XtraGrid.Views.Base.ShowButtonModeEnum.ShowAlways;
103
        }
104

    
105

    
106
        private void GridViewKeyword_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
107
        {
108
            if (e.Column == null || (e.Column.AppearanceHeader.BackColor == Color.Empty && !e.Column.AppearanceHeader.Options.UseBackColor))
109

    
110
                return;
111

    
112
            Rectangle rect = e.Bounds;
113

    
114
            rect.Inflate(-1, -1);
115

    
116
            // Fill the title color.
117

    
118
            e.Graphics.FillRectangle(new SolidBrush(e.Column.AppearanceHeader.BackColor), rect);
119

    
120
            e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect);
121

    
122
            // Draw filter and sort buttons.
123

    
124
            foreach (DrawElementInfo info in e.Info.InnerElements)
125

    
126
            {
127

    
128
                if (!info.Visible) continue;
129

    
130
                ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo);
131

    
132
            }
133

    
134
            e.Handled = true;
135
        }
136

    
137
        public void InitData()
138
        {
139
            DataTable dt = DB.SelectEquipmentNoPocketSetting();
140
            DataTable typeDT = gridEquipment.DataSource as DataTable;
141
            foreach (DataRow row in dt.Rows)
142
            {
143
                int index = Convert.ToInt32(row["INDEX"]);
144
                string Type = row["TYPE"].ToString();
145
                string SppidSymbolName = row["NAME"].ToString();
146

    
147
                typeDT.Rows.Add(index, Type, SppidSymbolName, null);
148
            }
149
            
150
        }
151
      
152
        private void removeSymbolButton_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
153
        {
154
            DataTable dt = gridEquipment.DataSource as DataTable;
155
            DataRow rows = dt.Rows[gridViewEquipment.FocusedRowHandle];
156
            if (rows != null)
157
                dt.Rows.Remove(rows);
158
        }
159

    
160
        public void SetSymbol(RepositoryItemTreeListLookUpEdit treeListLookUpEdit)
161
        {
162
            string imgPath = ID2Info.ImageDirPath;
163
            string[] filesPath = Directory.GetFiles(imgPath, "*.png", SearchOption.AllDirectories);            
164

    
165
            DataTable dt = new DataTable();
166
            dt.Columns.Add("ID", typeof(int));
167
            dt.Columns.Add("ParentID", typeof(int));
168
            dt.Columns.Add("Name", typeof(string));
169
            dt.Columns.Add("Level", typeof(int));
170
            dt.Columns.Add("Image", typeof(Image));
171
            dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] };
172

    
173
            treeListLookUpEdit.DataSource = dt;
174
            treeListLookUpEdit.ValueMember = "Name";
175
            treeListLookUpEdit.DisplayMember = "Name";
176
            treeListLookUpEdit.TreeList.Columns["Level"].Visible = false;
177
            treeListLookUpEdit.NullText = "";
178

    
179
            treeListLookUpEdit.EditValueChanging += new DevExpress.XtraEditors.Controls.ChangingEventHandler(TreeList_BeforeCheckNode);            
180
            
181
            treeListLookUpEdit.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
182

    
183
            bool bLine = true;
184
            List<string> level1Index = new List<string>();
185
            foreach (var path in filesPath)
186
            {
187
                if (Path.GetFileNameWithoutExtension(path).Contains("_display"))
188
                    continue;
189

    
190
                string root = path.Remove(0, imgPath.Length);
191
                string[] split = root.Split(new string[] { @"\" }, StringSplitOptions.None);
192
                string level1 = split[0];
193
                if (!level1Index.Contains(level1))
194
                {
195
                    level1Index.Add(level1);
196
                    dt.Rows.Add(level1Index.IndexOf(level1) + 1, 0, level1, 0);
197
                }
198

    
199
                int parentId = level1Index.IndexOf(level1) + 1;
200
                string level2 = split[1];
201
                //combobox image size 변경
202
                Image image = Image.FromFile(Path.Combine(imgPath, root));
203
                Bitmap imgbitmap = new Bitmap(image);
204
                Image resizedImage = resizeImage(imgbitmap, new Size(200, 200));
205

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

    
208
                if (Path.GetFileNameWithoutExtension(path) == "Connect To Process" && bLine)
209
                {
210
                    bLine = false;
211
                    dt.Rows.Add(filesPath.ToList().IndexOf(path) + 20000, parentId, "Primary", 1, resizedImage);
212
                    dt.Rows.Add(filesPath.ToList().IndexOf(path) + 30000, parentId, "Secondary", 1, resizedImage);
213
                }
214
            }
215
        }
216
              
217
        public static Image resizeImage(Image imgToResize, Size size)
218
        {
219
            return (Image)(new Bitmap(imgToResize, size));
220
        }
221

    
222
        private void btnAddSymbol_Click(object sender, EventArgs e)
223
        {
224
            if (currentEquipmentNoPocketInfo == null)
225
            {
226
                currentEquipmentNoPocketInfo = new EquipmentNoPocketInfo();
227
            }
228

    
229
            DataTable dt = gridEquipment.DataSource as DataTable;
230
            dt.Rows.Add(dt.Rows.Count + 1, null, null, null);
231
            gridViewEquipment.Columns["Index"].BestFit();
232

    
233

    
234

    
235
            //if (currentEquipmentNoPocketInfo == null)
236
            //{
237
            //    currentEquipmentNoPocketInfo = new EquipmentNoPocketInfo();
238
            //}
239

    
240
          
241
            //dt.Rows.Add(null, null, null, null);
242
            //gridViewEquipment.Columns["Type"].BestFit();
243
        }
244

    
245

    
246
        public void ReNumbering(EquipmentNoPocketInfo equipmentNoPocketInfo)
247
        {
248
            DataTable dt = gridEquipment.DataSource as DataTable;
249
            equipmentNoPocketInfo.EquipmentNoPocketItem.Clear();
250
            for (int i = 0; i < dt.Rows.Count; i++)
251
            {
252
                DataRow row = dt.Rows[i];
253
                row["Index"] = i + 1;
254
                equipmentNoPocketInfo.EquipmentNoPocketItem.Add(new EquipmentNoPocketItem()
255
                {
256
                    Index = i + 1,
257
                    Type = row["Type"].ToString(),
258
                    Name = row["SppidSymbolName"].ToString()
259
                });
260
            }
261
        }
262

    
263
        private void gridViewType_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e)
264
        {
265
            ReNumbering(currentEquipmentNoPocketInfo);
266
        }
267

    
268
       
269
        private void TreeList_BeforeCheckNode(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
270
        {
271
            DevExpress.XtraEditors.TreeListLookUpEdit treeListLookUpEdit = sender as DevExpress.XtraEditors.TreeListLookUpEdit;
272
            if (treeListLookUpEdit.Properties.TreeList.FocusedNode == null)
273
                return;
274

    
275
            if (treeListLookUpEdit.Properties.TreeList.FocusedNode.Level == 0)
276
                e.Cancel = true;
277

    
278
           
279
        }
280

    
281
        private void btnSave_Click(object sender, EventArgs e)
282
        {
283
            if (currentEquipmentNoPocketInfo == null)
284
            {
285
                currentEquipmentNoPocketInfo = new EquipmentNoPocketInfo();
286
            }
287

    
288
            ReNumbering(currentEquipmentNoPocketInfo);
289
            if (currentEquipmentNoPocketInfo.EquipmentNoPocketItem.Find(x => x.Type == string.Empty || x.Name == string.Empty) != null)
290
            {
291
                MessageBox.Show("Please save after entering data.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
292
                return;
293
            }
294

    
295
            if (DB.SaveEquipmentNopocketSetting(currentEquipmentNoPocketInfo.EquipmentNoPocketItem))
296
                MessageBox.Show("Save was successful", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
297
            else
298
                MessageBox.Show("Failed to save", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
299

    
300

    
301
        }
302

    
303
        private void btnClose_Click(object sender, EventArgs e)
304
        {
305
            DialogResult = DialogResult.Cancel;
306
        }
307
    }
308
}
클립보드 이미지 추가 (최대 크기: 500 MB)