Report.cs
96.5 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
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Configuration;
using System.Web.Mvc;
using System.Web.Security;
using System.Xml;
using Vrh.XmlProcessing;
using Vrh.OneReport.Lib.Areas.OneReport.Helpers;
using Vrh.OneReport.Lib.Areas.OneReport.XMLParametersFileProcessor;
using Vrh.OneReport.Lib.Areas.OneReport.DbModels;
namespace Vrh.OneReport.Lib.Areas.OneReport.Models
{
/// <summary>
/// Structure to hold the data of a report.
/// </summary>
public class Report
{
#region Static private variables
/// <summary>
/// Object to handle XMl document.
/// </summary>
protected static XmlDocument Xml = null;
/// <summary>
/// XML namespace.
/// </summary>
protected const string XmlNamespace = "http://www.vonalkod.hu/Log4Pro";
/// <summary>
/// XML namespace manager object.
/// </summary>
protected static XmlNamespaceManager XmlNSManager = null;
#endregion //Static private variables
#region private variables
/// <summary>
/// If true, the report can be generated.
/// </summary>
private bool _isCompleted = false;
/// <summary>
/// The list of report (rdl) parameters.
/// </summary>
protected Dictionary<string, string> RdlParameters = new Dictionary<string, string>();
/// <summary>
/// The report ID used in html environment.
/// </summary>
protected string ID;
/// <summary>
/// Report is OneReport
/// </summary>
private bool isOneReport = false;
#endregion //private variables
#region public variables
/// <summary>
/// Report is OneReport
/// </summary>
public bool IsOneReport
{
get
{
return isOneReport;
}
set
{
isOneReport = value;
}
}
/// <summary>
/// The name of the report.
/// </summary>
public string Name { get; set; }
/// <summary>
/// The description of the report.
/// </summary>
public string Description { get; set; }
/// <summary>
/// The filename of the report.
/// </summary>
public string FileName { get; set; }
/// <summary>
/// The parameters of the report (must be filled by the user).
/// </summary>
public Dictionary<string, ReportParameter> Parameters = new Dictionary<string, ReportParameter>();
/// <summary>
/// List of the parameters (in the displaying sequence).
/// </summary>
public List<ReportParameter> ParameterList = null;
/// <summary>
/// List of the datasets used by the report.
/// </summary>
public List<DataSetDescriptor> DataSets = new List<DataSetDescriptor>();
/// <summary>
/// The number of columns in displaying the parameters' dialog.
/// </summary>
public int MaxCol = 0;
/// <summary>
/// If true, the report can be generated.
/// </summary>
public bool isCompleted
{
get
{
return Parameters.Count == 0 || _isCompleted;
}
set
{
_isCompleted = value;
}
}
/// <summary>
/// The list of report (rdl) parameters in whitch the parameters are replaced by their values.
/// </summary>
public Dictionary<string, string> RdlEvaluatedParameters = new Dictionary<string, string>();
#endregion //public variables
#region Static public methods
/// <summary>
/// Creates a report list from the report definitions XML file.
/// <return>The report list grouped by user roles.</returns>
/// </summary>
public static List<UserRoleGroupModel> ReadReports()
{
List<UserRoleGroupModel> rv = new List<UserRoleGroupModel>();
List<string> roles = (Roles.Enabled ? new List<string>(Roles.GetRolesForUser()) : new List<string>());
Dictionary<string, UserRoleGroupModel> ugm_map = new Dictionary<string, UserRoleGroupModel>();
roles.Insert(0, "*");
foreach (var role in roles)
{
ReadReportsForRole(role, rv, ugm_map);
}
for (int i = 0; i < rv.Count; i++)
{
if (rv[i].Items.Count == 0)
{
rv.RemoveAt(i);
i--;
}
}
if (rv != null && rv.Count > 0 && !rv.Any(x => x.GroupState == UserRoleGroupModel.ItemGroupState.Opened))
{
var item = rv.FirstOrDefault(x => x.GroupState == UserRoleGroupModel.ItemGroupState.Unknown);
if (item != null)
item.GroupState = UserRoleGroupModel.ItemGroupState.Opened;
}
return rv;
}
/// <summary>
/// Creates a report list belonging to the given user role from the report definitions XML file.
/// <param name="userrole">A user role.</param>
/// <param name="groups">List of the usergroups.</param>
/// <param name="ugm_map">Hashmap of the used userroles (internal use).</param>
/// </summary>
public static void ReadReportsForRole(string userrole, List<UserRoleGroupModel> groups, Dictionary<string, UserRoleGroupModel> ugm_map)
{
UserRoleGroupModel ugm = null;
ItemDescriptor item;
XmlNode general;
LangHelperNS langHelper = LangHelperNS.ReportXML;
string defaultName = string.Format(LangHelperNS.ReportView.GetTranslation("Report.UsersReportsText", "{0} listái"), (userrole == "*" ? LangHelperNS.QueryView.GetTranslation("Report.UserText", "Felhasználó") : userrole));
try
{
if (Xml == null)
{
Xml = new XmlDocument();
Xml.Load(GetReportFileName());
XmlNSManager = new XmlNamespaceManager(Xml.NameTable);
XmlNSManager.AddNamespace("vlp", XmlNamespace);
}
if ((general = Xml.SelectSingleNode("vlp:userroles/vlp:general", XmlNSManager)) != null)
{
foreach (XmlNode node in general.ChildNodes)
{
if (node.NodeType == XmlNodeType.Element)
{
switch (node.Name.ToLower())
{
case "wordcodeseparator":
string sep = node.InnerText.Trim();
if (sep.Length > 0)
langHelper = new LangHelperNS(langHelper, sep, sep, sep);
break;
}
}
}
}
foreach (XmlNode node in Xml.SelectNodes("vlp:userroles/vlp:userrole", XmlNSManager))
{
string rolename = node.GetAttributeValue("name");
string groupname = node.GetAttributeValue("ReportGroupName", node.GetAttributeValue("GroupName"));
string isopened = node.GetAttributeValue("IniStateOpen");
bool bOK = false;
XmlNode subnode;
string itemname, itemid;
if (rolename == null)
{
bOK = (userrole == "*");
}
else
{
string[] rolelist = rolename.Split(new char[] { ';' });
foreach (var r in rolelist)
{
if (r.Equals(userrole, StringComparison.CurrentCultureIgnoreCase))
{
bOK = true;
break;
}
}
}
if (bOK)
{
if (string.IsNullOrEmpty(groupname))
{
groupname = defaultName;
}
else
{
groupname = langHelper.TranslateText(null, groupname);
}
if (ugm_map.ContainsKey(groupname))
{
ugm = ugm_map[groupname];
}
else
{
ugm = new UserRoleGroupModel();
ugm.Name = groupname;
ugm.Items = new List<ItemDescriptor>();
ugm.GroupState = UserRoleGroupModel.ItemGroupState.Unknown;
ugm_map.Add(ugm.Name, ugm);
groups.Add(ugm);
}
if (isopened != null)
{
if ((isopened.ToLower().StartsWith("t") || isopened.ToLower().StartsWith("i")))
ugm.GroupState = UserRoleGroupModel.ItemGroupState.Opened;
else if (ugm.GroupState == UserRoleGroupModel.ItemGroupState.Unknown)
ugm.GroupState = UserRoleGroupModel.ItemGroupState.Closed;
}
foreach (XmlNode reportnode in node.SelectNodes("vlp:reports/vlp:report", XmlNSManager))
{
if ((subnode = reportnode.SelectSingleNode("vlp:id", XmlNSManager)) == null)
{
//log: név nélküli report
#if (DEBUG)
itemid = "Nevtelen!!!!!!!!!!!!!";
#else
itemid = null;
#endif
}
else
{
itemid = subnode.InnerText.Trim();
}
if (itemid != null)
{
item = new ItemDescriptor();
item.Action = "Display";
item.Controller = "Report";
if ((subnode = reportnode.SelectSingleNode("vlp:name", XmlNSManager)) == null)
{
itemname = langHelper.GetTranslation(itemid);
}
else
{
itemname = langHelper.TranslateText(null, subnode.InnerText);
}
if ((subnode = reportnode.SelectSingleNode("vlp:description", XmlNSManager)) == null)
{
item.Description = itemname;
}
else
{
item.Description = langHelper.TranslateText(null, subnode.InnerText);
}
item.Name = itemname;
item.Params = new { role = userrole, report = itemid };
ugm.Items.Add(item);
}
}
}
}
}
catch (Exception e)
{
Log.Error(e.Message);
}
Xml = null;
XmlNSManager = null;
}
/// <summary>
/// Creates a report object representing the given report from the report definitions XML file.
/// <param name="userrole">A user role.</param>
/// <param name="listname">The ID of the report.</param>
/// <param name="parameters">The value of the report parameters.</param>
/// <param name="modelstate">Object to hold the error messages.</param>
/// <return>A report.</returns>
/// </summary>
public static Report ReadReport(string userrole, string listname, NameValueCollection parameters = null, ModelStateDictionary modelstate = null)
{
LangHelperNS langHelper = LangHelperNS.ReportXML;
if (string.IsNullOrEmpty(userrole))
userrole = "*";
List<string> directories = new List<string>();
string generalconnectionstring = null;
bool bOK = (userrole == "*");
Report rv = null;
XmlNode general;
if (!bOK)
{
foreach (var r in Roles.GetRolesForUser())
{
if (r.Equals(userrole, StringComparison.CurrentCultureIgnoreCase))
{
bOK = true;
break;
}
}
}
if (bOK)
{
rv = new Report();
if (Xml == null)
{
Xml = new XmlDocument();
Xml.Load(GetReportFileName());
XmlNSManager = new XmlNamespaceManager(Xml.NameTable);
XmlNSManager.AddNamespace("vlp", XmlNamespace);
}
if ((general = Xml.SelectSingleNode("vlp:userroles/vlp:general", XmlNSManager)) != null)
{
foreach (XmlNode node in general.ChildNodes)
{
if (node.NodeType == XmlNodeType.Element)
{
switch (node.Name.ToLower())
{
case "directory":
directories.Add(node.InnerText);
break;
case "connectionstring":
generalconnectionstring = node.InnerText;
break;
case "wordcodeseparator":
string sep = node.InnerText.Trim();
if (sep.Length > 0)
langHelper = new LangHelperNS(langHelper, sep, sep, sep);
break;
default:
Log.Warning(string.Format(LangHelperNS.ReportView.GetTranslation("Report.UnknownTypeInGeneralText", "Ismeretlen típus: {0}, helye 'userroles/general'"), node.Name));
break;
}
}
}
}
foreach (XmlNode node in Xml.SelectNodes("vlp:userroles/vlp:userrole", XmlNSManager))
{
string rolename = node.GetAttributeValue("name");
if (rolename == null)
{
bOK = (userrole == "*");
}
else
{
string[] rolelist = rolename.Split(new char[] { ';' });
foreach (var r in rolelist)
{
if (r.Equals(userrole, StringComparison.CurrentCultureIgnoreCase))
{
bOK = true;
break;
}
}
}
if (bOK)
{
XmlNode report = node.SelectSingleNode(string.Format("vlp:reports/vlp:report[vlp:id=\"{0}\"]", listname), XmlNSManager);
if (report != null)
{
List<string> dirs = new List<string>(directories);
//connectionstring = generalconnectionstring;
//if ((general = report.SelectSingleNode("vlp:general", XmlNSManager)) != null)
//{
// foreach (XmlNode n in general.ChildNodes)
// {
// if (n.NodeType == XmlNodeType.Element)
// {
// switch (n.Name)
// {
// case "directory":
// dirs.Add(n.InnerText);
// break;
// case "connectionstring":
// connectionstring = n.InnerText;
// break;
// default:
// Log.Warning(string.Format(LangHelperNS.ReportView.GetTranslation("Report.UnknownTypeInListText", "Ismeretlen típus: {0}, lista ID: '{1}'"), node.Name, listname));
// break;
// }
// }
// }
//}
//rv = ReadReport(report, dirs, connectionstring, listname);
rv = ReadReport(report, dirs, generalconnectionstring, listname, langHelper);
break;
}
}
}
Xml = null;
}
else
{
Log.Info(string.Format(LangHelperNS.ReportView.GetTranslation("Report.NoAccessRightText", "Nincs a '{0}' felhasználónak joga a '{1}/{2}' listához."), System.Web.HttpContext.Current.User.Identity.Name, userrole, listname));
}
return rv;
}
#endregion //Static public methods
#region Static private methods
/// <summary>
/// Gets the report definitions XML file name with path.
/// <return>The report definitions XML file name with path.</returns>
/// </summary>
private static string GetReportFileName()
{
string reportfile = WebConfigurationManager.AppSettings.Get("ReportsDescriptorsXMLFile");
if (!string.IsNullOrEmpty(reportfile) || !File.Exists(reportfile))
reportfile = System.Web.HttpContext.Current.Server.MapPath(reportfile);
if (string.IsNullOrEmpty(reportfile) || !File.Exists(reportfile))
reportfile = System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Reports/Reports.xml");
return reportfile;
}
/// <summary>
/// Gets the report definitions from an XML structure.
/// <param name="report">A node containing the report definition.</param>
/// <param name="dirs">A list of directories where the report file (rdlc) can be searched for.</param>
/// <param name="connectionstring">A default connectionstring.</param>
/// <param name="listname">The searched name of the report.</param>
/// <param name="defaultLangHelper">The (default) translator object.</param>
/// <return>A report.</returns>
/// </summary>
private static Report ReadReport(XmlNode report, List<string> dirs, string connectionstring, string listname, LangHelperNS defaultLangHelper)
{
Report rv = new Report();
string connstr = connectionstring, file, paramname, paramvalue, filepath;
string[] fileinfo = new string[2];
List<string> directory_list = new List<string>(dirs);
XmlNode general;
LangHelperNS langHelper = defaultLangHelper;
rv.Name = listname;
if ((general = report.SelectSingleNode("vlp:general", XmlNSManager)) != null)
{
foreach (XmlNode n in general.ChildNodes)
{
if (n.NodeType == XmlNodeType.Element)
{
switch (n.Name)
{
case "directory":
directory_list.Add(n.InnerText);
break;
case "connectionstring":
connstr = n.InnerText;
break;
case "wordcodeseparator":
string sep = n.InnerText.Trim();
if (sep.Length > 0)
langHelper = new LangHelperNS(langHelper, sep, sep, sep);
break;
default:
Log.Warning(string.Format(LangHelperNS.ReportView.GetTranslation("Report.UnknownTypeInReportText", "Ismeretlen típus: {0}, lista ID: '{1}'"), n.Name, listname));
break;
}
}
}
}
foreach (XmlNode node in report.ChildNodes)
{
if (node.NodeType == XmlNodeType.Element)
{
switch (node.Name.ToLower())
{
case "reportfile":
foreach (XmlNode n in node.ChildNodes)
{
if (n.NodeType == XmlNodeType.Element)
{
switch (n.Name.ToLower())
{
case "name":
case "filename":
file = langHelper.TranslateText(null, n.InnerText.Trim());
if (File.Exists(file))
{
rv.FileName = file;
}
else
{
fileinfo[1] = file;
foreach (string dir in dirs)
{
fileinfo[0] = dir;
filepath = Path.Combine(fileinfo);
if (File.Exists(filepath))
{
rv.FileName = filepath;
break;
}
else if (File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/" + filepath)))
{
rv.FileName = System.Web.HttpContext.Current.Server.MapPath("~/" + filepath);
break;
}
}
}
break;
case "param":
paramname = n.GetAttributeValue("name");
if (!string.IsNullOrEmpty(paramname))
{
paramvalue = n.GetNodeValue();
if (rv.RdlParameters.ContainsKey(paramname))
{
Log.Warning(string.Format(LangHelperNS.ReportView.GetTranslation("Report.DuplicateParameterNameText", "Duplikált paraméter (reportfile/param): {0}, lista ID: '{1}'"), paramname, listname));
}
else
{
rv.RdlParameters.Add(paramname, paramvalue);
}
}
else
{
Log.Warning(string.Format(LangHelperNS.ReportView.GetTranslation("Report.MissingParameterNameText", "Hiányzó paraméternév (reportfile/param), lista ID: '{0}'"), listname));
}
break;
default:
Log.Warning(string.Format(LangHelperNS.ReportView.GetTranslation("Report.UnknownTypeInReportText", "Ismeretlen típus: {0}, lista ID: '{1}'"), n.Name, listname));
break;
}
}
}
break;
case "name":
rv.Name = langHelper.TranslateText(null, node.InnerText.Trim());
break;
case "id":
rv.ID = node.InnerText.Trim();
break;
case "description":
rv.Description = langHelper.TranslateText(null, node.InnerText.Trim());
break;
case "datasets":
ReadDataSetDescriptor(node, rv, connstr, langHelper);
break;
case "parameters":
ReadParameterDescriptor(node, rv, connstr, langHelper);
break;
case "general":
//Már korábban megtörtént.
break;
default:
Log.Warning(string.Format(LangHelperNS.ReportView.GetTranslation("Report.UnknownTypeInReportText", "Ismeretlen típus: {0}, lista ID: '{1}'"), node.Name, listname));
break;
}
}
}
return rv;
}
/// <summary>
/// Reads the parameter descriptor part of the report definition.
/// <param name="parameters">A node containing the parameter descriptors.</param>
/// <param name="connectionstring">A default connectionstring.</param>
/// <param name="langHelper">The translator object.</param>
/// </summary>
protected static void ReadParameterDescriptor(XmlNode parameters, Report report, string connectionstring, LangHelperNS langHelper)
{
ReportParameter rp;
XmlNode subnode;
string val, optiontextfield, optionidfield, filter, id;
ParameterReplace pr;
foreach (XmlNode parameter in parameters.SelectNodes("vlp:parameter", XmlNSManager))
{
val = parameter.GetAttributeValue("name");
if (string.IsNullOrEmpty(val))
{
Log.Warning(string.Format(LangHelperNS.ReportView.GetTranslation("Report.NoParameterNameText", "Nincs neve a paraméternek (lista ID: '{0}')!"), report.Name));
}
else
{
rp = new ReportParameter();
rp.Label = rp.Name = val;
if (!string.IsNullOrEmpty(rp.Name))
{
rp.Paramtype = parameter.GetAttributeValue("type", rp.Paramtype);
rp.ReplaceID = parameter.GetAttributeValue("replacestring", "@" + rp.Name + '@');
while (report.Parameters.ContainsKey(rp.ID))
{
rp.Name += "_";
}
report.Parameters.Add(rp.ID, rp);
foreach (XmlNode node in parameter.ChildNodes)
{
if (node.NodeType == XmlNodeType.Element)
{
switch (node.Name.ToLower())
{
case "label":
rp.Label = langHelper.TranslateText(null, node.GetNodeValue());
break;
case "value":
rp.DefaultValue = node.GetAttributeValue("default", node.GetNodeValue());
rp.MinValue = node.GetAttributeValue("min");
rp.MaxValue = node.GetAttributeValue("max");
break;
case "required":
rp.Required = true;
break;
case "showseconds":
rp.ShowSeconds = true;
break;
case "length":
val = node.GetNodeValue();
if (!string.IsNullOrEmpty(val))
rp.MinLength = rp.MaxLength = int.Parse(val);
val = node.GetAttributeValue("min");
if (!string.IsNullOrEmpty(val))
rp.MinLength = int.Parse(val);
val = node.GetAttributeValue("max");
if (!string.IsNullOrEmpty(val))
rp.MaxLength = int.Parse(val);
break;
case "display":
val = node.GetAttributeValue("row");
if (!string.IsNullOrEmpty(val))
rp.Row = int.Parse(val);
val = node.GetAttributeValue("col");
if (!string.IsNullOrEmpty(val))
rp.Column = int.Parse(val);
break;
case "spincontrol":
if (rp.Paramtype.Equals("I", StringComparison.CurrentCultureIgnoreCase))
{
rp.SpinControl = new SpinControl();
val = node.GetAttributeValue("inc");
if (!string.IsNullOrEmpty(val))
rp.SpinControl.SpinIncrementValue = int.Parse(val);
val = node.GetAttributeValue("dec");
if (!string.IsNullOrEmpty(val))
rp.SpinControl.SpinDecrementValue = int.Parse(val);
if (rp.SpinControl.SpinIncrementValue == 0)
rp.SpinControl.SpinIncrementValue = 1;
if (rp.SpinControl.SpinDecrementValue == 0)
rp.SpinControl.SpinDecrementValue = 1;
if (rp.MinValue == null)
rp.MinValue = int.MinValue;
if (rp.MaxValue == null)
rp.MaxValue = int.MaxValue;
}
else
{
Log.Warning(string.Format(LangHelperNS.ReportView.GetTranslation("Report.SpinControlMisuseText", "Spincontrol jelenleg csak egész számoknál használható (paraméter '{0}', lista ID: '{1}')"), rp.Name, report.Name));
}
break;
case "sqlreplace":
id = node.GetAttributeValue("replacestring", rp.ReplaceID);
if (rp.Replaces.ContainsKey(id))
{
Log.Warning(string.Format(LangHelperNS.ReportView.GetTranslation("Report.DuplicateSQLReplaceText", "Duplikált 'sqlreplace' azonosító: {0} (paraméter: '{1}', lista ID: '{2}')"), id, rp.Name, report.Name));
}
else
{
pr = new ParameterReplace(id);
foreach (XmlNode value in node.SelectNodes("vlp:replace", XmlNSManager))
{
val = value.InnerText.Trim();
if (value.Attributes.GetNamedItem("value") == null)
filter = null;
else
filter = value.Attributes.GetNamedItem("value").Value;
pr.AddItem(filter, val);
}
rp.Replaces.Add(id, pr);
}
break;
case "values":
if (rp.SelectOptions == null)
rp.SelectOptions = new List<SelectListItem>();
foreach (XmlNode value in node.SelectNodes("vlp:value", XmlNSManager))
{
val = value.GetNodeValue();
id = value.GetAttributeValue("id", val);
rp.SelectOptions.Add(new SelectListItem() { Value = id, Text = val });
}
if (rp.SelectOptions.Count > 0)
{
rp.WidgetType = "DropDownList";
}
break;
case "reference":
optiontextfield = optionidfield = null;
if ((subnode = node.SelectSingleNode("vlp:optiontext", XmlNSManager)) != null)
{
optiontextfield = subnode.GetNodeValue();
}
if ((subnode = node.SelectSingleNode("vlp:optionid", XmlNSManager)) != null)
{
optionidfield = subnode.GetNodeValue();
}
if (optionidfield == null)
optionidfield = optiontextfield;
if (optiontextfield == null)
optiontextfield = optionidfield;
if ((subnode = node.SelectSingleNode("vlp:sql", XmlNSManager)) == null)
{
Log.Warning(string.Format(LangHelperNS.ReportView.GetTranslation("Report.InvalidReferenceDefinitionText", "Hibás referencia definíció, nincs 'sql' rész (paraméter: '{0}', lista ID: '{1}')"), rp.Name, report.Name));
#if (DEBUG)
if (rp.SelectOptions == null)
{
rp.SelectOptions = new List<SelectListItem>();
rp.SelectOptions.Add(new SelectListItem() { Text = "Invalid reference!", Value = "Error", Selected = true });
rp.WidgetType = "DropDownList";
}
#endif
}
else
{
rp.Reference = new ParameterReference();
rp.Reference.Command = new DatabaseCommand(subnode.InnerText.Trim(), connectionstring, DatabaseCommand.DBCommandType.SQL);
rp.Reference.IDField = optionidfield;
rp.Reference.NameField = optiontextfield;
rp.WidgetType = "AutocompleteTextBox";
val = subnode.GetAttributeValue("type");
if (!string.IsNullOrEmpty(val) && val.Equals("proc", StringComparison.CurrentCultureIgnoreCase))
{
rp.Reference.Command.CommandType = DatabaseCommand.DBCommandType.StoredProcedure;
}
if ((subnode = node.SelectSingleNode("vlp:connectionstring", XmlNSManager)) != null)
{
rp.Reference.Command.ConnectionString = subnode.GetNodeValue();
}
if (String.IsNullOrEmpty(rp.Reference.Command.ConnectionString))
{
rp.Reference.Command.ConnectionString = ConnectionStringStore.Get(QueryContext.APM_CONTEXT_NAME);
}
}
break;
default:
Log.Warning(string.Format(LangHelperNS.ReportView.GetTranslation("Report.UnknownTypeInReportText", "Ismeretlen típus: {0}, lista ID: '{1}'"), node.Name, report.Name));
break;
}
}
}
}
}
}
report.ArrangeParams();
report.SetDefaultValues();
}
/// <summary>
/// Reads the dataset descriptor part of the report definition.
/// <param name="parameters">A node containing the dataset descriptors.</param>
/// <param name="connstr">A default connectionstring.</param>
/// <param name="langHelper">The translator object.</param>
/// </summary>
protected static void ReadDataSetDescriptor(XmlNode datasets, Report report, string connstr, LangHelperNS langHelper)
{
DataSetDescriptor ds;
string connectionstr, value, id, command;
XmlNode sqlnode;
foreach (XmlNode dataset in datasets.SelectNodes("vlp:dataset", XmlNSManager))
{
value = dataset.GetAttributeValue("name");
if (string.IsNullOrEmpty(value))
{
Log.Error(string.Format(LangHelperNS.ReportView.GetTranslation("Report.InvalidDatasetDefinitionText", "Hibás adatkapcsolatleíró (lista ID = {0}): nincs megadva név!"), report.ID));
}
else
{
ds = new DataSetDescriptor();
ds.Name = value;
connectionstr = !String.IsNullOrEmpty(connstr) ? connstr : ConnectionStringStore.Get(QueryContext.APM_CONTEXT_NAME);
foreach (XmlNode node in dataset.ChildNodes)
{
if (node.NodeType == XmlNodeType.Element)
{
switch (node.Name)
{
case "initcommand":
sqlnode = node.SelectSingleNode("vlp:sql", XmlNSManager);
command = (sqlnode == null ? node.GetNodeValue() : sqlnode.GetNodeValue());
if (!string.IsNullOrEmpty(command))
{
System.Data.DbType type;
command = langHelper.TranslateText(null, command);
ds.InitCommand = new DatabaseCommand(command, connectionstr, DatabaseCommand.DBCommandType.SQL);
value = node.GetAttributeValue("type");
if (!string.IsNullOrEmpty(value) && value.Equals("proc", StringComparison.CurrentCultureIgnoreCase))
{
ds.InitCommand.CommandType = DatabaseCommand.DBCommandType.StoredProcedure;
}
foreach (XmlNode param in node.SelectNodes("vlp:param", XmlNSManager))
{
id = param.GetAttributeValue("name");
if (string.IsNullOrEmpty(id))
{
Log.Error(string.Format(LangHelperNS.ReportView.GetTranslation("Report.NoSQLParameterNameText", "Névtelen SQL paraméter (adatkapcsolat neve: '{0}', lista ID: '{1}')!"), ds.Name, report.ID));
}
else
{
value = param.GetNodeValue();
type = DatabaseCommand.GetDBTypeFromName(param.GetAttributeValue("type"));
ds.InitCommand.AddParameter(id, type, value);
}
}
}
break;
case "datacommand":
sqlnode = node.SelectSingleNode("vlp:sql", XmlNSManager);
command = (sqlnode == null ? node.GetNodeValue() : sqlnode.GetNodeValue());
if (!string.IsNullOrEmpty(command))
{
System.Data.DbType type;
command = langHelper.TranslateText(null, command);
ds.DataCommand = new DatabaseCommand(command, connectionstr, DatabaseCommand.DBCommandType.SQL);
value = node.GetAttributeValue("type");
if (!string.IsNullOrEmpty(value) && value.Equals("proc", StringComparison.CurrentCultureIgnoreCase))
{
ds.DataCommand.CommandType = DatabaseCommand.DBCommandType.StoredProcedure;
}
foreach (XmlNode param in node.SelectNodes("vlp:param", XmlNSManager))
{
id = param.GetAttributeValue("name");
if (string.IsNullOrEmpty(id))
{
Log.Error(string.Format(LangHelperNS.ReportView.GetTranslation("Report.NoSQLParameterNameText", "Névtelen SQL paraméter (adatkapcsolat neve: '{0}', lista ID: '{1}')!"), ds.Name, report.ID));
}
else
{
value = param.GetNodeValue();
type = DatabaseCommand.GetDBTypeFromName(param.GetAttributeValue("type"));
ds.DataCommand.AddParameter(id, type, value);
}
}
}
break;
case "connectionstring":
connectionstr = node.GetNodeValue();
break;
default:
Log.Error(string.Format(LangHelperNS.ReportView.GetTranslation("Report.UnknownTypeInDatasetDescriptionText", "Hibás adatkapcsolatleíró (name = {0}): ismeretlen típus: {1} (lista ID: '{2}')!"), ds.Name, node.Name, report.ID));
break;
}
}
}
if (ds.DataCommand == null)
{
Log.Error(string.Format(LangHelperNS.ReportView.GetTranslation("Report.NoDataCommandInDatasetDescriptionText", "Hibás adatkapcsolatleíró (name = {0}): nincs 'datacommand' elem (lista ID: '{1}')!"), ds.Name, report.ID));
}
else
{
ds.DataCommand.ConnectionString = connectionstr;
if (ds.InitCommand != null)
ds.InitCommand.ConnectionString = connectionstr;
report.DataSets.Add(ds);
}
}
}
}
#endregion //Static private methods
#region private methods
/// <summary>
/// Arranges the parameters into a table to display in the dialog.
/// </summary>
private bool ArrangeParams()
{
int idx, colidx;
SortedList<int, SortedList<int, ReportParameter>> sl = new SortedList<int, SortedList<int, ReportParameter>>();
SortedList<int, ReportParameter> columns = new SortedList<int, ReportParameter>();
SortedList<int, ReportParameter> row;
List<ReportParameter> orphans = new List<ReportParameter>();
ReportParameter last = null;
foreach (var item in Parameters)
{
if (item.Value.WidgetType != "hidden")
{
if (item.Value.Row >= 0)
{
if (sl.ContainsKey(item.Value.Row))
{
row = sl[item.Value.Row];
}
else
{
row = new SortedList<int, ReportParameter>();
sl.Add(item.Value.Row, row);
}
}
else
{
row = columns;
}
if (item.Value.Column >= 0)
{
if (item.Value.Column > MaxCol)
MaxCol = item.Value.Column;
row.Add(item.Value.Column, item.Value);
}
else
{
orphans.Add(item.Value);
}
}
}
foreach (var column in columns)
{
idx = 0;
while (sl.ContainsKey(idx) && sl[idx].ContainsKey(column.Key))
idx++;
if (!sl.ContainsKey(idx))
{
sl.Add(idx, new SortedList<int, ReportParameter>());
}
sl[idx].Add(column.Key, column.Value);
column.Value.Row = idx;
}
columns = null;
idx = 0;
foreach (var item in orphans)
{
while (sl.ContainsKey(idx) && sl[idx].Count > MaxCol)
idx++;
if (!sl.ContainsKey(idx))
{
sl.Add(idx, new SortedList<int, ReportParameter>());
}
row = sl[idx];
colidx = 0;
while (row.ContainsKey(colidx))
colidx++;
row.Add(colidx, item);
item.Row = idx;
item.Column = colidx;
}
ParameterList = new List<ReportParameter>();
foreach (var r in sl)
{
foreach (var c in r.Value)
{
if (last != null)
{
if (c.Value.Row == last.Row)
last.ColSpan = c.Value.Column - last.Column;
else
last.ColSpan = MaxCol - last.Column + 1;
}
last = c.Value;
ParameterList.Add(c.Value);
}
}
if (last != null)
{
last.ColSpan = MaxCol - last.Column + 1;
}
return true;
}
/// <summary>
/// Sets the default values of the dropdownlist widgets.
/// </summary>
private void SetDefaultValues()
{
ReportParameter rp;
object dv;
foreach (var item in Parameters)
{
rp = item.Value;
if ((dv = rp.DefaultValue) != null && rp.SelectOptions != null)
{
foreach (var option in rp.SelectOptions)
{
if (option.Value.Equals(dv))
option.Selected = true;
}
}
}
}
#endregion //private methods
#region internal methods
/// <summary>
/// Checks the parameter values and prepares the report for displaying.
/// <param name="parameters">The parameter values given by the user.</param>
/// <param name="modelstate">The object for the error messages.</param>
/// </summary>
internal void CheckValues(NameValueCollection parameters, ModelStateDictionary modelstate, bool bForceParamDisplay)
{
ReportParameter rp;
if (parameters == null)
{
_isCompleted = !Parameters.Any(p => p.Value.WidgetType != "hidden");
}
else
{
for (int i = 0; i < parameters.Count; i++)
{
if (Parameters.ContainsKey(parameters.GetKey(i)))
{
Parameters[parameters.GetKey(i)].ResetError();
Parameters[parameters.GetKey(i)].DefaultValue = parameters.Get(i);
}
}
_isCompleted = !bForceParamDisplay && string.IsNullOrEmpty(parameters.Get("paramButton"));
if (_isCompleted)
foreach (var item in Parameters)
{
if (!item.Value.CheckValue(modelstate))
_isCompleted = false;
}
}
if (_isCompleted)
{
Dictionary<string, string> sql_replaces = new Dictionary<string, string>();
Dictionary<string, string> param_replaces = new Dictionary<string, string>();
//composing sqls
RdlEvaluatedParameters.Clear();
foreach (var item in Parameters)
{
rp = item.Value;
if (rp.Replaces.Count > 0)
foreach (var repl in rp.Replaces)
{
sql_replaces.Add(repl.Key, repl.Value.GetReplaceValue(rp, false));
param_replaces.Add(repl.Key, repl.Value.GetReplaceValue(rp, true));
}
if (!sql_replaces.ContainsKey(rp.ReplaceID))
sql_replaces.Add(rp.ReplaceID, rp.GetSQLValue(false));
if (!param_replaces.ContainsKey(rp.ReplaceID))
param_replaces.Add(rp.ReplaceID, rp.GetSQLValue(true));
}
foreach (var ds in DataSets)
{
if (ds.DataCommand != null)
{
ds.DataCommand.PrepareSQLCommand(sql_replaces, param_replaces);
}
if (ds.InitCommand != null)
{
ds.InitCommand.PrepareSQLCommand(sql_replaces, param_replaces);
}
}
foreach (var rdlparam in RdlParameters)
{
if (rdlparam.Value != null)
{
if (RdlEvaluatedParameters.ContainsKey(rdlparam.Key))
RdlEvaluatedParameters[rdlparam.Key] = RdlEvaluatedParameters[rdlparam.Key].Replace(param_replaces);
else
RdlEvaluatedParameters.Add(rdlparam.Key, rdlparam.Value.Replace(param_replaces));
}
}
//Nullozza az üreseket.
var RdlKeys = new List<string>(RdlEvaluatedParameters.Keys);
foreach (var key in RdlKeys)
{
if (string.IsNullOrEmpty(RdlEvaluatedParameters[key]))
{
RdlEvaluatedParameters[key] = null;
}
}
}
if (string.IsNullOrEmpty(FileName))
{
string msg = string.Format(LangHelperNS.ReportView.GetTranslation("Report.NoReportFileNameText", "Nncs megadva vagy hibás a report fájl neve (lista ID: '{0}')"), this.ID);
Log.Warning(msg);
modelstate.AddModelError(string.Empty, msg);
_isCompleted = false;
}
}
#endregion //internal methods
}
/// <summary>
/// Structure to hold data for a parameter description.
/// </summary>
public class ReportParameter
{
#region private variables
/// <summary>
/// The error indicator.
/// </summary>
private bool _bError;
/// <summary>
/// The minimum value if any.
/// </summary>
private string _MinValue;
/// <summary>
/// The maximum value if any.
/// </summary>
private string _MaxValue;
/// <summary>
/// The data type of the parameter.
/// Valid options are: C (text), I (integer), F (float), B (bool), D (date), T (time), DT (datetime).
/// </summary>
private string _Paramtype = "C";
/// <summary>
/// The (default) value of the parameter in string format.
/// </summary>
private string _DefaultValue;
/// <summary>
/// The (default) code value of the parameter in string format.
/// </summary>
private string _DefaultCodeValue;
#endregion private variables
#region public variables
/// <summary>
/// The possible values of caracter case.
/// </summary>
public enum FieldCaseType
{
Normal,
Uppercase,
Lowercase
}
/// <summary>
/// The name of the parameter.
/// </summary>
public string Name;
/// <summary>
/// The text representing the given parameter in texts. It will be replaced with the value.
/// </summary>
public string ReplaceID;
/// <summary>
/// The ID of the parameter used in html environment.
/// </summary>
public string ID
{
get
{
return Name.Trim(new char[] { '@', '[', ']', ' ', '\t', '{', '}', '(', ')', '&', '#' });
}
}
/// <summary>
/// The label of the parameter used in the parameter window.
/// </summary>
public string Label = null;
/// <summary>
/// If the value of the property is true than the seconds are displayed and used.
/// Valid only for datetime and time in DateTimeBox and TimeBox.
/// </summary>
public bool ShowSeconds = false;
/// <summary>
/// Stores the spincontrol extra data if the control is to be displayed. Valid only for integer.
/// </summary>
public SpinControl SpinControl = null;
/// <summary>
/// The type of the widget used for data input.
/// Values are: TextBox (default), CheckBox, DateBox, DateTimeBox, TimeBox, DropDownList, AutocompleteTextBox.
/// </summary>
public string WidgetType = "TextBox";
/// <summary>
/// The case attribute of the widget text. Valid only for texts.
/// </summary>
public FieldCaseType FieldCase = FieldCaseType.Normal;
/// <summary>
/// The list of the choosable options. Valid only for 'DropDownList'.
/// </summary>
public List<SelectListItem> SelectOptions = null;
/// <summary>
/// The list of characters that can be used in the given control. Empty string means no restriction.
/// </summary>
public string FilterCharacterSet = "";
/// <summary>
/// The row number where the control is to be placed (starts from 0). If its value is -1, the control will be placed automatically.
/// </summary>
public int Row = -1;
/// <summary>
/// The column number where the control is to be placed (starts from 0). If its value is -1, the control will be placed automatically.
/// </summary>
public int Column = -1;
/// <summary>
/// The number of columns used by the control.
/// </summary>
public int ColSpan = 1;
/// <summary>
/// The minimum value if any.
/// </summary>
public object MinValue
{
get
{
return GetValue(_MinValue);
}
set
{
_MinValue = (string)value;
}
}
/// <summary>
/// The maximum value if any.
/// </summary>
public object MaxValue
{
get
{
return GetValue(_MaxValue);
}
set
{
_MaxValue = (string)value;
}
}
/// <summary>
/// If its value is true, the field is required.
/// </summary>
public bool Required = false;
/// <summary>
/// Minimum value of text's length if any.
/// </summary>
public int MinLength;
/// <summary>
/// Maximum value of text's length if any.
/// </summary>
public int MaxLength;
/// <summary>
/// The data type of the parameter.
/// Valid options are: C (text), I (integer), F (float), B (bool), D (date), T (time), DT (datetime), X:Name (extra, rejtett paraméterek).
/// </summary>
public string Paramtype
{
get
{
return _Paramtype;
}
set
{
_Paramtype = value.ToUpper();
switch (_Paramtype)
{
case "C": //text
WidgetType = "TextBox";
FieldCase = ReportParameter.FieldCaseType.Normal;
break;
case "E": //expression
WidgetType = "TextBox";
FieldCase = ReportParameter.FieldCaseType.Normal;
break;
case "I": //integer
WidgetType = "TextBox";
FieldCase = ReportParameter.FieldCaseType.Normal;
FilterCharacterSet = "0123456789 +-";
break;
case "F": //float
WidgetType = "TextBox";
FieldCase = ReportParameter.FieldCaseType.Normal;
FilterCharacterSet = "0123456789 .,+-";
break;
case "B": //bool
WidgetType = "CheckBox";
break;
case "D": //date
WidgetType = "DateBox";
break;
case "DT": //datetime
WidgetType = "DateTimeBox";
break;
case "T": //time
WidgetType = "TimeBox";
break;
default:
if (_Paramtype.StartsWith("X:"))
{
WidgetType = "hidden";
SetInternalParameter(_Paramtype.Substring(2));
}
else
{
//hibás típus
}
break;
}
}
}
/// <summary>
/// The (default) value of the parameter in native format (corresponding to Paramtype).
/// </summary>
public object DefaultValue
{
get
{
return GetValue(_DefaultValue);
}
set
{
_DefaultValue = (string)value;
if (this.SelectOptions != null)
{
_DefaultCodeValue = _DefaultValue;
}
else if (this.Reference != null)
{
_DefaultCodeValue = this.GetCodeValue();
}
else
{
_DefaultCodeValue = _DefaultValue;
}
}
}
/// <summary>
/// The (default) code value of the parameter in native format (corresponding to Paramtype).
/// </summary>
public object DefaultCodeValue
{
get
{
return GetValue(_DefaultCodeValue);
}
}
/// <summary>
/// The list of the replaces of the parameter.
/// </summary>
public Dictionary<string, ParameterReplace> Replaces = new Dictionary<string, ParameterReplace>();
/// <summary>
/// The ParameterReference object if any.
/// </summary>
public ParameterReference Reference;
#endregion //public variables
/// <summary>
/// Sets the value of an internal parameters.
/// <param name="p">The name of the parameter.</param>
/// </summary>
private void SetInternalParameter(string p)
{
MembershipUser user;
switch (p.ToUpper())
{
case "USERID":
_Paramtype = "G";
user = System.Web.Security.Membership.GetUser();
if (user != null)
DefaultValue = user.ProviderUserKey.ToString();
break;
case "USERNAME":
_Paramtype = "C";
user = System.Web.Security.Membership.GetUser();
if (user != null)
DefaultValue = user.UserName;
break;
case "NOW":
_Paramtype = "DT";
DefaultValue = "now";
break;
case "TODAY":
_Paramtype = "D";
DefaultValue = "today";
break;
}
}
/// <summary>
/// Converts the given string value to the parameters's native format.
/// <param name="p">The string value to be converted.</param>
/// <return>The converted value.</returns>
/// </summary>
private object GetValue(string p)
{
object rv = null;
string s = (Paramtype.Equals("C") || p == null ? p : p.Split(new char[] { ',' })[0]);
if (!string.IsNullOrEmpty(p))
{
try
{
LangHelperNS langHelper = LangHelperNS.ReportView;
System.Globalization.CultureInfo cultureInfo = System.Threading.Thread.CurrentThread.CurrentUICulture;
string timeFormat = (ShowSeconds) ? (langHelper.GetTranslation("DateTime.LongTimeFormat", cultureInfo.DateTimeFormat.LongTimePattern)) : (langHelper.GetTranslation("DateTime.ShortTimeFormat", cultureInfo.DateTimeFormat.ShortTimePattern)),
dateFormat = langHelper.GetTranslation("DateTime.DateFormat", cultureInfo.DateTimeFormat.ShortDatePattern);
switch (Paramtype)
{
case "C": //text
rv = s;
break;
case "I": //integer
rv = int.Parse(s);
break;
case "F": //float
rv = float.Parse(s, System.Globalization.CultureInfo.InvariantCulture);
break;
case "B": //bool
rv = bool.Parse(s);
break;
case "D": //date
rv = RelativeDateParser.Parse(s, dateFormat, null);
break;
case "DT": //datetime
rv = RelativeDateParser.Parse(s, dateFormat, timeFormat);
break;
case "T": //time
rv = RelativeDateParser.Parse(s, null, timeFormat);
break;
case "G": //guid
rv = Guid.Parse(s);
break;
default:
Log.Error(string.Format(LangHelperNS.ReportView.GetTranslation("Report.UnknownDataTypeText", "Ismeretlen adattípus: {0}, paraméter neve: {1}"), this.Paramtype, this.Name));
this._bError = true;
break;
}
}
catch (Exception e)
{
Log.Error(e.Message);
this._bError = true;
}
}
return rv;
}
#region internal (public) methods
/// <summary>
/// Checks whether the given filter value matches to the value of the parameter.
/// <param name="p">The filter value.</param>
/// <return>True if the match is succeded.</returns>
/// </summary>
internal bool Matches(string p)
{
bool rv = false;
object val = DefaultCodeValue;
try
{
if (p == null)
rv = true;
else if (p.Length == 0)
{
rv = (val == null || (val is string && ((string)val).Length == 0));
}
else
{
int i;
string op = "=";
object pval;
for (i = 0; i < p.Length && ">=<".IndexOf(p[i]) >= 0; i++) ;
if (i > 0)
{
op = p.Substring(0, i);
p = p.Remove(0, i);
}
pval = GetValue(p);
switch (op)
{
case "=":
rv = pval.Equals(val);
break;
case "<":
if (pval is string)
{
rv = (((string)pval).CompareTo(val) > 0);
}
else if (pval is int)
{
rv = (((int)pval).CompareTo(val) > 0);
}
else if (pval is float)
{
rv = (((float)pval).CompareTo(val) > 0);
}
else if (pval is DateTime)
{
rv = (((DateTime)pval).CompareTo(val) > 0);
}
else if (pval is bool)
{
rv = (((bool)pval).CompareTo(val) > 0);
}
break;
case "<=":
if (pval is string)
{
rv = (((string)pval).CompareTo(val) >= 0);
}
else if (pval is int)
{
rv = (((int)pval).CompareTo(val) >= 0);
}
else if (pval is float)
{
rv = (((float)pval).CompareTo(val) >= 0);
}
else if (pval is DateTime)
{
rv = (((DateTime)pval).CompareTo(val) >= 0);
}
else if (pval is bool)
{
rv = (((bool)pval).CompareTo(val) >= 0);
}
break;
case ">":
if (pval is string)
{
rv = (((string)pval).CompareTo(val) < 0);
}
else if (pval is int)
{
rv = (((int)pval).CompareTo(val) < 0);
}
else if (pval is float)
{
rv = (((float)pval).CompareTo(val) < 0);
}
else if (pval is DateTime)
{
rv = (((DateTime)pval).CompareTo(val) < 0);
}
else if (pval is bool)
{
rv = (((bool)pval).CompareTo(val) < 0);
}
break;
case ">=":
if (pval is string)
{
rv = (((string)pval).CompareTo(val) <= 0);
}
else if (pval is int)
{
rv = (((int)pval).CompareTo(val) <= 0);
}
else if (pval is float)
{
rv = (((float)pval).CompareTo(val) <= 0);
}
else if (pval is DateTime)
{
rv = (((DateTime)pval).CompareTo(val) <= 0);
}
else if (pval is bool)
{
rv = (((bool)pval).CompareTo(val) <= 0);
}
break;
default:
Log.Error(string.Format(LangHelperNS.ReportView.GetTranslation("Report.UnknownOperatorText", "Ismeretlen operátor: '{0}', paraméter neve: {1}"), op, this.Name));
this._bError = true;
break;
}
}
}
catch (Exception e)
{
rv = false;
Log.Error(e.Message);
this._bError = true;
}
return rv;
}
/// <summary>
/// Gets the value of the parameter whitch can be used in an SQL expression.
/// <param name="bForSQLparams">If true, the value will be used in a SQL parameter.</param>
/// <return>The converted value.</returns>
/// </summary>
internal string GetSQLValue(bool bForSQLparams)
{
string rv = "";
object val = DefaultCodeValue;
if (val != null)
{
try
{
switch (Paramtype)
{
case "C": //text
if (bForSQLparams)
rv = val as string;
else
rv = "'" + ((string)val).Replace("'", "''") + "'";
break;
case "E": //expression
rv = (string)val;
break;
case "I": //integer
rv = ((int)val).ToString();
break;
case "F": //float
rv = ((float)val).ToString();
break;
case "B": //bool
rv = (((bool)val) ? "1" : "0");
break;
case "D": //date
rv = ((DateTime)val).ToString("s");
rv = rv.Remove(rv.IndexOf('T'));
if (!bForSQLparams)
{
rv = "'" + rv + "'";
}
break;
case "DT": //datetime
rv = ((DateTime)val).ToString("s").Replace('T', ' ');
if (!ShowSeconds)
rv = rv.Remove(rv.Length - 3);
if (!bForSQLparams)
{
rv = "'" + rv + "'";
}
break;
case "T": //time
rv = ((DateTime)val).ToString("s");
rv = rv.Remove(0, rv.IndexOf('T') + 1);
if (!bForSQLparams)
{
rv = "'" + rv + "'";
}
break;
case "G": //guid
rv = val.ToString();
if (!bForSQLparams)
{
rv = "'" + rv + "'";
}
break;
default:
Log.Error(string.Format(LangHelperNS.ReportView.GetTranslation("Report.UnknownDataTypeText", "Ismeretlen adattípus: {0}, paraméter neve: {1}"), this.Paramtype, this.Name));
this._bError = true;
break;
}
}
catch (Exception e)
{
Log.Error(e.Message);
this._bError = true;
rv = "";
}
}
return rv;
}
/// <summary>
/// Checks if the given values of parameters meet the criterias.
/// <param name="modelstate">The object used to collect the error messages.</param>
/// <return>True if the parameters fulfill the conditions.</returns>
/// </summary>
internal bool CheckValue(ModelStateDictionary modelstate)
{
bool rv = true;
if (this.DefaultCodeValue == null)
{
if (this.Required)
{
modelstate.AddModelError(this.ID, LangHelperNS.ReportView.GetTranslation("Report.FieldRequiredText", "A mezőt ki kell tölteni!"));
rv = false;
}
}
else if (this.MinLength > 0 && this._DefaultCodeValue.Length < this.MinLength)
{
modelstate.AddModelError(this.ID, string.Format(LangHelperNS.ReportView.GetTranslation("Report.StringTooShortText", "Túl rövid a mező tartalma (min. {0} karakter kell)!"), this.MinLength));
rv = false;
}
else if (this.MaxLength > 0 && this._DefaultCodeValue.Length > this.MaxLength)
{
modelstate.AddModelError(this.ID, string.Format(LangHelperNS.ReportView.GetTranslation("Report.StringTooLongText", "Túl hosszú a mező tartalma (max. {0} karakter lehet)!"), this.MaxLength));
rv = false;
}
else if (this.MinValue != null && Matches("<" + _MinValue))
{
modelstate.AddModelError(this.ID, string.Format(LangHelperNS.ReportView.GetTranslation("Report.ValueTooSmallText", "Nagyobb értéket kell megadni (min. {0} kell)!"), this.MinValue));
rv = false;
}
else if (this.MaxValue != null && Matches(">" + _MaxValue))
{
modelstate.AddModelError(this.ID, string.Format(LangHelperNS.ReportView.GetTranslation("Report.ValueTooLargeText", "Kisebb értéket kell megadni (max. {0} lehet)!"), this.MaxValue));
rv = false;
}
return rv && !this._bError;
}
/// <summary>
/// Gets the text value of an autocomplete fields.
/// <return>The value or null.</returns>
/// </summary>
internal string GetCodeValue()
{
string rv = null;
if (!string.IsNullOrEmpty(_DefaultValue) && Reference != null)
{
SqlConnection mySqlConnection = null;
SqlCommand mySqlCommand = null;
SqlDataReader mySqlDataReader = null;
try
{
Reference.Command.PrepareSQLCommand();
mySqlConnection = new SqlConnection();
mySqlConnection.ConnectionString = Reference.Command.ConnectionString;
mySqlCommand = new SqlCommand();
mySqlCommand.CommandText = Reference.Command.PreparedCommand;
mySqlCommand.Parameters.Add(new SqlParameter("filter", _DefaultValue));
mySqlCommand.CommandType = System.Data.CommandType.Text;
mySqlCommand.Connection = mySqlConnection;
CommandParameter.SetCommandTimeout(mySqlCommand);
mySqlCommand.Connection.Open();
mySqlDataReader = mySqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection | System.Data.CommandBehavior.SingleRow);
int iKod = mySqlDataReader.GetOrdinal(Reference.IDField);
int iName = mySqlDataReader.GetOrdinal(Reference.NameField);
if (mySqlDataReader.HasRows)
{
while (mySqlDataReader.Read())
{
//rv = mySqlDataReader.GetString(iKod);
//WIND 2014.05.28 Ezzel nem lehet részértéket megadni
rv = string.Format("{0}", mySqlDataReader.GetValue(iKod)); //TG
}
//WIND 2014.05.28 Azért, hogy részértéket is meg lehessen adni
if (rv.Contains(_DefaultValue))
rv = _DefaultValue;
}
else
{
Log.modelstate.AddModelError(this.ID, string.Format(LangHelperNS.ReportView.GetTranslation("Report.ValueNotFoundInDatabaseText", "Nincs ilyen érték az adatbázisban: {0}!"), _DefaultValue));
this._bError = true;
}
}
catch (System.Exception e)
{
Log.Error(e.Message);
this._bError = true;
}
if (mySqlDataReader != null)
mySqlDataReader.Dispose();
if (mySqlCommand != null)
mySqlCommand.Dispose();
if (mySqlConnection != null)
mySqlConnection.Dispose();
}
return rv;
}
/// <summary>
/// Resets the error flag.
/// </summary>
internal void ResetError()
{
this._bError = false;
}
#endregion //internal (public) methods
}
/// <summary>
/// Structure to hold the dataset descriptor values.
/// </summary>
public class DataSetDescriptor
{
/// <summary>
/// The name of the dataset. Must meet to the dataset name in the report file (rdlc).
/// </summary>
public string Name;
/// <summary>
/// The command used to get the data.
/// </summary>
public DatabaseCommand DataCommand;
/// <summary>
/// The command used to init the data.
/// </summary>
public DatabaseCommand InitCommand;
}
/// <summary>
/// Holds the data need for a spincontrol.
/// </summary>
public class SpinControl
{
/// <summary>
/// The value of increment.
/// </summary>
public int SpinIncrementValue;
/// <summary>
/// The value of decrement.
/// </summary>
public int SpinDecrementValue;
}
/// <summary>
/// Holds information and methods to handle parameter replacement.
/// </summary>
public class ParameterReplace
{
/// <summary>
/// A filter - value pair.
/// </summary>
private class ReplaceItem
{
/// <summary>
/// A filter text. The '>', '>=', '<', '<=' operators can be used. Lack of any operators means '=' operator.
/// </summary>
public string Filter;
/// <summary>
/// A text to replace if the value of the parameter matches the filter.
/// </summary>
public string Value;
}
#region private variables
/// <summary>
/// A string (id) to be replaced.
/// </summary>
private string ParamID;
/// <summary>
/// A list of filter - value pairs.
/// </summary>
private List<ReplaceItem> Replaces;
#endregion //private variables
/// <summary>
/// A constructor.
/// <param name="paramID">The text to be replaced (parameter id).</param>
/// </summary>
public ParameterReplace(string paramID)
{
this.ParamID = paramID;
this.Replaces = new List<ReplaceItem>();
}
#region public Methods
/// <summary>
/// Add a filter - value pair to the list.
/// <param name="filter">The filter.</param>
/// <param name="value">A text to replace if the value of the parameter matches the filter.</param>
/// </summary>
public void AddItem(string filter, string value)
{
Replaces.Add(new ReplaceItem() { Filter = filter, Value = value });
}
/// <summary>
/// Replaces the ID of the given parameter with the parameter's value in the first replace string where the filter
/// matches the value of the parameter.
/// <param name="rp">A ReportParameter object.</param>
/// <param name="bForSQLParams">If true the value will be used in a SQL parameter.</param>
/// <return>The found string in where the parameter§s ID is replaced with the parameter's value or null if no match is found.</returns>
/// </summary>
public string GetReplaceValue(ReportParameter rp, bool bForSQLParams)
{
foreach (var repl in Replaces)
{
if (rp.Matches(repl.Filter))
{
return repl.Value.Replace(rp.ReplaceID, rp.GetSQLValue(bForSQLParams));
}
}
return null;
}
#endregion // public Methods
}
/// <summary>
/// Holds the data for a parameter reference, i.e. an sql to collecting a table's data.
/// </summary>
public class ParameterReference
{
/// <summary>
/// The command to get the reference data.
/// </summary>
public DatabaseCommand Command;
/// <summary>
/// The name of the 'ID' field.
/// </summary>
public string IDField;
/// <summary>
/// The name of the 'name' field.
/// </summary>
public string NameField;
}
/// <summary>
/// Holds the data needed for a database command.
/// </summary>
public class DatabaseCommand
{
/// <summary>
/// Possible types of a database command.
/// </summary>
public enum DBCommandType
{
None,
SQL,
StoredProcedure
}
#region private variables
/// <summary>
/// The SQL command or stored procedure.
/// </summary>
private string Command;
/// <summary>
/// The parameters of the command.
/// </summary>
private Dictionary<string, CommandParameter> CommandParameters;
#endregion //private variables
#region public variables
/// <summary>
/// The prepared command, ready to be executed.
/// </summary>
public string PreparedCommand;
/// <summary>
/// The prepared parameters, ready to be used in execution.
/// </summary>
public Dictionary<string, CommandParameter> PreparedCommandParameters;
/// <summary>
/// The type of the database command.
/// </summary>
public DBCommandType CommandType;
/// <summary>
/// The connection string.
/// </summary>
public string ConnectionString;
#endregion //public variables
/// <summary>
/// The constructor.
/// </summary>
public DatabaseCommand(string Command, string ConnectionString, DBCommandType CommandType = DBCommandType.SQL)
{
this.Command = Command;
this.ConnectionString = ConnectionString;
this.CommandType = CommandType;
}
/// <summary>
/// The empty.
/// </summary>
public DatabaseCommand()
{
this.CommandType = DBCommandType.None;
}
/// <summary>
/// Prepares the command string and parameters for use.
/// <param name="sql_values">The key-value pairs used in the replacement of SQL statement.</param>
/// <param name="param_values">The key-value pairs used in the replacement of parameters.</param>
/// </summary>
public void PrepareSQLCommand(Dictionary<string, string> sql_values = null, Dictionary<string, string> param_values = null)
{
if (sql_values == null)
PreparedCommand = Command;
else
PreparedCommand = Command.Replace(sql_values);
if (CommandParameters == null)
{
PreparedCommandParameters = null;
}
else
{
if (PreparedCommandParameters == null)
PreparedCommandParameters = new Dictionary<string, CommandParameter>();
else
PreparedCommandParameters.Clear();
if (param_values != null)
{
foreach (var item in CommandParameters)
{
PreparedCommandParameters.Add(item.Key, new CommandParameter(item.Value.Name, item.Value.Type, item.Value.Value.Replace(param_values)));
}
}
else
{
PreparedCommandParameters = new Dictionary<string, CommandParameter>(CommandParameters);
}
}
}
/// <summary>
/// Adds a SQL parameter to the parameter list.
/// <param name="id">The parameter id.</param>
/// <param name="type">The parameter's type.</param>
/// <param name="val">The parameter value.</param>
/// </summary>
public void AddParameter(string id, System.Data.DbType type, string val)
{
if (CommandParameters == null)
CommandParameters = new Dictionary<string, CommandParameter>();
if (!CommandParameters.ContainsKey(id))
CommandParameters.Add(id, new CommandParameter(id, type, val));
}
/// <summary>
/// Gets the data type name.
/// <param name="type">The data type name as string.</param>
/// <return>The data type corrensponding the given parameter.</returns>
/// </summary>
public static System.Data.DbType GetDBTypeFromName(string type)
{
System.Data.DbType rv = System.Data.DbType.String;
if (!string.IsNullOrEmpty(type))
{
switch (type.ToLower())
{
case "ansistring": //A variable-length stream of non-Unicode characters ranging between 1 and 8,000 characters.
rv = System.Data.DbType.AnsiString;
break;
case "binary": //A variable-length stream of binary data ranging between 1 and 8,000 bytes.
rv = System.Data.DbType.Binary;
break;
case "byte": //An 8-bit unsigned integer ranging in value from 0 to 255.
rv = System.Data.DbType.Byte;
break;
case "boolean": //A simple type representing Boolean values of true or false.
rv = System.Data.DbType.Boolean;
break;
case "currency": //A currency value ranging from -2 63 (or -922,337,203,685,477.5808) to 2 63 -1 (or +922,337,203,685,477.5807) with an accuracy to a ten-thousandth of a currency unit.
rv = System.Data.DbType.Currency;
break;
case "date": //A type representing a date value.
rv = System.Data.DbType.Date;
break;
case "datetime": //A type representing a date and time value.
rv = System.Data.DbType.DateTime;
break;
case "decimal": //A simple type representing values ranging from 1.0 x 10 -28 to approximately 7.9 x 10 28 with 28-29 significant digits.
rv = System.Data.DbType.Decimal;
break;
case "double": //A floating point type representing values ranging from approximately 5.0 x 10 -324 to 1.7 x 10 308 with a precision of 15-16 digits.
rv = System.Data.DbType.Double;
break;
case "guid": //A globally unique identifier (or GUID).
rv = System.Data.DbType.Guid;
break;
case "int16": //An integral type representing signed 16-bit integers with values between -32768 and 32767.
rv = System.Data.DbType.Int16;
break;
case "int32": //An integral type representing signed 32-bit integers with values between -2147483648 and 2147483647.
rv = System.Data.DbType.Int32;
break;
case "int64": //An integral type representing signed 64-bit integers with values between -9223372036854775808 and 9223372036854775807.
rv = System.Data.DbType.Int64;
break;
case "object": //A general type representing any reference or value type not explicitly represented by another DbType value.
rv = System.Data.DbType.Object;
break;
case "sbyte": //An integral type representing signed 8-bit integers with values between -128 and 127.
rv = System.Data.DbType.SByte;
break;
case "single": //A floating point type representing values ranging from approximately 1.5 x 10 -45 to 3.4 x 10 38 with a precision of 7 digits.
rv = System.Data.DbType.Single;
break;
case "string": //A type representing Unicode character strings.
rv = System.Data.DbType.String;
break;
case "time": //A type representing a SQL Server DateTime value. If you want to use a SQL Server time value, use Time.
rv = System.Data.DbType.Time;
break;
case "uint16": //An integral type representing unsigned 16-bit integers with values between 0 and 65535.
rv = System.Data.DbType.UInt16;
break;
case "uint32": //An integral type representing unsigned 32-bit integers with values between 0 and 4294967295.
rv = System.Data.DbType.UInt32;
break;
case "uint64": //An integral type representing unsigned 64-bit integers with values between 0 and 18446744073709551615.
rv = System.Data.DbType.UInt64;
break;
case "varnumeric": //A variable-length numeric value.
rv = System.Data.DbType.VarNumeric;
break;
case "ansistringfixedlength": //A fixed-length stream of non-Unicode characters.
rv = System.Data.DbType.AnsiStringFixedLength;
break;
case "stringfixedlength": //A fixed-length string of Unicode characters.
rv = System.Data.DbType.StringFixedLength;
break;
case "xml": //A parsed representation of an XML document or fragment.
rv = System.Data.DbType.Xml;
break;
case "datetime2": //Date and time data. Date value range is from January 1,1 AD through December 31, 9999 AD. Time value range is 00:00:00 through 23:59:59.9999999 with an accuracy of 100 nanoseconds.
rv = System.Data.DbType.DateTime2;
break;
case "datetimeoffset": //Date and time data with time zone awareness. Date value range is from January 1,1 AD through December 31, 9999 AD. Time value range is 00:00:00 through 23:59:59.9999999 with an accuracy of 100 nanoseconds. Time zone value range is -14:00 through +14:00.
rv = System.Data.DbType.DateTimeOffset;
break;
}
}
return rv;
}
}
}