运费另计

时间:2014-11-17 09:55:06

标签: vb.net shipping

在vb 2010中遇到运输额外费用的问题,问题是为超大容器计算每件5.00美元的额外处理费用(选中Oversize Container CheckBox)。以下是我为运费率制定的代码。我已经将超大尺寸定义为常数但我无法使其工作

我们被告知要做的是确保在检查超大号检查箱时应计算每单位5美元的超大金额,并将其添加到已选择的任何运费中。在我的情况下,我有4个运输

每单位增加7美元,邮政空运每单位8.5美元,联邦快递每单位9.2美元,联邦航空每单位12美元

Public Class Lab5


'ship mode constants
Const U_P_S_DECIMAL As Decimal = 7D
Const FED_EX_AIR_DECIMAL As Decimal = 12D
Const FED_EX_GROUND_DECIMAL As Decimal = 9.25D
Const US_POSTRAL_AIR_DECIMAL As Decimal = 8.5D


Const SALES_TAX_RATE_SINGLE As Single = 0.1 '10 Percent Rate

'declear module-level variables
Private TotalQuantityInteger As Integer
Private TotalSalesDecimal As Decimal




Private Sub ComputeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComputeButton.Click, ComputeToolStripMenuItem.Click
    Try


        Dim TotalCostDecimal, ShippingCostDecimal, SalesTaxDecimal, OversizeDecimal, TotalDueDecimal As Decimal


        'Declare variables and convert value from textbox controls to memory
        Dim PriceDecimal As Decimal = Decimal.Parse(PriceTextBox.Text, Globalization.NumberStyles.Currency)
        Dim QuantityInteger As Integer = Integer.Parse(QuantityTextBox.Text, Globalization.NumberStyles.Number)

        'Process - Compute values
        'Subtotal = price times the quantity of books
        TotalCostDecimal = PriceDecimal * QuantityInteger



        'Sales tex = sales tax rate times the subtotal minus discount amount
        If RetailCheckBox.Checked Then
            SalesTaxDecimal = Decimal.Round(Convert.ToDecimal(TotalCostDecimal * SALES_TAX_RATE_SINGLE), 2)
        End If


        If CustomerIDMaskedTextBox.MaskCompleted = False Then
            'incomplete telephone number
            MessageBox.Show("Incomplete or missing CustomerID", "CustomerID Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            CustomerIDMaskedTextBox.Focus()
            CustomerIDMaskedTextBox.SelectAll()
        ElseIf NameTextBox.Text.Trim = String.Empty Then
            'Customer name is required
            MessageBox.Show("Customer Name is required", "Customer Name Missing Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            NameTextBox.Focus()
            NameTextBox.SelectAll()
        ElseIf StateTextBox.Text.Trim = String.Empty Then
            'Shipping address required
            MessageBox.Show("State is required", "State Missing Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            StateTextBox.Focus()
            StateTextBox.SelectAll()
        ElseIf PartTextBox.Text.Trim = String.Empty Then
            'Missing Part Number Required
            MessageBox.Show("Part Number is missing", "Part Number Missing Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            PartTextBox.Focus()
            PartTextBox.SelectAll()
        ElseIf DescriptionTextBox.Text.Trim = String.Empty Then
            'Description is Required
            MessageBox.Show("Product Description is missing", "Product Description Missing Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            DescriptionTextBox.Focus()
            DescriptionTextBox.SelectAll()
        ElseIf IsNumeric(PriceTextBox.Text) = False Then
            'the purchase price textbox must contain a numeric value
            MessageBox.Show("Price must contain a numeric value", "Price Not Numeric Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            PriceTextBox.Focus()
            PriceTextBox.SelectAll()
        ElseIf IsNumeric(QuantityTextBox.Text) = False Then
            'the Quantity purchased Testbox must contain a numeric value
            MessageBox.Show("Quantity must be input", "Quantity Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            QuantityTextBox.Focus()
            QuantityTextBox.SelectAll()
        ElseIf Decimal.Parse(QuantityTextBox.Text, Globalization.NumberStyles.Number) < 0 Then
            'the quantity purchased must be greater than zero
            MessageBox.Show("The quantity must be greater than zero", "Quantity Purchased not greater than zero Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
        End If


        'Shipping cost

        If UPSRadioButton.Checked Then 'compute the shipping cost
            ShippingCostDecimal = U_P_S_DECIMAL * QuantityInteger

        ElseIf FedExAirRadioButton.Checked Then
            ShippingCostDecimal = FED_EX_AIR_DECIMAL * QuantityInteger

        ElseIf FedExGroundRadioButton.Checked Then
            ShippingCostDecimal = FED_EX_GROUND_DECIMAL * QuantityInteger

        ElseIf USPostalAirRadioButton.Checked Then
            ShippingCostDecimal = US_POSTRAL_AIR_DECIMAL * QuantityInteger

        End If

        'Compute TotalDue
        TotalDueDecimal = SalesTaxDecimal + ShippingCostDecimal + TotalCostDecimal

        'Data computed output
        SubtotalTextBox.Text = TotalCostDecimal.ToString("C")
        TotalDueTextBox.Text = TotalDueDecimal.ToString("C2")
        SalesTaxTextBox.Text = SalesTaxDecimal.ToString("N")
        ShippingCostTextBox.Text = ShippingCostDecimal.ToString("N")

        'Accumulate total sales and total books sold
        TotalQuantityInteger += QuantityInteger
        TotalSalesDecimal += TotalDueDecimal
    Catch ex As Exception
        MessageBox.Show("unexpected error", "Compute Button Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub

2 个答案:

答案 0 :(得分:0)

正如我的评论所述...... 你说你需要增加5美元的超大费率,但这一行

OversizeDecimal = ShippingCostDecimal * OVERSIZE_RATE_DECIMAL 

似乎乘以5 尝试

 OversizeDecimal = ShippingCostDecimal + (OVERSIZE_RATE_DECIMAL * QuantityInteger)

答案 1 :(得分:0)

我终于弄清楚了自己

Public Class Lab5

'ship mode constants
Const U_P_S_DECIMAL As Decimal = 7D
Const FED_EX_AIR_DECIMAL As Decimal = 12D
Const FED_EX_GROUND_DECIMAL As Decimal = 9.25D
Const US_POSTRAL_AIR_DECIMAL As Decimal = 8.5D
Const OVERSIZE_RATE_DECIMAL As Decimal = 5D

Const SALES_TAX_RATE_SINGLE As Single = 0.1 '10 Percent Rate

        'Oversized Handling Charges
        If OversizedCheckBox.Checked Then
            ShippingCostDecimal = QuantityInteger * (OVERSIZE_RATE_DECIMAL + U_P_S_DECIMAL)

        ElseIf OversizedCheckBox.Checked Then
            ShippingCostDecimal = QuantityInteger * (OVERSIZE_RATE_DECIMAL + FED_EX_AIR_DECIMAL)

        ElseIf OversizedCheckBox.Checked Then
            ShippingCostDecimal = QuantityInteger * (OVERSIZE_RATE_DECIMAL + FED_EX_GROUND_DECIMAL)

        ElseIf OversizedCheckBox.Checked Then
            ShippingCostDecimal = QuantityInteger * (OVERSIZE_RATE_DECIMAL + US_POSTRAL_AIR_DECIMAL)
        End If