我在Visual Studio 2012上使用VB.NET构建了一个桌面应用程序。我使用Crystal Report来显示报告。但是当用户生成报告并尝试导出到另一个文件(excel等)时,它总是导致我的应用程序"没有响应"并关闭申请。
这是内存问题还是我必须安装别的东西?
我在reportviewer控制器中加载报告的代码
Thread.CurrentThread.CurrentCulture = New CultureInfo("id-ID")
Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol = "Rp "
Thread.CurrentThread.CurrentCulture.DateTimeFormat.DateSeparator = "-"
Thread.CurrentThread.CurrentCulture.DateTimeFormat.FullDateTimePattern = "dd/MM/yyyy hh:mm:ss"
Dim PeriodeAwal As DateTime
Dim PeriodeAkhir As DateTime
If lblTodayOrMonth.Text.ToLower = "custom" Then
PeriodeAwal = New DateTime(frmJenisLaporan.dtpAwal.Value.Year, frmJenisLaporan.dtpAwal.Value.Month, frmJenisLaporan.dtpAwal.Value.Day)
PeriodeAkhir = New DateTime(frmJenisLaporan.dtpAkhir.Value.Year, frmJenisLaporan.dtpAkhir.Value.Month, frmJenisLaporan.dtpAkhir.Value.Day)
End If
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
Dim ds As DataSet = New DataSet
Dim t As DataTable = ds.Tables.Add("Transaksi")
Dim r As DataRow
t.Columns.Add("IDHORDER", Type.GetType("System.Int32"))
t.Columns.Add("TANGGAL", Type.GetType("System.DateTime"))
t.Columns.Add("NOINVOICE", Type.GetType("System.String"))
t.Columns.Add("MEJA", Type.GetType("System.String"))
t.Columns.Add("Total", Type.GetType("System.Decimal"))
t.Columns.Add("Diskon", Type.GetType("System.Decimal"))
t.Columns.Add("TotalBersih", Type.GetType("System.Decimal"))
t.Columns.Add("PEMBAYARAN", Type.GetType("System.Decimal"))
t.Columns.Add("KEMBALIAN", Type.GetType("System.Decimal"))
t.Columns.Add("JENISORDER", Type.GetType("System.String"))
t.Columns.Add("CREATEDBY", Type.GetType("System.String"))
t.Columns.Add("PAX", Type.GetType("System.String"))
t.Columns.Add("NAMA", Type.GetType("System.String"))
t.Columns.Add("IDDORDER", Type.GetType("System.Int32"))
t.Columns.Add("IDMENU", Type.GetType("System.Int32"))
t.Columns.Add("QTY", Type.GetType("System.Int32"))
t.Columns.Add("HARGASAATORDER", Type.GetType("System.Decimal"))
t.Columns.Add("SUBTOTAL", Type.GetType("System.Decimal"))
t.Columns.Add("NAMAMENU", Type.GetType("System.String"))
t.Columns.Add("NAMARESTORAN", Type.GetType("System.String"))
t.Columns.Add("REVISIORNOT", Type.GetType("System.String"))
t.Columns.Add("SERVICECHARGE", Type.GetType("System.Decimal"))
t.Columns.Add("LOGOLOCATION", Type.GetType("System.String"))
t.Columns.Add("PAJAK", Type.GetType("System.Decimal"))
t.Columns.Add("ALASANDISKON", Type.GetType("System.String"))
t.Columns.Add("DISKONBY", Type.GetType("System.String"))
t.Columns.Add("CUSTOMERNAME", Type.GetType("System.String"))
t.Columns.Add("GETPOIN", Type.GetType("System.Int32"))
t.Columns.Add("CUSTOMERTOTALPOIN", Type.GetType("System.Int32"))
t.Columns.Add("DISKONEXTRA", Type.GetType("System.Decimal"))
Dim counterJumlahPorsi As Integer = 0
Dim TotalNominal As Decimal = 0
'ambil data transaksi
'cmdtxt = "SELECT H.IDHORDER, H.TANGGAL, H.NOINVOICE, H.MEJA, H.TOTAL, H.DISKON, H.TOTALBERSIH, H.PEMBAYARAN, H.KEMBALIAN, H.JENISORDER, H.CREATEDBY, H.PAX, H.NAMA, D.IDDORDER, D.IDMENU, D.QTY, D.HARGASAATORDER, D.SUBTOTAL, M.NAMAMENU, H.SERVICECHARGE,H.PAJAK,H.ALASANDISKON,H.DISKONBY FROM HORDER AS H, DORDER AS D, MENU AS M WHERE (((M.IDMENU)=[D].[IDMENU]) AND ((D.IDHORDER)=[H].[IDHORDER])) AND COMPLETED=True AND KEEPRECORD=True"
cmdtxt = "SELECT H.IDHORDER, H.TANGGAL, H.NOINVOICE, H.MEJA, H.TOTAL, H.DISKON, H.TOTALBERSIH, H.PEMBAYARAN, H.KEMBALIAN, H.JENISORDER, H.CREATEDBY, H.PAX, H.NAMA, D.IDDORDER, D.IDMENU, D.QTY, D.HARGASAATORDER, D.SUBTOTAL, M.NAMAMENU, H.SERVICECHARGE,H.PAJAK,H.ALASANDISKON,H.DISKONBY, H.GETPOIN, IIF(H.IDCUSTOMER=0,'Non Member',C.NAMACUSTOMER) AS NAMACUSTOMER,H.DISKONEXTRA FROM ((HORDER AS H INNER JOIN DORDER AS D ON D.IDHORDER=H.IDHORDER) INNER JOIN MENU AS M ON M.IDMENU=D.IDMENU) LEFT JOIN CUSTOMER AS C ON C.IDCUSTOMER=H.IDCUSTOMER WHERE H.COMPLETED=TRUE AND H.KEEPRECORD=TRUE"
If lblTodayOrMonth.Text.ToLower = "today" Then
cmdtxt &= " AND DAY(H.TANGGAL)=" & Date.Now.Day & " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "month" Then
cmdtxt &= " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "custom" Then
'cmdtxt &= " AND DATEVALUE('" & PeriodeAwal & "')<=H.TANGGAL AND H.TANGGAL<=DATEVALUE('" & PeriodeAkhir.AddDays(1) & "')"
cmdtxt &= " AND DATEVALUE('" & PeriodeAwal.Month & "-" & PeriodeAwal.Day & "-" & PeriodeAwal.Year & "')<=H.TANGGAL AND H.TANGGAL<=DATEVALUE('" & PeriodeAkhir.AddDays(1).Month & "-" & PeriodeAkhir.AddDays(1).Day & "-" & PeriodeAkhir.AddDays(1).Year & "')"
End If
cmd = New OleDbCommand(cmdtxt, conn)
reader = cmd.ExecuteReader
If reader.HasRows Then
While reader.Read
r = t.NewRow()
r("IDHORDER") = reader.GetValue(0)
r("TANGGAL") = reader.GetValue(1)
r("NOINVOICE") = reader.GetValue(2)
Dim totalMeja() As String = reader.GetValue(3).ToString.Split(",")
r("MEJA") = totalMeja(0)
r("Total") = reader.GetValue(4)
r("Diskon") = reader.GetValue(5)
r("TotalBersih") = reader.GetValue(6)
r("PEMBAYARAN") = reader.GetValue(7)
r("KEMBALIAN") = reader.GetValue(8)
r("JENISORDER") = reader.GetValue(9)
r("CREATEDBY") = reader.GetValue(10)
r("PAX") = reader.GetValue(11)
r("NAMA") = reader.GetValue(12)
r("IDDORDER") = reader.GetValue(13)
r("IDMENU") = reader.GetValue(14)
r("QTY") = reader.GetValue(15)
r("HARGASAATORDER") = reader.GetValue(16)
r("SUBTOTAL") = reader.GetValue(17)
r("NAMAMENU") = reader.GetValue(18)
r("NAMARESTORAN") = NamaRestoran
r("SERVICECHARGE") = reader.GetValue(19)
r("LOGOLOCATION") = LogoRestoran
r("PAJAK") = reader.GetValue(20)
r("ALASANDISKON") = reader.GetValue(21)
r("DISKONBY") = reader.GetValue(22)
r("GETPOIN") = reader.GetValue(23)
r("CUSTOMERNAME") = reader.GetValue(24)
r("CUSTOMERTOTALPOIN") = 0
r("DISKONEXTRA") = reader.GetValue(25)
t.Rows.Add(r)
counterJumlahPorsi += reader.GetValue(15)
End While
End If
reader.Close()
'hitung total Nominal Penjualan
cmdtxt = "SELECT H.TOTALBERSIH FROM HORDER AS H WHERE COMPLETED=True AND KEEPRECORD=True"
If lblTodayOrMonth.Text.ToLower = "today" Then
cmdtxt &= " AND DAY(H.TANGGAL)=" & Date.Now.Day & " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "month" Then
cmdtxt &= " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "custom" Then
cmdtxt &= " AND DATEVALUE('" & PeriodeAwal.Month & "-" & PeriodeAwal.Day & "-" & PeriodeAwal.Year & "')<=H.TANGGAL AND H.TANGGAL<=DATEVALUE('" & PeriodeAkhir.AddDays(1).Month & "-" & PeriodeAkhir.AddDays(1).Day & "-" & PeriodeAkhir.AddDays(1).Year & "')"
End If
cmd = New OleDbCommand(cmdtxt, conn)
reader = cmd.ExecuteReader
While reader.Read
TotalNominal += reader.GetValue(0)
End While
reader.Close()
Dim trptTotal As DataTable = ds.Tables.Add("TotalMenuSold")
Dim rrptTotal As DataRow
trptTotal.Columns.Add("IDHORDER", Type.GetType("System.Int32"))
trptTotal.Columns.Add("IDMENU", Type.GetType("System.Int32"))
trptTotal.Columns.Add("NAMAMENU", Type.GetType("System.String"))
trptTotal.Columns.Add("HARGAJUAL", Type.GetType("System.Decimal"))
trptTotal.Columns.Add("TANGGAL", Type.GetType("System.String"))
trptTotal.Columns.Add("QTY", Type.GetType("System.Int32"))
trptTotal.Columns.Add("SUBTOTAL", Type.GetType("System.Decimal"))
trptTotal.Columns.Add("TOTALDISKONMEMBER", Type.GetType("System.Decimal"))
trptTotal.Columns.Add("TOTALDISKONEXTRA", Type.GetType("System.Decimal"))
trptTotal.Columns.Add("TOTALPAJAK", Type.GetType("System.Decimal"))
'ambil total diskon
Dim varTotalDiskonMember As Decimal = 0
Dim vartotalDiskonExtra As Decimal = 0
Dim vartotalPajak As Decimal = 0
cmdtxt = "SELECT SUM(DISKON) AS 'TOTALDISKONMEMBER',SUM(DISKONEXTRA) AS 'TOTALDISKONEXTRA',SUM(PAJAK) AS 'TOTALPAJAK' FROM HORDER H WHERE h.COMPLETED=True AND h.KEEPRECORD=True "
If lblTodayOrMonth.Text.ToLower = "today" Then
cmdtxt &= " AND DAY(H.TANGGAL)=" & Date.Now.Day & " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "month" Then
cmdtxt &= " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "custom" Then
cmdtxt &= " AND DATEVALUE('" & PeriodeAwal.Month & "-" & PeriodeAwal.Day & "-" & PeriodeAwal.Year & "')<=H.TANGGAL AND H.TANGGAL<=DATEVALUE('" & PeriodeAkhir.AddDays(1).Month & "-" & PeriodeAkhir.AddDays(1).Day & "-" & PeriodeAkhir.AddDays(1).Year & "')"
End If
cmd = New OleDbCommand(cmdtxt, conn)
reader = cmd.ExecuteReader
If reader.HasRows Then
reader.Read()
varTotalDiskonMember = reader.GetValue(0)
vartotalDiskonExtra = reader.GetValue(1)
vartotalPajak = reader.GetValue(2)
End If
reader.Close()
'ambil total menu terjual
cmdtxt = "SELECT m.IDMENU, m.NAMAMENU, m.HARGAJUAL, SUM(d.QTY) as 'SOLD' FROM MENU M, HORDER H, DORDER D WHERE h.COMPLETED=True AND h.KEEPRECORD=True AND M.IDMENU=D.IDMENU AND H.IDHORDER=D.IDHORDER "
If lblTodayOrMonth.Text.ToLower = "today" Then
cmdtxt &= " AND DAY(H.TANGGAL)=" & Date.Now.Day & " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "month" Then
cmdtxt &= " AND MONTH(H.TANGGAL)=" & Date.Now.Month & " AND YEAR(H.TANGGAL)=" & Date.Now.Year
ElseIf lblTodayOrMonth.Text.ToLower = "custom" Then
cmdtxt &= " AND DATEVALUE('" & PeriodeAwal.Month & "-" & PeriodeAwal.Day & "-" & PeriodeAwal.Year & "')<=H.TANGGAL AND H.TANGGAL<=DATEVALUE('" & PeriodeAkhir.AddDays(1).Month & "-" & PeriodeAkhir.AddDays(1).Day & "-" & PeriodeAkhir.AddDays(1).Year & "')"
End If
cmdtxt &= " GROUP BY M.IDMENU,M.NAMAMENU, M.HARGAJUAL"
cmd = New OleDbCommand(cmdtxt, conn)
reader = cmd.ExecuteReader
If reader.HasRows Then
While reader.Read
rrptTotal = trptTotal.NewRow()
rrptTotal("IDHORDER") = -1
rrptTotal("IDMENU") = reader.GetValue(0)
rrptTotal("NAMAMENU") = reader.GetValue(1)
rrptTotal("HARGAJUAL") = reader.GetValue(2)
rrptTotal("QTY") = reader.GetValue(3)
rrptTotal("SUBTOTAL") = reader.GetValue(2) * reader.GetValue(3)
rrptTotal("TOTALDISKONMEMBER") = varTotalDiskonMember
rrptTotal("TOTALDISKONEXTRA") = vartotalDiskonExtra
rrptTotal("TOTALPAJAK") = vartotalPajak
trptTotal.Rows.Add(rrptTotal)
End While
End If
reader.Close()
Dim rptTotal As New crTotalMenuSold
rptTotal.Subreports(0).SetDataSource(ds.Tables(0)) ' define table data for sub report
rptTotal.SetDataSource(ds.Tables(1))
'Isi total porsi terjual per periode laporan
Dim crParamDefinitions As ParameterFieldDefinitions
Dim paramDefinition As ParameterFieldDefinition
Dim crParamValues As New ParameterValues
Dim paramFieldValue As New ParameterDiscreteValue
paramFieldValue.Value = counterJumlahPorsi
crParamDefinitions = rptTotal.Subreports(0).DataDefinition.ParameterFields
paramDefinition = crParamDefinitions.Item("TotalPorsi")
crParamValues = paramDefinition.CurrentValues
crParamValues.Clear()
crParamValues.Add(paramFieldValue)
paramDefinition.ApplyCurrentValues(crParamValues)
paramDefinition = crParamDefinitions.Item("PeriodeLaporan")
crParamValues = New ParameterValues
crParamValues = paramDefinition.CurrentValues
crParamValues.Clear()
paramFieldValue = New ParameterDiscreteValue
If lblTodayOrMonth.Text.ToLower = "today" Then
paramFieldValue.Value = "HARI INI"
ElseIf lblTodayOrMonth.Text.ToLower = "month" Then
paramFieldValue.Value = "BULAN INI"
ElseIf lblTodayOrMonth.Text.ToLower = "custom" Then
paramFieldValue.Value = PeriodeAwal.ToString("dd MMM yyyy") & " - " & PeriodeAkhir.ToString("dd MMM yyyy")
End If
crParamValues.Add(paramFieldValue)
paramDefinition.ApplyCurrentValues(crParamValues)
paramDefinition = crParamDefinitions.Item("TotalDalamRupiah")
crParamValues = New ParameterValues
crParamValues = paramDefinition.CurrentValues
crParamValues.Clear()
paramFieldValue = New ParameterDiscreteValue
paramFieldValue.Value = TotalNominal
crParamValues.Add(paramFieldValue)
paramDefinition.ApplyCurrentValues(crParamValues)
'===========================================================
'Isi total porsi terjual per periode laporan
Dim crParamDefinitionsrptTotal As ParameterFieldDefinitions
Dim paramDefinitionrptTotal As ParameterFieldDefinition
Dim crParamValuesrptTotal As ParameterValues
Dim paramFieldValuerptTotal As ParameterDiscreteValue
crParamDefinitionsrptTotal = rptTotal.DataDefinition.ParameterFields
paramDefinitionrptTotal = crParamDefinitionsrptTotal.Item("PeriodeLaporan")
crParamValuesrptTotal = New ParameterValues
crParamValuesrptTotal = paramDefinitionrptTotal.CurrentValues
crParamValuesrptTotal.Clear()
paramFieldValuerptTotal = New ParameterDiscreteValue
If lblTodayOrMonth.Text.ToLower = "today" Then
paramFieldValuerptTotal.Value = "HARI INI"
ElseIf lblTodayOrMonth.Text.ToLower = "month" Then
paramFieldValuerptTotal.Value = "BULAN INI"
ElseIf lblTodayOrMonth.Text.ToLower = "custom" Then
paramFieldValuerptTotal.Value = PeriodeAwal.ToString("dd MMM yyyy") & " - " & PeriodeAkhir.ToString("dd MMM yyyy")
End If
crParamValuesrptTotal.Add(paramFieldValuerptTotal)
paramDefinitionrptTotal.ApplyCurrentValues(crParamValuesrptTotal)
'===========================================================
rptViewer.ReportSource = rptTotal
rptViewer.Refresh()
If conn.State = ConnectionState.Open Then
conn.Close()
End If