一 没用模式前
Code
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 Demo
{
public partial class main : Form
{
public main()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
double price = Convert.ToDouble(textBox1.Text);
double num = Convert.ToInt32(textBox2.Text);
string content = comboBox1.SelectedValue.ToString();
listBox1.Items.Add("商品:" + "" + " 单价:" + price + " 数量:" + num + " 合计:" + sum(price, num, content) + " 打折情况:" + content);
double m = 0;
for (int i = 0; i < listBox1.Items.Count; i++)
{
m += Convert.ToDouble(sum(price, num, content));
}
label4.Text = "RMB " + Convert.ToString(m) + "元";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
public double sum(double price, double num, string content)
{
Strategy.BaseInterface IFBase;
double allPrice = price * num;
switch (content)
{
case "全价":
return allPrice;
break;
case "八折":
return allPrice * 0.8;
break;
case "六折":
return allPrice * 0.6;
break;
case "买一送一":
return allPrice;
break;
case "满二百减一百":
if (allPrice >= 200)
{
int div = Convert.ToInt32(allPrice / 200);
return allPrice - div * 100;
}
else
{
return allPrice;
}
break;
default :
return 0;
break;
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
listBox1.Items.Clear();
label4.Text = "";
}
private void Form1_Load(object sender, EventArgs e)
{
SqlDataBase.DB db = new SqlDataBase.DB();
comboBox1.DataSource = db.ComBind();
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}
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 Demo
{
public partial class main : Form
{
public main()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
double price = Convert.ToDouble(textBox1.Text);
double num = Convert.ToInt32(textBox2.Text);
string content = comboBox1.SelectedValue.ToString();
listBox1.Items.Add("商品:" + "" + " 单价:" + price + " 数量:" + num + " 合计:" + sum(price, num, content) + " 打折情况:" + content);
double m = 0;
for (int i = 0; i < listBox1.Items.Count; i++)
{
m += Convert.ToDouble(sum(price, num, content));
}
label4.Text = "RMB " + Convert.ToString(m) + "元";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
public double sum(double price, double num, string content)
{
Strategy.BaseInterface IFBase;
double allPrice = price * num;
switch (content)
{
case "全价":
return allPrice;
break;
case "八折":
return allPrice * 0.8;
break;
case "六折":
return allPrice * 0.6;
break;
case "买一送一":
return allPrice;
break;
case "满二百减一百":
if (allPrice >= 200)
{
int div = Convert.ToInt32(allPrice / 200);
return allPrice - div * 100;
}
else
{
return allPrice;
}
break;
default :
return 0;
break;
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
listBox1.Items.Clear();
label4.Text = "";
}
private void Form1_Load(object sender, EventArgs e)
{
SqlDataBase.DB db = new SqlDataBase.DB();
comboBox1.DataSource = db.ComBind();
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}
利用模式