Page1:
From Date: TXTBOX1 To Date: TXTBOX2
BTNSUBMIT-CLICK
{
server.transfer("page2.aspx");
}
Page 2:
if (PreviousPage != null)
{
TextBox txt1 = PreviousPage.FindControl("TXTBOX1") as TextBox;
TextBox txt2 = PreviousPage.FindControl("TXTBOX2") as TextBox;
if (txt1.Text.Length != 0 && txt2.Text.Length != 0)
{
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("MyReport.rpt");
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new
ParameterDiscreteValue();
crParameterDiscreteValue.Value = txt1.Text + txt2.Text;
crParameterFieldDefinitions =
cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition =
crParameterFieldDefinitions["MyParameter"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
CrystalReportViewer1.ReportSource = cryRpt;
}
}
Formula In Formula Editor:
{Command.Date} >= {?MyParameter} and {Command.Date} <= {?MyParameter}
It works fine If report is displayed for single date. Not for Date Range.
Any Suggestions? Where i am wrong in formula / code ???
You should pass the date fields as separate parameters, and reference them in your Formula Editor like this:
{Command.Date} >= {?ParamDateFrom} and {Command.Date} <= {?ParamDateTo}
Use a ParameterRangeValue instead of a ParameterDiscreteValue, and set the StartValue and EndValue properties to your start and end dates.
Update:
Here's some sample code that worked on a test report:
ParameterFieldDefinitions paramDefinitions = report.DataDefinition.ParameterFields;
ParameterFieldDefinition paramDefinition = paramDefinitions["DateRange"];
ParameterValues paramValues = paramDefinition.CurrentValues;
ParameterRangeValue rangeValue = new ParameterRangeValue();
rangeValue.StartValue = new DateTime(2010, 10, 31);
rangeValue.EndValue = new DateTime(2010, 12, 15);
paramValues.Add(rangeValue); ;
paramDefinition.ApplyCurrentValues(paramValues);
Make sure that your MyParameter is a range value, and that the select statement in Crystal is dateField = {?MyParameter}
Related
I have a sub called addchartPrevious24()
This sub is being called on the initial load and when the user calls for a refresh. The job of this sub is to go out to an access database query the information. Populate into a dataset. Then create a chart and chart area. The dataset is then set as the datasource of the chart. My issue is if i reexecute the sub it does not update the chart with the new data although the dataset does get updated.
Public Sub addchartPrevious24()
Dim Connection As OleDb.OleDbConnection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\manage.mdb;Jet OLEDB:Database Password=password")
Dim da1 As New OleDb.OleDbDataAdapter
Dim ds1 As New DataSet()
Dim Command As New OleDb.OleDbCommand
Connection.Open()
da1.SelectCommand = New OleDb.OleDbCommand("SELECT General_Counters_Table.product_id, Sum(General_Counters_Table.ulboardcyclecount) AS SumOfulboardcyclecount, ltrim(STR(Month(General_Counters_Table.Date_Time)))+ '/'+Ltrim(STR(Day(General_Counters_Table.Date_Time))) + '/'+ltrim(STR(Year(General_Counters_Table.Date_Time))) + ' hour ' +Ltrim(STR(Hour(General_Counters_Table.Date_Time))) as DATEConverted FROM General_Counters_Table where Date_Time >=(NOW()-1) and Date_Time <= (NOW()) GROUP BY General_Counters_Table.product_id, Year(General_Counters_Table.Date_Time), Month(General_Counters_Table.Date_Time), Day(General_Counters_Table.Date_Time), Hour(General_Counters_Table.Date_Time) ORDER BY Year(General_Counters_Table.Date_Time), Month(General_Counters_Table.Date_Time), Day(General_Counters_Table.Date_Time), Hour(General_Counters_Table.Date_Time)", Connection)
da1.Fill(ds1, "Throughput")
Connection.Close()
'Defines Chart and Chart Area
Dim chart1 = New Chart()
Dim chartarea1 As ChartArea = New ChartArea()
TabPage2.Controls.Add(chart1)
chartarea1.Name = "ChartArea1"
chart1.ChartAreas.Add(chartarea1)
Chart1.Location = New System.Drawing.Point(10, 10)
chart1.Name = "Chart1"
Chart1.Size = New System.Drawing.Size(800, 400)
chart1.TabIndex = 0
chart1.Text = "Chart1"
chartarea1.AxisX.LabelStyle.Angle = -60
chartarea1.AxisX.Interval = 1
chartarea1.AxisY.MajorGrid.Interval = 5
chartarea1.BackColor = Color.Azure
chartarea1.ShadowColor = Color.Red
chartarea1.Area3DStyle.Enable3D = True
chartarea1.AxisX.MajorGrid.Enabled = False
chartarea1.AxisX.LabelStyle.Font = New System.Drawing.Font("Times New Roman", 11.0F, System.Drawing.FontStyle.Italic)
'Legend
Dim legend1 As Legend = New Legend()
legend1.Name = "Legend1"
chart1.Legends.Add(legend1)
'Series
Dim series1 As Series = New Series()
series1.ChartType = SeriesChartType.StackedColumn
series1.ChartArea = "ChartArea1"
series1.Legend = "Legend1"
series1.Name = "Throughput"
chart1.Series.Add(series1)
chart1.Series("Throughput").XValueMember = "DateConverted"
chart1.Series("Throughput").YValueMembers = "sumofulboardcyclecount"
chart1.Series("Throughput").IsValueShownAsLabel = True 'shows label on datapoint
chart1.DataSource = ds1.Tables("Throughput")
chart1.Update()
chart1.DataBind()
End Sub
I had the same problem, a resolution is presented for "This Question"
Try clearing your data points using:
Chart.Series.Points.Clear()
and then adding them again.
I have the following code which lets me append a gridview and detailview as PDF file
But what I hope to achieve is not to download it but to attach it as email to send to the designated user. Is there any way I can modify the code so that I can send it as email and instead of download.
Dim strQuery As String = "SELECT * FROM [PointOrder] WHERE PointOrderId =" & Session("PointOrder")
Dim cmd As New SqlCommand(strQuery)
Dim dt As DataTable = GetData(cmd)
Dim DetailsView1 As New DetailsView()
DetailsView1.AllowPaging = False
DetailsView1.DataSource = dt
DetailsView1.DataBind()
Dim strQuery2 As String = "SELECT PointsOrderDetail.RedeemId, Redeem.RedeemName, Redeem.RedeemPoints, PointsOrderDetail.RedeemOrderQuantity, Redeem.RedeemPoints * PointsOrderDetail.RedeemOrderQuantity AS Total_Points FROM PointsOrderDetail INNER JOIN Redeem ON PointsOrderDetail.RedeemId = Redeem.RedeemId WHERE PointsOrderDetail.PointOrderId = " & Session("PointOrder")
Dim cmd2 As New SqlCommand(strQuery2)
Dim dt2 As DataTable = GetData(cmd2)
Dim GridView1 As New GridView()
GridView1.AllowPaging = False
GridView1.DataSource = dt2
GridView1.DataBind()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=" & Session("ID") & "-" & Session("PointOrder") & "-RedeemConfirm.pdf")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
DetailsView1.RenderControl(hw)
GridView1.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F)
Dim htmlparser As New HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response.End()
Private Function GetData(ByVal cmd As SqlCommand) As DataTable
Dim dt As New DataTable()
Dim strConnString As [String] = System.Configuration.ConfigurationManager.ConnectionStrings("LegacySGConnectionString").ConnectionString()
Dim con As New SqlConnection(strConnString)
Dim sda As New SqlDataAdapter()
cmd.CommandType = CommandType.Text
cmd.Connection = con
Try
con.Open()
sda.SelectCommand = cmd
sda.Fill(dt)
Return dt
Catch ex As Exception
Throw ex
Finally
con.Close()
sda.Dispose()
con.Dispose()
End Try
End Function
I have a date range for a report from a selector. How can I print that range on the report header? I am inside a Crystal Report - not from code. I have a select expert using a IsBetween on a date field. The form prints everything fine. I just want to display the date range. I have tried the OnFirstRecord and OnLastRecord and WhilePrintingRecord to populate a string within a function - it just shows up as blank in the report.
// {#range}
// note case of format string
ToText(Minimum({?date_range}),"MM/dd/yyyy") + " - " + ToText(Maximum({?date_range}),"MM/dd/yyyy")
Add one or two Parameter in crystal report as per your requirement and then assign your date range to that parameters.
ParameterFields paramFields = new ParameterFields();
// ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
ParameterField paramField = new ParameterField();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "#Date1";
paramDiscreteValue.Value = TextBox1.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField = new ParameterField(); // <-- This line is added
paramDiscreteValue = new ParameterDiscreteValue(); // <-- This line is added
paramField.Name = "#Date2";
paramDiscreteValue.Value = TextBox2.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
I found the NthSmallest and NthLargest functions - works perfectly now!
I have my codes as bellow and it shows me empty page after compiling:
ReportViewerControl = new ReportViewer();
ShowZoomControl="false"
ReportViewerControl.ServerReport.ReportServerUrl = new Uri(ReportServerUri);
ReportViewerControl.ServerReport.ReportPath = Model.Report.ReportPath;
ReportViewerControl.Visible = true;
ReportViewerControl.ShowReportBody = true;
ReportViewerControl.ShowParameterPrompts = false;
ReportViewerControl.ProcessingMode = ProcessingMode.Remote;
ReportViewerControl.ShowZoomControl = false;
ReportViewerControl.ShowBackButton = false;
ReportViewerControl.InteractivityPostBackMode = InteractivityPostBackMode.AlwaysAsynchronous;
ReportViewerControl.Height = 780;
ReportViewerControl.Width = 800;
IList<ReportParameter> FishSpeciesParameters = new List<ReportParameter>();
ReportParameter SPStatus = new ReportParameter();
SPStatus.Name = "SPStatus";
if (Model.Report.ID == 8)
SPStatus.Values.Add("T,E,C");
ReportParameter FishCode = new ReportParameter();
FishCode.Name = "FishCode";
FishCode.Values.Add("11");
FishSpeciesParameters.Add(SPStatus);
FishSpeciesParameters.Add(FishCode);
ReportViewerControl.ServerReport.SetParameters(FishSpeciesParameters);
ReportViewerControl.ServerReport.Refresh();
Any Ideas to view SSRS Report into ReportViewer on Fly?
maily you just need to set ServerReport.ReportServerUrl to something like this:
"http://localhost:8080/ReportServer"
and the ReportPath to
reportFolder + "/" + reportName;
Last time I used two parameter to query & show report. It worked well. Right now I am trying to use same code with another extra parameter but its not working. I am confused. Let me show you my code.
Code which worked well:
Parameter fields : bdate and edate
Crystal report formula : {Bal_sheet.bsdate} >= {?bdate} and {Bal_sheet.bsdate} <= {?edate}
Code to show report :
Private Sub butsbalsrep_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butsbalsrep.Click
Dim cryRpt As New ReportDocument
cryRpt.Load(Application.StartupPath & "\CrystalReport3.rpt")
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterFieldDefinitions1 As ParameterFieldDefinitions
Dim crParameterFieldDefinition1 As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterValues1 As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
Dim crParameterDiscreteValue1 As New ParameterDiscreteValue
crParameterDiscreteValue.Value = cmbbdate.Text
crParameterDiscreteValue1.Value = cmbedate.Text
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("bdate")
crParameterFieldDefinitions1 = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition1 = crParameterFieldDefinitions.Item("edate")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues1 = crParameterFieldDefinition1.CurrentValues
crParameterValues.Clear()
crParameterValues1.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterValues1.Add(crParameterDiscreteValue1)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
crParameterFieldDefinition1.ApplyCurrentValues(crParameterValues1)
crysrepbalsht.ReportSource = cryRpt
crysrepbalsht.Refresh()
End Sub
Code which is not working:
Parameter fields : idnmb and acyer and etyp
Crystal report formula : {res_info.stu_id} = {?idnmb} and {res_info.yr} = {?acyer} and {res_info.etype} = {?etyp}
Code to show report :
Private Sub butsrrepsr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butsrrepsr.Click
Dim cryRpt As New ReportDocument
cryRpt.Load(Application.StartupPath & "\CrystalReport3.rpt")
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldDefinition As ParameterFieldDefinition
Dim crParameterFieldDefinitions1 As ParameterFieldDefinitions
Dim crParameterFieldDefinition1 As ParameterFieldDefinition
Dim crParameterFieldDefinitions2 As ParameterFieldDefinitions
Dim crParameterFieldDefinition2 As ParameterFieldDefinition
Dim crParameterValues As New ParameterValues
Dim crParameterValues1 As New ParameterValues
Dim crParameterValues2 As New ParameterValues
Dim crParameterDiscreteValue As New ParameterDiscreteValue
Dim crParameterDiscreteValue1 As New ParameterDiscreteValue
Dim crParameterDiscreteValue2 As New ParameterDiscreteValue
crParameterDiscreteValue.Value = cmbsrrepidn.Text
crParameterDiscreteValue1.Value = cmbsrrepay.Text
crParameterDiscreteValue2.Value = cmbsrrepet.Text
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition = crParameterFieldDefinitions.Item("idnmb")
crParameterFieldDefinitions1 = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition1 = crParameterFieldDefinitions.Item("acyer")
crParameterFieldDefinitions2 = cryRpt.DataDefinition.ParameterFields
crParameterFieldDefinition2 = crParameterFieldDefinitions.Item("etyp")
crParameterValues = crParameterFieldDefinition.CurrentValues
crParameterValues1 = crParameterFieldDefinition1.CurrentValues
crParameterValues2 = crParameterFieldDefinition2.CurrentValues
crParameterValues.Clear()
crParameterValues1.Clear()
crParameterValues2.Clear()
crParameterValues.Add(crParameterDiscreteValue)
crParameterValues1.Add(crParameterDiscreteValue1)
crParameterValues2.Add(crParameterDiscreteValue2)
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
crParameterFieldDefinition1.ApplyCurrentValues(crParameterValues1)
crParameterFieldDefinition2.ApplyCurrentValues(crParameterValues2)
CrystalReportViewer3.ReportSource = cryRpt
CrystalReportViewer3.Refresh()
End Sub
I am confused why its not working! When I click on show report button it shows nothing(I dont get error message and getting no records back.). I have written {res_info.stu_id} = {?idnmb} and {res_info.yr} = {?acyer} and {res_info.etype} = {?etyp} it there in formula workshop-record selection formula editor. Please help me to get rid of this problem!
Yes you are right LittleBobbyTables. When I click on show report button it shows nothing(I dont get error message but getting no records back.) Yes I have written {res_info.stu_id} = {?idnmb} and {res_info.yr} = {?acyer} and {res_info.etype} = {?etyp} it there in formula workshop-record selection formula editor