9ee8a65d72d96432942c6308ee7d9ea5f9a483da
FAQ/PreExecuteReportSet.md
| ... | ... | @@ -2,146 +2,13 @@ |
| 2 | 2 | |
| 3 | 3 | [[_TOC_]] |
| 4 | 4 | |
| 5 | -##Hidden Filter C♯ |
|
| 5 | +##About |
|
| 6 | 6 | |
| 7 | -This is a code sample showing how to add a hidden filter to a report. The first filter uses the _strArray_, but you will need to write a function which returns the columns which you wish to filter upon. |
|
| 7 | +The PreExecuteReportSet method is used to modify the report before it is sent to the Report Viewer or Report Preview for viewing. Overriding this method can add granular control of fields, filters, and other properties of the report before the person designing/viewing the report will see it. |
|
| 8 | 8 | |
| 9 | -```csharp |
|
| 10 | -public override void PreExecuteReportSet(Izenda.AdHoc.ReportSet reportSet) |
|
| 9 | +##Examples |
|
| 11 | 10 | |
| 12 | -{ |
|
| 13 | - /* First Example, multi valued filter */ |
|
| 14 | - //columns to filter - write your own function |
|
| 11 | +Here are a couple examples of using the PreExecuteReportSet method. |
|
| 15 | 12 | |
| 16 | - string[] strArray = new string[3] {"Beverages", "Seafood", "Produce"}; |
|
| 17 | - |
|
| 18 | - if(reportSet.Source.Contains("[dbo].[Categories]")) |
|
| 19 | - { |
|
| 20 | - Izenda.AdHoc.Filter newFilter = new Izenda.AdHoc.Filter(); |
|
| 21 | - newFilter.Column="CategoryName"; |
|
| 22 | - newFilter.Operator=OperatorTypes.In; |
|
| 23 | - newFilter.Values = strArray; |
|
| 24 | - |
|
| 25 | - reportSet.Filters.AddHidden(newFilter); |
|
| 26 | - // will only show the category names corresponding to the array values |
|
| 27 | - } //end if |
|
| 28 | - |
|
| 29 | - /* Second Example, single valued filter */ |
|
| 30 | - if (reportSet.Source.Contains("[dbo].[OtherCategories]")) |
|
| 31 | - { |
|
| 32 | - Izenda.AdHoc.Filter newFilter = new Izenda.AdHoc.Filter(); |
|
| 33 | - newFilter.Column = "CategoryName"; |
|
| 34 | - newFilter.Operator = OperatorTypes.Like; |
|
| 35 | - newFilter.Value = "Sea"; |
|
| 36 | - reportSet.Filters.AddHidden(newFilter); |
|
| 37 | - // will only show category names having the exact string "Sea" in them |
|
| 38 | - } //end if |
|
| 39 | -}//end method |
|
| 40 | -``` |
|
| 41 | -Essentially, to use a multi valued filter, you must use the In operator (basically an equals operator with comma separated values) and the .Values specifier. |
|
| 42 | - |
|
| 43 | -To use a single valued operator such as "Like" (basically a case sensitive contains), you can not use an array and must use the .Value specifier. |
|
| 44 | - |
|
| 45 | -##Hidden Filter with sql override |
|
| 46 | - |
|
| 47 | -```csharp |
|
| 48 | -Public Overrides Sub PreExecuteReportSet(ByVal reportSet As Izenda.AdHoc.ReportSet) |
|
| 49 | - |
|
| 50 | - MyBase.PreExecuteReportSet(reportSet) |
|
| 51 | - 'If reportSet.Source.Equals("[dbo].[Customers]") Then |
|
| 52 | - Dim filter As New Izenda.AdHoc.Filter() |
|
| 53 | - filter.Column = "email" |
|
| 54 | - filter.SqlOverride = "(aspnet_Membership.email = 'greg@edelinsolutions.com' or aspnet_Membership.email='gedelin@yahoo.com')" |
|
| 55 | - reportSet.Filters.AddHidden(filter) |
|
| 56 | - 'End If |
|
| 57 | -End Sub |
|
| 58 | -``` |
|
| 59 | - |
|
| 60 | -##Hidden Filter VB.NET |
|
| 61 | - |
|
| 62 | -```visualbasic |
|
| 63 | -Public Overrides Sub PreExecuteReportSet(ByVal reportSet As Izenda.AdHoc.ReportSet) |
|
| 64 | - MyBase.PreExecuteReportSet(reportSet) |
|
| 65 | - Dim emails(1) As String |
|
| 66 | - emails(0) = "greg@edelinsolutions.com" |
|
| 67 | - emails(1) = "gedelin@yahoo.com1" |
|
| 68 | - Dim filter As New Izenda.AdHoc.Filter() |
|
| 69 | - filter.Column = "email" |
|
| 70 | - filter.Operator = OperatorTypes.In |
|
| 71 | - filter.Values = emails |
|
| 72 | - reportSet.Filters.AddHidden(filter) |
|
| 73 | -End Sub |
|
| 74 | -``` |
|
| 75 | - |
|
| 76 | -##Using a stored procedure |
|
| 77 | - |
|
| 78 | -This example uses a stored procedure to populate a table before report design or execution. As shown in the comments, the table StoredProcResults must already exist. Every time a report is created or viewed this stored procedure will update the results of the _StoredProcResults_ table. |
|
| 79 | - |
|
| 80 | -```csharp |
|
| 81 | -// Customize a report on the fly prior to execution on a per user basis |
|
| 82 | -public override void PreExecuteReportSet(Izenda.AdHoc.ReportSet reportSet) |
|
| 83 | -{ |
|
| 84 | - |
|
| 85 | - /*this sample uses the adventure works database |
|
| 86 | - |
|
| 87 | - Here is the definition of the table and |
|
| 88 | - stored procedure created for this report. |
|
| 89 | - |
|
| 90 | - CREATE TABLE [dbo].[StoredProcResults] |
|
| 91 | - [ProductID] [int] NOT NULL, |
|
| 92 | - [OrderQuantity] [int] NOT NULL, |
|
| 93 | - [Total] [int] NOT NULL, |
|
| 94 | - [DueDate] [smalldatetime] NOT NULL |
|
| 95 | - ) ON [PRIMARY] |
|
| 96 | - |
|
| 97 | - CREATE PROCEDURE DoCustomAction ( |
|
| 98 | - @date1 as smalldatetime, |
|
| 99 | - @date2 as smalldatetime |
|
| 100 | - ) |
|
| 101 | - AS |
|
| 102 | - BEGIN |
|
| 103 | - |
|
| 104 | - insert into StoredProcResults |
|
| 105 | - select ProductID,OrderQty,LineTotal,ModifiedDate |
|
| 106 | - from Sales.SalesOrderDetail |
|
| 107 | - where ModifiedDate >= @date1 and ModifiedDate <= @date2 |
|
| 108 | - |
|
| 109 | - END |
|
| 110 | - */ |
|
| 111 | - |
|
| 112 | - string currentReportName = |
|
| 113 | - HttpContext.Current.Request.QueryString["rn"]; |
|
| 114 | - |
|
| 115 | - if (currentReportName == "StoredProcExample") |
|
| 116 | - { |
|
| 117 | - SqlConnection myConnection = new |
|
| 118 | - SqlConnection(Izenda.AdHoc.AdHocSettings.SqlServerConnectionString); |
|
| 119 | - SqlCommand myCommand = new SqlCommand("DoCustomAction", myConnection); |
|
| 120 | - |
|
| 121 | - // Mark the Command as a SPROC |
|
| 122 | - myCommand.CommandType = System.Data.CommandType.StoredProcedure; |
|
| 123 | - |
|
| 124 | - // Add Parameters to SPROC |
|
| 125 | - SqlParameter parameterdate1 = new SqlParameter |
|
| 126 | - ("@date1", System.Data.SqlDbType.SmallDateTime); |
|
| 127 | - parameterdate1.Value = "1/1/2003"; |
|
| 128 | - myCommand.Parameters.Add(parameterdate1); |
|
| 129 | - |
|
| 130 | - SqlParameter parameterdate2 = new SqlParameter |
|
| 131 | - ("@date2", System.Data.SqlDbType.SmallDateTime); |
|
| 132 | - parameterdate2.Value = "12/31/2003"; |
|
| 133 | - myCommand.Parameters.Add(parameterdate2); |
|
| 134 | - |
|
| 135 | - try |
|
| 136 | - |
|
| 137 | - myConnection.Open(); |
|
| 138 | - myCommand.ExecuteNonQuery(); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - finally |
|
| 142 | - { |
|
| 143 | - myConnection.Close(); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | -} |
|
| 147 | -``` |
|
| ... | ... | \ No newline at end of file |
| 0 | +* [[Hidden Filter Example|/FAQ/applying-hidden-filter-using-inner-query]] |
|
| 1 | +* [[Using Stored Procedures|/FAQ/Questions/Using-Stored-Procedures-In-Izenda-6]] |
|
| ... | ... | \ No newline at end of file |