下載/瀏覽

Download Report

Transcript 下載/瀏覽

計算機程式及實習
期末報告PPT製作
題目:披薩店結帳系統
南台科技大學
機械工程系
自控一乙
學號:4A012122
姓名:林忠翰
目錄
• 表單設計-解題分析
• 版面配置-屬性設定
• 程式碼設計
• 程式說明
• 心得
• 參考文獻
題目說明:披薩店結帳
設計披薩店結帳系統,
填寫數量,按下計算
鈕之後,即會顯示總
金額。按下「清除」
按鍵,再輸入數量3,
並點選「會員價打9
折」,再按下「計算」
按鍵,便會得到打完
九折後的540交易金
額。
程式開始畫面-改總匯披薩數量
• 改總匯披薩數量為1按「計算」按鈕後,得到第1
筆200金額資料。
再輸入燻雞蘑菇披薩的數量為5
• 按「清除」按鈕,
清除剛剛的總匯披
薩後,再輸入燻雞
蘑菇披薩的數量為
5,並點選「特定
客戶打8折」,再
按下「計算」鈕,
得到打8折後的那
一筆800金額資料。
滿2000元打75折
•
在總匯披薩旁的數
量欄中輸入15並按
下「計算」鈕。
•
發現因為超過2000
元,所以畫面中的
滿2000打75折的選
項,已經在程式運
作下自動選取,得
到2250的交易金額。
加大多100元
• 在海鮮披薩旁的數
量欄中輸入5的數
量,並勾選加大選
項,將會把數量5
的海鮮披薩都加大,
的到一筆1500的金
額。
版面配置
屬性設定
披薩種類
Label1
Label2
Label3
價格
TBoxPrice1
TBoxPrice2
TBoxPrice3
數量
TBoxQty1
TBoxQty2
TBoxQty3
加大
CheckBox1
CheckBox2
CheckBox3
優惠專案
GroupBox1
RadioButton1
RadioButton2
RadioButton3
列出點餐
ListBox1
金額
Label6
Label7
Button2
Button1
物件
屬性
設定
說明
TBoxPrice1 Text
總匯披薩價格
TBoxPrice2 Text
燻雞蘑菇披薩價格
TBoxPrice3 Text
海鮮披薩價格
TBoxQty1 Text
總匯披薩數量
TBoxQty2 Text
燻雞蘑菇披薩數量
TBoxQty3 Text
海鮮披薩數量
RadioButton1
Text
會員價打9折
RadioButton2
Text
特定客戶打8折
RadioButton3
Text
滿2000打75折
Button1
Text
清除
Button2
Text
計算
ListBox1
由程式控制
程式碼設計
1
Public Class Form1
2
Dim total, total1, total2, total3, 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)
7
Label6.ForeColor = Color.Red
8
total = 0
9
accTotal = 0
10
End Sub
12
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
13
total = Val(TBoxPrice1.Text) * Val(TBoxQty1.Text) + Val(TBoxPrice2.Text) *
Val(TBoxQty2.Text) + Val(TBoxPrice3.Text) * Val(TBoxQty3.Text)
14
total1 = Val(TBoxPrice1.Text) * Val(TBoxQty1.Text)
15
total2 = Val(TBoxPrice2.Text) * Val(TBoxQty2.Text)
16
total3 = Val(TBoxPrice3.Text) * Val(TBoxQty3.Text)
17
If total And CheckBox1.Checked Then
total1 = (Val(TBoxPrice1.Text) + 100) * Val(TBoxQty1.Text)
18
End If
If total And CheckBox2.Checked Then
total2 = (Val(TBoxPrice2.Text) + 100) * Val(TBoxQty2.Text)
19
End If
If total And CheckBox3.Checked Then
total3 = (Val(TBoxPrice3.Text) + 100) * Val(TBoxQty3.Text)
20
End If
total = total1 + total2 + total3
21
If total > 2000 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
22
Label6.Text = “$” & total & “元﹐” accTotal = accTotal + total
Label7.Text = "累計:$" & accTotal & "元﹐"
ListBox1.Items.Add(total & "-->" & "總匯披薩" & TBoxPrice1.Text & "*" & TBoxQty1.Text
& "燻雞蘑菇披薩" & TBoxPrice2.Text & "*" & TBoxQty2.Text & "海鮮披薩" &
TBoxPrice3.Text & "*" & TBoxQty3.Text)
23
End Sub
25 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
26 TBoxQty1.Text = 0
27 TBoxQty2.Text = 0
28 TBoxQty3.Text = 0
29 total = 0
30 Label6.Text = "$" & total & "元﹐"
31 End Sub
33
Private Sub ListBox1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseUp
34
accTotal = accTotal - (Val(ListBox1.SelectedItem))
35
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
36
Label7.Text = "累計:$" & accTotal & "元﹐"
37
End Sub
38
End Class
程式說明
•
Dim total, total1, total2, total3, accTotal As Integer →定義總金額及累計金額的參數。
•
total = Val(TBoxPrice1.Text) * Val(TBoxQty1.Text) + Val(TBoxPrice2.Text) * Val(TBoxQty2.Text)
+ Val(TBoxPrice3.Text) * Val(TBoxQty3.Text) →算出單筆交易的總金額。
•
If total > 2000 Then RadioButton3.Checked = True →總金額>2000元時RadioButton3 (即
滿2000元打75折按鈕)自動選取。
•
If RadioButton1.Checked = True Then total = total * 0.9 →進行會員價打9折的動作。
•
If RadioButton2.Checked = True Then total = total * 0.8 →進行特定客戶打8折的動作。
•
If RadioButton3.Checked = True Then total = total * 0.75 →進行滿2000元打75折的動作。
•
•
accTotal = accTotal + total →累加至累計金額。
ListBox1.Items.Add(total & “-->” & “總匯披薩” & TBoxPrice1.Text & “*” & TBoxQty1.Text & “燻
雞蘑菇披薩" & TBoxPrice2.Text & "*" & TBoxQty2.Text & "海鮮披薩" & TBoxPrice3.Text &
"*" & TBoxQty3.Text)→把單筆交易記錄至ListBox1中。
•
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
•
total = 0
•
Label6.Text = "$" & total & "元﹐"
•
End Sub →行為「清除」按鈕的歸零動作。
•
Private Sub ListBox1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseUp
•
accTotal = accTotal - (Val(ListBox1.SelectedItem))
•
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
•
Label7.Text = "累計:$" & accTotal & "元﹐"
•
End Sub
•
End Class→處理利用滑鼠在ListBox1上點選時,放開滑鼠左鍵的刪除記錄動作。
•
accTotal = accTotal - (Val(ListBox1.SelectedItem)) →扣除該筆記錄在累加值中的數值。
•
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) →實際於ListBox1中刪除,刪除該筆
記錄。
•
Label7.Text = “累計:$” & accTotal & “元﹐”→把更正後的累加值,再度顯示出來。
心得
這次的課題,有些難度,但在經過同學的指導和自己
實際去操作後才漸漸了解其中的方法,感謝老師這
學期教我們VB程式的應用,讓我們了解這個第一次
接觸到的程式,能夠利用這個程式設計出更多更不
同的東西,雖然這學期學得只是VB的基本應用,並
在製作程式的過程中也遇到不少阻礙,不過還是很
想要去破解這些難題,但在順利的解決之後也就變
得很有成就感,VB真的是一個很好玩的程式,希望
以後還能在VB上再做延伸,這樣就能自己寫出自己
想要的程式了,最後謝謝老師你上課認真、用心、
風趣的講解!!
參考文獻
• Visual Basic程式設計 余忠潔 全華2010