体验套餐管理系统
一:项目总体效果图
二:首先建成两个类
1.套餐类:HealthCheckSet(其中代码)
public class HealthCheckSet
{
//HealthCheckItem的集合
public List<HealthCheckItem> Items { get; set; }
//套餐价格
public string Price { get; set; }
//套餐名称
public string Namee { get; set; }
//构造方法
public HealthCheckSet(string name, List<HealthCheckItem> items)
{
this.Namee = name;
this.Items = items;
}
public void CalcPrice()
{
int totalPrice = 0;
foreach (HealthCheckItem item in Items)
{
totalPrice += int.Parse(item.Price);
}
this.Price = totalPrice.ToString();
}
}
2.项目名称类 HealthCheckItem(其中代码)
public class HealthCheckItem
{
//项目描述
public string Description { get; set; }
//项目名称
public string Nameee{ get; set; }
//项目价格
public string Price { get; set; }
public HealthCheckItem(string nameee, string description, string price)
{
this.Nameee = nameee;
this.Description = description;
this.Price = price;
}
}
三:创建一个对象接收其中全部项目名称,价格,描述
HealthCheckItem list1, list2, list3, list4, list5, list6, list7;
public static List<HealthCheckItem> List = new List<HealthCheckItem>();
//创建一个新的对象来接受自己选定的检查项的所有项
HealthCheckSet healthCheckset;
List<HealthCheckSet> ite = new List<HealthCheckSet>();
List<HealthCheckItem> items = new List<HealthCheckItem>();
public void Bick()
{
comboBox1.Items.Add("请选择");
comboBox2.Items.Add("请选择");
list1 = new HealthCheckItem("身高", "检查身高多少", "5");
list2 = new HealthCheckItem("体重", "检查体重多少", "5");
list3 = new HealthCheckItem("视力", "检查视力多少", "10");
list4 = new HealthCheckItem("听力", "检查听力多少", "5");
list5 = new HealthCheckItem("肝功能", "检查肝功能多少", "60");
list6 = new HealthCheckItem("B超", "检查B超多少", "60");
list7 = new HealthCheckItem("心电图", "检查心电图多少", "50");
items.Add(list1);
items.Add(list2);
items.Add(list3);
items.Add(list4);
items.Add(list5);
items.Add(list6);
items.Add(list7);
foreach(HealthCheckItem item in items){
comboBox1.Items.Add(item.Nameee);
}
四:实现入学体检套餐
//学生人学体检
All.Add(list1);
All.Add(list2);
All.Add(list3);
healthCheckset = new HealthCheckSet("入学检测", All);
ite.Add(healthCheckset);
// CalcPrice();
comboBox2.Items.Add(healthCheckset.Namee);
if (comboBox1.Text.Trim() == "请选择")
{
dataGridView1.DataSource = new BindingList<HealthCheckItem>();
}
//this.bntName1.Enabled = false;
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
string a = this.comboBox2.Text;
this.lblName2.Text = a;
if (a != "请选择")
{
//All.Add(list1);
//All.Add(list2);
//All.Add(list3);
foreach (HealthCheckSet item in ite)
{
healthCheckset = item;
lblName2.Text = item.Namee;
item.CalcPrice();
label3.Text = item.Price;
this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(All);
break;
}
this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(All);
}
else if (a=="请选择")
{
this.lblName2.Text = null;
}
}
五:实现对套餐名进行赋值
tring a = this.comboBox2.Text;
this.lblName2.Text = a;
if (a != "请选择")
{
//All.Add(list1);
//All.Add(list2);
//All.Add(list3);
foreach (HealthCheckSet item in ite)
{
healthCheckset = item;
lblName2.Text = item.Namee;
item.CalcPrice();
label3.Text = item.Price;
this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(All);
break;
}
this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(All);
}
else if (a=="请选择")
{
this.lblName2.Text = null;
}
六:实现删除功能
private void bntShan_Click(object sender, EventArgs e)
{
string d = dataGridView1.SelectedRows[0].Cells["Nameee"].Value.ToString();
DialogResult delete;
delete = MessageBox.Show("确定要删除吗?", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (delete == DialogResult.Yes)
{
foreach (HealthCheckItem item in All)
{
if (item.Nameee == d)
{
All.Remove(item);
MessageBox.Show("删除成功!");
break;
}
}
}
healthCheckset.CalcPrice();
label3.Text = healthCheckset.Price;
this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(All);
}
七:实现对添加检查项目名的代码
//添加检查项的方法
List<HealthCheckItem> All = new List<HealthCheckItem>();
public void UqdateChneckitem()
{
string name = comboBox1.Text;
for (int i = 0; i < All.Count;i++ ) {
if(name.Equals(All[i].Nameee)){
MessageBox.Show("已经有检查项了!不能再添加了");
return;
}
}
All.Add(items[comboBox1.SelectedIndex-1]);
this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(All);
}
private void bntName1_Click(object sender, EventArgs e)
{
UqdateChneckitem();
healthCheckset.CalcPrice();
label3.Text = healthCheckset.Price;
}
八:实现价格计算总数:
public void CalcPrice()
{
int totalPrice = 0;
foreach (HealthCheckItem item in Items)
{
totalPrice += int.Parse(item.Price);
}
this.Price = totalPrice.ToString();
}
九:在做这个项目思路一定要清晰,不然会很乱,影响完成别项!