Как я могу заставить мой errProvider правильно отображаться? - PullRequest
0 голосов
/ 23 февраля 2020

Значок errProvider отображается независимо от ответа. Если пользователь выбирает из списка или раскрывающегося меню значок ошибки по-прежнему отображается рядом с полями. Поле депозита работает правильно. Не могли бы вы посмотреть, в чем может быть проблема? Вот мой код

Public Class Form1
    Private ReadOnly Insurance_Rate As Double = 0.1
    Private ReadOnly TaxRate As Double = 0.07

    Enum DurationType
        oneDay
        twoDay
        threeDay
        week
        twoWeek
    End Enum

    Enum EquipmentType
        Skis_Basic
        Skis_Advanced
        Snow_Basic
        Snow_Advanced
        Ski_Boots
        Snow_Boots
        Helmet_Std
        Helmet_Deluxe
    End Enum

    Private priceArray(,) As Double =
    {{35, 45, 80, 150, 280},
    {45, 55, 90, 170, 320},
    {32, 42, 78, 148, 275},
    {45, 55, 100, 175, 335},
    {10, 15, 25, 50, 90},
    {10, 15, 20, 45, 80},
    {10, 12, 15, 50, 90},
    {15, 20, 25, 70, 110}}


    Public Function GetRentalPrice(ByVal equip As EquipmentType, ByVal duration As DurationType) As Double

        Return priceArray(equip, duration)
    End Function

    Private Sub lnkForecast_LinkClicked() Handles lnkForecast.LinkClicked

        BrowserForm.WebBrowser1.Navigate("http://www.google.com/#q=breckenridge+weather")
        BrowserForm.Show()

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        lblDate.Text = DateAndTime.Today()
    End Sub

    Private Sub btnClose_Click() Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub btnCalculate_Click() Handles btnCalculate.Click
        'If lstEquipment.SelectedIndex = -1 Then
        '   MsgBox("Please select equipment")
        'End If

        'If cboDuration.SelectedIndex = -1 Then
        '   MsgBox("Please select days")
        'End If

        Dim days As String
        If cboDuration.SelectedValue = False Then
            Label3.Text = "Please Enter Information"
            errProvider.SetError(cboDuration, "Please select a day")

        Else

            errProvider.SetError(cboDuration, "")
        End If

        'Dim days As Double
        'If Not Double.TryParse(cboDuration.Text, days) Then
        '   Label3.Text = "Please Enter Information"
        '   errProvider.SetError(cboDuration, "Please select a day")
        'Else

        '   errProvider.SetError(cboDuration, "")
        'End If

        Dim equipment As Double
        If Not Double.TryParse(lstEquipment.Text, equipment) Then
            Label3.Text = "Please Enter Information"
            errProvider.SetError(lstEquipment, "Please select equipment")

        Else

            errProvider.SetError(lstEquipment, "")
        End If

        Dim deposit As Double
        If Not Double.TryParse(txtDeposit.Text, deposit) Then
            Label3.Text = "Please Enter Information"
            errProvider.SetError(txtDeposit, "Deposit must be a positive number")
            txtDeposit.Focus()
            Return
        Else

            errProvider.SetError(txtDeposit, "")
        End If

        Dim duration As DurationType = CType(cboDuration.SelectedIndex, DurationType)
        Dim subtotal As Double = 0

        For Each index As Integer In lstEquipment.SelectedIndices
            Dim equipType As EquipmentType = CType(index, EquipmentType)
            subtotal += GetRentalPrice(equipType, duration)

        Next


        Dim insurance As Double = 0
        If chkInsurance.Checked Then
            insurance = subtotal * Insurance_Rate
        End If

        subtotal += insurance
        Dim tax As Double = (subtotal * TaxRate)
        Dim balance As Double = subtotal + tax - deposit

        lblSubtotal.Text = subtotal.ToString("n")
        lblTax.Text = tax.ToString("n")
        lblBalance.Text = balance.ToString("c")


    End Sub

    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        Label3.Text = ""
        txtDeposit.Clear()
        errProvider.Clear()
        lstEquipment.ClearSelected()
        cboDuration.SelectedIndex = -1
        chkInsurance.CheckState = False
        chkWaiver.CheckState = False
        lblSubtotal.Text = ""
        lblTax.Text = ""
        lblBalance.Text = ""
    End Sub
End Class
...