如何修复“太多参数” - 错误

时间:2015-02-03 10:59:22

标签: vb.net

我在vb中处理这个销售点系统并且我遇到了错误

  

错误2'Public Overridable Overloads Function的参数太多   插入(ItemName As String,BuyPrice As Integer?,SellPrice As   整数?)作为整数'。

我该如何清除它?

双头**是错误的地方

我的代码:添加项目窗口

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

   Public Class AddItem

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Me.DialogResult = Windows.Forms.DialogResult.Cancel
End Sub

'used to insert the item

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    'perform validation for barcode
    If TextBox1.Text.Trim = "" Then
        MsgBox("You should enter a barcode number", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox1.Focus()
        Exit Sub

    End If

    If Not IsNumeric(TextBox1.Text) Then
        MsgBox("You should enter a numeric barcode number", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox1.Focus()
        Exit Sub
    End If

    If TextBox1.Text.Contains(".") Or TextBox1.Text.Contains("-") Then
        MsgBox("The barcode number should not contain special characters", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox1.Focus()
        Exit Sub
    End If

    'perform check for the item name
    If TextBox2.Text.Trim = "" Then
        MsgBox("You should enter a name for the item", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox2.Focus()
        Exit Sub

    End If

    'perform a check for the buy price
    If TextBox3.Text.Trim = "" Then
        MsgBox("You should enter the buying price", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox3.Focus()
        Exit Sub

    End If

    If Not IsNumeric(TextBox3.Text) Then
        MsgBox("You should enter a numeric buying price", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox3.Focus()
        Exit Sub
    End If

    Dim BuyPrice As Decimal = Decimal.Parse(TextBox3.Text)
    If BuyPrice < 0 Then
        MsgBox("The buying price cannot be negative", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox3.Focus()
        Exit Sub
    End If

    'perform a check for the selling price
    If TextBox4.Text.Trim = "" Then
        MsgBox("You should enter the selling price", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox4.Focus()
        Exit Sub

    End If

    If Not IsNumeric(TextBox4.Text) Then
        MsgBox("You should enter a numeric selling price", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox4.Focus()
        Exit Sub
    End If

    Dim SellPrice As Decimal = Decimal.Parse(TextBox4.Text)
    If SellPrice < 0 Then
        MsgBox("The selling price cannot be negative", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox4.Focus()
        Exit Sub
    End If

    If SellPrice <= BuyPrice Then
        MsgBox("The selling price cannot be less than buying price", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        TextBox4.Focus()
        Exit Sub
    End If

    'perform check for quantity
    'If Not IsNumeric(TextBox5.Text) Then
    'MsgBox("You should enter a numeric digits", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
    'TextBox5.Focus()
    'Exit Sub
    'End If

    'Dim Quantity As Decimal = Decimal.Parse(TextBox5.Text)
    'If Quantity < 0 Then
    'MsgBox("Quantity cant be negative", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
    ' TextBox5.Focus()
    'Exit Sub
    'End If


    'insert the item

    Try
        'create the adapter
        Dim TA As New POSDSTableAdapters.ItemsTableAdapter

        'insert the item
        'TA.Insert(TextBox1.Text, TextBox2.Text, BuyPrice, SellPrice, Quantity)
        TA.Insert(TextBox2.Text, BuyPrice, SellPrice)


        Me.DialogResult = Windows.Forms.DialogResult.OK

    Catch ex As Exception

        'display error message
        'handle error
        MsgBox(ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)

    End Try
End Sub

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

End Sub

结束班

主窗口代码: 公共类MainWindow

Private Sub MainWindow_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'MyDataset.Items' table. You can move, or remove it, as needed.
    Me.ItemsTA.Fill(Me.MyDataset.Items)

    Try


    'get the username from the user
        'Dim USRWin As New PasswordPicker

    'get the password from the user
        ' Dim PSWWin As New PasswordPicker


    'if the user hits the exit button then stop executing the program
        'If PSWWin.ShowDialog <> Windows.Forms.DialogResult.OK Then

        'End

        ' End If

        'get the usernme
        'Dim USR As String = USRWin.TextBox1.text
        'get the password
        'Dim PSW As String = PSWWin.TextBox2.text


        'get the password from the database
        ' Dim TA As New POSDSTableAdapters.ValuesTableAdapter
        'Dim TB = TA.GetDataByKey("password")
        ' Dim DBPSW As String = TB.Rows(0).Item(1)

        'check the passwords match
        ' If PSW <> DBPSW Then
        'MsgBox("Invalid password", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        ' End If

        'get the username
        ' Dim TK = TA.GetDataByKey("username")
        'Dim DBUSR As String = TK.Rows(0).Item(2)

        'check the username match
        'If USR <> DBUSR Then
        'MsgBox("Invalid username", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
        'End If

        'load the items info from db into the dataset
        ItemsTA.Fill(MyDataset.Items)


    Catch ex As Exception

        'handle error
        MsgBox(ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)

    End Try
End Sub

Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)

End Sub

'add item to the db
Private Sub AddItemToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AddItemToolStripMenuItem.Click
    Dim AddItemWindow As New AddItem
    If AddItemWindow.ShowDialog = Windows.Forms.DialogResult.OK Then
        'load the info of items from db
        ItemsTA.Fill(MyDataset.Items)
    End If


End Sub

'used to select an item
Private Sub EditItemToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EditItemToolStripMenuItem.Click

    'make sure an item is selected
    If DataGridView1.SelectedRows.Count = 0 Then
        Exit Sub
    End If

    'get the barcode of the item
    Dim Barcode = DataGridView1.SelectedRows(0).Cells(0).Value

    'create the edit window
    Dim EditItemWindow As New EditItem

    'fill the window with information
    EditItemWindow.FillItemInfo(Barcode)

    If EditItemWindow.ShowDialog = Windows.Forms.DialogResult.OK Then
        'load the info of items from db
        ItemsTA.Fill(MyDataset.Items)
    End If
End Sub

结束班

1 个答案:

答案 0 :(得分:4)

错误信息是否不言自明?

  

公共可覆盖过载功能的参数太多   插入(ItemName As String,BuyPrice As Integer?,SellPrice As   整数?)作为整数&#39;

您正在传递四个参数:

 TA.Insert(TextBox1.Text, TextBox2.Text, BuyPrice, SellPrice)

也许你想要:

TA.Insert(TextBox1.Text, BuyPrice, SellPrice)