体检套餐管理项目

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("添加成功!");

10:结束项目!

转载于:https://www.cnblogs.com/chimingyang/p/5367977.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【资源说明】 Java开发基于SSM框架的医院体检预约管理系统源码+项目说明.zip Java开发基于SSM框架的医院体检预约管理系统源码+项目说明.zip 1、该资源内项目代码都是经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果有一点儿基础,亦可在此代码基础上进行修改,以实现其他功能。 功能需求: 系统分为三个角色:系统管理员、医生和体检人员。 系统管理员主要有以下几个功能: 体检人员管理:增删改查,模糊查询 医生人员管理:增删改查,模糊查询 预约审批:体检人员预约以后,可以审批通过或者不通过 角色管理:增删改查,分配权限给不同的角色 个人信息:查看和修改自己的个人信息 密码修改:修改自己的系统密码 统计分析:系统中出现的各种疾病的男女比例 医生有以下功能: 体检人员管理:增删改查模糊查询体检人员 体检项目管理:增删改查体检项目 套餐管理:增删改查体检套餐 体检管理:给体检人员反馈体检情况 个人信息:查看和修改自己的个人信息 密码修改:修改自己的系统密码 统计分析:系统中出现的各种疾病的男女比例 体检人员有以下功能: 个人体检预约:预约体检 个人信息:查看和修改自己的个人信息 密码修改:修改自己的系统密码 统计分析:系统中出现的各种疾病的男女比例 项目技术 后台:SSM(Spring+Spring MVC+ Mybits) 前台:主要是layui,还有jsp+jquery+ajax
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值