ช่วยหน่อยค่ะ ต้องการวนลูปโดยใช้วันที่ค่ะ ช่วยหน่อยค่ะ เป็นการวนลูปโดยใช้ระยะเวลาค่ะ
ช่วยหน่อยค่ะ เป็นการวนลูปโดยใช้ระยะเวลาค่ะ ทำแล้วมันไม่วนให้ค่ะ มันเก็บแต่ค่าเดือนสุดท้าย คือ ซื้อของวันที่ 1/04/2553 ผ่อน 3 เดือน จะมีกำหนดผ่อนสิ้นเดือน จะเก็บทั้งหมด 3 เดือน แต่นี่มันเก็บเดือนสุดท้ายเดือนเดียว ช่วยดูโค้ดให้หน่อนค่ะ ว่าทำผิดตรงไหนถึงไม่วนลูปให้ค่ะ
Dim recordaffected As Integer
Dim sqlsale As String = ""
Dim sqlsale1 As String = ""
Dim sqladd As String = ""
Dim tmpmessage As String
Dim tmpproductinshop As Integer = 0
Dim i As Integer = 0
Dim paiddate As Date
Dim numlast As Date
Dim lastdatepaid As Date
paiddate = Date.Now
lastdatepaid = Date.Now
Dim myCNN As New SqlClient.SqlConnection("Data Source=NONGPEAR-65E3E3;Initial Catalog=mobile;Persist Security Info=True;User ID=sa;Password=1234")
myCNN.Open()
sqlsale = "insert into Creditsale(creid,productid,productname,cusid,"
sqlsale &= "creditcompanyid,saledate,paiddate,lastpaid,inforpaidlate,price,"
sqlsale &= "vat,cash,intpremonth,paidmonth,netprice)"
sqlsale &= "values('" & txtcreid.Text & "',"
sqlsale &= "'" & txtproductid.Text & "',"
sqlsale &= "'" & lblproductname.Text & "',"
sqlsale &= "'" & txtcustomerid.Text & "',"
sqlsale &= "'" & CStr(cbocreditcompany.SelectedValue) & "',"
sqlsale &= "'" & lblDate.Text & "',"
sqlsale &= "'" & CDate(DateTimePicker1.Value) & "',"
sqlsale &= "'" & CInt(txtlastpaid.Text) & "',"
sqlsale &= "'" & CSng(txtintforpaidlate.Text) & "',"
sqlsale &= "'" & CInt(lblprice.Text) & "',"
sqlsale &= "'" & CSng(txtvat.Text) & "',"
sqlsale &= "'" & CInt(txtcash.Text) & "',"
sqlsale &= "'" & CSng(txtintpermonth.Text) & "',"
sqlsale &= "'" & CInt(lblpaidpermonth.Text) & "',"
sqlsale &= CInt(lblnetprice.Text) & ")"
Else
sqlsale = "insert into Creditsale(creid,productid,productname,cusid,"
sqlsale &= "creditcompanyid,saledate,paiddate,lastpaid,inforpaidlate,price,"
sqlsale &= "vat,cash,intpremonth,paidmonth,netprice)"
sqlsale &= "values('" & txtcreid.Text & "',"
sqlsale &= "'" & CStr(grdcreditlist.Item(useselectrow, 1)) & "',"
sqlsale &= "'" & CStr(grdcreditlist.Item(useselectrow, 13)) & "',"
sqlsale &= "'" & txtcustomerid.Text & "',"
sqlsale &= "'" & CStr(grdcreditlist.Item(useselectrow, 4)) & "',"
sqlsale &= "'" & lblDate.Text & "',"
sqlsale &= "'" & DateTimePicker1.Value & "',"
sqlsale &= "'" & CInt(grdcreditlist.Item(useselectrow, 16)) & "',"
sqlsale &= "'" & CInt(grdcreditlist.Item(useselectrow, 11)) & "',"
sqlsale &= "'" & CInt(lblprice.Text) & "',"
sqlsale &= "'" & CSng(txtvat.Text) & "',"
sqlsale &= "'" & CInt(grdcreditlist.Item(useselectrow, 6)) & "',"
sqlsale &= "'" & CSng(txtintpermonth.Text) & "',"
sqlsale &= "'" & CInt(grdcreditlist.Item(useselectrow, 7)) & "',"
sqlsale &= CInt(grdcreditlist.Item(useselectrow, 3)) & ")" Else
sqlsale = "insert into Creditsale(creid,productid,productname,cusid,"
sqlsale &= "creditcompanyid,inforpaidlate,price,"
sqlsale &= "vat,cash,intpremonth,paidmonth,netprice,lastdatepaid,saledate,paiddate)"
sqlsale &= "values('" & txtcreid.Text & "',"
sqlsale &= "'" & CStr(grdcreditlist.Item(useselectrow, 1)) & "',"
sqlsale &= "'" & CStr(grdcreditlist.Item(useselectrow, 13)) & "',"
sqlsale &= "'" & txtcustomerid.Text & "',"
sqlsale &= "'" & CStr(grdcreditlist.Item(useselectrow, 4)) & "',"
sqlsale &= "'" & CInt(grdcreditlist.Item(useselectrow, 9)) & "',"
sqlsale &= "'" & CInt(lblprice.Text) & "',"
sqlsale &= "'" & CSng(txtvat.Text) & "',"
sqlsale &= "'" & CInt(grdcreditlist.Item(useselectrow, 6)) & "',"
sqlsale &= "'" & CSng(txtintpermonth.Text) & "',"
sqlsale &= "'" & CInt(grdcreditlist.Item(useselectrow, 7)) & "',"
sqlsale &= "'" & CInt(grdcreditlist.Item(useselectrow, 3)) & "',"
sqlsale &= "'" & CDate(grdcreditlist.Item(useselectrow, 14)) & "',"
sqlsale &= "'" & lblDate.Text & "',"
paiddate = paiddate.AddMonths(1)
sqlsale &= paiddate.ToString("d", dtfinfo) & ")"
tmpmessage = "ทำการลงบันทึกข้อมูลเป็นที่เรียบร้อยแล้ว!!"
End If
Dim mycommand As New SqlCommand(sqlsale, myCNN)
recordaffected = mycommand.ExecuteNonQuery()
paiddate = Date.Now
lastdatepaid = Date.Now
If chkdefinecredit.Checked = True Then
For i = 0 To CInt(lblduration.Text) ------------------>วนลูปตามระยะเวลาการผ่อนชำระ ถ้าผ่อน 3 เดือน จะต้องมีระยะเวลาของ 3 เดือนวนตั้งแต่เดือนแรกจนเดือนสุดท้าย แต่มันขึ้นแค่เดือนสุดท้าย
sqlsale1 = " INSERT INTO creditsaledetail (creid,paiddate,lastdatepaid,cuspaiddate,paidmonth,inforpaidlate,netpaid)"
sqlsale1 &= " VALUES ( '" & txtcreid.Text & "',"
paiddate = paiddate.AddMonths(1)
sqlsale1 &= "'" & paiddate.ToString("d", dtfinfo) & "',"
numlast = CInt(txtlastpaid.Text)
lastdatepaid = paiddate.AddDays(numlast)
sqlsale1 &= "'" & lastdatepaid.ToString("d", dtfinfo) & "',"
sqlsale1 &= "'" & lastdatepaid.ToString("d", dtfinfo) & "',"
sqlsale1 &= "'" & CSng(lblpaidpermonth.Text) & "',"
sqlsale1 &= "'" & CInt(txtintforpaidlate.Text) & "',"
sqlsale1 &= CSng(lblpaidpermonth.Text) & ")"
Next
Else
For i = 0 To CInt(lblduration.Text)
sqlsale1 = " INSERT INTO creditsaledetail ( creid,paiddate,lastdatepaid,cuspaiddate,paidmonth,inforpaidlate,netpaid)"
sqlsale1 &= " VALUES ( '" & txtcreid.Text & "',"
paiddate = paiddate.AddMonths(1)
sqlsale1 &= "'" & paiddate.ToString("d", dtfinfo) & "',"
numlast = CInt(txtlastpaid.Text)
lastdatepaid = paiddate.AddDays(numlast)
sqlsale1 &= "'" & lastdatepaid.ToString("d", dtfinfo) & "',"
sqlsale1 &= "'" & lastdatepaid.ToString("d", dtfinfo) & "',"
sqlsale1 &= "'" & CSng(lblpaidpermonth.Text) & "',"
sqlsale1 &= "'" & CInt(grdcreditlist.Item(useselectrow, 9)) & "',"
sqlsale1 &= CInt(grdcreditlist.Item(useselectrow, 7)) & ")" Next
End If
Dim command As New SqlCommand(sqlsale1, myCNN)
recordaffected = command.ExecuteNonQuery()Tag : - - - -
Date :
2010-04-03 05:07:49
By :
253132
View :
1154
Reply :
1
แปลงเป็น datetime แล้วใช้ datediff ดู
การใช้งาน datediff ไปหาอ่านเอาในบทความ
Date :
2010-04-03 09:09:41
By :
tungman
Load balance : Server 04