以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]求助关于日期判断的问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=38215)

--  作者:fjt4444
--  发布时间:2013/7/23 8:47:00
--  [求助]求助关于日期判断的问题

表名:扣款表

 

  卡  号 

扣款日期      扣款金额    状态 
   111    2013-05-03    100.0    已扣
   222    2013-05-03    100.0    已扣
   111    2013-06-04    200.0    月扣
   222    2013-06-04    200.0    月扣

 

 


图片点击可在新窗口打开查看此主题相关图片如下:1.jpg
图片点击可在新窗口打开查看

确定按钮的功能我已经实现,我现在就是不知道一个验证方法该怎么写。。。。情况是这样的,输入金额和日期后,单击确定,然后扣款表就会为“卡号表”中所有卡进行扣款,同时“状态”会变更为“月扣”。重点来了,我希望每次单击确定按钮的时候就验证一下,凡是相对应卡号在当年当月已经做过“月扣”处理的,

MessageBox.Show“已经在该月为该卡做过扣款处理”。   我完全不知道怎么把“2013-06-04”分解,提取出2013年和   06月来验证。求大神帮帮我。我确定按钮的代码如下,不知道IF 后代码怎么写……

 

 

Dim je As WinForm.TextBox = e.Form.Controls("TextBox3")
Dim rq As WinForm.DateTimePicker = e.Form.Controls("DateTimePicker1")

If “????????" Then
Messagebox.show("该月已经扣款!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Return
Else
For Each r As DataRow In DataTables("car").DataRows
    Dim dr As DataRow = DataTables("规费记录").addnew
    dr("卡号")=r("卡号")
    dr("车牌号")=r("车牌号")
    dr("车主")=r("车主")
    dr("扣款日期")=rq.Value
    dr("扣款金额")=je.Text
    dr("状态")="月扣"
Next
End If
Messagebox.show("扣款成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)


--  作者:Bin
--  发布时间:2013/7/23 8:51:00
--  
这样可以生成一个新的Date  Dim d As Date = new Date(2011,1,2)




--  作者:fjt4444
--  发布时间:2013/7/23 9:12:00
--  

文档上面只是说筛选  自己指定的年份月份。我希望分解我datetimepicker控件上输入的那个时间。。。。把它分解为年、月就行了。

您看?


--  作者:狐狸爸爸
--  发布时间:2013/7/23 9:15:00
--  

分解年月日? 好简单的:

 

http://www.foxtable.com/help/topics/1424.htm

http://www.foxtable.com/help/topics/1337.htm

 


--  作者:Bin
--  发布时间:2013/7/23 9:15:00
--  
d.Day
d.Month
d.Year
可以分别获取年月日

请你认真看一下,里面就有你所要的.  
--  作者:fjt4444
--  发布时间:2013/7/23 9:18:00
--  
好的  我这就去试试
--  作者:fjt4444
--  发布时间:2013/7/23 9:46:00
--  

Dim je As WinForm.TextBox = e.Form.Controls("TextBox3")
Dim rq As WinForm.DateTimePicker = e.Form.Controls("DateTimePicker1")


Dim d As Date = rq.Value
Dim y As Integer = d.Year
Dim m As Integer = d.Month
Dim dt1 As New Date(y, m, 1)
Dim dt2 As New Date(y, m, Date.DaysInMonth(y,m)) \'获取该月的最后一天


For Each rx As DataRow In DataTables("规费记录").DataRows
If rx("扣款日期") >=  # " & dt1 & " # And rx("扣款日期")<= # " & dt2 & " #  And rx("状态")="月扣"  Then
Messagebox.show("该月已经扣款!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Return
Else
For Each r As DataRow In DataTables("car").DataRows
    Dim dr As DataRow = DataTables("规费记录").addnew
    dr("卡号")=r("卡号")
    dr("车牌号")=r("车牌号")
    dr("车主")=r("车主")
    dr("扣款日期")=rq.Value
    dr("扣款金额")=je.Text
    dr("状态")="月扣"
Next
End If
Messagebox.show("扣款成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Next

 

 

 

 

求助,红色代码出错。。。。。真心不知道怎么改


--  作者:Bin
--  发布时间:2013/7/23 9:55:00
--  
If rx("扣款日期") >= dt1  And rx("扣款日期")<= dt2  And rx("状态")="月扣"  Then
--  作者:fjt4444
--  发布时间:2013/7/23 10:08:00
--  
For Each rx As DataRow In DataTables("规费记录").DataRows
If rx("扣款日期") >=   dt1  # And rx("扣款日期")<=  dt2  And rx("状态")="月扣"  Then
Messagebox.show("该月已经扣款!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Return
Else
For Each r As DataRow In DataTables("car").DataRows
    Dim dr As DataRow = DataTables("规费记录").addnew
    dr("卡号")=r("卡号")
    dr("车牌号")=r("车牌号")
    dr("车主")=r("车主")
    dr("扣款日期")=rq.Value
    dr("扣款金额")=je.Text
    dr("状态")="月扣"
Next
End If
Messagebox.show("扣款成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Next

 

 

 

 

这里用 For Each 不行哎,这个循环有问题。。。。能麻烦您帮我话一段吗?不用for  each


--  作者:Bin
--  发布时间:2013/7/23 10:11:00
--  
你这 FOr  EACH 代码没有问题啊. 报什么错?