Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Detecting user and displaying corresponding reults Post Reply Post New Topic
Author Message
gguthrie
Newbie
Newbie


Joined: 06 May 2009
Location: United States
Online Status: Offline
Posts: 13
Quote gguthrie Replybullet Topic: Detecting user and displaying corresponding reults
    Posted: 06 May 2009 at 1:06pm
I am using vb and .net user and roles. I can find out who the user is whose logged in by user.identity, which is equal to a field in a table.
 
Now I have created a crystal report with a wizard because I need to get three parameters from the user (status, start date, end date). Everything works fine if I don't display the results by the user, but I don't know how to get the user into crystal reports.
 
I use a selection formula in my report, and it shows all 4 parameter inputs when it loads, but I only want the 3 to show (not UserName)
 
{tblTireJobs.Status} = {?Status} AND {tblTireJobs.DateReported} >= {?StartDate} AND
{tblTireJobs.DateReported} <= {?EndDate} AND {aspnet_Users.UserId} = {?UserName}
 
I've tried this in my vb code:
myReport.Load("CrystalReport1.rpt")
myReport.SetDatabaseLogon("****", "****")
myReport.SetParameterValue("UserName", User.Identity)
CrystalReportViewer1.ReportSource = myReport
 
and it will not work. Also I can't write a sql query that will take a User.Identity value because it doesn't exist in crystal reports.
 
What I am looking for is some help on getting the username (by their login to the web application) and using it to help sort the reults I want to display, because each user is only allowed to view the results that they are allowed to view.
 
I am a newbie, so pointing me in the right direction would also help.
 
IP IP Logged
gguthrie
Newbie
Newbie


Joined: 06 May 2009
Location: United States
Online Status: Offline
Posts: 13
Quote gguthrie Replybullet Posted: 06 May 2009 at 2:32pm
For a little idea of what I am trying to do with this. Is there anyway I can get the below code to be read by crystal reports. I need UserName to be dynamic and change with each user opening the report? (the bolded parts I just can't get to work with crystal)
 

Dim objDataSet As New DataSet()

Dim objDataAdapter As SqlClient.SqlDataAdapter

Dim UserName As String = User.Identity.Name

objConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("CsiConnectionString").ConnectionString)

If User.IsInRole("consultant") Then

objDataAdapter = New SqlDataAdapter("SELECT tblTireJobs.JobID, tblTireJobs.Status, tblTireJobs.FirstName, tblTireJobs.LastName, tblTireJobs.DateReported, tblTireShop.TireKingdomID, tblTireShop.Name " & _

"FROM tblTireJobs INNER JOIN tblTireShop ON tblTireJobs.ShopID = tblTireShop.ShopID WHERE tblTireShop.FBCID='" & UserName & "' ORDER BY tblTireShop.Name", objConnection)

Else

objDataAdapter = New SqlDataAdapter("SELECT tblTireJobs.JobID, tblTireJobs.Status, tblTireJobs.FirstName, tblTireJobs.LastName, tblTireJobs.DateReported, tblTireShop.TireKingdomID, tblTireShop.Name " & _

"FROM tblTireJobs INNER JOIN tblTireShop ON tblTireJobs.ShopID = tblTireShop.ShopID ORDER BY tblTireShop.Name", objConnection)

End If

objDataSet = New DataSet()

objDataAdapter.Fill(objDataSet)

 

 

IP IP Logged
gguthrie
Newbie
Newbie


Joined: 06 May 2009
Location: United States
Online Status: Offline
Posts: 13
Quote gguthrie Replybullet Posted: 07 May 2009 at 6:19am
This might be a better question, as I'm really having trouble trying to articulate what I am looking for.
 
Can I set one parameter in the code (which would be the UserName) and pass that to the crystal report. While the user can still select three parameters on their own (on the set parameter page).
 
The problem is if I choose a parameter for UserName it pops up with the other three parameters in the set parameter page. Is there a way to add a parameter in crystal reports and choose for it to not display on the set parameter page, so I can pass that result with code?
 
btw, thanks in advance
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.