1.主界面图
2.需要的类
3.加载信息
1 //套餐集合 2 List<HealthCheckSet> list = new List<HealthCheckSet>(); 3 4 //套餐对象 5 HealthCheckSet healthcheckset; 6 7 //cboCheckedList的数据 8 List<HealthCheckItem> list1 = new List<HealthCheckItem>(); 9 10 //加载信息 11 public void Into() 12 { 13 cboComboList.Items.Add("请选择"); 14 cboCheckedList.Items.Add("请选择"); 15 //绑定cboCheckedList数据 16 HealthCheckItem heal1 = new HealthCheckItem("身高", 10, "用于检测身高"); 17 HealthCheckItem heal2 = new HealthCheckItem("体重", 8, "用于检测体重"); 18 HealthCheckItem heal3 = new HealthCheckItem("视力", 120, "用于检测视力"); 19 HealthCheckItem heal4 = new HealthCheckItem("听力", 20, "用于检测听力"); 20 HealthCheckItem heal5 = new HealthCheckItem("肝功能", 50, "用于检测肝功能"); 21 HealthCheckItem heal6 = new HealthCheckItem("B超", 180, "用于检测B超"); 22 HealthCheckItem heal7 = new HealthCheckItem("心电图", 160, "用于检测心电图"); 23 list1.Add(heal1); 24 list1.Add(heal2); 25 list1.Add(heal3); 26 list1.Add(heal4); 27 list1.Add(heal5); 28 list1.Add(heal6); 29 list1.Add(heal7); 30 foreach (HealthCheckItem item in list1) 31 { 32 cboCheckedList.Items.Add(item.Name); 33 } 34 //初始信息 35 List<HealthCheckItem> list2 = new List<HealthCheckItem>(); 36 list2.Add(heal1); 37 list2.Add(heal2); 38 list2.Add(heal3); 39 list2.Add(heal4); 40 list2.Add(heal5); 41 list2.Add(heal6); 42 HealthCheckSet set = new HealthCheckSet("入学检测",list2); 43 list.Add(set); 44 set.CalcPrice(); 45 cboComboList.Items.Add(set.Name); 46 //cboComboList的默认显示,cboCheckedList的默认显示 47 cboComboList.SelectedIndex = 1; 48 cboCheckedList.SelectedIndex = 0; 49 //dgvPro绑定数据 50 dgvPro.DataSource = new BindingList<HealthCheckItem>(list2); 51 }
4.查看功能和删除功能
1 //删除 2 private void btnDeleteList_Click(object sender, EventArgs e) 3 { 4 int count = 0; 5 if(dgvPro.SelectedRows.Count>0) 6 { 7 foreach (HealthCheckItem item in healthcheckset.Items) 8 { 9 if(item.Name==dgvPro.SelectedRows[0].Cells[1].Value.ToString().Trim()) 10 { 11 healthcheckset.Items.RemoveAt(count); 12 MessageBox.Show("删除成功!"); 13 break; 14 } 15 count++; 16 } 17 healthcheckset.CalcPrice(); 18 lblComboPrice.Text = healthcheckset.Price.ToString(); 19 dgvPro.DataSource = new BindingList<HealthCheckItem>(healthcheckset.Items); 20 } 21 } 22 23 //cboComboList下载框改变 24 private void cboComboList_SelectedIndexChanged(object sender, EventArgs e) 25 { 26 if (cboComboList.Text.Trim() == "请选择") 27 { 28 dgvPro.DataSource = new BindingList<HealthCheckItem>(); 29 lblNameCombo.Text = ""; 30 lblComboPrice.Text = ""; 31 cboCheckedList.SelectedIndex = 0; 32 btnAddList.Enabled = false; 33 btnDeleteList.Enabled = false; 34 } 35 else 36 { 37 foreach (HealthCheckSet item in list) 38 { 39 if (cboComboList.Text.Trim() == item.Name) 40 { 41 healthcheckset = item; 42 lblNameCombo.Text = item.Name; 43 lblComboPrice.Text = item.Price.ToString(); 44 dgvPro.DataSource = new BindingList<HealthCheckItem>(item.Items); 45 cboCheckedList.SelectedIndex = 0; 46 btnAddList.Enabled = true; 47 btnDeleteList.Enabled = true; 48 break; 49 } 50 } 51 if (cboCheckedList.Text.Trim() == "请选择") 52 { 53 btnAddList.Enabled = false; 54 } 55 if(dgvPro.RowCount==0) 56 { 57 btnDeleteList.Enabled = false; 58 } 59 } 60 } 61 62 //cboCheckedList下载框改变 63 private void cboCheckedList_SelectedIndexChanged(object sender, EventArgs e) 64 { 65 if (cboCheckedList.Text.Trim() == "请选择") 66 { 67 btnAddList.Enabled = false; 68 } 69 else 70 { 71 btnAddList.Enabled = true; 72 } 73 }
5.添加套餐和检查项目
//添加套餐 private void btnAddCombo_Click(object sender, EventArgs e) { if(txtComboName.Text.Trim().Length==0) { MessageBox.Show("输入有空!"); return; } foreach (HealthCheckSet item in list) { if (txtComboName.Text.Trim() == item.Name) { MessageBox.Show("该套餐已有!"); return; } } List<HealthCheckItem> heallist=new List<HealthCheckItem>(); HealthCheckSet set1 = new HealthCheckSet(txtComboName.Text,heallist); list.Add(set1); cboComboList.Items.Add(set1.Name); cboComboList.Text = txtComboName.Text; MessageBox.Show("添加成功!"); } //添加套餐项目 private void btnAddList_Click(object sender, EventArgs e) { foreach (HealthCheckItem item in healthcheckset.Items) { if (cboCheckedList.Text.Trim() == item.Name) { MessageBox.Show("该检测项目已有!"); return; } } foreach (HealthCheckItem item in list1) { if(cboCheckedList.Text.Trim()==item.Name) { healthcheckset.Items.Add(item); MessageBox.Show("添加成功!"); break; } } healthcheckset.CalcPrice(); lblComboPrice.Text = healthcheckset.Price.ToString(); dgvPro.DataSource = new BindingList<HealthCheckItem>(healthcheckset.Items); }