RosterList.cs
39.8 KB
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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
/*-------------------------------------------------------------------------------------------
* 人员名单操作类
* 创建:杨斌 2011-12-13
* ----------------------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections.Specialized;
using GeneralLib;
using System.Collections;
using System.Timers;
//using System.Timers;
namespace SunVoteARSPPT
{
public class RosterCloumn
{
public int ColumnID { get; set; }
public int ColumnIndex { get; set; }
/// <summary>
/// 名单字段显示名称
/// </summary>
public string ColumnName { get; set; }
///// <summary>
///// 名单中键盘编号字段ID,现默认为名单中的第1列
///// </summary>
//public string ClolumnIDKeypadID { get; set; }
///// <summary>
///// 签到吗字段ID
///// </summary>
//public string ClolumnIDSingnInCode { get; set; }
///// <summary>
///// 反馈明细显示的姓名字段ID
///// </summary>
//public string ClolumnIDShowNameDetail { get; set; }
}
public class RosterRow
{
public int RowID { get; set; }
public int RowIndex { get; set; }
/// <summary>
/// 对应名单中的各列字段值,索引从0开始
/// </summary>
public string[] Cells { get; set; }
}
public class RosterList
{
/// <summary>
/// 名单列
/// </summary>
public TDictionary<string, RosterCloumn> Columns { get; set; }
/// <summary>
/// 名单行
/// </summary>
public TDictionary<string, RosterRow> Rows { get; set; }
private Dictionary<string, string> VIDToRIDs = null;
/// <summary>
/// 会议ID
/// </summary>
public string MeetID { get; set; }
/// <summary>
/// 键盘编号字段索引,无则为-1,默认为0即第一列
/// </summary>
public int KeypadIdColumnIndex { get; set; }
/// <summary>
/// 人员名单签到码字段索引,无则为-1
/// </summary>
public int SingnInCodeColumnIndex { get; set; }
public RosterList()
{
Columns = new TDictionary<string, RosterCloumn>();
Rows = new TDictionary<string, RosterRow>();
if (MeetID == null) MeetID = "";
KeypadIdColumnIndex = 0;
SingnInCodeColumnIndex = -1;
}
/// <summary>
/// 全局的人员名单。在切换PPT,导入名单时加载
/// 杨斌 2015-11-25
/// </summary>
public static RosterList RosterLoad = null;
/// <summary>
/// 创建 赵丽 2012-06-18
/// 记录签到码索引
/// </summary>
public int SignInCodeIndex
{
get
{
int res = 0;
try
{
string sql = "Select M_SignInCodeColumn From ST_Meet Where M_ID='0'";
DataSet ds = GlobalInfo.DBOperation.GetDataSet(sql);
DataTable tb = ds.Tables[0];
if (tb.Rows.Count > 0)
{
try
{
res = (int)(tb.Rows[0]["M_SignInCodeColumn"]);
}
catch { res = 0; }
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
set
{
try
{
string sql = "Update ST_Meet Set M_SignInCodeColumn=" + value.ToString() + " Where M_ID='0'";
GlobalInfo.DBOperation.ExecuteNonQuery(sql);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
}
/// <summary>
/// 投票权重字段名称
/// 创建:杨斌 2012-11-27
/// </summary>
public const string RateIndexColName = "M_VoteRateColumn";
/// <summary>
/// 投票权重字段索引
/// 创建:杨斌 2012-11-27
/// </summary>
public int VoteRateIndex
{
get
{
GlobalInfo.DBOperation.AddTableColumnInt("ST_Meet", RateIndexColName, 0);
int res = 0;
try
{
string sql = "Select " + RateIndexColName + " From ST_Meet Where M_ID='0'";
DataSet ds = GlobalInfo.DBOperation.GetDataSet(sql);
DataTable tb = ds.Tables[0];
if (tb.Rows.Count > 0)
res = ConvertOper.Convert(tb.Rows[0][RateIndexColName].ToString()).ToInt;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
set
{
GlobalInfo.DBOperation.AddTableColumnInt("ST_Meet", RateIndexColName, 0);
try
{
string sql = "Update ST_Meet Set " + RateIndexColName + "=" + value.ToString() + " Where M_ID='0'";
GlobalInfo.DBOperation.ExecuteNonQuery(sql);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
}
/// <summary>
/// 是否启用名单
/// </summary>
public bool RosterEnabled
{
get
{
bool res = false;
try
{
string sql = "Select M_RosterEnabled From ST_Meet Where M_ID='0'";
//2012-12-04 修改演示模式 快捷键报错的问题 赵丽
DataSet ds = GlobalInfo.DBOperation.GetDataSet(sql);
if (ds.Tables.Count > 0)//杨斌 2013-11-27
{
DataTable tb = ds.Tables[0];
if (tb.Rows.Count > 0)
res = (bool)(tb.Rows[0]["M_RosterEnabled"]);
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
set
{
try
{
//string sql = "Select M_RosterEnabled From ST_Meet Where M_ID='0'";
//GlobalInfo.DBOperation.OpenDataSet(sql);
//DataTable tb = GlobalInfo.DBOperation.DataSet.Tables[0];
//DataRow row=null;
//if (tb.Rows.Count > 0)
//{
// row = tb.Rows[0];
//}
//else
//{
// row = tb.NewRow();
// tb.Rows.Add(row);
//}
//row["M_RosterEnabled"] = value;
//GlobalInfo.DBOperation.UpdateDataSet();
//GlobalInfo.DBOperation.CloseDataSet();
string sql = "Update ST_Meet Set M_RosterEnabled=" + value.ToString() + " Where M_ID='0'";
GlobalInfo.DBOperation.ExecuteNonQuery(sql);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
}
}
/// <summary>
/// 加载名单字段
/// </summary>
public bool LoadCloumn(DBOper dbOperation)
{
bool res = false;
try
{
Columns.Clear();
string sql = "Select * From ST_RosterColumn Order By RC_Index Asc";
DataSet ds = dbOperation.GetDataSet(sql);
if (ds.Tables.Count > 0)
{
DataTable tb = ds.Tables[0];
for (int i = 0; i < tb.Rows.Count; i++)
{
RosterCloumn col = new RosterCloumn();
col.ColumnID = ConvertOper.Convert(tb.Rows[i]["RC_ID"].ToString()).ToInt;
col.ColumnIndex = i + 1;
col.ColumnName = tb.Rows[i]["RC_Name"].ToString();
Columns.Add(col.ColumnID.ToString(), col);
}
}
//杨斌 2017-03-30
Dictionary<string, string> dicRUID = GetDicRUID();
if (dicRUID.Count > 0)
{
RosterCloumn col = new RosterCloumn();
col.ColumnID = -100;
col.ColumnIndex = Columns.Count + 1;
col.ColumnName = GlobalInfo.SysLanguage.LPT.ReadString("PanelSignIn", "rbtSignInModeRandom", "随机码签到");
Columns.Add(col.ColumnID.ToString(), col);
}
res = true;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
public static Dictionary<string, string> GetDicRUID()
{
TagSet tagSet = new TagSet(Globals.SunVoteARSAddIn.Application.ActivePresentation.Tags);
string uidRandom = tagSet.GetValue(TagKey.SignInUIDRandom).Value;
string[] aryRUID = uidRandom.Split('|');
Dictionary<string, string> dicRUID = new Dictionary<string, string>();
if (aryRUID.Length >= 0)
{
foreach (var v in aryRUID)
{
string[] ary2 = v.Split('=');
if (ary2.Length >= 2)
{
if (!dicRUID.ContainsKey(ary2[1]))
dicRUID.Add(ary2[1], ary2[0]);
}
}
}
return dicRUID;
}
public void LoadVIDToRID(DBOper dbOperation)
{
if (VIDToRIDs == null)
VIDToRIDs = new Dictionary<string, string>();
VIDToRIDs.Clear();
string sql = "Select * From ST_Voter";
dbOperation.OpenDataSet(sql);
if (dbOperation.DataSet.Tables.Count < 1) return;
DataTable tb = dbOperation.DataSet.Tables[0];
for (int i = 0; i < tb.Rows.Count; i++)
{
string vid = ConvertOper.Convert(tb.Rows[i]["V_ID"].ToString()).Value;
string rosterID = ConvertOper.Convert(tb.Rows[i]["RR_ID"].ToString()).Value;
if (!VIDToRIDs.ContainsKey(vid))
VIDToRIDs.Add(vid, rosterID);
}
dbOperation.CloseDataSet();
}
public RosterRow GetRowByVoterID(string vid)
{
RosterRow res = null;
if (VIDToRIDs.ContainsKey(vid))
{
string rosterID = VIDToRIDs[vid];
if (Rows.Contains(rosterID))
res = Rows[rosterID];
}
return res;
}
public bool LoadRow(DBOper dbOperation)
{
bool res = false;
try
{
Rows.Clear();
string sql = "Select * From ST_RosterRow Order By RR_Index ASC";
DataSet ds = dbOperation.GetDataSet(sql);
DataTable tb = ds.Tables[0];
for (int i = 0; i < tb.Rows.Count; i++)
{
RosterRow row = new RosterRow();
row.RowID = ConvertOper.Convert(tb.Rows[i]["RR_ID"].ToString()).ToInt;
row.RowIndex = i + 1;
row.Cells = new string[Columns.Count];
Rows.Add(row.RowID.ToString(), row);
}
LoadVIDToRID(dbOperation);
res = true;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
private Dictionary<string, RosterRow> DicKeyToRow = new Dictionary<string, RosterRow>();
/// <summary>
/// 获取键盘编号对应的名单行
/// 杨斌 2015-04-21
/// </summary>
/// <param name="keyId"></param>
/// <returns></returns>
public RosterRow GetRowByKeyId(string keyId)
{
RosterRow res = null;
if (DicKeyToRow.ContainsKey(keyId))
res = DicKeyToRow[keyId];
return res;
}
public bool LoadValue(DBOper dbOperation)
{
bool res = false;
try
{
string sql = "SELECT ST_RosterValue.RR_ID, ST_RosterValue.RC_ID, ST_RosterRow.RR_Index, ST_RosterColumn.RC_Index, ST_RosterValue.RV_Text" +
" FROM ST_RosterColumn INNER JOIN (ST_RosterRow INNER JOIN ST_RosterValue ON ST_RosterRow.RR_ID = ST_RosterValue.RR_ID)" +
" ON ST_RosterColumn.RC_ID = ST_RosterValue.RC_ID";
DataSet ds = dbOperation.GetDataSet(sql);
DataTable tb = ds.Tables[0];
for (int i = 0; i < tb.Rows.Count; i++)
{
string rowId = tb.Rows[i]["RR_ID"].ToString();
string colId = tb.Rows[i]["RC_ID"].ToString();
int col = Columns[colId].ColumnIndex - 1;
//Rows[rowId].Cells = new string[Columns.Count];
Rows[rowId].Cells[col] = tb.Rows[i]["RV_Text"].ToString();
}
//杨斌 2017-03-30
int lastCol = Columns.Count - 1;
if (Columns[lastCol].ColumnID == -100)
{
Dictionary<string, string> dicRUID = GetDicRUID();
for (int i = 0; i < Rows.Count; i++)
{
string rid = Rows[i].RowIndex + "";
if (dicRUID.ContainsKey(rid))
Rows[i].Cells[lastCol] = dicRUID[rid];
}
}
//杨斌 2014-11-05
if (RosterEnabled)
{
if (Columns.Count > 1)
GlobalInfo.response.ShowNameCol = this.Columns[1].ColumnName;
else if (Columns.Count > 0)
GlobalInfo.response.ShowNameCol = this.Columns[0].ColumnName;
}
//杨斌 2015-04-21
DicKeyToRow.Clear();
for (int i = 0; i < Rows.Count; i++)
{
string keyId = Rows[i].Cells[0];
if (!string.IsNullOrEmpty(keyId))//杨斌 2016-03-31
{
if ((keyId.Length > 0) && (!DicKeyToRow.ContainsKey(keyId)))
DicKeyToRow.Add(keyId, Rows[i]);
}
else
{
string a = keyId;
}
}
res = true;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
/// <summary>
/// 加载人员名单
/// </summary>
/// <returns></returns>
public bool LoadRoster()
{
bool res = false;
//System.Diagnostics.Stopwatch t = System.Diagnostics.Stopwatch.StartNew();
res = LoadCloumn(GlobalInfo.DBOperation);
res = (res && LoadRow(GlobalInfo.DBOperation));
res = (res && LoadValue(GlobalInfo.DBOperation));
//System.Windows.Forms.MessageBox.Show("LoadRoster" + t.ElapsedMilliseconds);
return res;
}
/// <summary>
/// 获取名单二位数组,含列标题
/// </summary>
/// <returns></returns>
public string[,] GetArrayTable()
{
string[,] aryTable = null;
int rowCount = 1 + Rows.Count;
int colCount = Columns.Count;
if ((rowCount > 0) && (colCount > 0))
{
aryTable = new string[rowCount, colCount];
for (int col = 0; col < colCount; col++)
{
aryTable[0, col] = Columns[col].ColumnName;
}
for (int row = 1; row < rowCount; row++)
{
for (int col = 0; col < colCount; col++)
{
aryTable[row, col] = Rows[row - 1].Cells[col];
}
}
}
return aryTable;
}
/// <summary>
/// 保存名单
/// </summary>
/// <param name="aryTable">名单二位数组,含列标题</param>
/// <returns></returns>
public bool SaveRoster(string[,] aryTable)
{
return SaveRoster(aryTable, true);
}
/// <summary>
/// 保存名单。杨斌 2015-03-31
/// </summary>
/// <param name="aryTable"></param>
/// <param name="beSaveColumns"></param>
/// <param name="dbOperation"></param>
/// <returns></returns>
public bool SaveRoster(string[,] aryTable, bool beSaveColumns, DBOper dbOperation, bool beLoadData = true)
{
bool res = false;
try
{
//开始事务
dbOperation.BeginTrans();
TDictionary<string, int> KeyToRowID = new TDictionary<string, int>();
string sql = "";
//删除列记录
if (beSaveColumns)//杨斌 2014-04-11
{
sql = "Delete * From ST_RosterColumn";
dbOperation.ExecuteNonQuery(sql);
}
//删除行记录
sql = "Delete * From ST_RosterRow";
dbOperation.ExecuteNonQuery(sql);
//添加列记录
if (beSaveColumns)//杨斌 2014-04-11
{
sql = "Select * From ST_RosterColumn";
dbOperation.OpenDataSet(sql);
for (int i = 0; i < aryTable.GetLength(1); i++)
{
DataRow row = dbOperation.DataSet.Tables[0].NewRow();
row["RC_Index"] = i + 1;
row["RC_Name"] = aryTable[0, i];
dbOperation.DataSet.Tables[0].Rows.Add(row);
}
dbOperation.UpdateDataSet();
dbOperation.CloseDataSet();
}
//添加行记录
sql = "Select * From ST_RosterRow";
dbOperation.OpenDataSet(sql);
for (int i = 1; i < aryTable.GetLength(0); i++)
{
DataRow row = dbOperation.DataSet.Tables[0].NewRow();
row["RR_Index"] = i + 1;
dbOperation.DataSet.Tables[0].Rows.Add(row);
}
dbOperation.UpdateDataSet();
dbOperation.CloseDataSet();
//更新列记录
LoadCloumn(dbOperation);
//更新行记录
LoadRow(dbOperation);
//添加值记录
sql = "Select * From ST_RosterValue";
dbOperation.OpenDataSet(sql);
int lastCol = Columns.Count - 1;
int colDel = 0;
if (Columns[lastCol].ColumnID == -100)
colDel = 1;
for (int i = 0; i < Rows.Count; i++)
{
for (int n = 0; n < Columns.Count - colDel; n++)
{
DataRow row = dbOperation.DataSet.Tables[0].NewRow();
row["RR_ID"] = Rows[i].RowID;
row["RC_ID"] = Columns[n].ColumnID;
row["RV_Text"] = aryTable[i + 1, n];
dbOperation.DataSet.Tables[0].Rows.Add(row);
if (Columns[n].ColumnIndex == 1)
{
string keyIds = row["RV_Text"].ToString();
int rowId = ConvertOper.Convert(row["RR_ID"].ToString()).ToInt;
if (ConvertOper.Convert(keyIds).ToInt > 0)
{
if (!KeyToRowID.Contains(keyIds))
KeyToRowID.Add(keyIds, rowId);
}
}
}
}
dbOperation.UpdateDataSet();
dbOperation.CloseDataSet();
//更新关联名单的ID
sql = "Select * From ST_Voter";
dbOperation.OpenDataSet(sql);
for (int i = 0; i < dbOperation.DataSet.Tables[0].Rows.Count; i++)
{
DataRow row = dbOperation.DataSet.Tables[0].Rows[i];
string keyIds = row["V_KeypadID"].ToString();
if (KeyToRowID.Contains(keyIds))
{
row["RR_ID"] = KeyToRowID[keyIds];
}
}
dbOperation.UpdateDataSet();
dbOperation.CloseDataSet();
//提交事务
dbOperation.CommitTrans();
if (beLoadData)//系统库不需重复加载
{
//更新值记录
LoadValue(dbOperation);
}
res = true;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
dbOperation.RollbackTrans();
}
return res;
}
/// <summary>
/// 保存名单
/// </summary>
/// <param name="aryTable">名单二位数组,含列标题</param>
/// <param name="beSaveColumns">是否更新列</param>
/// <returns></returns>
public bool SaveRoster(string[,] aryTable, bool beSaveColumns)
{
//杨斌 2015-03-31
return SaveRoster(aryTable, beSaveColumns, GlobalInfo.DBOperation);
/*
bool res = false;
try
{
//开始事务
GlobalInfo.DBOperation.BeginTrans();
TDictionary<string, int> KeyToRowID = new TDictionary<string, int>();
string sql = "";
//删除列记录
if (beSaveColumns)//杨斌 2014-04-11
{
sql = "Delete * From ST_RosterColumn";
GlobalInfo.DBOperation.ExecuteNonQuery(sql);
}
//删除行记录
sql = "Delete * From ST_RosterRow";
GlobalInfo.DBOperation.ExecuteNonQuery(sql);
//添加列记录
if (beSaveColumns)//杨斌 2014-04-11
{
sql = "Select * From ST_RosterColumn";
GlobalInfo.DBOperation.OpenDataSet(sql);
for (int i = 0; i < aryTable.GetLength(1); i++)
{
DataRow row = GlobalInfo.DBOperation.DataSet.Tables[0].NewRow();
row["RC_Index"] = i + 1;
row["RC_Name"] = aryTable[0, i];
GlobalInfo.DBOperation.DataSet.Tables[0].Rows.Add(row);
}
GlobalInfo.DBOperation.UpdateDataSet();
GlobalInfo.DBOperation.CloseDataSet();
}
//添加行记录
sql = "Select * From ST_RosterRow";
GlobalInfo.DBOperation.OpenDataSet(sql);
for (int i = 1; i < aryTable.GetLength(0); i++)
{
DataRow row = GlobalInfo.DBOperation.DataSet.Tables[0].NewRow();
row["RR_Index"] = i + 1;
GlobalInfo.DBOperation.DataSet.Tables[0].Rows.Add(row);
}
GlobalInfo.DBOperation.UpdateDataSet();
GlobalInfo.DBOperation.CloseDataSet();
//更新列记录
LoadCloumn();
//更新行记录
LoadRow();
//添加值记录
sql = "Select * From ST_RosterValue";
GlobalInfo.DBOperation.OpenDataSet(sql);
for (int i = 0; i < Rows.Count; i++)
{
for (int n = 0; n < Columns.Count; n++)
{
DataRow row = GlobalInfo.DBOperation.DataSet.Tables[0].NewRow();
row["RR_ID"] = Rows[i].RowID;
row["RC_ID"] = Columns[n].ColumnID;
row["RV_Text"] = aryTable[i + 1, n];
GlobalInfo.DBOperation.DataSet.Tables[0].Rows.Add(row);
if (Columns[n].ColumnIndex == 1)
{
string keyIds = row["RV_Text"].ToString();
int rowId = ConvertOper.Convert(row["RR_ID"].ToString()).ToInt;
if (ConvertOper.Convert(keyIds).ToInt > 0)
{
if (!KeyToRowID.Contains(keyIds))
KeyToRowID.Add(keyIds, rowId);
}
}
}
}
GlobalInfo.DBOperation.UpdateDataSet();
GlobalInfo.DBOperation.CloseDataSet();
//更新关联名单的ID
sql = "Select * From ST_Voter";
GlobalInfo.DBOperation.OpenDataSet(sql);
for (int i = 0; i < GlobalInfo.DBOperation.DataSet.Tables[0].Rows.Count; i++)
{
DataRow row = GlobalInfo.DBOperation.DataSet.Tables[0].Rows[i];
string keyIds = row["V_KeypadID"].ToString();
if (KeyToRowID.Contains(keyIds))
{
row["RR_ID"] = KeyToRowID[keyIds];
}
}
GlobalInfo.DBOperation.UpdateDataSet();
GlobalInfo.DBOperation.CloseDataSet();
//提交事务
GlobalInfo.DBOperation.CommitTrans();
//更新值记录
LoadValue();
res = true;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
GlobalInfo.DBOperation.RollbackTrans();
}
return res;
//**/
}
Timer TmrSaveRosterMeet = null;
bool IsRunTmrSaveRosterMeet = false;
private void TmrSaveRosterMeet_Elapsed(object sender, ElapsedEventArgs e)
{
if (IsRunTmrSaveRosterMeet)
return;
if (VoteServer.DicRosterMeet.Count < 1)
return;
IsRunTmrSaveRosterMeet = true;
//string meetName = DicRosterMeet.Keys.ToList()[0];
//List<List<string>> lstTable = DicRosterMeet[meetName];
//string meetNo = lstTable[0][0];
//lstTable.RemoveAt(0);
//DicRosterMeet.Remove(meetName);
//RosterAddMeetSave(lstTable, meetNo, meetName);
SaveRosterMeet();
IsRunTmrSaveRosterMeet = false;
}
/// <summary>
/// 追加分会场名单。杨斌 2017-12-11
/// </summary>
public void RosterAddMeet(List<List<string>> lstTable, string meetNo, string meetName)
{
if (VoteServer.DicRosterMeet.ContainsKey(meetName))
VoteServer.DicRosterMeet[meetName] = lstTable;
else
VoteServer.DicRosterMeet.Add(meetName, lstTable);
VoteServer.DicRosterMeet[meetName].Insert(0, new List<string> { meetNo, meetName });
//if (TmrSaveRosterMeet == null)
//{
// TmrSaveRosterMeet = new Timer();
// TmrSaveRosterMeet.Elapsed += TmrSaveRosterMeet_Elapsed;
// TmrSaveRosterMeet.Interval = 10;
// TmrSaveRosterMeet.AutoReset = false;
//}
//TmrSaveRosterMeet.Enabled = true;
}
public bool SaveRosterMeet()
{
bool res = false;
DBOper dbOperation = GlobalInfo.DBOperation;
try
{
int rowCount = 0;
int colCount = Columns.Count;
foreach (var v in VoteServer.DicRosterMeet)
{
int rowCountA = v.Value.Count - 2;
rowCount += rowCountA;
}
rowCount++;
string[,] aryTable = new string[rowCount, colCount];
for (int col = 0; col < colCount; col++)
aryTable[0, col] = Columns[col].ColumnName;
int row = 1;
foreach (var v in VoteServer.DicRosterMeet)
{
string meetNo = v.Value[0][0];
string meetName = v.Value[0][1];
for (int i = 2; i < v.Value.Count; i++)
{
for (int col = 0; col < colCount; col++)
{
if (col == 0)
aryTable[row, col] = meetNo + "F" + v.Value[i][0];
else if (col == 1)
aryTable[row, col] = meetName;
else if (v.Value[i].Count >= col)
aryTable[row, col] = v.Value[i][col - 1];
}
row++;
}
}
res = SaveRoster(aryTable, false, dbOperation, true);
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
}
return res;
}
public bool RosterAddMeetSave(List<List<string>> lstTable, string meetNo, string meetName)
{
bool res = false;
DBOper dbOperation = GlobalInfo.DBOperation;
try
{
//开始事务
dbOperation.BeginTrans();
TDictionary<string, int> KeyToRowID = new TDictionary<string, int>();
string sql = "";
int exCount = 0;
//查询会场名对应列ID
int RC_ID = -1;
sql = "Select RC_ID From ST_RosterColumn Where RC_Index=2";
dbOperation.OpenDataSet(sql);
if (dbOperation.DataSet.Tables.Count > 0)
{
if (dbOperation.DataSet.Tables[0].Rows.Count > 0)
RC_ID = (int)dbOperation.DataSet.Tables[0].Rows[0]["RC_ID"];
}
dbOperation.CloseDataSet();
//删除分会场名单
if (RC_ID != -1)
{
//删除名单值
sql = "DELETE * FROM ST_RosterValue WHERE((ST_RosterValue.RC_ID = " + RC_ID + ") And(ST_RosterValue.RV_Text = '" + meetName + "'))";
exCount = dbOperation.ExecuteNonQuery(sql);
//删除名单行
sql = "DELETE * FROM ST_RosterRow WHERE RR_ID In(SELECT RR_ID FROM ST_RosterValue WHERE((ST_RosterValue.RC_ID = " + RC_ID + ") And(ST_RosterValue.RV_Text = '" + meetName + "')))";
exCount = dbOperation.ExecuteNonQuery(sql);
}
//添加行记录
int countRow = 0;
sql = "Select * From ST_RosterRow";
dbOperation.OpenDataSet(sql);
if (dbOperation.DataSet.Tables.Count > 0)
{
DataTable dataTable = dbOperation.DataSet.Tables[0];
countRow = dataTable.Rows.Count;
for (int i = 1; i < lstTable.Count; i++)//索引0是列标题,数据从索引1开始
{
DataRow row = dbOperation.DataSet.Tables[0].NewRow();
row["RR_Index"] = i + 1;
dbOperation.DataSet.Tables[0].Rows.Add(row);
int rr_id = (int)row["RR_ID"];
}
}
dbOperation.UpdateDataSet();
dbOperation.CloseDataSet();
//更新列记录
LoadCloumn(dbOperation);
//更新行记录
LoadRow(dbOperation);
//添加纪录
sql = "SELECT ST_RosterRow.RR_ID, ST_RosterRow.RR_Index, ST_RosterValue.RC_ID, ST_RosterValue.RV_Text FROM ST_RosterRow INNER JOIN ST_RosterValue ON ST_RosterRow.RR_ID = ST_RosterValue.RR_ID";
dbOperation.OpenDataSet(sql);
if (dbOperation.DataSet.Tables.Count > 0)
{
DataTable dataTable = dbOperation.DataSet.Tables[0];
int rowNo = dataTable.Rows.Count;
for (int i = 1; i < lstTable.Count; i++)//索引0是列标题,数据从索引1开始
{
rowNo++;
List<string> lsRow = lstTable[i];
for (int n = 0; n < Columns.Count; n++)
{
if (lsRow.Count >= n)
{
DataRow row = dataTable.NewRow();
row["RR_Index"] = rowNo;
row["RC_ID"] = Columns[n].ColumnID;
if (n == 0)
{
row["RV_Text"] = meetNo + "F" + lsRow[0];
}
else if (n == 1)
{
row["RV_Text"] = meetName;
}
else
{
row["RV_Text"] = lsRow[n - 1];
}
dataTable.Rows.Add(row);
}
}
}
}
dbOperation.UpdateDataSet();
dbOperation.CloseDataSet();
////添加值记录
//sql = "Select * From ST_RosterValue";
//dbOperation.OpenDataSet(sql);
//int lastCol = Columns.Count - 1;
//int colDel = 0;
//if (Columns[lastCol].ColumnID == -100)
// colDel = 1;
//for (int i = 0; i < Rows.Count; i++)
//{
// for (int n = 0; n < Columns.Count - colDel; n++)
// {
// DataRow row = dbOperation.DataSet.Tables[0].NewRow();
// row["RR_ID"] = Rows[i].RowID;
// row["RC_ID"] = Columns[n].ColumnID;
// row["RV_Text"] = aryTable[i + 1, n];
// dbOperation.DataSet.Tables[0].Rows.Add(row);
// if (Columns[n].ColumnIndex == 1)
// {
// string keyIds = row["RV_Text"].ToString();
// int rowId = ConvertOper.Convert(row["RR_ID"].ToString()).ToInt;
// if (ConvertOper.Convert(keyIds).ToInt > 0)
// {
// if (!KeyToRowID.Contains(keyIds))
// KeyToRowID.Add(keyIds, rowId);
// }
// }
// }
//}
//dbOperation.UpdateDataSet();
//dbOperation.CloseDataSet();
//更新关联名单的ID
sql = "Select * From ST_Voter";
dbOperation.OpenDataSet(sql);
for (int i = 0; i < dbOperation.DataSet.Tables[0].Rows.Count; i++)
{
DataRow row = dbOperation.DataSet.Tables[0].Rows[i];
string keyIds = row["V_KeypadID"].ToString();
if (KeyToRowID.Contains(keyIds))
{
row["RR_ID"] = KeyToRowID[keyIds];
}
}
dbOperation.UpdateDataSet();
dbOperation.CloseDataSet();
//提交事务
dbOperation.CommitTrans();
//更新值记录
LoadValue(dbOperation);
res = true;
}
catch (Exception ex)
{
SystemLog.WriterLog(ex);
dbOperation.RollbackTrans();
}
return res;
//*/
}
/// <summary>
/// 根据键盘ID、列名称查找对应列值
/// 杨斌 2013-12-23
/// </summary>
/// <param name="columnName"></param>
/// <param name="keyID"></param>
/// <returns></returns>
public static string GetRushAnswerShow(string columnName, string keyID)
{
string result = "";
if (string.IsNullOrEmpty(columnName)) return result;
if (!GlobalInfo.response.EnableList) return result;
try
{
string keyColName = "";
DataSet ds = new DataSet();
string sql = "SELECT ST_RosterColumn.RC_Name" +
" FROM ST_RosterColumn" +
" WHERE (((ST_RosterColumn.RC_Index)=1))";
ds = GlobalInfo.DBOperation.GetDataSet(sql);
if (ds != null && ds.Tables.Count > 0)
{
DataTable t = ds.Tables[0];
if (t.Rows.Count > 0)
keyColName = t.Rows[0][0].ToString();
}
if (keyColName.Length > 0)
{
sql = "SELECT V_VoterList2." + columnName +
" FROM V_VoterList2" +
" WHERE (((V_VoterList2." + keyColName + ")='" + keyID + "'))";
ds = GlobalInfo.DBOperation.GetDataSet(sql);
if (ds != null && ds.Tables.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
result = dr[0].ToString();
}
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, true);
}
return result;
}
/// <summary>
/// 获取字段名称索引
/// 杨斌 2015-11-25
/// </summary>
/// <param name="colName"></param>
/// <returns></returns>
public static int GetRosterColumIndex(string colName)
{
int colIndex = -1;
try
{
RosterList Roster = RosterList.RosterLoad;
if (Roster != null)
{
for (int i = 0; i < Roster.Columns.Count; i++)
{
if (Roster.Columns[i].ColumnName == colName)
{
colIndex = i;
break;
}
}
}
}
catch (Exception ex)
{
SystemLog.WriterLog(ex, true);
}
return colIndex;
}
}
}