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