ad902a0da7281aec10216687718279be6f0aa3f3
FAQ/ListReports.md
| ... | ... | @@ -4,9 +4,13 @@ |
| 4 | 4 | |
| 5 | 5 | ##About |
| 6 | 6 | |
| 7 | -The ListReports method allows you to dynamically alter the list of reports that Izenda uses on the Report List page. Below is an example of logic you could use with this method. |
|
| 7 | +The ListReports method allows you to dynamically alter the list of reports that Izenda uses on the Report List page. Below are examples of logic you could use with this method. |
|
| 8 | 8 | |
| 9 | -##Sample Method (DatabaseAdHocConfig) |
|
| 9 | +##Sample C♯ Methods |
|
| 10 | + |
|
| 11 | +These examples are basic customized methods of obtaining a list of reports done using the different methods that Izenda supports. |
|
| 12 | + |
|
| 13 | +###[[DatabaseAdHocConfig|http://wiki.izenda.us/FAQ/Storing-Reports#Database-Mode]] |
|
| 10 | 14 | |
| 11 | 15 | ```csharp |
| 12 | 16 | public override Izenda.AdHoc.ReportInfo[] ListReports() { |
| ... | ... | @@ -38,7 +42,7 @@ public override Izenda.AdHoc.ReportInfo[] ListReports() { |
| 38 | 42 | |
| 39 | 43 | ``` |
| 40 | 44 | |
| 41 | -##Sample Method (FileSystemAdHocConfig) |
|
| 45 | +### [[FileSystemAdHocConfig|http://wiki.izenda.us/FAQ/Storing-Reports#File-System-Mode]] |
|
| 42 | 46 | |
| 43 | 47 | ```csharp |
| 44 | 48 | /* BEGIN Filesystem Mode Code Sample */ |
| ... | ... | @@ -46,12 +50,12 @@ public override Izenda.AdHoc.ReportInfo[] ListReports() { |
| 46 | 50 | public override ReportInfo[] ListReports() { |
| 47 | 51 | ArrayList reportNames = new ArrayList(); |
| 48 | 52 | |
| 49 | - if (ReportPath != null) { |
|
| 50 | - DirectoryInfo dir = new DirectoryInfo(ReportPath); |
|
| 53 | + if (AdHocSettings.ReportsPath != null) { |
|
| 54 | + DirectoryInfo dir = new DirectoryInfo(AdHocSettings.ReportsPath); |
|
| 51 | 55 | if (dir.Exists) { |
| 52 | 56 | string dirName = Path.GetFullPath(dir.FullName); |
| 53 | 57 | ArrayList fileArray = new ArrayList(); |
| 54 | - GetAllXmlFiles(dir, fileArray); |
|
| 58 | + GetAllXmlFiles(dir, fileArray); //your method for obtaining XML files from your file server |
|
| 55 | 59 | FileInfo[] files = (FileInfo[])fileArray.ToArray(typeof(FileInfo)); |
| 56 | 60 | foreach (FileInfo file in files) { |
| 57 | 61 | if (file.Extension == ".xml") { |
| ... | ... | @@ -80,4 +84,41 @@ public override ReportInfo[] ListReports() { |
| 80 | 84 | }//end if |
| 81 | 85 | }//end if |
| 82 | 86 | }//end method |
| 87 | +``` |
|
| 88 | + |
|
| 89 | +##Controlling report access |
|
| 90 | + |
|
| 91 | +This is an example of how to override this method using some basic security checks ensuring a user can only get reports available to him/her. We will provide a C♯ sample using [[DatabaseAdHocConfig|http://wiki.izenda.us/FAQ/Storing-Reports#Database-Mode]]. You can transform this code sample as needed to suit your own company's needs. |
|
| 92 | + |
|
| 93 | +``` |
|
| 94 | +public class CustomAdHocConfig : Izenda.AdHoc.DatabaseAdHocConfig |
|
| 95 | +{ |
|
| 96 | + |
|
| 97 | + protected override Izenda.AdHoc.ReportInfo[] ListReports() |
|
| 98 | + { |
|
| 99 | + ArrayList reportNames = new ArrayList(); |
|
| 100 | + string sql = String.Format("SELECT Name, CreatedDate, ModifiedDate FROM {0} ORDER BY Name WHERE UserID='{1}'", AdHocSettings.SavedReportsTable, AdHocSettings.CurrentUserName); |
|
| 101 | + |
|
| 102 | + System.Data.IDbCommand command = null; |
|
| 103 | + try |
|
| 104 | + { |
|
| 105 | + command = Izenda.AdHoc.AdHocContext.Driver.CreateCommand(sql); |
|
| 106 | + System.Data.IDataReader reader = command.ExecuteReader(); |
|
| 107 | + |
|
| 108 | + while (reader.Read()) |
|
| 109 | + { |
|
| 110 | + string reportName = reader["Name"].ToString(); |
|
| 111 | + DateTime createdDate = (DateTime)reader["CreatedDate"]; |
|
| 112 | + DateTime modifiedDate = (DateTime)reader["ModifiedDate"]; |
|
| 113 | + if (reportName != "") |
|
| 114 | + reportNames.Add(new Izenda.AdHoc.ReportInfo(reportName, false, createdDate, modifiedDate)); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + catch (Exception) { } |
|
| 118 | + |
|
| 119 | + if (command.Connection.State == System.Data.ConnectionState.Open) |
|
| 120 | + command.Connection.Close(); |
|
| 121 | + return (Izenda.AdHoc.ReportInfo[])reportNames.ToArray(typeof(Izenda.AdHoc.ReportInfo)); |
|
| 122 | + } |
|
| 123 | +} |
|
| 83 | 124 | ``` |
| ... | ... | \ No newline at end of file |