我无法解决有关日期表格的问题 [英] I can't solve the problem about date form

查看:72
本文介绍了我无法解决有关日期表格的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub set_CutoffDates()

        sqlstring = "SELECT " &
            "       * " &
            "   FROM " &
            "       tblBillingProcess "


        read_record(sqlstring, "tblBillingProcess")

        txtDate.Text = Date.Now.ToShortDateString


        ' check if first billing get the last month's dates
        If ds.Tables("tblBillingProcess").Rows.Count = 0 Then


            'Dim datenow As Date = Now.Date
            'Dim Prev_Month As String = Month(DateAdd("m", -1, datenow))
            'Dim Prev_Year As String = Year(DateAdd("m", -1, datenow))
            'Dim firstdayprevmonth As String = Prev_Month & "/01/" & Prev_Year

            'Dim GetLastDayOfMonth As String = DateSerial(CInt(Prev_Year), CInt(Prev_Month) + 1, 0)

            'txtFrom.Text = firstdayprevmonth
            'txtTo.Text = GetLastDayOfMonth





            Dim datenow As Date = Now.Date

            Dim Prev_Month As String = Month(DateAdd("m", -1, datenow))
            Dim Prev_Year As String = Year(DateAdd("m", -1, datenow))
            'Dim firstdayprevmonth As String = Prev_Month & "/01/" & Prev_Year

            Dim periodFrom As String = Prev_Month & "/21/" & Prev_Year


            Dim NOW_Month As String = Month(datenow)
            Dim NOW_Year As String = Year(datenow)





            Dim firstdayofmonth As String = NOW_Month & "/01/" & NOW_Year
            Dim GetLastDayOfMonth As String = NOW_Month & "/20/" & NOW_Year

            'Dim duedate As String = DateAdd("d", +10, datenow)

            Dim duedate As String = DateAdd("d", +10, GetLastDayOfMonth)


            txtFrom.Text = periodFrom
            txtTo.Text = GetLastDayOfMonth
            txtDueDate.Text = duedate



        Else
            Dim datenow As Date


            'sqlstring = "SELECT " & _
            '    "       MAX(Periodfrom) as Periodfrom " & _
            '    "   FROM " & _
            '    "       tblBillingProcess "

            sqlstring = "SELECT " &
           "       MAX(Periodto) as Periodfrom " &
           "   FROM " &
           "       tblBillingProcess "

            read_record(sqlstring, "tblBillingProcessdate")

            datenow = CDate(ds.Tables("tblBillingProcessdate").Rows(0).Item("Periodfrom").ToString)


            'Dim Prev_Month As String = Month(DateAdd("m", -1, datenow))
            'Dim Prev_Year As String = Year(DateAdd("m", -1, datenow))


            Dim Prev_Month As String = Month(datenow)
            Dim Prev_Year As String = Year(datenow)

            Dim periodFrom As String = Prev_Month & "/21/" & Prev_Year




            Dim NOW_Month As String = Month(DateAdd("m", +1, datenow))
            Dim NOW_Year As String = Year(DateAdd("m", -1, datenow))

            Dim firstdayofmonth As String = NOW_Month & "/01/" & NOW_Year
            Dim GetLastDayOfMonth As String = NOW_Month & "/20/" & NOW_Year

            Dim duedate As String = DateAdd("d", +10, CDate(GetLastDayOfMonth))


            txtFrom.Text = periodFrom
            txtTo.Text = GetLastDayOfMonth
            txtDueDate.Text = duedate


        End If



    End Sub


Private Sub btnadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click
        Try

            If btnadd.Text = "&Add" Then

                If Get_PendingPresentReading() = True Then
                    MsgBox("You must complete all present reading before creating new billing process ",
                                    MsgBoxStyle.Exclamation, Text)
                    Exit Sub
                End If



                reset_controls()
                dgProcess.Rows.Clear()
                txtBillingNo.Text = String.Empty
                txtFrom.Text = String.Empty
                txtTo.Text = String.Empty
                txtDueDate.Text = String.Empty
                txtDate.Text = String.Empty



                generate_billingNO()
                load_data()
                set_CutoffDates()

                btnadd.Text = "&Save"

                btnedit.Enabled = False
                btncancel.Enabled = True
                btnMain.Enabled = False
                btnFind.Enabled = False
            Else

                If MsgBox("Are you sure to save this transaction ",
                          MsgBoxStyle.Question + MsgBoxStyle.YesNo, Me.Text) = MsgBoxResult.No Then
                    Exit Sub
                End If





我尝试了什么:



当我尝试添加新账单时出现问题



消息说:



转换表格字符串4/20/2017输入日期无效。在VB女士。编译器服务转换。 ToDate(字符串值)



第1054行中的问题



What I have tried:

the problem appear when I try to add new bill

The message said:

conversion form string "4/20/2017" to type 'date' in not valid. at Ms VB. compiler Services conversions . ToDate(string value)

the problem in the line 1054

Dim duedate As String = DateAdd("d", +10, CDate(GetLastDayOfMonth))





和1102行



and in line 1102

<pre>set_CutoffDates







问题照片

[ ^ ]

推荐答案

首先,第二个和第三个: date是一个日期,而不是它的字符串表示!



结论:你的所有代码都错了!



检查:

First of all, second of all and third of all: date is a date, not its string representation!

Conclusion: all your code is wrong!

Check this:
'needs to import Microsoft.VisualBasic
Dim DateNow As Date = Date.Now
Dim FirstDayOfPrevMonth As Date = DateAdd("M", -1, DateAdd("d", - Day(DateNow) +1, DateNow))
Console.WriteLine("{0}", FirstDayOfPrevMonth.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)) 'displays: 2018-02-01





但是(!),你必须使用日期时间结构(系统) [ ^ ]。请参阅:



But(!), you have to use DateTime Structure (System)[^]. See:

Dim DateNow As DateTime = DateTime.Now
Dim FirstDayOfPrevMonth As DateTime = DateNow.AddDays(- Day(DateNow) +1).AddMonths(-1)
Console.WriteLine("{0}", FirstDayOfPrevMonth.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))





你看到了区别吗?



Do you see the difference?


这篇关于我无法解决有关日期表格的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆