我已经弄清了这个任务的大部分内容,并且我添加了第二个包含单选按钮的部分。

时间:2014-10-28 10:15:51

标签: vb.net visual-studio-2010

我必须使用两个单选按钮,一个用于新客户,另一个用于现有客户。现有客户单选按钮将在列表框中选择所选行,并将信息放在三个文本框中。我应该使用拆分来从列表框中获取信息到文本框。我输入了家庭作业第一部分的数据,当我点击新客户radiobox时,它会将信息添加到我的新列表框中,但是我在代码底部的单选按钮上遇到了问题。我已将我的代码评论到这一部分,所以我希望我一直在做所有事情是可以理解的。

Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
    'I am dimming my variables that I need 
    Dim name As String
    Dim address As String
    Dim city As String
    Dim firstlast As String
    Dim invoicenumber As String
    Dim chairs As Double
    Dim sofas As Double

    'I am assigning value to my variables
    name = txtName.Text
    address = txtAddress.Text
    city = txtCity.Text
    chairs = CDbl(txtChairs.Text) * 350
    sofas = CDbl(txtSofas.Text) * 925

    'I am using if clauses to make sure the user puts values into the text boxes and if not then a message box will appear
    If name = "" Then
        MessageBox.Show("Please Enter Your Name.")
        txtName.Focus()
    End If
    If address = "" Then
        MessageBox.Show("Please Enter Your Address.")
        txtAddress.Focus()
    End If
    If city = "" Then
        MessageBox.Show("Please Enter Your City, State, and Zip in Correct Format.")
        txtCity.Focus()
    End If
    If address.Contains(",") = False Then
        MessageBox.Show("Please Enter In Correct Format:  City, St., Zip.")
    End If

    'These are my functions that I made for the invoice number and name reverse
    invoicenumber = GenerateinvoiceNumber(txtName.Text)
    firstlast = RevName(name)

    'I am adding all of the items to my listbox
    lstResults.Items.Clear()
    lstResults.Items.Add("INVOICE NUMBER: " & " " & invoicenumber.ToUpper)
    lstResults.Items.Add(String.Empty)
    lstResults.Items.Add("Name: " & "   " & RevName(txtName.Text.ToUpper))
    lstResults.Items.Add("Address: " & "" & address.ToUpper)
    lstResults.Items.Add("City: " & "       " & city.ToUpper)
    lstResults.Items.Add(String.Empty)
    lstResults.Items.Add("Number of Chairs: " & "" & txtChairs.Text)
    lstResults.Items.Add("Number of Sofas: " & " " & txtSofas.Text)
    lstResults.Items.Add(String.Empty)
    lstResults.Items.Add("Cost: " & "           " & FormatCurrency(chairs + sofas))
    lstResults.Items.Add("Sales Tax:" & "   " & FormatCurrency((chairs + sofas) * 0.05))
    lstResults.Items.Add("--------------------------------------------")
    lstResults.Items.Add("Total Cost: " & " " & FormatCurrency((chairs + sofas) * 1.05))

End Sub
'This is the function for the name reverse. 
Function RevName(ByVal name As String) As String

    Dim firstlast() As String

    'This split is to take the part of the word after the comma
    firstlast = Split(txtName.Text.ToUpper, ", ")
    'This if clause is to make sure that the name is formatted correctly with a comma
    If name.Contains(", ") = False Then
        MessageBox.Show("Please Enter Your Name In Correct Format.")
    End If

    'This will show the function and the correct formatting in my list box
    Return firstlast(1) & " " & firstlast(0)

End Function
'This is my function to create the invoice number
Function GenerateinvoiceNumber(ByVal s As String) As String
    'Dimming the variables I need for my function
    Dim initials() As String
    Dim firstInitial, invoicenumber, city As String

    'Assigning values to the variables
    'I am using a split to get the letters from the last name
    initials = s.Split(CChar(","))
    'I am taking the letters that I need using a substring
    firstInitial = initials(0).Trim.Substring(0, 2).ToUpper

    city = txtCity.Text
    'This is to get the value of the textbox city and the length of the input
    Dim length = city.Length
    'This is to get the first two letters of the name behind the comma and the city substring will extract the last four characters in the city textbox
    invoicenumber = (firstInitial & city.Substring(length - 4, 4))
    'This is to return the value of the function
    Return invoicenumber
End Function
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
    'This is to clear the form and start over
    txtName.Clear()
    txtAddress.Clear()
    txtCity.Clear()
    txtChairs.Clear()
    txtSofas.Clear()
    lstResults.Items.Clear()
End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    'This is to end the entire form
    Me.Close()
End Sub

Private Sub rbtnNew_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnNew.CheckedChanged
    lstCustomer.Items.Add(RevName(txtName.Text.ToUpper) & (txtAddress.Text) & (txtCity.Text))
End Sub


Private Sub rbtnExisting_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnExisting.CheckedChanged
    Dim name1 As String
    Dim address2 As String
    Dim city2 As String

    name1 = txtName.Text
    address2 = txtAddress.Text
    city2 = txtCity.Text

    lstCustomer.GetSelected(CInt(ToTextBoxes(Name, address2, city2)))

End Sub
Function ToTextBoxes(ByRef name As String, ByRef Address As String, ByRef city As String) As String
    Dim output() As String
    output = Split(lstCustomer.SelectedItem.ToString(), ",")


    Return CStr(CStr(output(0) = txtName.Text) & output(1) = txtAddress.Text & output(2) = CBool(txtCity.Text))

End Function

结束班

0 个答案:

没有答案