体验套餐类!!
///
/// 体验套餐类!!
///
public class HealthCheckSet
{
private List
internal List
{
get { return _items; }
set { _items = value; }
}
private int _price; //套餐价格!!
public int Price
{
get { return _price; }
set { _price = value; }
}
private string _name; //套餐名称!!
public string Name
{
get { return _name; }
set { _name = value; }
}
//采用泛型集合List保存所有的体验项目!!
List
//采用泛型集合List保存套餐中的体验项目!!
List
///
/// 套餐价格计算方法!!
///
public void CalcPrice()
{
int totalPrice = 0;
foreach (HealthCheckItem item in this.Items)
{
totalPrice += item.Price;
}
this.Price = totalPrice;
}
}
检查项目类!
///
/// 检查项目类!!
///
public class HealthCheckItem
{
///
/// 带参构造方法!!
///
public HealthCheckItem(string name,string desc,int price)
{
this.Description = desc;
this.Name = name;
this.Price = price;
}
private string _description; //项目描述!!
public string Description
{
get { return _description; }
set { _description = value; }
}
private string _name; //项目名称!!
public string Name
{
get { return _name; }
set { _name = value; }
}
private int _price; //项目价格!!
public int Price
{
get { return _price; }
set { _price = value; }
}
}
主窗体!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Chapter05
{
public partial class FrmMain : Form
{
public HealthCheckSet healthset;
//采用泛型集合List保存所有的体验项目!!
public List
//保存套餐中的体验项目!!
public List
//字典存套餐!!
public Dictionary<string, HealthCheckSet> HealthSet = new Dictionary<string, HealthCheckSet>();
public FrmMain()
{
InitializeComponent();
}
#region 初始化信息!!
///
/// 初始化信息!!
///
public void Init()
{
HealthCheckItem hci = new HealthCheckItem( "身高","用于检查身高", 5);
HealthCheckItem hci1 = new HealthCheckItem( "体重","用于检查体重", 5);
HealthCheckItem hci2 = new HealthCheckItem("肝功能","用于检查肝功能", 30);
HealthCheckItem hci3 = new HealthCheckItem("B超","用于B超检查", 50);
HealthCheckItem hci4 = new HealthCheckItem( "视力","用于检查眼睛", 5);
HealthCheckItem hci5 = new HealthCheckItem( "听觉","用于检查听觉", 5);
HealthCheckItem hci6 = new HealthCheckItem( "11","肝功能", 30);
HealthCheckItem hci7 = new HealthCheckItem( "B213","B超检查", 50);
AllItem.Add(hci);
AllItem.Add(hci1);
AllItem.Add(hci2);
AllItem.Add(hci3);
AllItem.Add(hci4);
AllItem.Add(hci5);
AllItem.Add(hci6);
AllItem.Add(hci7);
healthset = new HealthCheckSet();
healthset.Name = "请选择";
healthset.Name = "入学体验";
//healthset.Items.Add(hci4);
//healthset.Items.Add(hci5);
//healthset.Items.Add(hci6);
//healthset.Items.Add(hci7);
//healthset.CalcPrice();
HealthSet.Add("请选择", healthset);
HealthSet.Add("入学体验", healthset);
}
#endregion
#region 刷新方法!!
///
/// 刷新方法!!
///
///
public void Update(HealthCheckSet set)
{
this.dgvHealthList.DataSource = new BindingList
set.CalcPrice();
}
#endregion
#region 套餐列表下拉事件!!
///
/// 套餐列表下拉事件!!
///
///
///
private void cboLiebiao_SelectedIndexChanged(object sender, EventArgs e)
{
string setName = this.cboLiebiao.SelectedItem.ToString();
if(setName == "请选择")
{
this.dgvHealthList.DataSource = new BindingList
lblTaoCanM.Text = "";
lblJiaGe.Text = "";
//控件:删除为不可用状态!!
this.btnQuXiao.Enabled = false;
return;
}
else
{
//设置套餐名称!!
lblTaoCanM.Text = this.HealthSet[setName].Name;
//设置套餐总价!!
lblJiaGe.Text = this.HealthSet[setName].Price.ToString();
//控件:删除为可用状态!!
this.btnQuXiao.Enabled = true;
//绑定DataGirlView!!
this.dgvHealthList.DataSource = new BindingList
}
}
#endregion
#region 窗体加载事件!
///
/// 窗体加载事件!
///
///
///
private void FrmMain_Load(object sender, EventArgs e)
{
//初始化信息!!
Init();
//项目绑定!!
this.cboPgriom.DisplayMember = "name";
this.cboPgriom.DataSource = AllItem;
//套餐循环绑定!
foreach (string key in HealthSet.Keys)
{
this.cboLiebiao.Items.Add(key);
}
//默认选中一行!!
this.cboLiebiao.SelectedIndex = 0;
}
#endregion
private void btnQuXiao_Click(object sender, EventArgs e)
{
//获取选中的项!!
string _key = this.dgvHealthList.SelectedRows[0].Cells[0].Value.ToString();
}
}
}