您的位置:首页 > 编程语言 > C#

体检套餐管理系统

2018-01-10 23:05 555 查看

一.任务描述:

1.加载默认体检套餐

2.维护体检套餐

维护功能主要包括以下几个方面:

显示指定套餐的项目明细;

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

删除套餐中的项目信息;

新建套餐

二.窗体及代码示例:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace chapter5{public partial class frmMain : Form{public frmMain(){InitializeComponent();}//用于保存所有单个套餐项目HealthCheckItem height, weight, sight, hearing, liverFun, ekg, bWaves, bloodPressure, bloodTest;//allItem用于保存所有的套餐项目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>();//用于初始化所有套餐项public void Init(){height = new HealthCheckItem("身高", 5, "用于检查身高.");weight = new HealthCheckItem("体重", 5, "用于检查体重.");sight = new HealthCheckItem("视力", 10, "用于检查视力.");hearing = new HealthCheckItem("听力", 10, "用于检查听力.");liverFun = new HealthCheckItem("肝功能", 50, "用于检查肝功能.");bWaves = 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(sight.Name, sight);allItem.Add(hearing.Name, hearing);allItem.Add(liverFun.Name, liverFun);allItem.Add(bWaves.Name, bWaves);allItem.Add(ekg.Name, ekg);allItem.Add(bloodPressure.Name, bloodPressure);allItem.Add(bloodTest.Name, bloodTest);}//初始化一个套餐public void InitHealth(){item.Add(height.Name,height);item.Add(weight.Name, weight);item.Add(sight.Name, sight);set = new HealthCheckSet("入学体检",item);set.CalcPrice();allSet.Add("入学体检",set);}//将初始化套餐信息绑定到下拉列表框中public void InitSet(){this.cboList.Items.Clear();this.cboList.Items.Add("请选择");foreach (string item in allSet.Keys){this.cboList.Items.Add(item);}this.cboList.SelectedIndex = 0;}//窗体加载事件private void frmMain_Load(object sender, EventArgs e){this.lblSetName.Text = "";this.lblSetPrice.Text = "";Init();InitHealth();InitSet();}//更新套餐检查项目private void UpdateSet(HealthCheckSet set){this.dgvShow.DataSource = new BindingList<HealthCheckItem>(set.Items.Values.ToList());}private void cboList_SelectedIndexChanged(object sender, EventArgs e){string name = this.cboList.Text;if(name=="请选择"){this.dgvShow.DataSource=new BindingList<HealthCheckItem>();this.lblSetName.Text = "";this.lblSetPrice.Text = "";return;}this.lblSetName.Text =name;this.lblSetPrice.Text =allSet[name].Price.ToString();UpdateSet(allSet[name]);}//上"增加"按钮事件private void btnAdd1_Click(object sender, EventArgs e){if (this.cboProject.SelectedIndex == 0){MessageBox.Show("请选择套餐项");return;}string name = this.cboList.Text;if(name=="请选择"){MessageBox.Show("请选择套餐");return;}if (!allSet[name].Items.Keys.ToList().Contains(this.cboProject.Text)){allSet[name].Items.Add(this.cboProject.Text, allItem[this.cboProject.Text]);allSet[name].CalcPrice();this.lblSetName.Text = name;this.lblSetPrice.Text = allSet[name].Price.ToString();UpdateSet(allSet[name]);}else{MessageBox.Show("该项已经存在了!");}}//下“添加”按钮事件private void btnAdd_Click(object sender, EventArgs e){if (this.txtName.Text.Trim() != null && this.txtName.Text.Trim() != ""){HealthCheckSet set = new HealthCheckSet();allSet.Add(this.txtName.Text.Trim(), set);InitSet();this.cboList.SelectedIndex = allSet.Count();}else{MessageBox.Show("请输入添加的套餐名称");}}//“删除”按钮事件private void btnDelete_Click(object sender, EventArgs e){string name = this.dgvShow.SelectedRows[0].Cells["Name"].Value.ToString();string healthname = this.cboList.Text;allSet[healthname].Items.Remove(name);UpdateSet(allSet[healthname]);}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace chapter5{//检查项目类class HealthCheckItem{//无参构造方法public HealthCheckItem(){}//带参构造方法public HealthCheckItem(string name,int price,string description){this.Name = name;this.Description = description;this.Price = price;}public string Description { get; set; }//项目描述public string Name { get; set; }//项目名称public int Price { get; set; }//项目价格}}
using System;using System.Collections.Generic;using System.Linq;using System.Te4000xt;using System.Threading.Tasks;namespace chapter5{//体检套餐class HealthCheckSet{public Dictionary<string,HealthCheckItem> Items { get; set; }//HealthCheckItem的集合public double Price { get; set; }//套餐价格public string Name { get; set; }//套餐名称public HealthCheckSet(){Items = new Dictionary<string, HealthCheckItem>();}public HealthCheckSet(string name,Dictionary<string,HealthCheckItem> items){this.Name = name;this.Items = items;}//计算套餐内所有套餐项的总价格public void CalcPrice(){int totalPrice = 0;foreach (HealthCheckItem item in this.Items.Values){totalPrice += item.Price;}this.Price = totalPrice;}}}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息