/
SetForm.cs
351 lines (315 loc) · 11.8 KB
/
SetForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OrderEasy.common;
namespace OrderEasy
{
public partial class SetForm : Form
{
private SourceGrid.Cells.Views.ColumnHeader headerView = new SourceGrid.Cells.Views.ColumnHeader();
private SourceGrid.Cells.Views.Cell cellView = new SourceGrid.Cells.Views.Cell();
private SourceGrid.Cells.Views.CheckBox checkView = new SourceGrid.Cells.Views.CheckBox();
private int _W = 230;
private int _H = 25;
private Common comon;
private OrderEasy frmMain;
public SetForm(OrderEasy _frmMain)
{
InitializeComponent();
this.frmMain = _frmMain;
}
private void initView()
{
DevAge.Drawing.RectangleBorder border = new DevAge.Drawing.RectangleBorder(new DevAge.Drawing.BorderLine(Color.DarkGreen), new DevAge.Drawing.BorderLine(Color.DarkGreen));
DevAge.Drawing.VisualElements.ColumnHeader flatHeader = new DevAge.Drawing.VisualElements.ColumnHeader();
flatHeader.Border = border;
flatHeader.BackColor = Color.LightBlue;
flatHeader.BackgroundColorStyle = DevAge.Drawing.BackgroundColorStyle.Solid;
headerView.Font = new Font(grid_addr.Font, FontStyle.Bold);
headerView.Background = flatHeader;
headerView.ForeColor = Color.Black;
headerView.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleCenter;
cellView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.White, Color.White, 500);
cellView.Border = border;
checkView = new SourceGrid.Cells.Views.CheckBox();
checkView.Background = new DevAge.Drawing.VisualElements.BackgroundLinearGradient(Color.White, Color.White, 45);
checkView.Border = border;
}
private void SetGrid(SourceGrid.Grid grid, Dictionary<string, bool> dic, string c1, string c2)
{
grid.BorderStyle = BorderStyle.FixedSingle;
grid.Redim(dic.Count + 1, 2);
AddOneRow(grid, 0, c1, c2, true);
int i = 0;
foreach (KeyValuePair<string, bool> pair in dic)
{
string showState = pair.Value ? "on" : "off";
AddOneRow(grid, i++ + 1, pair.Key, showState, false);
}
grid.Selection.SelectRow(1, true);
grid.Selection.EnableMultiSelection = false;
}
private void SetAddrGrid()
{
SetGrid(grid_addr, comon.addrDic, "地址", "状态");
grid_addr.Rows[0].Height = _H;
grid_addr.Columns[0].Width = 215;
}
private void SetFutureGrid()
{
grid_account.BorderStyle = BorderStyle.FixedSingle;
grid_account.Redim(comon.futureDic.Count + 1, 5);
AddOneRowFutureHead(grid_account, true);
int i = 0;
foreach (KeyValuePair<string, Future> pair in comon.futureDic)
{
Future f = pair.Value;
AddOneRowFuture(grid_account, i++ + 1, pair.Key, f.isActive, f.tick.ToString(),f.point,f.symbols);
}
}
private void SetStockGrid()
{
grid_category.BorderStyle = BorderStyle.FixedSingle;
grid_category.Redim(comon.stockDic.Count + 1, 4);
AddOneRowFutureHead(grid_category, false);
int i = 0;
foreach (KeyValuePair<string, Future> pair in comon.stockDic)
{
Future f = pair.Value;
AddOneRowFuture(grid_category, i++ + 1, pair.Key, f.isActive, f.tick.ToString(), f.point, "");
}
}
private void init() {
initView();
comon = Common.Instance();
SetAddrGrid();
SetFutureGrid();
SetStockGrid();
}
private void SetForm_Load(object sender, EventArgs e)
{
init();
}
private void AddOneRowFutureHead(SourceGrid.Grid grid, bool isFutrue)
{
try
{
string fristName = isFutrue ? "品种" : "合约";
grid[0, 0] = new SourceGrid.Cells.Cell(fristName, typeof(string));
grid[0, 0].View = headerView;
grid[0, 1] = new SourceGrid.Cells.Cell("状态", typeof(string));
grid[0, 1].View = headerView;
grid[0, 2] = new SourceGrid.Cells.Cell("TICK", typeof(string));
grid[0, 2].View = headerView;
grid[0, 3] = new SourceGrid.Cells.Cell("小数点", typeof(string));
grid[0, 3].View = headerView;
if (isFutrue)
{
grid[0, 4] = new SourceGrid.Cells.Cell("合约", typeof(string));
grid[0, 4].View = headerView;
}
}
catch (System.Exception ex)
{
Program.log.Error(ex, ex);
}
}
private void AddOneRowFuture(SourceGrid.Grid grid, int r, string product, bool isCheck, string tick,int point, string symbol)
{
try
{
grid[r, 0] = new SourceGrid.Cells.Cell(product, typeof(string));
grid[r, 0].View = cellView;
grid[r, 1] = new SourceGrid.Cells.CheckBox(null, isCheck);
grid[r, 1].View = checkView;
grid[r, 2] = new SourceGrid.Cells.Cell(tick, typeof(string));
grid[r, 2].View = cellView;
grid[r, 3] = new SourceGrid.Cells.Cell(point, typeof(int));
grid[r, 3].View = cellView;
if (!string.IsNullOrEmpty(symbol))
{
grid[r, 4] = new SourceGrid.Cells.Cell(symbol, typeof(string));
grid[r, 4].View = cellView;
}
}
catch (System.Exception ex)
{
Program.log.Error(ex, ex);
}
}
private void AddOneRow(SourceGrid.Grid grid, int r, string c1, string c2, bool isHead)
{
try
{
//int rowCount = grid.RowsCount;
//grid.Redim(rowCount + 1, 2);
grid[r, 0] = new SourceGrid.Cells.Cell(c1, typeof(string));
grid[r, 0].View = isHead ? headerView : cellView;
if (isHead)
{
grid[r, 1] = new SourceGrid.Cells.Cell(c2, typeof(string));
grid[r, 1].View = headerView;
}
else
{
bool isCheck = c2 == "on" ? true : false;
grid[r, 1] = new SourceGrid.Cells.CheckBox(null, isCheck);
grid[r, 1].View = checkView;
}
//grid.Refresh();
}
catch (System.Exception ex)
{
Program.log.Error(ex, ex);
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
string name = tabControl1.SelectedTab.Name;
if ("tab_addr_m".Equals(name))
{
//AddOneRow(grid_addr, comon.addrList.Count + 1, "", "显示", false);
int rowCount = grid_addr.RowsCount;
grid_addr.Redim(rowCount + 1, 2);
AddOneRow(grid_addr, rowCount, "tcp://192.168.0.10:6006", "on", false);
grid_addr.Refresh();
}
else if ("tab_account_m".Equals(name))
{
int rowCount = grid_account.RowsCount;
grid_account.Redim(rowCount + 1, 2);
AddOneRow(grid_account, rowCount, "0000", "on", false);
grid_account.Refresh();
}
else
{
int rowCount = grid_category.RowsCount;
grid_category.Redim(rowCount + 1, 2);
AddOneRow(grid_category, rowCount, "XX", "on", false);
grid_category.Refresh();
}
}
private int DeleteRow(SourceGrid.Grid grid){
for (int i =0;i<grid.Rows.Count;i++)
{
if (grid.Selection.IsSelectedRow(i))
{
grid.Rows.Remove(i);
grid.Refresh();
return i;
}
}
return -1;
}
/// <summary>
///
/// </summary>
/// <param name="grid"></param>
/// <param name="rowMove">-1:down 1:up</param>
/// <returns></returns>
private int changeIndex(SourceGrid.Grid grid,int rowMove)
{
for (int i = 0; i < grid.Rows.Count; i++)
{
if (grid.Selection.IsSelectedRow(i))
{
if (i + rowMove > grid.Rows.Count - 1)
{
MessageBox.Show("已到最底!");
return -1;
}
else if (i + rowMove <0)
{
MessageBox.Show("已到最顶!");
return -1;
}
grid.Refresh();
return i;
}
}
return -1;
}
private void btnSub_Click(object sender, EventArgs e)
{
string name = tabControl1.SelectedTab.Name;
if ("tab_addr_m".Equals(name))
{
int deleteIndex = DeleteRow(grid_addr);
ZMQControl.Instance().DisConnect(grid_addr[deleteIndex,0].Value + "");
return;
}
else if ("tab_account_m".Equals(name))
{
DeleteRow(grid_account);
//return;
}
else
{
DeleteRow(grid_category);
}
}
private void btnUp_Click(object sender, EventArgs e)
{
//string name = tabControl1.SelectedTab.Name;
//if ("tab_addr_m".Equals(name))
//{
// return;
//}
//else if ("tab_account_m".Equals(name))
//{
// changeIndex(grid_account);
// //return;
//}
//else
//{
// changeIndex(grid_category);
//}
}
private void btnDown_Click(object sender, EventArgs e)
{
}
private void Rest(Dictionary<string, bool> dic, SourceGrid.Grid grid)
{
//list.Clear();
dic.Clear();
for (int i = 1; i < grid.RowsCount; i++)
{
bool isChecked = (bool)grid[i, 1].Value;
string key = grid[i, 0].Value + "";
if (!dic.ContainsKey(key))
{
dic.Add(key, isChecked);
}
}
}
private void AddrConHandle()
{
foreach (KeyValuePair<string, bool> pair in comon.addrDic)
{
if (pair.Value)
{
ZMQControl.Instance().Connect(pair.Key);
}
else
{
ZMQControl.Instance().DisConnect(pair.Key);
}
}
}
private void btnOk_Click(object sender, EventArgs e)
{
Rest(comon.addrDic, grid_addr);
//Rest(comon.futureDic, grid_account);
//Rest(comon.productDic, grid_category);
frmMain.updateGridHandle();
AddrConHandle();
comon.SaveConfig();
this.Close();
}
}
}