門票銷售計算器

akaohiiragi發表於2009-09-24

我只是個初學者而已。

===========================

1.門票型別的選擇:成人票,兒童票,打折票。
2.選擇打折票的時候執行3種打折方式:9折,8折,6.5折。
3.選擇門票型別時,給出相應的票價。
4.根據打折程度,顯示票價。
5.允許輸入購票數量。
6.根據購票數量,自動計算應付款,並顯示(購票數*票價=應付款)
7.允許輸入當前預付購票款
8.自動計算顯示找零。
9.打折票預設為9折。


=====================================

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ticket
{
    public partial class Form1 : Form
    {
        private const double CommonPrice = 45.00;
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();

        }

        private void radioButton1_Click(object sender, EventArgs e)
        {
            Price_textBox.Text = string.Format("{0:f2}", CommonPrice * 90 / 100);
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            Price_textBox.Text = string.Format("{0:f2}", CommonPrice * 80/ 100);
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            Price_textBox.Text = string.Format("{0:f2}", CommonPrice * 65/ 100);
        }

        private void ticket_type_ComboBOX_SelectedValueChanged(object sender, EventArgs e)
        {
            //開啟購票數量與購票款輸入功能

            total_ticket_textBox.ReadOnly = false;
            patment_textBox.ReadOnly=false;

            //清空“應收款”,“找零“顯示內容
            receiving_textBox.Text = "";
            balance_textBox.Text = "";
            //設定折扣不可用
            discount_groupBox.Enabled = false;
                      
            //判斷當前選擇票的型別
            switch(ticket_type_ComboBOX.SelectedIndex)
            {
                case 0:
                    Price_textBox.Text = string.Format("{0:f2}", CommonPrice);
                        break;
                case 1:
                        Price_textBox.Text = string.Format("{0:f2}", CommonPrice * 50 / 100);
                    break;
                case 2:
                    discount_groupBox.Enabled=true;
                    radioButton1.Checked = true;
                    Price_textBox.Text = string.Format("{0:f2}", CommonPrice * 90 / 100);
                    break;
                  
            }


        }

        private void button1_Click(object sender, EventArgs e)
        {
            double payment, receiving, price,balance;
            int tickets;
            try
            {
                tickets = Int32.Parse(total_ticket_textBox.Text);
                payment = double.Parse(patment_textBox.Text);
                price = double.Parse(Price_textBox.Text);

                //計算應該收款並輸出
                receiving = tickets * price;
                receiving_textBox.Text = string.Format("{0:f2}", receiving);
                //計算並輸出找零
                balance = payment - receiving;
                balance_textBox.Text = string.Format("{0:f2}", balance);
            }
            catch
            {
                MessageBox.Show("輸入有錯誤!請檢查購票型別,折扣。數量與應付款");
                return;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }


    }
}

相關文章