下載/瀏覽

Download Report

Transcript 下載/瀏覽

計算機程式及實習
課堂作業之口頭報告ppt製作
題目:精緻排餐結帳系統
南台科技大學
機械工程系
奈米一乙
學號:49914096
老師:謝慶存
題目說明:精緻排餐結帳
試設計快餐店結帳
系統,填寫數量再按下
計算鈕之後,即會顯示
結帳總金額。按「清除」
按鈕,再輸入數量,並
點選「老客戶*0.95」,
再按下「計算」鈕,得
到打95折後的那一筆總
金額資料。
程式開始畫面-改雞排數量
改雞排數量為1
按「結帳」按鈕後,
得到第1筆結帳資
料。
再輸入牛排的數量為2
按「清除」按鈕,
清除剛剛的雞排一份後,
再輸入牛排的數量為2,
並點選「老客戶*0.95」,
再按下「計算」鈕,得
到打95折後的那一筆228
元資料。
超過2500元*0.85
在豬排旁的數量欄中
輸入50並按下
「計算」鈕。
發現因為超過2500元,
所以畫面中的
>2500*0.85選項,
已經在程式運作
下自動選取。
刪除用法
假設228元這筆資料是
錯誤的,必須刪除掉。
使用者只需直接以滑鼠
點選這筆資料,這筆資
料就會自動被刪除,同
時,累計值會自動把這
筆資料的228元,從累
計金額中扣除。
版面配置
屬性設定
排餐
Label1
Label2
Label3
單價
TextBox
TextBox
TextBox
數量
TextBox
TextBox
TextBox
優待
GroupBox1
RadioButton1
RadioButton2
RadioButton3
列出點餐
ListBox1
金額
Label6
Label7
Button1
Button2
程式碼設計
1 Public Class Form1
2
Dim total, accTotal As Integer
3
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
4
Label6.Text = "$" & total & "元"
5
Label7.Text = "累計:$" & accTotal & "元"
6
Label6.Font = New Font("新細明體", 24)
Label6.ForeColor = Color.Red
7
total = 0
8
9
accTotal = 0
End Sub
10
11
12
13
14
15
16
17
18
19
20
21
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
total = Val(TextBox1.Text) * Val(TextBox4.Text) + Val(TextBox2.Text) *
Val(TextBox5.Text) + Val(TextBox3.Text) * Val(TextBox6.Text)
If total > 2500 Then RadioButton3.Checked = True
If RadioButton1.Checked = True Then total = total * 0.95
If RadioButton2.Checked = True Then total = total * 0.8
If RadioButton3.Checked = True Then total = total * 0.85
Label6.Text = "$" & total & "元"
accTotal = accTotal + total
Label7.Text = "累計:$" & accTotal & "元"
ListBox1.Items.Add(total & "-->" & "雞排" & TextBox1.Text & "*" &
TextBox4.Text & "牛排" & TextBox2.Text & "*" & TextBox5.Text & "豬排" &
TextBox3.Text & "*" & TextBox6.Text)
End Sub
22
Private Sub Button2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button2.Click
23
TextBox4.Text = 0
24
TextBox5.Text = 0
25
TextBox6.Text = 0
26
total = 0
27
28
Label6.Text = "$" & total & "元"
End Sub
29 Private Sub ListBox1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseUp
30
accTotal = accTotal - (Val(ListBox1.SelectedItem))
31
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
32
Label7.Text = "累計:$" & accTotal & "元“
33
End Sub
34 End Class
程式說明
第2行定義總金額及累計金額的參數。
第12行求出單筆交易的總金額。
第13行讓總金額>2500時RadioButton3 (即
>2500元*0.85鈕)自動選取。
第14-16行處理折扣動作。
第18行累加至累計金額。
第20行把單筆交易記錄至ListBox1中。
第22-28行為「清除」按鈕的歸零動作。
第29-34行處理利用滑鼠在ListBox1上點選
時,放開滑鼠左鍵的刪除記錄動作。
第30行扣除該筆記錄在累加值中的數值。
第31行實際於ListBox1中刪除,刪除該筆
記錄。
第32行把更正後的累加值,再度顯示出來