作者在 2011-09-28 20:48:08 发布以下内容
闲着无聊做了个门票销售计算器
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 门票销售计算器
{
public partial class Form2 : Form
{
private double commanPrice;
public Form2()
{
InitializeComponent();
}
{
public partial class Form2 : Form
{
private double commanPrice;
public Form2()
{
InitializeComponent();
}
private void buttonClose_Click(object sender, EventArgs e)
{
if (MessageBox.Show("您确定要结束门票购买马?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Application.Exit();
}
}
{
if (MessageBox.Show("您确定要结束门票购买马?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Application.Exit();
}
}
private void Form2_Load(object sender, EventArgs e)
{
commanPrice = 45;
discount_groupBox.Enabled = false;
}
{
commanPrice = 45;
discount_groupBox.Enabled = false;
}
private void radioNine_CheckedChanged(object sender, EventArgs e)
{
receiving_textBox.Clear();
payment_textBox.Clear();
balance_textBox.Clear();
total_ticket_textBox.Clear();
price_textBox.Text = String.Format("{0:F2}", commanPrice * 0.9);
}
{
receiving_textBox.Clear();
payment_textBox.Clear();
balance_textBox.Clear();
total_ticket_textBox.Clear();
price_textBox.Text = String.Format("{0:F2}", commanPrice * 0.9);
}
private void radioEight_CheckedChanged(object sender, EventArgs e)
{
receiving_textBox.Clear();
payment_textBox.Clear();
balance_textBox.Clear();
total_ticket_textBox.Clear();
price_textBox.Text = String.Format("{0:F2}", commanPrice * 0.8);
}
{
receiving_textBox.Clear();
payment_textBox.Clear();
balance_textBox.Clear();
total_ticket_textBox.Clear();
price_textBox.Text = String.Format("{0:F2}", commanPrice * 0.8);
}
private void radioSixFive_CheckedChanged(object sender, EventArgs e)
{
receiving_textBox.Clear();
payment_textBox.Clear();
balance_textBox.Clear();
total_ticket_textBox.Clear();
price_textBox.Text = String.Format("{0:F2}", commanPrice * 0.65);
}
{
receiving_textBox.Clear();
payment_textBox.Clear();
balance_textBox.Clear();
total_ticket_textBox.Clear();
price_textBox.Text = String.Format("{0:F2}", commanPrice * 0.65);
}
private void ticket_type_ComBox_SelectedIndexChanged(object sender, EventArgs e)
{
double price;
total_ticket_textBox.ReadOnly = false;
payment_textBox.ReadOnly = false;
receiving_textBox.Clear();
payment_textBox.Clear();
balance_textBox.Clear();
total_ticket_textBox.Clear();
discount_groupBox.Enabled = false;
switch (ticket_type_ComBox.SelectedIndex)
{
case 0:
price_textBox.Text = string.Format("{0:F2}", commanPrice);
break;
case 1:
price = commanPrice * 50.0 / 100.0;
price_textBox.Text = string.Format("{0:F2}",price);
break;
case 2:
discount_groupBox.Enabled = true;
radioNine.Checked = true;
price = commanPrice * 90.0 / 100.0;
price_textBox.Text = string.Format("{0:F2}",price);
break;
}
}
{
double price;
total_ticket_textBox.ReadOnly = false;
payment_textBox.ReadOnly = false;
receiving_textBox.Clear();
payment_textBox.Clear();
balance_textBox.Clear();
total_ticket_textBox.Clear();
discount_groupBox.Enabled = false;
switch (ticket_type_ComBox.SelectedIndex)
{
case 0:
price_textBox.Text = string.Format("{0:F2}", commanPrice);
break;
case 1:
price = commanPrice * 50.0 / 100.0;
price_textBox.Text = string.Format("{0:F2}",price);
break;
case 2:
discount_groupBox.Enabled = true;
radioNine.Checked = true;
price = commanPrice * 90.0 / 100.0;
price_textBox.Text = string.Format("{0:F2}",price);
break;
}
}
private void total_ticket_textBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(13))
{
int tickets = Int32.Parse(total_ticket_textBox.Text);
double price = double.Parse(price_textBox.Text);
double receiving = tickets * price;
receiving_textBox.Text = string.Format("{0:f2}", receiving);
payment_textBox.Focus();
}
}
{
if (e.KeyChar == Convert.ToChar(13))
{
int tickets = Int32.Parse(total_ticket_textBox.Text);
double price = double.Parse(price_textBox.Text);
double receiving = tickets * price;
receiving_textBox.Text = string.Format("{0:f2}", receiving);
payment_textBox.Focus();
}
}
private void buttonBuy_Click(object sender, EventArgs e)
{
try
{
int tickets = Int32.Parse(total_ticket_textBox.Text);
double price = double.Parse(price_textBox.Text);
double payment = double.Parse(payment_textBox.Text);
double receiving = tickets * price;
receiving_textBox.Text = string.Format("{0:f2}", receiving);
double balance = payment - receiving;
balance_textBox.Text = string.Format("{0:f2}", balance);
}
catch(Exception )
{
MessageBox.Show("输入有错!请检查购票类型、折扣值、购票数量或实付款!", "错误提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
{
try
{
int tickets = Int32.Parse(total_ticket_textBox.Text);
double price = double.Parse(price_textBox.Text);
double payment = double.Parse(payment_textBox.Text);
double receiving = tickets * price;
receiving_textBox.Text = string.Format("{0:f2}", receiving);
double balance = payment - receiving;
balance_textBox.Text = string.Format("{0:f2}", balance);
}
catch(Exception )
{
MessageBox.Show("输入有错!请检查购票类型、折扣值、购票数量或实付款!", "错误提示!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
}
}