รบกวนช่วยดูโค้ด VB 2008 ให้ทีครับเป็นโค้ดเกี่ยวกับรายงานประจำเดือนครับขอบคุณครับ
คือเมื่อผมติ๊กเลือกดูรายงานประจำเดือนทีไรมันจะขึ้น Error ตรงบันทัดนี้ตลอดเลยอะครับ (บันทัดที่ผมทำสีไว้ให้) แต่รายงานประจำวันกับรายงานประจำปีดูได้ปกติครับ วานผู้รู้ช่วยตอบทีนะครับ ขอบคุณมากครับ
Public Class FrmSelectReport
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdMonth.CheckedChanged
End Sub
Private Sub FrmSelectReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dtStart.Value = Date.Now
dtEnd.Value = Date.Now
dMonthStart.SelectedIndex = Date.Now.Month - 1
dMonthEnd.SelectedIndex = Date.Now.Month - 1
dYearStart.Text = Date.Now.Year
dYearEnd.Text = Date.Now.Year
dStartYear.Text = Date.Now.Year
dEndYear.Text = Date.Now.Year
End Sub
Private Sub btnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnView.Click
CallReport("V_Sale", "SaleAll.rpt", "SaleDay.rpt", "SaleMonth.rpt", "SaleYear.rpt")
'Show Report
Dim frm As FrmReport = FrmReport
frm.Show()
End Sub
Private Sub chkAll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkAll.CheckedChanged
rdDay.Checked = False
rdMonth.Checked = False
rdYear.Checked = False
If chkAll.Checked = True Then
GroupTime.Enabled = False
Else
GroupTime.Enabled = True
rdDay.Checked = True
End If
End Sub
Private Sub CallReport(ByVal tblname As String, ByVal reportAll As String, ByVal reportDay As String, ByVal reportMonth As String, ByVal reportYear As String)
Dim sql As String = "select * from " & tblname & ""
If rdDay.Checked = True Then
GlobalVar.StartDate = dtStart.Value
GlobalVar.EndDate = dtEnd.Value
GlobalVar.Reportname = reportDay
Dim ds As String = " '" & dtStart.Value.Year & "/" & dtStart.Value.Day & "/" & dtStart.Value.Month & "' "
Dim de As String = " '" & dtEnd.Value.Year & "/" & dtEnd.Value.Day & "/" & dtEnd.Value.Month & "' "
sql = sql & " where DateTimeS between convert(datetime," & ds & ",103)"
sql = sql & " and convert(datetime," & de & ",103)"
sql = sql & " order by DateTimeS asc"
ElseIf rdMonth.Checked = True Then
'By Mounth
GlobalVar.StartDate = New Date(Integer.Parse(dYearStart.Text), Integer.Parse(dMonthStart.Text), 1)
GlobalVar.EndDate = New Date(Integer.Parse(dYearEnd.Text), Integer.Parse(dMonthEnd.Text), 31)
sql = sql & " where (month(DateTimeS) between " & dMonthStart.Text & " and " & dMonthEnd.Text & " )"
sql = sql & " and (year(DateTimeS) between " & dYearStart.Text & " and " & dYearEnd.Text & ")"
sql = sql & " order by DateTimeS asc"
GlobalVar.Reportname = reportMonth
ElseIf rdYear.Checked = True Then
'By Year
GlobalVar.StartDate = New Date(Integer.Parse(dStartYear.Text), 1, 1)
GlobalVar.EndDate = New Date(Integer.Parse(dEndYear.Text), 12, 31)
sql = sql & " where (month(DateTimeS) between " & dMonthStart.Text & " and " & dMonthEnd.Text & " )"
sql = sql & " and (year(DateTimeS) between " & dStartYear.Text & " and " & dEndYear.Text & ")"
sql = sql & " order by DateTimeS asc"
GlobalVar.Reportname = reportYear
Else
GlobalVar.StartDate = New Date(1900, 1, 1)
GlobalVar.EndDate = New Date(3000, 12, 31)
GlobalVar.Reportname = reportAll
End If
GlobalVar.DtReport = Database.SqlGetDataQuery(sql)
'MessageBox.Show(GlobalVar.Reportname)
'MessageBox.Show(GlobalVar.StartDate.ToString())
'MessageBox.Show(GlobalVar.EndDate.ToString())
End Sub
End ClassTag : .NET, Crystal Report, Win (Windows App)
Date :
2011-02-21 14:50:55
By :
kitsana
View :
1347
Reply :
2
GlobalVar.EndDate = New Date(Integer.Parse(dYearEnd.Text), Integer.Parse(dMonthEnd.Text), 31 )
น่าจะผิดที่ตัวเลขที่ผมใส่สีไว้นะครับ (เอาคืนเล่นใส่สีเหลืองอ่านแทบไม่ออก) เพราะบางเดือนมันไม่ได้มี 31 วันอ่ะครับ
Date :
2011-02-21 15:49:47
By :
kaimuk
Code (VB.NET)
GlobalVar.EndDate = New Date(Integer.Parse(dYearEnd.Text), Integer.Parse(dMonthEnd.Text), Date.DaysInMonth(Today.Year.ToString, Today.Month) )
.....
Date :
2011-03-13 04:46:59
By :
duzija1
Load balance : Server 01