体检套餐管理系统

          1.任务描述

                 1.加载默认体检套餐

                    

              2.维护体检套餐

                    

                    维护功能主要有以下几个方面

                    1.显示指定套餐的项目明细

                    2.向指定套餐添加检查项目信息

                    3.删除套餐中的项目信息

                    4.新建套餐

         

          2.实现代码      

              1.搭建体检套餐管理系统的主窗体

                          

              2.创建体检套餐项目维护中的检查项目类,体检套餐类

                 

              3.系统默认提供一种套餐“入学套餐”填充检查项目对象到窗体

                 

 1   //套餐类
 2    public class HealthCheckSet
 3     {
 4         private string name;
 5 
 6         public string Name
 7         {
 8             get { return name; }
 9             set { name = value; }
10         }
11 
12         private int price;
13 
14         public int Price
15         {
16             get { return price; }
17             set { price = value; }
18         }
19 
20         private Dictionary<string, HealthCheckItem> item;
21 
22         public Dictionary<string, HealthCheckItem> Item
23         {
24             get { return item; }
25             set { item = value; }
26         }
27 
28         public HealthCheckSet() 
29         {
30             item = new Dictionary<string, HealthCheckItem>();
31         }
32 
33         public HealthCheckSet(string name,Dictionary<string,HealthCheckItem> item) 
34         {
35             this.Name = name;
36             this.Item = item;
37         }
38 
39         public void GetPrice() 
40         {
41             int sum = 0;
42             foreach (HealthCheckItem i in item.Values)
43             {
44                 sum += i.Price;
45             }
46             this.price = sum;
47         }
48     }

 

 1   //项目类
 2    public class HealthCheckItem
 3     {
 4         private string name;
 5 
 6         public string Name
 7         {
 8             get { return name; }
 9             set { name = value; }
10         }
11         private int price;
12 
13         public int Price
14         {
15             get { return price; }
16             set { price = value; }
17         }
18         private string description;
19 
20         public string Description
21         {
22             get { return description; }
23             set { description = value; }
24         }
25         public HealthCheckItem(string name, int price, string description) 
26         {
27             this.Name = name;
28             this.Price = price;
29             this.Description = description;
30         }
31     }

 

 1 //窗体中主要实现代码
 2         public frmMain()
 3         {
 4             InitializeComponent();
 5         }
 6         //用于保存单个项目
 7         HealthCheckItem h1, h2, h3, h4, h5, h6, h7, h8;
 8         //单个项目集合
 9         Dictionary<string, HealthCheckItem> allItem = new Dictionary<string, HealthCheckItem>();
10         //一个套餐所包含的项目
11         Dictionary<string, HealthCheckItem> items = new Dictionary<string, HealthCheckItem>(); 
12         //套餐集合
13         Dictionary<string, HealthCheckSet> allSet = new Dictionary<string, HealthCheckSet>();
14         //定义一个初始化套餐
15         HealthCheckSet set;
16         //向初始化的套餐添加各个项目
17         public void GetItems() 
18         {
19             h1 = new HealthCheckItem("身高",5,"用于检查身高");
20             h2 = new HealthCheckItem("体重", 5, "用于检查体重");
21             h3 = new HealthCheckItem("视力", 5, "用于检查视力");
22             h4 = new HealthCheckItem("听力", 5, "用于检查听力");
23             h5 = new HealthCheckItem("B超", 30, "用于检查B超");
24             h6 = new HealthCheckItem("肝功能", 30, "用于检查肝功能");
25             h7 = new HealthCheckItem("心电图", 50, "用于检查心电图");
26             h8 = new HealthCheckItem("血常规", 50, "用于检查血常规");
27             allItem.Add(h1.Name, h1);
28             allItem.Add(h2.Name, h2);
29             allItem.Add(h3.Name, h3);
30             allItem.Add(h4.Name, h4);
31             allItem.Add(h5.Name, h5);
32             allItem.Add(h6.Name, h6);
33             allItem.Add(h7.Name, h7);
34             allItem.Add(h8.Name, h8);
35 
36         }
37         //添加一个套餐
38         public void GetSet() 
39         {
40             items.Add(h1.Name,h1);
41             items.Add(h3.Name, h3);
42             items.Add(h4.Name, h4);
43             set = new HealthCheckSet("入学体检",items);
44             set.GetPrice();
45             allSet.Add("入学体检",set);
46         }
47         //绑定下拉框 
48         public void GetCbo() 
49         {
50             cboSetList.Items.Clear();
51             cboSetList.Items.Add("请选择");
52             foreach (string a in allSet.Keys)
53             {
54                 cboSetList.Items.Add(a);
55             }
56             this.cboSetList.SelectedIndex = 0;
57 
58             cbolitemsList.Items.Clear();
59             cbolitemsList.Items.Add("请选择");
60             foreach (string a in allItem.Keys)
61             {
62                 cbolitemsList.Items.Add(a);
63             }
64             this.cbolitemsList.SelectedIndex = 0;
65         }
66         //窗体加载时调用各个方法
67         private void frmMain_Load(object sender, EventArgs e)
68         {
69 
70             GetItems();
71             GetSet();
72             GetCbo();
73         }

 

          实现效果:

      

     4.实现删除体检套餐信息

         

 //删除
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string name = this.dgvList.SelectedRows[0].Cells[0].Value.ToString();
            string Setname = this.cboSetList.Text;
            MessageBox.Show(string.Format("确定要删除"+name+"这一项吗?","提示"));
            allSet[Setname].Item.Remove(name);
            UpdateSet(allSet[Setname]);
        }

实现效果:

 

5.向套餐中添加检查项目

//向套餐中添加项目
        private void btnItemAdd_Click(object sender, EventArgs e)
        {
            if(this.cbolitemsList.SelectedIndex==0)
            {
                MessageBox.Show("请选择要添加的项目");
                return;
            }
            string name=this.cboSetList.Text;
            if(name=="请选择")
            {
                MessageBox.Show("请选择套餐");
                return;
            }
            if (!allSet[name].Item.Keys.ToList().Contains(this.cbolitemsList.Text))
            {
                allSet[name].Item.Add(this.cbolitemsList.Text, allItem[this.cbolitemsList.Text]);
                this.lblName.Text = name;
                GetPrice();
                UpdateSet(allSet[name]);
            }
            else 
            {
                MessageBox.Show("已有该项目");
            }
        }

实现效果:

 

6.新建套餐

 1 //添加套餐
 2         private void btnSetAdd_Click(object sender, EventArgs e)
 3         {
 4             string setName=this.txtSetName.Text;
 5             if (this.txtSetName.Text.Trim() != null && this.txtSetName.Text.Trim() != "")
 6             {
 7                 HealthCheckSet set = new HealthCheckSet();
 8                 allSet.Add(txtSetName.Text, set);
 9                 GetCbo();
10                 this.cboSetList.SelectedIndex = allSet.Count();
11             }
12             else 
13             {
14                 MessageBox.Show("请输入套餐名称");
15             }
16         }
17         //下拉框中套餐名字改变时DataGridView里面所绑定的项目也改变
18         private void cboSetList_SelectedIndexChanged(object sender, EventArgs e)
19         {
20             string name = this.cboSetList.Text;
21             if (name == "请选择")
22             {
23                 this.dgvList.DataSource = new BindingList<HealthCheckItem>();
24                 this.lblName.Text = "";
25                 this.lblPrice.Text = "";
26                 return;
27             }
28             this.lblName.Text = name;
29             GetPrice();
30             UpdateSet(allSet[name]);
31         }

实现效果:

 

项目基本功能实现,希望对你有所帮助

请关注我,Call_迪迦

版权声明:本文为javahenku原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/javahenku/p/8266910.html