1 |
88c1965b
|
gaqhf
|
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 |
|
|
private void removeSymbolButton_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
|
152 |
|
|
{
|
153 |
|
|
DataTable dt = gridEquipment.DataSource as DataTable;
|
154 |
|
|
DataRow rows = dt.Rows[gridViewEquipment.FocusedRowHandle];
|
155 |
|
|
if (rows != null)
|
156 |
|
|
dt.Rows.Remove(rows);
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
public void SetSymbol(RepositoryItemTreeListLookUpEdit treeListLookUpEdit)
|
160 |
|
|
{
|
161 |
|
|
string imgPath = ID2Info.ImageDirPath;
|
162 |
|
|
string[] filesPath = Directory.GetFiles(imgPath, "*.png", SearchOption.AllDirectories);
|
163 |
|
|
|
164 |
|
|
DataTable dt = new DataTable();
|
165 |
|
|
dt.Columns.Add("ID", typeof(int));
|
166 |
|
|
dt.Columns.Add("ParentID", typeof(int));
|
167 |
|
|
dt.Columns.Add("Name", typeof(string));
|
168 |
|
|
dt.Columns.Add("Level", typeof(int));
|
169 |
|
|
dt.Columns.Add("Image", typeof(Image));
|
170 |
|
|
dt.PrimaryKey = new DataColumn[] { dt.Columns["ID"] };
|
171 |
|
|
|
172 |
|
|
treeListLookUpEdit.DataSource = dt;
|
173 |
|
|
treeListLookUpEdit.ValueMember = "Name";
|
174 |
|
|
treeListLookUpEdit.DisplayMember = "Name";
|
175 |
|
|
treeListLookUpEdit.TreeList.Columns["Level"].Visible = false;
|
176 |
|
|
treeListLookUpEdit.NullText = "";
|
177 |
|
|
|
178 |
|
|
treeListLookUpEdit.EditValueChanging += new DevExpress.XtraEditors.Controls.ChangingEventHandler(TreeList_BeforeCheckNode);
|
179 |
|
|
|
180 |
|
|
treeListLookUpEdit.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
|
181 |
|
|
|
182 |
|
|
bool bLine = true;
|
183 |
|
|
List<string> level1Index = new List<string>();
|
184 |
|
|
foreach (var path in filesPath)
|
185 |
|
|
{
|
186 |
|
|
if (Path.GetFileNameWithoutExtension(path).Contains("_display"))
|
187 |
|
|
continue;
|
188 |
|
|
|
189 |
|
|
string root = path.Remove(0, imgPath.Length);
|
190 |
|
|
string[] split = root.Split(new string[] { @"\" }, StringSplitOptions.None);
|
191 |
|
|
string level1 = split[0];
|
192 |
|
|
if (!level1Index.Contains(level1))
|
193 |
|
|
{
|
194 |
|
|
level1Index.Add(level1);
|
195 |
|
|
dt.Rows.Add(level1Index.IndexOf(level1) + 1, 0, level1, 0);
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
int parentId = level1Index.IndexOf(level1) + 1;
|
199 |
|
|
string level2 = split[1];
|
200 |
|
|
//combobox image size 변경
|
201 |
|
|
Image image = Image.FromFile(Path.Combine(imgPath, root));
|
202 |
|
|
Bitmap imgbitmap = new Bitmap(image);
|
203 |
|
|
Image resizedImage = resizeImage(imgbitmap, new Size(200, 200));
|
204 |
|
|
|
205 |
|
|
dt.Rows.Add(filesPath.ToList().IndexOf(path) + 10000, parentId, Path.GetFileNameWithoutExtension(path), 1, resizedImage);
|
206 |
|
|
|
207 |
bd86dd48
|
이지연
|
if (bLine)
|
208 |
88c1965b
|
gaqhf
|
{
|
209 |
|
|
bLine = false;
|
210 |
9bb7a028
|
이지연
|
dt.Rows.Add(filesPath.ToList().IndexOf(path) + 20000, parentId, "Primary", 1, null);
|
211 |
|
|
dt.Rows.Add(filesPath.ToList().IndexOf(path) + 30000, parentId, "Secondary", 1, null);
|
212 |
88c1965b
|
gaqhf
|
}
|
213 |
|
|
}
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
public static Image resizeImage(Image imgToResize, Size size)
|
217 |
|
|
{
|
218 |
|
|
return (Image)(new Bitmap(imgToResize, size));
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
private void btnAddSymbol_Click(object sender, EventArgs e)
|
222 |
|
|
{
|
223 |
|
|
if (currentEquipmentNoPocketInfo == null)
|
224 |
|
|
{
|
225 |
|
|
currentEquipmentNoPocketInfo = new EquipmentNoPocketInfo();
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
DataTable dt = gridEquipment.DataSource as DataTable;
|
229 |
|
|
dt.Rows.Add(dt.Rows.Count + 1, null, null, null);
|
230 |
|
|
gridViewEquipment.Columns["Index"].BestFit();
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
|
234 |
|
|
//if (currentEquipmentNoPocketInfo == null)
|
235 |
|
|
//{
|
236 |
|
|
// currentEquipmentNoPocketInfo = new EquipmentNoPocketInfo();
|
237 |
|
|
//}
|
238 |
|
|
|
239 |
|
|
|
240 |
|
|
//dt.Rows.Add(null, null, null, null);
|
241 |
|
|
//gridViewEquipment.Columns["Type"].BestFit();
|
242 |
|
|
}
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
public void ReNumbering(EquipmentNoPocketInfo equipmentNoPocketInfo)
|
246 |
|
|
{
|
247 |
|
|
DataTable dt = gridEquipment.DataSource as DataTable;
|
248 |
|
|
equipmentNoPocketInfo.EquipmentNoPocketItem.Clear();
|
249 |
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
250 |
|
|
{
|
251 |
|
|
DataRow row = dt.Rows[i];
|
252 |
|
|
row["Index"] = i + 1;
|
253 |
|
|
equipmentNoPocketInfo.EquipmentNoPocketItem.Add(new EquipmentNoPocketItem()
|
254 |
|
|
{
|
255 |
|
|
Index = i + 1,
|
256 |
|
|
Type = row["Type"].ToString(),
|
257 |
|
|
Name = row["SppidSymbolName"].ToString()
|
258 |
|
|
});
|
259 |
|
|
}
|
260 |
|
|
}
|
261 |
|
|
|
262 |
|
|
private void gridViewType_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e)
|
263 |
|
|
{
|
264 |
|
|
ReNumbering(currentEquipmentNoPocketInfo);
|
265 |
|
|
}
|
266 |
|
|
|
267 |
|
|
|
268 |
|
|
private void TreeList_BeforeCheckNode(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
|
269 |
|
|
{
|
270 |
|
|
DevExpress.XtraEditors.TreeListLookUpEdit treeListLookUpEdit = sender as DevExpress.XtraEditors.TreeListLookUpEdit;
|
271 |
|
|
if (treeListLookUpEdit.Properties.TreeList.FocusedNode == null)
|
272 |
|
|
return;
|
273 |
|
|
|
274 |
|
|
if (treeListLookUpEdit.Properties.TreeList.FocusedNode.Level == 0)
|
275 |
|
|
e.Cancel = true;
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
private void btnSave_Click(object sender, EventArgs e)
|
281 |
|
|
{
|
282 |
|
|
if (currentEquipmentNoPocketInfo == null)
|
283 |
|
|
{
|
284 |
|
|
currentEquipmentNoPocketInfo = new EquipmentNoPocketInfo();
|
285 |
|
|
}
|
286 |
|
|
|
287 |
|
|
ReNumbering(currentEquipmentNoPocketInfo);
|
288 |
|
|
if (currentEquipmentNoPocketInfo.EquipmentNoPocketItem.Find(x => x.Type == string.Empty || x.Name == string.Empty) != null)
|
289 |
|
|
{
|
290 |
|
|
MessageBox.Show("Please save after entering data.", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
291 |
|
|
return;
|
292 |
|
|
}
|
293 |
|
|
|
294 |
|
|
if (DB.SaveEquipmentNopocketSetting(currentEquipmentNoPocketInfo.EquipmentNoPocketItem))
|
295 |
|
|
MessageBox.Show("Save was successful", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
296 |
|
|
else
|
297 |
|
|
MessageBox.Show("Failed to save", "ID2 " + ID2Info.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
298 |
|
|
|
299 |
|
|
|
300 |
|
|
}
|
301 |
|
|
|
302 |
|
|
private void btnClose_Click(object sender, EventArgs e)
|
303 |
|
|
{
|
304 |
|
|
DialogResult = DialogResult.Cancel;
|
305 |
|
|
}
|
306 |
|
|
}
|
307 |
|
|
} |