/// <summary> /// 生成默认套餐数据 /// </summary> private void InitSets() { //创建1种默认套餐对象 items = new Dictionary <string, HealthCheckItem>(); items.Add(height.Name, height); items.Add(weight.Name, weight); items.Add(liverFun.Name, liverFun); setA = new HealthCheckSet("入学体检", items); //计算套餐价格 setA.CalcPrice(); this.HealthSet.Add("入学体检", setA); }
//新建套餐 private void btnOK_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.txtHealthName.Text.Trim())) { MessageBox.Show("请输入套餐名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } HealthCheckSet Hch = new HealthCheckSet(); this.HealthSet.Add(this.txtHealthName.Text.Trim(), Hch); this.InitHealthSetList(); this.cboSets.SelectedIndex = this.HealthSet.Count; MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// 填充套餐的DataGridView /// </summary> /// <param name="set"></param> private void UpdateSet(HealthCheckSet set) { //注意:Dictionary的Values转换为List,可以使用ToList() .该方法必须引入命名空间System.Linq;(.NET FrameWork 4) this.dgvHealthList.DataSource = new BindingList <HealthCheckItem>(set.Items.Values.ToList()); }