Vb.net 额外运费

Vb.net 额外运费,vb.net,shipping,Vb.net,Shipping,我在vb 2010中遇到了运输额外成本的问题,问题是计算超大集装箱每件5.00美元的额外处理费(选中了超大集装箱复选框)。下面是我为运费所做的代码。我已经将超大尺寸定义为常数,但我无法使其工作 我们被告知要做的是确保在检查超大支票盒时,它应计算超大金额,即每单位5美元,并应将其添加到已选择的任何运费中。在我的情况下,我有4个航运这是 ups每件7美元,美国邮政航空每件8.5美元,联邦快递地面每件9.2美元,联邦快递航空每件12美元 Public Class Lab5 'ship mode c

我在vb 2010中遇到了运输额外成本的问题,问题是计算超大集装箱每件5.00美元的额外处理费(选中了超大集装箱复选框)。下面是我为运费所做的代码。我已经将超大尺寸定义为常数,但我无法使其工作


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

ups每件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
公共类Lab5
'船舶模式常数
常量U_P_S_十进制为十进制=7D
常数FED\u EX\u AIR\u十进制为十进制=12D
常量FED_EX_GROUND_十进制为十进制=9.25D
常量US_POSTRAL_AIR_十进制为十进制=8.5D
建筑销售税单体税率=0.1'10%
'清除模块级变量
私有TotalQuantityInteger作为整数
私有TotalSalesDecimal作为十进制
私有子计算按钮单击(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理计算按钮。单击,ComputeToolStripMenuItem。单击
尝试
Dim TotalCostDecimal、ShippingCostDecimal、SalesTaxDecimal、TotalDueDecimal作为十进制
'声明变量并将值从textbox控件转换为内存
Dim PriceDecimal As Decimal=Decimal.Parse(PriceTextBox.Text,Globalization.numberstyle.Currency)
Dim QuantityInteger作为Integer=Integer.Parse(QuantityTextBox.Text,Globalization.NumberStyles.Number)
'过程-计算值
'小计=价格乘以图书数量
TotalCostDecimal=PriceDecimal*QuantityInteger
'Sales tex=销售税率乘以小计减去折扣金额
如果选中复选框,则选中
SalesTaxDecimal=Decimal.Round(将.ToDecimal转换为Decimal(总成本Decimal*销售税税率单),2)
如果结束
如果CustomerIDMaskedTextBox.MaskCompleted=False,则
电话号码不全
MessageBox.Show(“CustomerID不完整或缺失”,“CustomerID错误”,MessageBoxButtons.OK,MessageBoxIcon.Error)
CustomerIDMaskedTextBox.Focus()
CustomerIDMaskedTextBox.SelectAll()
ElseIf NameTextBox.Text.Trim=String.Empty然后
'客户名称是必需的
MessageBox.Show(“需要客户名称”,“客户名称丢失错误”,MessageBoxButtons.OK,MessageBoxIcon.Error)
NameTextBox.Focus()
NameTextBox.SelectAll()
ElseIf StateTextBox.Text.Trim=String.Empty然后
'需要送货地址
显示(“状态是必需的”,“状态缺少错误”,MessageBoxButtons.OK,MessageBoxIcon.Error)
StateTextBox.Focus()
StateTextBox.SelectAll()
ElseIf PartTextBox.Text.Trim=字符串。然后为空
'缺少所需的零件号
显示(“缺少零件号”,“缺少零件号错误”,MessageBoxButtons.OK,MessageBoxIcon.Error)
PartTextBox.Focus()
PartTextBox.SelectAll()
ElseIf DescriptionTextBox.Text.Trim=字符串。然后为空
“需要说明
MessageBox.Show(“缺少产品说明”,“缺少产品说明错误”,MessageBoxButtons.OK,MessageBoxIcon.Error)
DescriptionTextBox.Focus()
DescriptionTextBox.SelectAll()
ElseIf IsNumeric(PriceTextBox.Text)=则为False
'购买价格文本框必须包含一个数值
Show(“价格必须包含数值”,“价格非数值错误”,MessageBoxButtons.OK,MessageBoxIcon.Error)
PriceTextBox.Focus()
PriceTextBox.SelectAll()
ElseIf IsNumeric(QuantityTextBox.Text)=False然后
'购买数量测试框必须包含数字值
显示(“必须输入数量”,“数量错误”,MessageBoxButtons.OK,MessageBoxIcon.Error)
QuantityTextBox.Focus()
QuantityTextBox.SelectAll()
ElseIf Decimal.Parse(QuantityTextBox.Text,Globalization.NumberStyles.Number)<0然后
'购买的数量必须大于零
MessageBox.Show(“数量必须大于零”,“购买数量不大于零错误”,MessageBoxButtons.OK,MessageBoxIcon.Error)
其他的
如果结束
“运费
如果选中,则“计算运输成本”
ShippingCostDecimal=U\U P\U S\U DECIMAL*QuantityInteger
艾尔塞夫·费德克斯·巴顿,检查过了吗
ShippingCostDecimal=FED_EX_AIR_DECIMAL*QuantityInteger
ElseIf联邦快递地面无线按钮。然后检查
ShippingCostDecimal=FED_EX_GROUND_DECIMAL*QuantityInteger
其他USPOSTALIRRADIOBUTTON。然后检查
ShippingCostDecimal=US\u POSTRAL\u AIR\u DECIMAL*QuantityInteger
如果结束
“计算总到期日
TotalDueDecimal=SalesTaxDecimal+ShippingCostDecimal+TotalCostDecimal
'数据计算输出
小计文本框.Text=TotalCostDecimal.ToString(“C”)
TotalDueTextBox.Text=TotalDueTecimal.ToString(“C2”)
SalesTaxTextBox.Text=SalesTaxDecimal.ToString(“N”)
ShippingCostTextBox.Text=ShippingCostDecimal.ToString(“N”)
'累计总销售额和总图书销售额
TotalQuantityInteger+=QuantityInteger
TotalSalesDecimal+=TotalDueDecimal
特例
显示(“意外错误”、“计算按钮错误”、MessageBoxButtons.OK、MessageBoxIcon.error)
结束尝试
端接头

正如我在评论中提到的。。。。
你说你需要增加5美元的超大价格,但这一行

OversizeDecimal = ShippingCostDecimal * OVERSIZE_RATE_DECIMAL 
似乎在乘以5 试一试


我终于明白了
 OversizeDecimal = ShippingCostDecimal + (OVERSIZE_RATE_DECIMAL * QuantityInteger)
'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