選購系統

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 DataGridView
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
DataGridViewRowCollection rows = dataGridViewmenu.Rows;
rows.Add(new Object[] { "招牌奶茶", 30 });
rows.Add(new Object[] { "珍珠奶茶", 35 });
rows.Add(new Object[] { "ㄉㄨㄞㄉㄨㄞ奶茶", 35 });
rows.Add(new Object[] { "仙草奶茶", 35 });
rows.Add(new Object[] { "椰果奶茶", 35 });
rows.Add(new Object[] { "幽浮奶茶", 35 });
rows.Add(new Object[] { "方圓奶茶", 35 });
rows.Add(new Object[] { "烏龍烤奶茶", 35 });
rows.Add(new Object[] { "拿鐵紅茶", 40 });
rows.Add(new Object[] { "蜂蜜鮮奶仙草凍", 50 });
rows.Add(new Object[] { "焦糖布丁奶茶", 40 });
rows.Add(new Object[] { "玫瑰奶綠", 40 });
rows.Add(new Object[] { "巧克力奶茶", 35 });
}

private void labelnumber_Click(object sender, EventArgs e)
{

}

private void buttonadd_Click(object sender, EventArgs e)
{
String name = label1.Text;
double price = double.Parse(textBox1.Text);
double number = (double)numericUpDown1.Value;
double sum = price * number;
textBox2.Text = sum.ToString();
dataGridVieworder.Rows.Add(new Object[] { name, price, number, sum });
numericUpDown1.Value = 0 ;

}

private void dataGridViewmenu_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridViewmenu.Rows[e.RowIndex].Cells[0].Value == null)
return;
label1.Text = dataGridViewmenu.Rows[e.RowIndex].Cells[0].Value.ToString();
textBox1.Text = dataGridViewmenu.Rows[e.RowIndex].Cells[1].Value.ToString();
}

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{

double price = double.Parse(textBox1.Text);
double number = (double)numericUpDown1.Value;
double sum = price * number;
textBox2.Text = sum.ToString();
}
private void calculate()
{
double sum = 0.0;
for (int i = 0; i < dataGridVieworder.Rows.Count; i++)
{
DataGridViewRow row = dataGridVieworder.Rows[i];
if (row.Cells[0].Value != null)
sum += (double)row.Cells[3].Value;
}
textBoxtotal.Text = sum.ToString();
}

private void buttonsum_Click(object sender, EventArgs e)
{
calculate();
}

private void button1_Click(object sender, EventArgs e)
{
String name = label1.Text;
double price = double.Parse(textBox1.Text);
double number = (double)numericUpDown1.Value;
double x = double.Parse(textBox2.Text);
x = x - 5;
textBox2.Text = x.ToString();
dataGridVieworder.Rows.Add(new Object[] { name, price, number, x });
numericUpDown1.Value = 0;

}

private void button2_Click(object sender, EventArgs e)
{
String name = label1.Text;
double price = double.Parse(textBox1.Text);
double number = (double)numericUpDown1.Value;
double x = double.Parse(textBox2.Text);
x = x - 10;
textBox2.Text = x.ToString();
dataGridVieworder.Rows.Add(new Object[] { name, price, number, x });
numericUpDown1.Value = 0;
}

private void button3_Click(object sender, EventArgs e)
{
String name = label1.Text;
double price = double.Parse(textBox1.Text);
double number = (double)numericUpDown1.Value;
double x = double.Parse(textBox2.Text);
x = x - 15;
textBox2.Text = x.ToString();
dataGridVieworder.Rows.Add(new Object[] { name, price, number, x });
numericUpDown1.Value = 0;
}
}
}