簡單的點餐系統
阿新 • • 發佈:2017-12-07
str lec count 組合 move count-1 添加 add box
使用了menuStrip 菜單組件,">"為button1,"<"為button2,"下單"為button3 ,兩個ListBox
畫好菜單後
private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < listBox1.SelectedItems.Count; i++) //選擇菜品然後計數 { string menu = listBox1.SelectedItems[i].ToString(); listBox2.Items.Add(menu); } } private void button2_Click(object sender, EventArgs e) { for (int i = listBox2.SelectedItems.Count-1; i >=0 ; i--) //重最後一個開始刪除 { listBox2.Items.Remove(listBox2.SelectedItems[i]); } }
private void SetListMenu(string[] data) //定義一個方法 { listBox1.Items.Clear(); for (int i = 0; i < data.Length; i++) { listBox1.Items.Add(data[i]); } }
插入菜品
private void 中餐ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "辣子雞丁", "紅燒排骨", "麻婆豆腐", "香脆裏脊", "糖醋排骨", "宮保雞丁", "香酥雞", "醋溜白菜", "小雞燉蘑菇", "豬肉燉粉條", "芹菜香幹", "魚香肉絲" }; SetListMenu(data); } private void 西餐ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "牛排", "豬扒", "意大利面", "雞扒", "香辣雞腿堡", "培根漢堡" }; SetListMenu(data); } private void 紅酒ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "拉斐", "長城幹紅", "華夏幹紅", "張裕" }; SetListMenu(data); } private void 飲料ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "雪碧", "可樂", "奶茶", "紅茶", "咖啡", "果汁", "開水" }; SetListMenu(data); } private void 湯ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "冬瓜排骨湯", "羅宋湯", "老鴨湯", "老母雞湯", "紫菜蛋花湯", "三鮮湯" }; SetListMenu(data); } private void 冰激淩ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "草莓", "巧爾滋", "聖代", "哈根達斯" }; SetListMenu(data); } private void 點心ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "巧克力蛋糕", "草莓蛋糕", "蘋果派", "水果" }; SetListMenu(data); } private void 小食ToolStripMenuItem_Click(object sender, EventArgs e) { string[] data = { "漢堡", "炸雞腿", "薯條", "雞塊" }; SetListMenu(data); }
前面有幾個組合菜品沒有添加,因為我沒有想到有什麽菜!!!
最後面下單顯示
private void button3_Click(object sender, EventArgs e) { string msg = string.Format("\t您共點餐{0}項\n\n點餐時間:{1}", listBox2.Items.Count,DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); MessageBox.Show(msg); }
簡單的點餐系統