http://blogs.msdn.com/b/bwelcker/archive/2007/07/11/laser-guided-missiles-report-localization-through-parameters.aspx
I am trying to implement this in WinForms.
I am getting an error that the multi valued parameter is not provided a value.
What I have done is I have a Dataset by name ResourceDictionary and I am using that in the "Available Value" for my multivalue param - ResourceParam.
Then for translation, I am using the expreession - =Code.GetLabel(Parameters!ResourceParam,Fields!TransactionType.Value)
Appreciate all help. Thanks
reportViewer.LocalReport.ReportPath = reportPath & "Expense.rdlc"
expenseList = ReportManager.GetExpenseReport(Application.AppDatabase, Application.FirmID, FromDate, ToDate, dtFormat, True, Application.AppResources)
Dim reportDataSource1 As New ReportDataSource()
reportDataSource1.Name = "ExpenseList"
reportDataSource1.Value = expenseList
reportViewer.LocalReport.DataSources.Add(reportDataSource1)
'reportViewer.LocalReport.DataSources.Add(New ReportDataSource With {.Name = "ResourceDictionary", .Value = res})
paramList.Add(New ReportParameter("Header1", UIHelper.GetRsxVal("date"), True))
paramList.Add(New ReportParameter("Header2", UIHelper.GetRsxVal("expensetype"), True))
paramList.Add(New ReportParameter("Header3", UIHelper.GetRsxVal("refno"), True))
paramList.Add(New ReportParameter("Header4", UIHelper.GetRsxVal("totalamt"), True))
paramList.Add(New ReportParameter("Header5", "", True))
paramList.Add(New ReportParameter("ReportHeader", UIHelper.GetRsxVal("expensehdr"), True))
reportViewer.LocalReport.SetParameters(paramList)
reportViewer.RefreshReport()
Hi see this article here that explains the error you described above and it's possible workarounds. The one that seems to be most straightforward is to set an rs param as follows:
Enable cookie sessions by specifying rs:ClearSession=true in the URL for the report
Related
I am pretty new to the RDLC report feature, I am looking to generate labels from Product data within a SQL database. When the user opens this Product/Part they are greeted with the information. When the user then clicks a button this will open the Report which will pass the parameters across to the Report in order to generate the label.
Dim myparam As ReportParameter
Dim testParameter As New List(Of ReportParameter)
myparam = New ReportParameter("PartID", "Test")
testParameter.Add(myparam)
myparam = New ReportParameter("MRPID", "Test MRP")
testParameter.Add(myparam)
myparam = New ReportParameter("PartName", "Test Name")
testParameter.Add(myparam)
ReportViewer1.LocalReport.SetParameters(testParameter)
Dim writer As New BarcodeWriter
writer.Format = BarcodeFormat.CODE_128
PictureBox1.Image = writer.Write(MRPID)
Me.ReportViewer1.RefreshReport()
As you can see, I am using XLing to generate my barcodes, which I have been successful in making work with the 3 lines of code you see above. However, I have no idea how I can pass this or have this generate on the report when ran. The barcode will be generated from the MRPID ie(TV001232). I understand this part is wrong "writer.Write(MRPID)" but I replaced the parameter value with MRPID so you could understand what I am trying to achieve.
Convert your image to Base64 string first using this:
Public Function ImageToBase64(ByVal image As Image, ByVal format As System.Drawing.Imaging.ImageFormat) As String
Dim base64String As String = ""
Using ms As New System.IO.MemoryStream()
image.Save(ms, format)
Dim imageBytes As Byte() = ms.ToArray()
base64String = Convert.ToBase64String(imageBytes)
End Using
Return base64String
End Function
So this:
myparam = New ReportParameter("MRPID", "Test MRP")
testParameter.Add(myparam)
Should be like this:
Dim writer As New BarcodeWriter
writer.Format = BarcodeFormat.CODE_128
myparam = New ReportParameter("MRPID", ImageToBase64(writer.Write(MRPID),<THE IMAGE FORMAT OF YOUR IMAGE>))
testParameter.Add(myparam)
Then, in your report set the following:
MIMEType = select the correct MIME type from the dropdown list
Source = Database
Value = <Expression>
and in the Expression window:
=System.Convert.FromBase64String(Parameters!MRPID.Value)
I am making a small application in VB to export a report from a server to a PDF. I have tested it with a report without parameters, and it worked fine so I know the URLs and everything are correct. But the parameters are not working, and I have Googled extensively and tried everything. I've tried both an array and a list of parameters (both shown in the code), and fiddled with every setting possible in the SSRS Report builder as far as hiding parameters goes. The buyer and supplier are chosen from a drop down list. The error always happens when I finally execute the SetParameters method. If anyone has any ideas I greatly appreciate it.
Dim report As ServerReport = New ServerReport()
'(setting up url stuff)
'use a list for parameters
Dim parameterList As New Generic.List(Of ReportParameter)
parameterList.Add(New ReportParameter("buyer", buyer, True))
parameterList.Add(New ReportParameter("supplier", supplier, True))
parameterList.Add(New ReportParameter("quoteDate", quoteDate.ToString, True))
parameterList.Add(New ReportParameter("reqDate", reqDate.ToString, True))
parameterList.Add(New ReportParameter("user", username, True))
'use an array for parameters
Dim params(4) As ReportParameter
params(0) = New ReportParameter("buyer", buyer, False)
params(1) = New ReportParameter("supplier", supplier, False)
params(2) = New ReportParameter("quoteDate", quoteDate.ToString, False)
params(3) = New ReportParameter("reqDate", reqDate.ToString, False)
params(4) = New ReportParameter("user", username, False)
report.SetParameters(params)
report.Refresh()
'for testing
Dim reportData As Byte() = report.Render("PDF")
System.IO.File.WriteAllBytes("C:\Users\....." & reportName & ".pdf", reportData)
I'm using EntityFrameWork 5 in VB MV4 project.
I have a database built from EntityFramework diagram (model firt as opposed to code first)
I have a ViewModel X, containing a List(ofT) T being one on my Entity
When I open my web application (on the browser) I ask a controller to give me the ViewModel X as a Json object that I use to populate a MVVC (knockout model) using the Knockout JS Mapping pluggin.
When I ask for the model, I populate it using code similar to what is shown below
Public Class DataServiceController
Inherits System.Web.Mvc.Controller
<Authorize()> _
Public Function RetrieveData() As JsonResult
Dim model As ViewModelX
model = New ViewModelX
'=====================================
' Resources and Tools
'=====================================
Dim fetchedResourceAndToolsQuery = From a In db.ResourceAndTools
Where a.ProfileId = profile.ProfileId Select a
For Each eachRes In fetchedResourceAndToolsQuery
Dim res As ResourceAndTools = New ResourceAndTools
res.Name = Trim(eachRes.Name)
res.URL = Trim(eachRes.URL)
res.Target = eachRes.Target
res.ResourceId = eachRes.ResourceId
model.ResourceAndTools.Add(res)
Next
Return Json(model, JsonRequestBehavior.AllowGet)
Everthing works great! Except... And here's the question
As mentionned above, ViewModelX contains a List(of T) T being ResourceAndTools
Is there a was to copy (clone, load, not sure of the term) the content of fetchedResourceAndToolsQuery (Result of the Linq Query) to model.ResourceAndTools (List(of T)) without instantiating a new object and copying the properties like I'm doing.
I've seached (Cloning, Deep Copying, Shallow Copying, etc.) The closest I came to a solution was some explanation on how to deep copy an object but it relied on serialisation, it did not work because not all properties of a Entity Framework object are serialisable.
Any help is appreciated
Thank you
Like this?
model.ResourceAndTools = (
From a In db.ResourceAndTools
Where a.ProfileId = profile.ProfileId
Select New ResourceAndTools() With { _
.Name = Trim(a.Name), _
.URL = Trim(a.URL), _
.Target = a.Target, _
.ResourceId = a.ResourceId}).ToList()
Following your comment, perhaps you could do,
Dim dataList = (
From a In db.ResourceAndTools
Where a.ProfileId = profile.ProfileId
Select New With
{
.Name = Trim(a.Name),
.URL = Trim(a.URL),
.Target = a.Target,
.ResourceId = a.ResourceId
}).ToList()
model.ResourceAndTools = dataList.ConvertAll(Function(data)
Return New ResourceAndTools() With
{
.Name = data.Name,
.Url = data.Url,
.Target = data.Target,
.ResourceId = data.ResourceId
}
End Function)
I have a function that updates a user in the asp.net membership provider.
<AcceptVerbs(HttpVerbs.Post)>
Public Function EnableUser(ByVal id As String) As JsonResult
Dim usr As StargatePortalUser = _membershipService.GetUser(id, Nothing)
usr.IsApproved = True
_membershipService.UpdateUser(usr)
Dim response As New AjaxResponse(usr.UserName)
Return Json(response)
End Function
I am trying to test this function to ensure the IsApproved property is set correctly
<TestMethod()>
Public Sub Service_Can_Enable_A_User_Account()
' Arrange
Dim usr As New Mock(Of MembershipUser)
usr.SetupProperty(Function(u) u.IsApproved)
_membershipService.Setup(Function(m) m.GetUser(It.IsAny(Of String), It.IsAny(Of Boolean))).Returns(usr.Object)
Dim target As New UsersController(_membershipService.Object)
target.ControllerContext = New ControllerContext(FakeAuthenticatedHttpContext("testuser", String.Empty, True, True, False), New RouteData, target)
' Act
Dim actual As JsonResult = target.EnableUser("userId")
' Assert
Assert.IsTrue(DirectCast(actual.Data, AjaxResponse).Success)
_membershipService.Verify(Sub(m) m.UpdateUser(It.IsAny(Of MembershipUser)), Times.Once)
usr.Verify(Function(u) u.IsApproved = True)
End Sub
When I try to verify that the IsApproved property has been set to True an exception is returned:
System.ArgumentException: Expression is not a method invocation: u => (u.IsApproved == True)
There are so few examples of using Moq in VB that I can't figure this out, any help would be appreciated.
This is an ASP.NET MVC2 app in VB.NET 10 (.NET 4.0)
EDIT:
Ok, turns out it's not quite so straight forward in VB.
usr.Verify(Function(u) u.IsApproved = True)
needs to be
usr.VerifySet(Function(u) InlineAssignHelper(u.IsApproved, True))
and you need to add the following function:
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
FURTHER EDIT:
Thinking around the problem I arrived at a more simple solution. I changed
Dim usr As New Mock(Of MembershipUser)
usr.SetupProperty(Function(u) u.IsApproved)
_membershipService.Setup(Function(m) m.GetUser(It.IsAny(Of String), It.IsAny(Of Boolean))).Returns(usr.Object)
for
Dim usr As New Mock(Of MembershipUser)
usr.SetupProperty(Function(u) u.IsApproved)
Dim usrObj = usr.Object
_membershipService.Setup(Function(m) m.GetUser(It.IsAny(Of String), It.IsAny(Of Boolean))).Returns(usrObj)
and then can replace
usr.VerifySet(Function(u) InlineAssignHelper(u.IsApproved, True))
with the more straightforward
Assert.IsTrue(usrOb.IsApproved)
Sometimes I just don't see the simple solution :)
You want to use the following (from http://code.google.com/p/moq/wiki/QuickStart):
// or verify the setter directly
mock.VerifySet(foo => foo.Name = "foo");
Right now the thing that you're feeding in is a comparison rather than an assignment, so even if Moq did process the statement without an exception, it would still not be Doing What You Mean.
Well this may be a little late, but I was facing the same problem and the solution was way simpler then using a InlineAssignHelper method.
Just change the Function to a Sub and it should work.
So try this instead:
usr.VerifySet(Sub(u) u.IsApproved = True)
VB.NET equivalent to this C# code?
ctx.Load(site,
x => x.Lists.Where(l => l.Title != null));
I've tried
ctx.Load(site, Function(x) x.Lists.Where(Function(l) l.Title IsNot Nothing))
but this errors with "The expression (Convert(l.Title) != null) is not supported."
Thoughts
if Title is string try use IsNullOrEmpty();
or
Nullable(Of T).HasValue if Title is Nullable
or
Sub Main()
Dim list As New List(Of A)
Dim a1 As New A
a1.Title = "sqws"
Dim a2 As New A
a2.Title = Nothing
list.Add(a1)
list.Add(a2)
Dim q = From c In list Where c.Title IsNot Nothing
End Sub
Public Class A
Dim t As String
Public Property Title() As String
Get
Title = t
End Get
Set(ByVal value As String)
t = value
End Set
End Property
End Class
This may be cheating, but I have used Reflector in the past to decompile my C# code and then display it as other .NET languages just to see how they would look as I am most fluent in C#
This really should work:
ctx.Load(site, Function(x) x.Lists.Where(Function(l) l.Title.IsNullOrEmpty = False))
If it does not, let me know the error message.
Have you tried the IsNothing function?
ctx.Load(site, Function(x) x.Lists.Where(Function(l) Not IsNothing(l.Title)))
EDIT:
Now that you've specified that Title is a String, then you should use the IsNullOrEmpty function.
ctx.Load(site, Function(x) x.Lists.Where(Function(l) Not String.IsNullOrEmpty(l.Title)))