C# 门票销售器

来源:互联网 发布:sql自连接查询例子 编辑:程序博客网 时间:2024/03/29 13:23

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 售票器
{
    public partial class Form1 : Form
    {
        private const float price = 50;  //在此强制输入门票单价
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double fukuan, yingfukuan, zhaoling, price; //付款(fukuan),应付款(yingfukuan),找零(zhaoling),单价(price)
            int shuliang;
            try
            {
                fukuan = double.Parse(textBox2.Text);
                shuliang = Int32.Parse(textBox1.Text);
                price = double.Parse(textBox5.Text);
            }
            catch (System.FormatException)
            {
                MessageBox.Show("");
                return;
            }
            yingfukuan = shuliang * price;
            textBox3.Text = string.Format("{0:f2}", yingfukuan);
            zhaoling = fukuan - yingfukuan;
            textBox4.Text = string.Format("{0:f2}", zhaoling);

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //开启购票数量和购票款输入功能
            textBox1.ReadOnly = false;
            textBox2.ReadOnly = false;
            //清空“应收款”和“找零”显示内容
            textBox3.Text = "";
            textBox4.Text = "";
            //置折扣设置不可用
            groupBox1.Enabled = false;
            //判断当前选择的是哪种票
            switch (comboBox1.SelectedIndex)
            {
                case 0:   //成人票
                    textBox5.Text = string.Format("{0:f2}", price);
                    break;
                case 1:  //儿童票
                    textBox5.Text = string.Format("{0:f2}", price * 0.5f);
                    break;
                case 2:  //折扣票
                    groupBox1.Enabled = true;
                    radioButton1.Checked = true;
                    textBox5.Text = string.Format("{0:f2}", price * 0.9f);
                    break;

            }


        }

        //分别单击九折,八折,六五折单选按钮

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            textBox5.Text = string.Format("{0:f2}", price * 0.9f);
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            textBox5.Text = string.Format("{0:f2}", price * 0.8f);
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {
            textBox5.Text = string.Format("{0:f2}", price * 0.65f);
        }
    }
}

原创粉丝点击