-
Notifications
You must be signed in to change notification settings - Fork 1
/
EBMContent.cs
538 lines (474 loc) · 18.5 KB
/
EBMContent.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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
using ControlAstro.Utils;
using EBMTable;
using EBMTest.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Web.Script.Serialization;
using System.Windows.Forms;
namespace EBMTest
{
public partial class EBMContent : Form
{
private BindingCollection<EBContent_AllData> EBContent_List_AllData;
private BindingCollection<EBContent_AllData> SelectEBContent_List;
public EBMContent()
{
InitializeComponent();
EBContent_List_AllData = new BindingCollection<EBContent_AllData>();
SelectEBContent_List = new BindingCollection<EBContent_AllData>();
Load += EBMContent_Load;
dgvEBContent.AutoGenerateColumns = false;
}
private void EBMContent_Load(object sender, EventArgs e)
{
InitEbmId();
InitContent();
showdata();
}
private void InitContent()
{
try
{
var jo = TableData.TableDataHelper.ReadTable(Enums.TableType.Content);
if (jo != null)
{
JavaScriptSerializer Serializer = new JavaScriptSerializer();
BindingCollection<EBContentTMP> EBContent_ListTMP = Serializer.Deserialize<BindingCollection<EBContentTMP>>(jo["0"].ToString());
BindingCollection<EBContent> EBContent_ListTMP2 = JsonConvert.DeserializeObject<BindingCollection<EBContent>>(jo["1"].ToString());
if (EBContent_ListTMP != null)
{
foreach (EBContentTMP item in EBContent_ListTMP)
{
EBContent_AllData tmp = new EBContent_AllData();
tmp.Guid = item.Guid;
tmp.SectionName = item.SectionName;
tmp.SendState = item.SendState;
tmp.EBM_ID = item.EBM_ID;
tmp.EBContentList = GetRelateEBContentlist(tmp.Guid, tmp.EBM_ID, EBContent_ListTMP2);
EBContent_List_AllData.Add(tmp);
}
}
}
}
catch (Exception)
{
throw;
}
}
private BindingCollection<EBContent> GetRelateEBContentlist(string guid, string ebmid, BindingCollection<EBContent> list)
{
BindingCollection<EBContent> tmp = new BindingCollection<EBContent>();
foreach (EBContent item in list)
{
if (item.Guid == guid && item.EBM_ID == ebmid)
{
tmp.Add(item);
}
}
return tmp;
}
private void InitEbmId()
{
List<string> ebmId = new List<string>();
var ebmIndex = (MdiParent as EBMMain).EBMIndex;
if (ebmIndex != null)
{
ebmId = ebmIndex.GetEbmId();
}
else
{
BindingCollection<EBMIndex.EBIndexEx> index = new BindingCollection<EBMIndex.EBIndexEx>();
ebmId = new List<string>();
var jo = TableData.TableDataHelper.ReadTable(Enums.TableType.Index);
if (jo != null)
{
index = JsonConvert.DeserializeObject<BindingCollection<EBMIndex.EBIndexEx>>(jo["0"].ToString());
}
foreach (var dex in index)
{
ebmId.Add(dex.S_EBM_id);
}
}
cbBoxEBMId.DataSource = ebmId;
}
public bool GetlistContentTable(ref List<EBContentTable> oldTableList)
{
try
{
oldTableList.Clear();
foreach (EBContent_AllData item in EBContent_List_AllData)
{
EBContentTable pp = new EBContentTable();
pp.ProtocolGX = SingletonInfo.GetInstance().IsProtocolGX;
List<MultilangualContent> listMulti = GetSendMultilangualContentNew(item.EBContentList);
if (listMulti == null || listMulti.Count == 0)
{
// return false;
continue;
}
pp.list_multilangual_content = listMulti;
pp.S_EBM_id = item.EBM_ID;
pp.Repeat_times = pnlRepeatTimes.GetRepeatTimes();
pp.Table_id = 0xfe;
pp.Table_id_extension = 0;
oldTableList.Add(pp);
}
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + ex.StackTrace);
return false;
}
}
private List<MultilangualContent> GetSendMultilangualContentNew(BindingCollection<EBContent> EBContent_List)
{
if (EBContent_List.Count == 0)
{
return null;
}
List<MultilangualContent> listMulti = new List<MultilangualContent>();
foreach (var content in EBContent_List)
{
var contentex = DeepCopy(content.MultilangualContent);
contentex.list_auxiliary_data = content.GetAuxiliaryData();
listMulti.Add(contentex);
}
return listMulti;
}
private T DeepCopy<T>(T obj)
{
//如果是字符串或值类型则直接返回
if (obj == null || obj is string || obj.GetType().IsValueType || obj.GetType().IsArray) return obj;
object retval = Activator.CreateInstance(obj.GetType());
FieldInfo[] fields = obj.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
foreach (FieldInfo field in fields)
{
try
{
field.SetValue(retval, DeepCopy(field.GetValue(obj)));
}
catch { }
}
return (T)retval;
}
#region 右键事件
private void MenuItemAdd_Click(object sender, System.EventArgs e)
{
AddSection();
}
private void MenuItemInfo_Click(object sender, System.EventArgs e)
{
InfoSection();
}
private void MenuItemUpdate_Click(object sender, System.EventArgs e)
{
UpdateSection();
}
private void MenuItemDel_Click(object sender, System.EventArgs e)
{
DelSection();
}
#endregion
private void MenuStripEBContent_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
MenuItemInfo.Enabled = dgvEBContent.RowCount > 0;
MenuItemDel.Enabled = dgvEBContent.RowCount > 0;
MenuItemUpdate.Enabled = dgvEBContent.RowCount > 0;
Point downPoint = dgvEBContent.PointToClient(MousePosition);
var hit = dgvEBContent.HitTest(downPoint.X, downPoint.Y);
if (hit.Type == DataGridViewHitTestType.Cell || hit.Type == DataGridViewHitTestType.RowHeader)
{
dgvEBContent.Rows[hit.RowIndex].Selected = true;
}
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
AddSection();
}
private void DelSection()
{
if (dgvEBContent.SelectedRows.Count > 0)
{
EBContent_AllData TobeDel = SelectEBContent_List[dgvEBContent.SelectedRows[0].Index];
SelectEBContent_List.RemoveAt(dgvEBContent.SelectedRows[0].Index);
string guid= TobeDel.Guid;
EBContent_AllData TobeDelNew = new EBContent_AllData();
foreach (var item in EBContent_List_AllData)
{
if (item.Guid == guid)
{
TobeDelNew = item;
}
}
if (TobeDelNew!=null)
{
EBContent_List_AllData.Remove(TobeDelNew);
}
}
else
{
MessageBox.Show("未选中任何索引");
}
}
/// <summary>
/// 增加Section
/// </summary>
private void AddSection()
{
try
{
if (cbBoxEBMId.SelectedValue != null)
{
if (dgvEBContent.Rows.Count == 0)
{
string EBM_ID = cbBoxEBMId.SelectedValue.ToString();
EBMContentSectionInfo form = new EBMContentSectionInfo(Enums.OperateType.Add, EBM_ID);
DialogResult result = form.ShowDialog();
if (result == DialogResult.OK && form.ContentAllData != null)
{
SelectEBContent_List.Add(form.ContentAllData);
EBContent_List_AllData.Add(form.ContentAllData);//同步到全局数据
}
form.Dispose();
}
else
{
MessageBox.Show("已添加过一条数据,不能再添加!");
}
}
else
{
MessageBox.Show("未发现可用EBM_ID");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 查看Section信息
/// </summary>
private void InfoSection()
{
if (dgvEBContent.SelectedRows.Count > 0)
{
string EBM_ID = cbBoxEBMId.SelectedValue.ToString();
new EBMContentSectionInfo(Enums.OperateType.Info, EBM_ID, SelectEBContent_List[dgvEBContent.SelectedRows[0].Index]).ShowDialog();
}
else
{
MessageBox.Show("未选中任何索引");
}
}
/// <summary>
/// 更新Section
/// </summary>
private void UpdateSection()
{
if (dgvEBContent.SelectedRows.Count > 0)
{
string EBM_ID = cbBoxEBMId.SelectedValue.ToString();
EBMContentSectionInfo form = new EBMContentSectionInfo(Enums.OperateType.Update, EBM_ID, SelectEBContent_List[dgvEBContent.SelectedRows[0].Index]);
DialogResult result = form.ShowDialog();
if (result == DialogResult.OK && form.ContentAllData != null)
{
SelectEBContent_List[dgvEBContent.SelectedRows[0].Index] = form.ContentAllData;
string guid = SelectEBContent_List[dgvEBContent.SelectedRows[0].Index].Guid;
EBContent_AllData TobeDel = new EBContent_AllData();
foreach (var item in EBContent_List_AllData)
{
if (item.Guid == guid)
{
TobeDel = item;
}
}
if (TobeDel!=null)
{
EBContent_List_AllData.Remove(TobeDel);
EBContent_List_AllData.Add(SelectEBContent_List[dgvEBContent.SelectedRows[0].Index]);
}
}
form.Dispose();
}
else
{
MessageBox.Show("未选中任何索引");
}
}
private void dgvEBContent_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
try
{
if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
{
if (e.ColumnIndex == ColumnSendState.Index)
{
SelectEBContent_List[e.RowIndex].SendState = !SelectEBContent_List[e.RowIndex].SendState;
(MdiParent as EBMMain).InitStreamTable();
}
if (e.ColumnIndex == Detail_data.Index)
{
EBMContentDe detail = new EBMContentDe(SelectEBContent_List[e.RowIndex]);
DialogResult result = detail.ShowDialog();
if (result == DialogResult.OK)
{
SelectEBContent_List[e.RowIndex].EBContentList = detail.EBContent_List;
#region 数据更新模块
string guid = SelectEBContent_List[dgvEBContent.SelectedRows[0].Index].Guid;
EBContent_AllData TobeDel = new EBContent_AllData();
foreach (var item in EBContent_List_AllData)
{
if (item.Guid == guid)
{
TobeDel = item;
}
}
if (TobeDel != null)
{
EBContent_List_AllData.Remove(TobeDel);
EBContent_List_AllData.Add(SelectEBContent_List[dgvEBContent.SelectedRows[0].Index]);
}
#endregion
}
detail.Dispose();
}
}
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
}
/// <summary>
/// 具有相同EBM_ID的
/// </summary>
public class EBContent_AllData
{
public bool SendState { get; set; }
public string EBM_ID { get; set; }
public string SectionName { get; set; }
public string Guid { get; set; }
public BindingCollection<EBContent> EBContentList { get; set; }
}
public class EBContentTMP
{
public bool SendState { get; set; }
public string EBM_ID { get; set; }
public string SectionName { get; set; }
public string Guid { get; set; }
}
public class EBContent
{
public string Guid { get; set; }
public string EBM_ID { get; set; }
public string SectionName { get; set; }
public MultilangualContent MultilangualContent { get; set; }
public byte B_code_character_set
{
get { return MultilangualContent.B_code_character_set; }
set { MultilangualContent.B_code_character_set = value; }
}
public byte[] B_message_text
{
get { return MultilangualContent.B_message_text; }
set { MultilangualContent.B_message_text = value; }
}
public string S_language_code
{
get { return MultilangualContent.S_language_code; }
set { MultilangualContent.S_language_code = value; }
}
public string MessageText { get; set; }
public List<Auxiliary> list_auxiliary_data { get; set; }
public List<AuxiliaryData> GetAuxiliaryData()
{
List<AuxiliaryData> data = new List<AuxiliaryData>();
if (list_auxiliary_data == null) return data;
for (int i = 0; i < list_auxiliary_data.Count; i++)
{
data.Add(list_auxiliary_data[i].GetAuxData());
}
return data;
}
}
public class Auxiliary
{
public AuxiliaryData GetAuxData()
{
AuxiliaryData data = new AuxiliaryData();
data.B_auxiliary_data_type = Type;
data.B_auxiliary_data = TableData.TableDataHelper.GetFileData(DisplayData);
return data;
}
public byte Type { get; set; }
public string DisplayData { get; set; }
private string typeString;
public string TypeString
{
get { return ComboBoxHelper.GetTypeStringValue(Enums.ParamType.ContentAuxiliaryData, Type); }
set { typeString = value; }
}
}
private void EBMContent_FormClosing(object sender, FormClosingEventArgs e)
{
TableData.TableDataHelper.WriteTable(Enums.TableType.Content, EBContent_List_AllData);
}
public void AppendDataText(string text)
{
richTextData.AppendText(text);
}
private void dgvEBContent_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
//MessageBox.Show(string.Format("列:{0} 行:{1} 数据输入异常,请检查,如需退出编辑请按Esc键", e.ColumnIndex, e.RowIndex));
e.ThrowException = false;
}
public void UpdateEbmIndex(List<string> list)
{
if (list != null && list.Count > 0)
{
cbBoxEBMId.DataSource = list;
}
}
/// <summary>
/// EBM_ID值发生变化时,对应的文本和辅助数据变化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cbBoxEBMId_SelectedValueChanged(object sender, EventArgs e)
{
try
{
showdata();
}
catch (Exception)
{
throw;
}
}
private void showdata()
{
if (cbBoxEBMId.SelectedValue != null)
{
SelectEBContent_List.Clear();
string ebmid = cbBoxEBMId.SelectedValue.ToString();
foreach (EBContent_AllData item in EBContent_List_AllData)
{
if (item.EBM_ID == ebmid)
{
SelectEBContent_List.Add(item);
}
}
dgvEBContent.DataSource = SelectEBContent_List;
}
else
{
MessageBox.Show("未发现可用EBM_ID");
}
}
}
}