体检套餐管理系统

 

体检套餐管理系统以下详细代码:

 

大致功能如图所示:添加套餐,添加套餐的具体项目,删除等功能。

首先先建两个类

     1.HealthCheckItem表示检查项目

具体属性有:Description:

项目描述  Name:

项目名称 Price:项目价格

      2.HelthCheckSet表示体检套餐

  类中具体属性有

  Item:HealthCheckItem的集合

  Price:套餐价格

  Name:套餐名称

  如图:

 

        private string description;   //项目描述
        private string name;          //项目名称
        private int price;            //项目价格
        public string Description
        {
            get { return description; }
            set { description = value; }
        }
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public int Price
        {
            get { return price; }
            set { price = value; }
        }
       //无参构造
         public HealthCheckItem()
        {
        }
         //有参构造
         public HealthCheckItem(string name, int price, string description)
        {
            this.Name = name;
            this.Price = price;
            this.Description = description;
        }

 

 

  private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private int price;

        public int Price
        {
            get { return price; }
            
        }
        private Dictionary<string, HealthCheckItem> items;

        public Dictionary<string, HealthCheckItem> Items
        {
            get { return items; }
            set { items = value; }
        }
        public HealthCheckSet()
        {
            items = new Dictionary<string, HealthCheckItem>();
        }
        public HealthCheckSet(string name, Dictionary<string, HealthCheckItem> item)
        {
            this.Name = name;
            this.Items = item;
        }

        //计算套餐内所有套餐项的总价格
       public int totalprice = 0;
        public void SumPirce()
        {
            //定义一个变量,来保存总价格
           
            //
            foreach (HealthCheckItem item in items.Values)
            {
                totalprice+=item.Price;
            }
            this.price = totalprice;
        }

 

 

 窗体运行时默认没有数据,并且当点击添加或者删除具体项目是会提示(如图)

 

 

我们会默认有一个学生套餐在选中学生套餐时会显示数据(如图)

首先我们需要创建几个双列集合具体功能如下

 //用于保存所有单个套餐项目
        HealthCheckItem height, weight, eyes, hearing, Gan, ekg, BC, bloodPressure, bloodTest;
        //用来 初始化全部信息 的双列集合
        Dictionary<string, HealthCheckItem> Allitem = new Dictionary<string, HealthCheckItem>();
        //定义一个套餐
        HealthCheckSet set;
        //定义一个套餐内的套餐项目列表
        Dictionary<string, HealthCheckItem> item = new Dictionary<string, HealthCheckItem>();
        //定义一个套餐的集合
        Dictionary<string, HealthCheckSet> allset = new Dictionary<string, HealthCheckSet>();

 

其次我们需要初始化存储权全部信息的集合,并在在Lode事件中调用

          //初始化存储全部信息的集合
            height = new HealthCheckItem("身高", 5, "用于检查身高.");
            weight = new HealthCheckItem("体重", 5, "用于检查体重.");
            eyes = new HealthCheckItem("视力", 10, "用于检查视力.");
            hearing = new HealthCheckItem("听力", 10, "用于检查听力.");
            Gan = new HealthCheckItem("肝功能", 50, "用于检查肝功能.");
            BC = new HealthCheckItem("B超", 30, "用于检查B超.");
            ekg = new HealthCheckItem("心电图", 50, "用于检查心电图.");
            bloodPressure = new HealthCheckItem("血压", 20, "用于检查血压.");
            bloodTest = new HealthCheckItem("血常规", 20, "用于检查血常规.");
            Allitem.Add(height.Name, height);
            Allitem.Add(weight.Name, weight);
            Allitem.Add(eyes.Name, eyes);
            Allitem.Add(hearing.Name, hearing);
            Allitem.Add(Gan.Name, Gan);
            Allitem.Add(BC.Name, BC);
            Allitem.Add(ekg.Name, ekg);
            Allitem.Add(bloodPressure.Name, bloodPressure);
            Allitem.Add(bloodTest.Name, bloodTest);
        }

 

下拉框的选中事件

 show();//初始化存储全部信息的集合
            //默认添加入学体检的数据
            item.Add(height.Name, height);
            item.Add(weight.Name, weight);
            item.Add(eyes.Name, eyes);
            set = new HealthCheckSet("入学体检", item);
            set.SumPirce();
            allset.Add("入学体检", set);
            //默认下拉框为第一项
            this.comlist.SelectedIndex = 0;
            this.comjc.SelectedIndex = 0;
            //将初始化套餐信息绑定到下拉框当中
            InitSet();
            this.lblTCname.Text = "";
            this.lblZprice.Text = "0";

 

添加套餐:如图我们添加了一个入职体检套餐

代码如下:

      //判断添加的套餐名称是否为空,不为空进入循环
            if (this.txtname.Text.Trim() != null && this.txtname.Text.Trim() != "")
            {
                // 实例化一个套餐类
                HealthCheckSet set = new HealthCheckSet();
                //添加数据
                allset.Add(this.txtname.Text.Trim(), set);
                //将初始化套餐信息绑定到下拉框当中
                InitSet();
                this.comlist.SelectedIndex = allset.Count;
            }
            else
            {
                //提示用户输入
                MessageBox.Show("请输入添加的套餐名称");
            }

 

然后就是添加具体的体检项目:(我先添加了一个听力项,然后又加了一个身高项(当我们添加重复数据时,会提示我们项目已经存在))

代码如下:

            if (this.comjc.SelectedIndex == 0)
            {
                MessageBox.Show("请选择您的套餐项");
                return;
            }
            string name = this.comlist.Text;
            if (name == "请选择")
            {
                MessageBox.Show("请选择套餐您的");
                return;
            }
            if (!allset[name].Items.Keys.ToList().Contains(this.comjc.Text))
            {
                allset[name].Items.Add(this.comjc.Text, Allitem[this.comjc.Text]);
                allset[name].SumPirce();
                this.lblname.Text = name;
                this.lblZprice.Text = allset[name].Price.ToString();
                UpdateSet(allset[name]);
            }
            else
            {
                MessageBox.Show("该项已经存在!");
            }
        } 

 

下面就是删除具体项目:

代码如下

            //判断是否选中行,没有则提示
            if (dgvlist.SelectedRows.Count > 0)
            {
                //删除的判断如果选择否     则取消删除
                DialogResult result = MessageBox.Show("确定要删除此项吗?", "提示",
                MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
                string name = this.dgvlist.SelectedRows[0].Cells["Name"].Value.ToString();
                if (DialogResult.OK == result)
                {
                  
                    string healthname = this.comlist.Text;
                    allset[healthname].Items.Remove(name);
                    UpdateSet(allset[healthname]);
                }
               
                else
                {
                    MessageBox.Show("删除错了?");
                }
            }
                
            else
            {
                //提示用户选择数据
                MessageBox.Show("请先选择数据后再删除");
            }
          

 

 项目就这么多。

 
 
 
 
 
 
 
 
 
 

posted on 2018-01-11 08:39  雅俗共赏_house  阅读(331)  评论(0编辑  收藏  举报

导航