You are on page 1of 6

Protected Sub btnpre_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnpre.

Click

Try Dim Dim Dim Dim ParamFields As ParameterFields SY As New ParameterField S As New ParameterField M As New ParameterField

Dim p_sy_value As New ParameterDiscreteValue Dim P_S_value As New ParameterDiscreteValue Dim P_M_value As New ParameterDiscreteValue Dim Sec As String = Me.DropDownList1.SelectedValue Dim y As Integer = Me.DropDownList2.SelectedValue Dim Mon As Integer = Me.DrpMonth.SelectedValue CrystalReportViewer1.Visible = True Dim ConnInfo As New ConnectionInfo With ConnInfo .ServerName = "192.168.20.154" .DatabaseName = "hscdb" .UserID = "hp" .Password = "hp2010" End With Me.CrystalReportViewer1.ParameterFieldInfo.Clear() Me.CrystalReportViewer1.ParameterFieldInfo.Clear() If Me.DropDownList1.SelectedValue = "All" Then Me.CrystalReportViewer1.ReportSource = Server.MapPath("../reports/CR_sumTicket1.rpt") ParamFields = Me.CrystalReportViewer1.ParameterFieldInfo SY.Name = "pYear" p_sy_value.Value = Me.DropDownList2.SelectedValue SY.CurrentValues.Add(p_sy_value) ParamFields.Add(SY) M.Name = "pMonth" P_M_value.Value = Me.DrpMonth.SelectedValue M.CurrentValues.Add(P_M_value) ParamFields.Add(M) Else Me.CrystalReportViewer1.ReportSource = Server.MapPath("../reports/CR_sumTicket1_Sec.rpt") ParamFields = Me.CrystalReportViewer1.ParameterFieldInfo SY.Name = "pYear" p_sy_value.Value = Me.DropDownList2.SelectedValue SY.CurrentValues.Add(p_sy_value) ParamFields.Add(SY) M.Name = "pMonth" P_M_value.Value = Me.DrpMonth.SelectedValue M.CurrentValues.Add(P_M_value) ParamFields.Add(M)

S.Name = "Sec" P_S_value.Value = Me.DropDownList1.SelectedValue S.CurrentValues.Add(P_S_value) ParamFields.Add(S) End If For Each cnInfo As TableLogOnInfo In Me.CrystalReportViewer1.LogOnInfo cnInfo.ConnectionInfo = ConnInfo Next Me.CrystalReportViewer1.RefreshReport() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "Errors") End Try End Sub

Protected Sub btndown_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btndown.Click Try Dim repDoc As New ReportDocument Dim Yr, Mth As New ParameterField Dim Sec As New ParameterField If Me.DropDownList1.SelectedValue = "All" Then Yr.Name = "pYear" Mth.Name = "pMonth" repDoc.Load(AppDomain.CurrentDomain.BaseDirectory & "\reports\CR_sumTicket1.rpt") Dim ParameterFields = Me.CrystalReportViewer1.ParameterFieldInfo Dim p_yr_value As New ParameterDiscreteValue Dim p_mth_value As New ParameterDiscreteValue p_yr_value.Value = Me.DropDownList2.SelectedValue p_mth_value.Value = Me.DrpMonth.SelectedValue Yr.CurrentValues.Add(p_yr_value) Mth.CurrentValues.Add(p_mth_value) repDoc.ParameterFields(0).CurrentValues.Add(p_yr_value) repDoc.ParameterFields(1).CurrentValues.Add(p_mth_value) Else Yr.Name = "pYear" Mth.Name = "pMonth" Sec.Name = "Sec" repDoc.Load(AppDomain.CurrentDomain.BaseDirectory & "\reports\CR_sumTicket1_Sec.rpt") Dim ParameterFields = Me.CrystalReportViewer1.ParameterFieldInfo Dim p_yr_value, p_mth_value, p_sec_value As New ParameterDiscreteValue

p_yr_value.Value = Me.DropDownList2.SelectedValue p_mth_value.Value = Me.DrpMonth.SelectedValue p_sec_value.Value = Me.DropDownList1.SelectedValue Yr.CurrentValues.Add(p_yr_value) Mth.CurrentValues.Add(p_mth_value) Sec.CurrentValues.Add(p_sec_value) repDoc.ParameterFields(0).CurrentValues.Add(p_yr_value) repDoc.ParameterFields(1).CurrentValues.Add(p_mth_value) repDoc.ParameterFields(2).CurrentValues.Add(p_sec_value) End If repDoc.SetDatabaseLogon("hp", "hp2010", "192.168.20.154", "hscdb") Response.Buffer = False Response.ClearContent() Response.ClearHeaders() If DropDownList3.SelectedValue = 0 Then repDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "Report") ElseIf DropDownList3.SelectedValue = 1 Then repDoc.ExportToHttpResponse(ExportFormatType.Excel, Response, True, "Report") ElseIf DropDownList3.SelectedValue = 2 Then repDoc.ExportToHttpResponse(ExportFormatType.WordForWindows, Response, True, "Report") End If Catch ex As Exception Console.WriteLine(ex.Message) End Try End Sub