体检套餐管理系统

1:搭建窗体(略)

2:用户自定义类:HealthCheckItem和HealthCheckSet

 1 namespace 体检套餐管理
 2 {
 3      public class HealthCheckItem
 4     {
 5         public HealthCheckItem(string name, int price, string description)//定义带参构造为三个属性赋初值
 6         {
 7             this.Name = name;
 8             this.Description = description;
 9             this.Price = price;
10         }
11         private string name;
12         public string Name//项目名
13         {
14             get { return name; }
15             set { name = value; }
16         }
17         private string description;
18         public string Description//项目描述
19         {
20             get { return description; }
21             set { description = value; }
22         }
23         private int price;
24         public int Price//项目价格
25         {
26             get { return price; }
27             set { price = value; }
28         }
29     }
30 }

namespace 体检套餐管理
{
  public
  class HealthCheckSet
    {
        public HealthCheckSet()//初始化HealthCheckItems项的集合
        {
            items = new List<HealthCheckItem>();
        }
        public HealthCheckSet(string name, List<HealthCheckItem> items)//有项目时给集合赋值的构造函数
        {
            this.Name = name;
            this.items = items;
        }
        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private List<HealthCheckItem> items;
        public List<HealthCheckItem> Items//表示HealthCheckItems中的项的集合
        {
            get { return items; }
            set { items = value; }
        }
        private int price;
        public int Price//套餐价格
        {
            get { return price; }
        }
        public void CalcPrice()//计算套餐价格的方法
        {
            int totalPrice = 0;
            foreach (HealthCheckItem item in items)
            {
                totalPrice += item.Price;
            }
            this.price = totalPrice;
        }
    }
}

3:定义两个List<T>单列集合,一个Dictionary<K,V>双列集合并且默认初始化一个体检套餐。

1 HealthCheckItem height, weight, eyes, ears, gan, Bchao, heart;
2         List<HealthCheckItem> allitems = new List<HealthCheckItem>();//保存所有的体检项目
3         List<HealthCheckItem> items = new List<HealthCheckItem>();//保存套餐中的体检项目
4         public Dictionary<string, HealthCheckSet> item = new Dictionary<string, HealthCheckSet>();//保存所有套餐
5         public HealthCheckSet numA;

4:初始化保存在allitems中的所有的体检项目以及默认套餐中的所有的体检项目。

 1         public void Show()//保存所有体检项目
 2         {
 3             height = new HealthCheckItem("身高", 5, "测量身高");
 4             weight = new HealthCheckItem("体重", 5, "检测体重");
 5             eyes = new HealthCheckItem("视力", 10, "测视力");
 6             ears = new HealthCheckItem("听力", 10, "测听力");
 7             gan = new HealthCheckItem("肝功能", 20, "测试肝功能");
 8             Bchao = new HealthCheckItem("B超", 20, "检测身体内部");
 9             heart = new HealthCheckItem("心电图", 50, "检查心脏");
10             allitems.Add(height);
11             allitems.Add(weight);
12             allitems.Add(eyes);
13             allitems.Add(ears);
14             allitems.Add(gan);
15             allitems.Add(Bchao);
16             allitems.Add(heart);
17         }
18         public void Num1()//默认的体检套餐
19         {
20             items = new List<HealthCheckItem>();
21             items.Add(height);
22             items.Add(weight);
23             items.Add(eyes);
24             numA = new HealthCheckSet("入学体检", items);
25             numA.CalcPrice();
26             this.item.Add("入学体检", numA);
27
28         }

5:向下拉框中添加数据,由于此控件是套餐下拉框,其储存的数据是双列集合dictionary<K,V>中的key值,即代码如下

 1   public void Chushi()
 2         {
 3             this.comboBox1.Items.Clear();
 4             this.comboBox1.Items.Add("请选择");
 5
 6             foreach (string key in this.item.Keys)
 7             {
 8                 this.comboBox1.Items.Add(key);
 9             }
10             this.comboBox1.SelectedIndex = 0;
11         }

6:在下拉框的SelectedIndexChanged事件中编写如下代码,目的是点击下拉框选项后将数据加载到datagridview控件中,并且实现显示套餐名称和价格的功能。

 1 string text = this.comboBox1.Text;
 2             if (text == "请选择")
 3             {
 4                 this.label3.Text = "";
 5                 this.label5.Text = "";
 6                 this.dataGridView1.DataSource = new BindingList<HealthCheckItem>();
 7                 return;
 8             }
 9             label3.Text = this.item[text].Name;
10             label5.Text = this.item[text].Price.ToString();
11             load(item[text]);
12             this.button2.Enabled = true;

备注:load()作用是将所有的体检项目的信息加载到datagridview中

1  public void load(HealthCheckSet set)//将所有的体检项目的信息加载到datagridview中
2         {
3             this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(set.Items);
4         }

7:实现删除套餐中的项目的功能,setName是套餐下拉框中所有项的文本的集合。item[setName].Item是指HealthCheckItems中所有项的集合,datagridview控件中加载的也是HealthCheckItems项的集合,所以可以根据datagridview中被选中行的下表来删除集合中的数据。并且重新加载标签中的价格

 1  string setName = this.comboBox1.Text;
 2
 3             if (this.dataGridView1.SelectedRows.Count == 0)
 4             {
 5                 MessageBox.Show("没有选择删除项。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
 6                 return;
 7             }
 8
 9             int index = this.dataGridView1.SelectedRows[0].Index;
10
11             this.item[setName].Items.RemoveAt(index);
12
13             this.item[setName].CalcPrice();
14
15             load(item[setName]);
16
17             this.label3.Text =numA.Name;
18             this.label5.Text = numA.Price.ToString();
19             MessageBox.Show("删除成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

8:实现添加项目的操作,首先判断集合中是否已经存在要添加的项目了,如果要添加的项目不在集合中,则执行添加操作。其次,从allitems所有体检项目的集合中提取数据,使用foreach遍历,如果被选择的项目等于allitems中的项目,将此项目添加到HealthCheckItem项的集合中去,并且改变价格,刷新datagridview控件

 1 if (this.comboBox2.SelectedIndex == 0)
 2             {
 3                 MessageBox.Show("请选择一个项目。");
 4                 return;
 5             }
 6
 7             string text = this.comboBox1.Text;
 8             if (text == "请选择")
 9             {
10                 MessageBox.Show("请选择套餐!");
11                 return;
12             }
13
14
15             foreach (HealthCheckItem cboitem in item[text].Items)
16             {
17                 if (cboitem.Name == comboBox2.SelectedItem.ToString())
18                 {
19                     MessageBox.Show("该项目存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
20                     return;
21                 }
22             }
23             foreach (HealthCheckItem addItem in allitems)
24             {
25                 if (addItem.Name == comboBox2.SelectedItem.ToString())
26                 {
27                     item[text].Items.Add(addItem);
28                 }
29                 this.item[text].CalcPrice();
30                 load(this.item[text]);
31                 this.label3.Text = this.item[text].Name;
32                 this.label5.Text = this.item[text].Price.ToString();
33
34
35             }

9:实现添加套餐操作,通过添加dictionary<K,V>中的Key值来添加套餐,并且刷新下拉列表。并在套餐下拉框中自动定位到刚被添加的套餐。

1  HealthCheckSet he = new HealthCheckSet();
2             this.item.Add(textBox1.Text, he);
3             this.Chushi();
4             this.comboBox1.SelectedIndex = item.Count;
5             MessageBox.Show("添加成功!");
时间: 2024-08-01 10:45:58

体检套餐管理系统的相关文章

05章 体检套餐管理系统

窗体搭建的效果图如下: 一:实现的功能主要有以下几个方面: ①:显示指定套餐的项目明细 ②:向指定套餐添加检查项目信息 ③:删除套餐中的项目信息 ④:新建套餐 二:创建体检项目维护系统中的检查项目类(HealthCheckItem).体检套餐类(HealthCheckSet) HealthCheckItem类中的属性说明如下: Description:项目描述 Name:项目名称 Price:项目价格 HealthCheckSet类中的属性说明如下: Items:HealthCheckItem的

第五章.体检套餐管理系统.刁汉生.20170408

1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace Le

体检套餐管理系统 05章

窗体搭建的效果图如下: 一:实现的功能主要有以下几个方面: ①:显示指定套餐的项目明细 ②:向指定套餐添加检查项目信息 ③:删除套餐中的项目信息 ④:新建套餐 二:创建体检项目维护系统中的检查项目类(HealthCheckItem).体检套餐类(HealthCheckSet) HealthCheckItem类中的属性说明如下: Description:项目描述 Name:项目名称 Price:项目价格 HealthCheckSet类中的属性说明如下: Items:HealthCheckItem的

第五章项目 体检套餐管理系统

1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace 体检

体检套餐管理系统的综合版

步骤: 定义几个类: HealthCheckItem类:检查项目 属性: public string Description { get; set; } public int Price { get; set; } public string Name { get; set; } HealthCheckItem类中的方法: //当选择套餐下拉框中的套餐时,套餐下所有检查项目都添加到dgvlist中显示 public HealthCheckItem(string name, int price,

第五章 体验套餐管理系统

体检套餐管理系统 套餐含义:体检套餐是一种形象的说法,体检的项目有很多,常规的项目就有几十种,个人体质.疾病的种类.体检者对体检项目的要求各不相同,全部的体检项目大概要几百种.普通的消费者不具备医学专业知识,所以也就无法从众多的体检项目中选择适合自己的体检项目.如果选择的项目过多,则浪费体检费用,选择的项目过少,又不能对需要检测的症状进行全面检测,很容易造成漏检.经过有多年经验的专家在对疾病预防经验的综合整理后,对体检项目进行科学分组,针对人群的年龄.体质.疾病类型.健康要求而制定的科学的体检项

体检套餐的项目

第5章 体检套餐管理系统1,课程内容回顾 第1章:深入.NET框架 .NET框架组件 CLR的作用及组成 .NET程序编译过程 .NET核心类库及命名空间 第2章 深入C#数据类型 类.对象.属性.封装 类图 结构 拆箱装箱 值类型和引用类型 静态成员和静态方法 第3章 使用集合组织相关数据 操作集合实现元素的增.删.查.遍历 ArrayList Hashtable 操作泛型集合实现元素的增.删.查.遍历 List<T> Dictionary<K,V> 泛型 第4章 深入类的方法

字典集合Dictionary&lt;K,V&gt;和构造的应用==&gt;&gt;体检套餐项目

效果 首先,我们先来准备我们需要的类 1.检查项目类 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 第五章_体检套餐管理系统_ { //项目类 public class HealthCheckItem { //项目描述 public string Description { get; set;

套餐管理系统

本套套餐管理系统,主要是使用泛型list<> 和泛型 dictionary<>集合的使用 public class HealthCheckItem { public string description { get; set; } public string name { get; set; } public int price { get; set; } public HealthCheckItem(string name, string description,int pric