体检套餐的笔记
Posted 秋风伊人
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了体检套餐的笔记相关的知识,希望对你有一定的参考价值。
---恢复内容开始---
体检套餐的关键性代码: 关键性作用
//创建一个套餐集合 List<HealthCheckItem> item = new List<HealthCheckItem>(); List<HealthCheckItem> item1 = new List<HealthCheckItem>(); HealthCheckSet seee = new HealthCheckSet(); Dictionary<string, HealthCheckSet> dic = new Dictionary<string, HealthCheckSet>();
向其中添加套餐,使其出现在套餐的下拉框中
private void button1_Click(object sender, EventArgs e) { foreach (string item in dic.Keys) { if (textBox1.Text == item) { MessageBox.Show("存在此套餐"); } else { dic.Add(textBox1.Text, new HealthCheckSet()); c(); //this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(dic[comboBox1.Text].items); break; } } }
筛选下拉框的内容,并使其添加到DataGradeView表中,若有添加重复的则提示不能再添加 ,已添加此项目
private void button2_Click(object sender, EventArgs e) { for (int i = 0; i < dic[comboBox1.Text].Items.Count; i++) { if (dic[comboBox1.Text].Items[i].Name.Equals(comboBox2.Text)) { //MessageBox.Show(i.ToString()); MessageBox.Show("存在这个项目"); return; } } dic[comboBox1.Text].Items.Add(item1[comboBox2.SelectedIndex]); this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(dic[comboBox1.Text].Items); //this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(dic[comboBox1.Text].Items); dic[comboBox1.Text].CarlPrice(); label7.Text = dic[comboBox1.Text].Price.ToString(); }
删除添加到的DataGradeView,选中将删除,并且更换刷新价格
private void button3_Click(object sender, EventArgs e) { string one = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); //MessageBox.Show(one); for (int i = 0; i < dic[comboBox1.Text].Items.Count; i++) { if (one == dic[comboBox1.Text].Items[i].Name) { dic[comboBox1.Text].Items.Remove(dic[comboBox1.Text].Items[i]); break; } } this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(dic[comboBox1.Text].Items); seee.CarlPrice(); label7.Text = seee.Price.ToString(); }
创建所属的类,包括(HealthCheckSet)和(HealthCheckItem)
List<HealthCheckItem> list; //套餐的价格 private double price; public double Price { get { return price; } set { price = value; } } //套餐名称 private string name; public string Name { get { return name; } set { name = value; } } //保存所有的 public List<HealthCheckItem> all = new List<HealthCheckItem>(); //保存体检套餐的 private List<HealthCheckItem> tems = new List<HealthCheckItem>(); public List<HealthCheckItem> Items { get { return tems; } set { tems = value; } } //计算总价格 public void CarlPrice() { double po = 0; foreach (HealthCheckItem item in this.Items) { po += item.Price; } this.Price = po; }
public class HealthCheckItem { //项目描述 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 double price; public double Price { get { return price; } set { price = value; } }
该项目的作用就是可以添加套餐 ,并且使添加的套餐添加到combox的下拉框中,相对应的在添加体检的内容添加到datagrideview表中,添加已有的项目会提示已有不能再次添加则价钱会随着添加项目的价钱进行综合,删除相对应的体检内容,都会随之变化,
以上是关于体检套餐的笔记的主要内容,如果未能解决你的问题,请参考以下文章