FAQ/SaveReportSet.md
... ...
@@ -11,62 +11,107 @@ This method is used to define how your reports are stored. By default, using [[D
11 11
###DatabaseAdHocConfig
12 12
13 13
```csharp
14
-public override void SaveReportSet(string reportName, ReportSet reportSet) {
15
- // BEGIN Database Mode Code Sample
16
- string SavedReportsTable = AdHocSettings.SavedReportsTable;
17
- string sql = string.Format(@"
18
-IF (EXISTS (SELECT Name FROM {2} WHERE Name = '{0}'))
19
-BEGIN
20
- UPDATE {2} SET Xml = '{1}' WHERE Name = '{0}'
21
-END
22
-ELSE
23
-BEGIN
24
- INSERT INTO {2} (Name, Xml) VALUES ('{0}', '{1}')
25
-END",
26
- reportName.Trim(),
27
- reportSet.WriteXml(),
28
- SavedReportsTable);
29
-
30
- System.Data.IDbCommand command = Izenda.AdHoc.AdHocContext.Driver.CreateCommand(sql);
31
- try {
32
- command.ExecuteNonQuery();
33
- }
34
- finally {
35
- if (command.Connection.State == System.Data.ConnectionState.Open)
36
- command.Connection.Close();
37
- }
38
- // END Database Mode Code Sample
39
-}
14
+public override void SaveReportSet(string reportName, ReportSet reportSet)
15
+ {
16
+ try
17
+ {
18
+ string connectionString = @"Persist Security Info=False;Initial Catalog=Northwind;Data Source=LESHA-PC\SQL2012;User ID=dataLogin;Password=dataPassword;Integrated Security=false;";
19
+ string sql = string.Format(@"IF (EXISTS (SELECT Name FROM {2} WHERE Name = '{0}'))
20
+ BEGIN UPDATE {2} SET Xml = '{1}', CreatedDate='{3}', ModifiedDate='{4}', TenantID='{5}' WHERE Name = '{0}' END
21
+ ELSE BEGIN INSERT INTO {2} (Name, Xml, CreatedDate, ModifiedDate, TenantID) VALUES ('{0}', '{1}', '{3}', '{4}', '{5}') END",
22
+ reportName.Trim(),
23
+ reportSet.WriteXml(),
24
+ AdHocSettings.SavedReportsTable,
25
+ reportSet.DateCreated.ToString(),
26
+ reportSet.DateModified.ToString(),
27
+ "_global_");
28
+ using (System.Data.IDbConnection connection = new System.Data.SqlClient.SqlConnection(connectionString))
29
+ {
30
+ connection.Open();
31
+ using (System.Data.IDbCommand command = connection.CreateCommand())
32
+ {
33
+ command.CommandText = sql;
34
+ command.ExecuteNonQuery();
35
+ }
36
+ }
37
+ }
38
+ catch
39
+ {
40
+ }
41
+ }
40 42
```
41 43
42 44
###FileSystemAdHocConfig
43 45
44 46
```csharp
45
-public override void SaveReportSet(string reportName, Izenda.AdHoc.ReportSet reportSet) {
46
- // BEGIN Filesystem Mode Code Sample
47
- DirectoryInfo dir = new DirectoryInfo(ReportPath);
48
- string message = string.Format("{0} does not exist, Set Izenda.AdHoc.AdHocSettings.ReportsPath to the proper path and give full permission to the {1} for that folder."
49
- , dir.FullName
50
- , Thread.CurrentPrincipal.Identity.Name);
51
- if (!dir.Exists)
52
- throw new DirectoryNotFoundException(message);
47
+ public override void SaveReportSet(string reportName, ReportSet reportSet)
48
+ {
49
+ System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(ReportPath);
50
+ string message = String.Format("{0} does not exist, Set Izenda.AdHoc.AdHocSettings.ReportsPath to the proper path and give full permission to the {1} for that folder.", dir.FullName, System.Threading.Thread.CurrentPrincipal.Identity.Name);
51
+ if (!dir.Exists)
52
+ throw new Exception(message);
53
+ string fileName = System.IO.Path.Combine(ReportPath, reportName + ".xml");
54
+ try
55
+ {
56
+ System.IO.FileInfo file = new System.IO.FileInfo(fileName);
57
+ if (!file.Directory.Exists)
58
+ file.Directory.Create();
59
+ System.IO.StreamWriter writer = file.CreateText();
60
+ string xml = reportSet.WriteXml();
61
+ writer.Write(xml);
62
+ writer.Close();
63
+ }
64
+ catch (UnauthorizedAccessException e)
65
+ {
66
+ throw new Exception("Make make sure 'NETWORK SERVICE' or 'ASPNET' has full permission to the Reports folder.\n" + e.Message);
67
+ }
68
+ }
69
+```
70
+
71
+##Sample VB.NET Methods
72
+###DatabaseAdHocConfig
73
+```visualbasic
74
+Public Overrides Sub SaveReportSet(reportName As String, reportSet As ReportSet)
75
+ Try
76
+ Dim connectionString As String = "Persist Security Info=False;Initial Catalog=Northwind;Data Source=LESHA-PC\SQL2012;User ID=dataLogin;Password=dataPassword;Integrated Security=false;"
77
+ Dim sql As String = String.Format("IF (EXISTS (SELECT Name FROM {2} WHERE Name = '{0}')) BEGIN UPDATE {2} SET Xml = '{1}', CreatedDate='{3}', ModifiedDate='{4}', TenantID='{5}' WHERE Name = '{0}' END ELSE BEGIN INSERT INTO {2} (Name, Xml, CreatedDate, ModifiedDate, TenantID) VALUES ('{0}', '{1}', '{3}', '{4}', '{5}') END", reportName.Trim(), reportSet.WriteXml(), AdHocSettings.SavedReportsTable, reportSet.DateCreated.ToString(), reportSet.DateModified.ToString(), "_global_")
78
+ Using connection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
79
+ connection.Open()
80
+ Using command As System.Data.IDbCommand = connection.CreateCommand()
81
+ command.CommandText = sql
82
+ command.ExecuteNonQuery()
83
+ End Using
84
+ End Using
85
+ Catch ex As Exception
86
+ End Try
87
+ End Sub
88
+
89
+```
90
+
91
+
92
+
93
+###FileSystemAdHocConfig
94
+```visualbasic
95
+Public Overrides Sub SaveReportSet(reportName As String, reportSet As ReportSet)
96
+ Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(ReportPath)
97
+ Dim message As String = String.Format("{0} does not exist, Set Izenda.AdHoc.AdHocSettings.ReportsPath to the proper path and give full permission to the {1} for that folder.", dir.FullName, System.Threading.Thread.CurrentPrincipal.Identity.Name)
98
+ If Not (dir.Exists) Then
99
+ Throw New Exception(message)
100
+ End If
101
+ Dim fileName As String = System.IO.Path.Combine(ReportPath, reportName + ".xml")
102
+ Try
103
+ Dim file As System.IO.FileInfo = New System.IO.FileInfo(fileName)
104
+ If Not (file.Directory.Exists) Then
105
+ file.Directory.Create()
106
+ End If
107
+ Dim writer As System.IO.StreamWriter = file.CreateText()
108
+ Dim xml As String = reportSet.WriteXml()
109
+ writer.Write(xml)
110
+ writer.Close()
111
+ Catch ex As UnauthorizedAccessException
112
+ Throw New Exception("Make make sure 'NETWORK SERVICE' or 'ASPNET' has full permission to the Reports folder.\n" + ex.Message)
113
+ End Try
114
+ End Sub
115
+
116
+```
53 117
54
- string fileName = Path.Combine(ReportPath, reportName + ".xml");
55
- try {
56
- FileInfo file = new FileInfo(fileName);
57
- if (!file.Directory.Exists)
58
- file.Directory.Create();
59
- StreamWriter writer = file.CreateText();
60
- string xml = reportSet.WriteXml();
61
- writer.Write(xml);
62
- writer.Close();
63
- }
64
- catch (UnauthorizedAccessException e) {
65
- throw new Exception("Make make sure 'NETWORK SERVICE' or 'ASPNET' has full permission to the Reports folder.\n" + e.Message);
66
- }
67
- catch (SecurityException e) {
68
- throw new Exception("Make make sure 'NETWORK SERVICE' or 'ASPNET' has full permission to the Reports folder.\n" + e.Message);
69
- }
70
- // END Filesystem Mode Code Sample
71
-}
72
-```
... ...
\ No newline at end of file