프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / ID2PSN / Form / MultiwaySetting.cs @ 0a8daaff

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

1 a2ab8a90 이지연
using System;
2
using System.Collections.Generic;
3
using System.Data;
4
using System.Drawing;
5
using System.Linq;
6
using System.Windows.Forms;
7
using System.IO;
8
using DevExpress.XtraEditors.Repository;
9
using DevExpress.XtraGrid.Columns;
10
using DevExpress.XtraGrid.Views.Grid;
11
using DevExpress.Utils;
12
using DevExpress.Utils.Drawing;
13
14
namespace ID2PSN
15
{
16
    public partial class MultiwaySetting : DevExpress.XtraBars.Ribbon.RibbonForm
17
    {
18
        ID2Info ID2Info = ID2Info.GetInstance();
19
        List<MultiwayInfo> MultiwayInfos = new List<MultiwayInfo>();
20
        MultiwayInfo currentMultiwayInfo = null;
21
22
        public MultiwaySetting()
23
        {
24
            InitializeComponent();
25
26
            InitGridMultiway();
27
28
            gridViewMultiway.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gridViewSymbol_CellValueChanged);
29
30
            MultiwayInfos = new List<MultiwayInfo>();
31
            currentMultiwayInfo = new MultiwayInfo();
32
33
            InitData();
34
            
35
            SuperToolTip sTooltip1 = new SuperToolTip();
36
            
37
            ToolTipTitleItem titleItem1 = new ToolTipTitleItem();
38
            titleItem1.Text = "Index Information";
39
            
40
            ToolTipItem item1 = new ToolTipItem();
41
            item1.ImageOptions.Image = ((Image)Properties.Resources.ResourceManager.GetObject("ToolTip1", System.Globalization.CultureInfo.CurrentCulture));
42
            //item1.Text = "Show the Edit popup menu";
43
            
44
            sTooltip1.Items.Add(titleItem1);
45
            sTooltip1.Items.Add(item1);
46
47
            labelControlToolTip.SuperTip = sTooltip1;
48
        }
49
50
        public void InitGridMultiway()
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
            gridControlMultiway.RepositoryItems.Add(btnRemove);
59
60
            DataTable dtType = new DataTable();
61
            dtType.Columns.Add("Index");
62
            dtType.Columns.Add("Name");
63
            dtType.Columns.Add(" ");
64
            gridControlMultiway.DataSource = dtType;
65
66
            GridColumn gridColumn = gridViewMultiway.Columns[0];
67
            gridColumn.Name = "Index";
68
            gridColumn.Caption = "Index";
69
            gridColumn.OptionsColumn.AllowEdit = false;
70
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
71
            gridColumn.VisibleIndex = 0;
72
            
73 4f02de16 이지연
            gridColumn = gridViewMultiway.Columns[1];
74 a2ab8a90 이지연
            gridColumn.Name = "Name";
75
            gridColumn.Caption = "ID2 Symbol Name";
76
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
77 4f02de16 이지연
            gridColumn.VisibleIndex = 1;
78 a2ab8a90 이지연
79
            RepositoryItemTreeListLookUpEdit treeListLookUpEdit = new RepositoryItemTreeListLookUpEdit();
80
            gridControlMultiway.RepositoryItems.Add(treeListLookUpEdit);
81
            SetSymbol(treeListLookUpEdit);
82
            gridColumn.ColumnEdit = treeListLookUpEdit;
83
84 4f02de16 이지연
            gridColumn = gridViewMultiway.Columns[2];
85 a2ab8a90 이지연
            gridColumn.Name = "Remove";
86
            gridColumn.Caption = "";
87
            gridColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
88 4f02de16 이지연
            gridColumn.VisibleIndex = 2;
89 a2ab8a90 이지연
            gridColumn.MaxWidth = 16;
90
            
91
            gridColumn.ColumnEdit = btnRemove;
92
            gridColumn.ShowButtonMode = DevExpress.XtraGrid.Views.Base.ShowButtonModeEnum.ShowAlways;
93
            //gridViewMultiway.CustomDrawColumnHeader += GridViewMultiway_CustomDrawColumnHeader;
94
        }
95
96
        private void GridViewMultiway_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
97
        {
98
            if (e.Column == null || (e.Column.AppearanceHeader.BackColor == Color.Empty && !e.Column.AppearanceHeader.Options.UseBackColor))
99
100
                return;
101
102
            Rectangle rect = e.Bounds;
103
104
            rect.Inflate(-1, -1);
105
106
            // Fill the title color.
107
108
            e.Graphics.FillRectangle(new SolidBrush(e.Column.AppearanceHeader.BackColor), rect);
109
110
            e.Appearance.DrawString(e.Cache, e.Info.Caption, e.Info.CaptionRect);
111
112
            // Draw filter and sort buttons.
113
114
            foreach (DrawElementInfo info in e.Info.InnerElements)
115
116
            {
117
118
                if (!info.Visible) continue;
119
120
                ObjectPainter.DrawObject(e.Cache, info.ElementPainter, info.ElementInfo);
121
122
            }
123
124
            e.Handled = true;
125
        }
126
127
        public void InitData()
128
        {
129
            DataTable dt = DB.SelectMultiwaysSetting();
130
            DataTable typeDT = gridControlMultiway.DataSource as DataTable;
131
            foreach (DataRow row in dt.Rows)
132
            {
133
                int index = Convert.ToInt32(row["INDEX"]);
134
                string name = row["NAME"].ToString();    
135 4f02de16 이지연
                typeDT.Rows.Add(index,  name, null);                
136 a2ab8a90 이지연
            }
137
        }
138
139
        private void removeSymbolButton_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
140
        {
141
            string value = gridViewMultiway.GetFocusedRowCellValue("Index").ToString();
142
            DataTable dt = gridControlMultiway.DataSource as DataTable;
143
            DataRow[] rows = dt.Select(string.Format("INDEX = '{0}'", value));
144
            if (rows.Length.Equals(1))
145
                dt.Rows.Remove(rows.First());
146
            ReNumbering(currentMultiwayInfo);
147
        }
148
149
        public void SetSymbol(RepositoryItemTreeListLookUpEdit treeListLookUpEdit)
150
        {
151
            string imgPath = ID2Info.ImageDirPath;
152
            string[] filesPath = Directory.GetFiles(imgPath, "*.png", SearchOption.AllDirectories);            
153
154
            DataTable dt = new DataTable();
155
            dt.Columns.Add("ID", typeof(int));
156
            dt.Columns.Add("ParentID", typeof(int));
157
            dt.Columns.Add("Name", typeof(string));
158
            dt.Columns.Add("Level", typeof(int));
159
            dt.Columns.Add("Image", typeof(Image));
160
            dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] };
161
162
            treeListLookUpEdit.DataSource = dt;
163
            treeListLookUpEdit.ValueMember = "Name";
164
            treeListLookUpEdit.DisplayMember = "Name";
165
            treeListLookUpEdit.TreeList.Columns["Level"].Visible = false;
166
            treeListLookUpEdit.NullText = "";
167
168
            treeListLookUpEdit.EditValueChanging += new DevExpress.XtraEditors.Controls.ChangingEventHandler(TreeList_BeforeCheckNode);
169
170
            treeListLookUpEdit.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
171
172
            bool bLine = true;
173
            List<string> level1Index = new List<string>();
174
            foreach (var path in filesPath)
175
            {
176
                if (Path.GetFileNameWithoutExtension(path).Contains("_display"))
177
                    continue;
178
179
                string root = path.Remove(0, imgPath.Length);
180
                string[] split = root.Split(new string[] { @"\" }, StringSplitOptions.None);
181
                string level1 = split[0];
182
                if (!level1Index.Contains(level1))
183
                {
184
                    level1Index.Add(level1);
185
                    dt.Rows.Add(level1Index.IndexOf(level1) + 1, 0, level1, 0);
186
                }
187
188
                int parentId = level1Index.IndexOf(level1) + 1;
189
                string level2 = split[1];
190
                //combobox image size 변경
191
                Image image = Image.FromFile(Path.Combine(imgPath, root));
192
                Bitmap imgbitmap = new Bitmap(image);
193
                Image resizedImage = resizeImage(imgbitmap, new Size(200, 200));
194
195
                dt.Rows.Add(filesPath.ToList().IndexOf(path) + 10000, parentId, Path.GetFileNameWithoutExtension(path), 1, resizedImage);
196
197 bd86dd48 이지연
                if (bLine)
198 a2ab8a90 이지연
                {
199
                    bLine = false;
200 9bb7a028 이지연
                    dt.Rows.Add(filesPath.ToList().IndexOf(path) + 20000, parentId, "Primary", 1, null);
201
                    dt.Rows.Add(filesPath.ToList().IndexOf(path) + 30000, parentId, "Secondary", 1, null);
202 a2ab8a90 이지연
                }
203
            }
204
        }
205
206
        public static Image resizeImage(Image imgToResize, Size size)
207
        {
208
            return (Image)(new Bitmap(imgToResize, size));
209
        }
210
211
        private void btnAddSymbol_Click(object sender, EventArgs e)
212
        {
213
            if (currentMultiwayInfo == null)
214
            {
215
                currentMultiwayInfo = new MultiwayInfo();
216
            }
217
218
            DataTable dt = gridControlMultiway.DataSource as DataTable;
219 4f02de16 이지연
            dt.Rows.Add(dt.Rows.Count + 1, null, null);
220 a2ab8a90 이지연
            gridViewMultiway.Columns["Index"].BestFit();
221
        }
222
223
        public void LoadGridSymbol(MultiwayInfo MultiwayInfo)
224
        {
225
            DataTable dt = gridControlMultiway.DataSource as DataTable;
226
            dt.Rows.Clear();
227
            for (int i = 0; i < MultiwayInfo.MultiwayItems.Count; i++)
228
            {
229
                MultiwayItem item = MultiwayInfo.MultiwayItems[i];
230 4f02de16 이지연
                dt.Rows.Add(item.Index, item.Name);
231 a2ab8a90 이지연
            }
232
        }
233
234
        public void ReNumbering(MultiwayInfo MultiwayInfo)
235
        {
236
            DataTable dt = gridControlMultiway.DataSource as DataTable;
237
            MultiwayInfo.MultiwayItems.Clear();
238
            for (int i = 0; i < dt.Rows.Count; i++)
239
            {
240
                DataRow row = dt.Rows[i];
241
                row["Index"] = i + 1;
242
                MultiwayInfo.MultiwayItems.Add(new MultiwayItem()
243
                {
244
                    Index = i + 1,
245 4f02de16 이지연
                    Name = row["Name"].ToString()
246 a2ab8a90 이지연
                });
247
            }
248
        }
249
250
        private void gridViewType_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e)
251
        {
252
            ReNumbering(currentMultiwayInfo);
253
        }
254
        private void gridViewSymbol_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
255
        {
256
            ReNumbering(currentMultiwayInfo);
257
        }
258
        private void TreeList_BeforeCheckNode(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
259
        {
260
            DevExpress.XtraEditors.TreeListLookUpEdit treeListLookUpEdit = sender as DevExpress.XtraEditors.TreeListLookUpEdit;
261
            if (treeListLookUpEdit.Properties.TreeList.FocusedNode == null)
262
                return;
263
264
            if (treeListLookUpEdit.Properties.TreeList.FocusedNode.Level == 0)
265
                e.Cancel = true;
266
        }
267
        private void btnSave_Click(object sender, EventArgs e)
268
        {
269
            if (currentMultiwayInfo == null)
270
            {
271
                currentMultiwayInfo = new MultiwayInfo();
272
            }
273
274
            ReNumbering(currentMultiwayInfo);
275 4f02de16 이지연
            if(currentMultiwayInfo.MultiwayItems.Find(x => x.Name == string.Empty) != null)
276 a2ab8a90 이지연
            {
277
                MessageBox.Show("Please save after entering data.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
278
                return;
279
            }
280
281
            if (DB.SaveMultiwaysSetting(currentMultiwayInfo.MultiwayItems))
282
                MessageBox.Show("Save was successful", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
283
            else
284
                MessageBox.Show("Failed to save", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
285
        }
286
287
        private void btnClose_Click(object sender, EventArgs e)
288
        {
289
            DialogResult = DialogResult.Cancel;
290
        }
291
    }
292
}
클립보드 이미지 추가 (최대 크기: 500 MB)