Transcript 下載/瀏覽
阿勇魚店結帳系統
南台科技大學
機械工程系
自控一甲
學號:49912098
姓名:葉佳勇
老師:謝慶存
學習重點
ListBox、RadioButton的使用方法。
對於程式的應用更加了解
題目說明:阿勇魚店結帳系統
在數量上面輸入
想要的數量並點
選「計算」就可
獲得價錢的數目,
再按「清除」,
便可把所有計算
出來的數目給清
除掉,再輸入想
要的數量並在旁
邊的「老客戶*0.
9 」點選,就可
把所計算出來的
價錢打9折的優
惠
改虱目魚數量
在虱目魚的數
量上輸入1並
按「計算」 ,
便可獲得價錢
總數。
老客戶的優惠
輸入虱目魚的數
量為1,並點選
旁邊的「老客戶
*0.9 」的選項,
再按「計算」 ,
便可獲得優惠的
價格。
超過20000元*0.75
在虱目魚的數量
上輸入3並在小
美人魚的數量上
輸入1,並按上
「計算」 。
因為總價大於
20000所以
獲得*0.75的優
惠價格
販賣種類
Label1
Label2
Label3
Label4
Label5
價格
TBoxPrice1
TBoxPrice2
TBoxPrice3
TBoxPrice4
TBoxPrice5
列出點餐
ListBox1
金額
Label9
Label10
數量
TBoxQty1
TBoxQty2
TBoxQty3
TBoxQty4
TBoxQty5
版面設計
手工處理
CheckBox1
CheckBox2
CheckBox3
CheckBox4
CheckBox5
優待
GroupBox1
RadioButton1
RadioButton2
RadioButton3
清除
Button2
計算
Button1
物件設定
物件
屬性
設定
說明
TBoxPrice1
Text
“”
虱目魚價格
TBoxPrice2
Text
“”
吳郭魚價格
TBoxPrice3
Text
“”
翻車魚價格
TBoxPrice4
Text
“”
黃魚價格
TBoxPrice5
Text
“”
小美人魚價格
TBoxQty1
Text
虱目魚數量
TBoxQty2
Text
吳郭魚數量
TBoxQty3
Text
翻車魚數量
TBoxQty4
Text
黃魚數量
TBoxQty5
Text
小美人魚數量
物件設定
物件
屬性
設定
RadioButton1
Text
老客戶*0.9
RadioButton2
Text
特約戶*0.8
RadioButton3
Text
>2000元*0.75
Button1
Text
計算
Button2
Text
清除
ListBox1
Text
說明
由程式控制
程式碼設計
Public Class Form1
Dim total, accTotal As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Label9.Text = "$" & total & "元"
Label10.Text = "累計:$" & accTotal & "元"
Label9.Font = New Font("新細明體", 24)
Label9.ForeColor = Color.Red
total = 0
accTotal = 0
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
total = Val(TBoxPrice1.Text) * Val(TBoxQty1.Text) + Val(TBoxPrice2.Text) *
Val(TBoxQty2.Text) + Val(TBoxPrice3.Text) * Val(TBoxQty3.Text) + Val(TBoxPrice4.Text) *
Val(TBoxQty4.Text) + Val(TBoxPrice5.Text) * Val(TBoxQty5.Text)
If total > 20000 Then RadioButton3.Checked = True
If RadioButton1.Checked = True Then total = total * 0.9
If RadioButton2.Checked = True Then total = total * 0.8
If RadioButton3.Checked = True Then total = total * 0.75
Label9.Text = "$" & total & "元"
accTotal = accTotal + total
Label10.Text = "累計:$" & accTotal & "元"
ListBox1.Items.Add(total & "-->" & "虱目魚" & TBoxPrice1.Text & "*" & TBoxQty1.Text & "
吳郭魚" & TBoxPrice2.Text & "*" & TBoxQty2.Text & "翻車魚" & TBoxPrice3.Text & "*" &
TBoxQty3.Text & "黃魚" & TBoxPrice4.Text & "*" & TBoxQty4.Text & "小美人魚" &
TBoxPrice5.Text & "*" & TBoxQty5.Text)
End Sub
Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
TBoxQty1.Text = 0
TBoxQty2.Text = 0
TBoxQty3.Text = 0
TBoxQty4.Text = 0
TBoxQty5.Text = 0
total = 0
Label9.Text = "$" & total & "元"
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal
sender As System.Object, ByVal e As System.EventArgs)
Handles ListBox1.SelectedIndexChanged
accTotal = accTotal - (Val(ListBox1.SelectedItem))
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
Label10.Text = "累計:$" & accTotal & "元"
End Sub
End Class
程式說明
第2行定義總金額及累計金額的參數。
第13行求出單筆交易的總金額。
第15行讓總金額>20000時RadioButton3 (即>20000元*
0.75鈕)自動選取。
第16-18行處理折扣動作。
第20行累加至累計金額。
第22行把單筆交易記錄至ListBox1中。