体检套餐管理系统
2016-04-09 14:32
351 查看
完成效果图
代码展示
代码展示
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.Runtime.Remoting.Messaging; 8 using System.Text; 9 using System.Threading.Tasks; 10 using System.Windows.Forms; 11 12 namespace 体检套餐管理系统_01 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 //定义检查项目 21 private HealthCheckItem height, weight, sight, hearing, liverFun, ekg, bWaves, bloodPressure, bloodTest; 22 23 //默认检查套餐“入学体检” 24 private HealthCheckSet setA; 25 26 //保存所有的体检项目 27 List<HealthCheckItem> AllItems = new List<HealthCheckItem>(); 28 29 //保存套餐中的体检项目,和套餐相关的项目 30 List<HealthCheckItem> item = new List<HealthCheckItem>(); 31 32 //使用字典保存套餐集合 33 public Dictionary<string,HealthCheckSet> HealthSet=new Dictionary<string, HealthCheckSet>(); 34 35 36 37 private void btnOK_Click(object sender, EventArgs e) 38 { 39 if (string.IsNullOrEmpty(txtHealthName.Text)) 40 { 41 MessageBox.Show("请输入套餐名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 42 return; 43 } 44 else 45 { 46 //声明一数组 47 HealthCheckSet Hch = new HealthCheckSet(); 48 49 this.HealthSet.Add(this.txtHealthName.Text,Hch); 50 this.InitHealthSetList(); 51 //向下拉框显示添加的内容 52 this.cboSets.SelectedIndex = this.HealthSet.Count; 53 lblSetName.Text = cboItems.Text; 54 Hch.Name = cboSets.Text; 55 56 MessageBox.Show("添加成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); 57 } 58 } 59 60 public void InitItems() 61 { 62 height = new HealthCheckItem("身高", 500, "用于检查身高"); 63 weight = new HealthCheckItem("体重", 500, "用于检查体重."); 64 sight = new HealthCheckItem("视力", 1000, "用于检查视力."); 65 hearing = new HealthCheckItem("听力", 100, "用于检查听力."); 66 liverFun = new HealthCheckItem("肝功能", 50000, "用于检查肝功能."); 67 bWaves = new HealthCheckItem("B超", 30000, "用于检查B超."); 68 ekg = new HealthCheckItem("心电图", 500000, "用于检查心电图."); 69 bloodPressure = new HealthCheckItem("血压", 2000000, "用于检查血压."); 70 bloodTest = new HealthCheckItem("血常规", 9999999, "用于检查血常规."); 71 72 AllItems.Add(height); 73 AllItems.Add(weight); 74 AllItems.Add(sight); 75 AllItems.Add(hearing); 76 AllItems.Add(liverFun); 77 AllItems.Add(bWaves); 78 AllItems.Add(ekg); 79 AllItems.Add(bloodPressure); 80 AllItems.Add(bloodTest); 81 } 82 //默认套餐数据 83 private void InitSets() 84 { 85 item = new List<HealthCheckItem>(); 86 item.Add(height); 87 item.Add(weight); 88 item.Add(liverFun); 89 90 setA = new HealthCheckSet("入学体检",item); 91 92 setA.CalcPrice(); 93 this.HealthSet.Add("入学体检",setA); 94 } 95 //加载体检套餐下拉列表 96 private void InitHealthSetList() 97 { 98 //清空下拉列表 99 this.cboSets.Items.Clear(); 100 this.cboSets.Items.Add("请选择"); 101 102 foreach (string key in this.HealthSet.Keys) 103 { 104 this.cboSets.Items.Add(key); 105 } 106 this.cboSets.SelectedIndex = 0; 107 108 } 109 110 private void UpdateSet(HealthCheckSet set) 111 { 112 dgvHealthList.DataSource = new BindingList<HealthCheckItem>(set.Items); 113 } 114 //实现添加项目的操作,首先判断集合中是否已经存在要添加的项目了,如果要添加的项目不在集合中,则执行添加操作。其次,从allitems所有体检项目的集合中提取数据,使用foreach遍历,如果被选择的项目等于allitems中的项目,将此项目添加到HealItem项的集合中去,并且改变价格,刷新datagridview控件 115 private void btnAdd_Click(object sender, EventArgs e) 116 { 117 if (this.cboItems.SelectedIndex == 0) 118 { 119 MessageBox.Show("请选择一个项目"); 120 return; 121 } 122 string cboSetText = this.cboSets.Text; 123 if (cboSetText == "请选择") 124 { 125 MessageBox.Show("请选择套餐!"); 126 return; 127 } 128 int index = this.cboItems.SelectedIndex - 1; 129 if (!this.HealthSet[cboSetText].Items.Contains(AllItems[index])) 130 { 131 this.HealthSet[cboSetText].Items.Add(AllItems[index]); 132 this.HealthSet[cboSetText].CalcPrice(); 133 UpdateSet(this.HealthSet[cboSetText]); 134 this.lblSetName.Text = this.HealthSet[cboSetText].Name; //刷新窗体集合A名称 135 this.lblSetPrice.Text = this.HealthSet[cboSetText].Price.ToString(); //刷新集合A价格 136 MessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 137 } 138 else 139 { 140 MessageBox.Show("该项目存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); 141 } 142 143 } 144 \\ 实现删除套餐中的项目的功能,setName是套餐下拉框中所有项的文本的集合。item[setName].Item是指HealItems中所有项的集合,datagridview控件中加载的也是HealItems项的集合,所以可以根据datagridview中被选中行的下表来删除集合中的数据。并且重新加载标签中的价格 145 private void btnDel_Click(object sender, EventArgs e) 146 { 147 string setgName = this.cboSets.Text; 148 if (this.dgvHealthList.SelectedRows.Count == 0) 149 { 150 MessageBox.Show("没有选择删除项","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); 151 return; 152 } 153 //获取选中的项目的索引 154 int index = this.dgvHealthList.SelectedRows[0].Index; 155 //删除检查项 156 this.HealthSet[setgName].Items.RemoveAt(index); 157 //重新计算价格 158 this.HealthSet[setgName].CalcPrice(); 159 //更新DateGridView显示 160 UpdateSet(HealthSet[setgName]); 161 //重设标签显示 162 lblSetName.Text = setA.Name; 163 string cboSetText = this.cboSets.Text; 164 lblSetPrice.Text = this.HealthSet[cboSetText].Price.ToString(); 165 MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 166 167 168 } 169 170 private void cboItems_SelectedIndexChanged(object sender, EventArgs e) 171 { 172 if (this.cboSets.Text != "请选择") 173 { 174 this.btnAdd.Enabled = true; 175 } 176 else 177 { 178 this.btnAdd.Enabled = false; 179 } 180 } 181 // 182 private void cboSets_SelectedIndexChanged(object sender, EventArgs e) 183 { 184 string setName = this.cboSets.Text; 185 if (setName == "请选择") 186 { 187 this.dgvHealthList.DataSource = null; 188 lblSetName.Text = ""; 189 lblSetPrice.Text = ""; 190 return; 191 } 192 //设置套餐名称 193 lblSetName.Text = this.HealthSet[setName].Name; 194 //设置套餐总价 195 lblSetPrice.Text = this.HealthSet[setName].Price.ToString(); 196 //更新套餐检查项目 197 UpdateSet(HealthSet[setName]); 198 //删除按钮为可用状态 199 btnDel.Enabled = true; 200 } 201 202 private void Form1_Load(object sender, EventArgs e) 203 { 204 this.lblSetName.Text = ""; 205 //设置套餐总价的值为空 206 this.lblSetPrice.Text = ""; 207 btnAdd.Enabled = false; 208 btnDel.Enabled = false; 209 //默认初始化所有检查项目 210 InitItems(); 211 //默认初始化套餐 212 InitSets(); 213 //加载下拉列表 214 InitHealthSetList(); 215 dgvHealthList.AutoGenerateColumns = false; 216 } 217 } 218 }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 体检套餐管理系统_01 { public class HealthCheckSet { public HealthCheckSet() { items = new List<HealthCheckItem>(); } public HealthCheckSet(string name, List<HealthCheckItem> items) { this.Name = name; this.items = items; } //套餐价格 private int price; //检查项目 private List<HealthCheckItem> items; private string name; public string Name { get { return name; } set { name = value; } } public List<HealthCheckItem> Items { get { return items; } set { items = value; } } public int Price { get { return price; } set { price = value; } } //套餐计算方法 public void CalcPrice() { int totalPrice = 0; foreach (HealthCheckItem item in items) { totalPrice += item.Price; } this.price = totalPrice; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 体检套餐管理系统_01 { public class HealthCheckItem { private int price; private string descripion; private string description; private string name; public string Name { get { return name; } set { name = value; } } public int Price { get { return price; } set { price = value; } } public string Description { get { return description; } set { description = value; } } public HealthCheckItem(string name, int price, string description) { //this this.Name = name; this.Description = description; this.Price = price; } } }
相关文章推荐
- 登录成功后跳转回登录前的页面,实现思路
- 指针和引用的区别
- 阅读STL源码剖析笔记 —— 迭代器概念
- 设置指定边界圆角
- BlockingQueue使用
- 写出完美论文的十个技巧10 Tips for Writing the Perfect Paper
- 使用viewpager或者fragmentActivity等一些v4包下的类,当我们按F3时无法查看到源码,这个时候就需要我们关联该源码,该源码的关联与android源码的关联不一样。
- HDOJ 1339 A Simple Task(简单数学题,暴力)
- Java技术_Java千百问(0024)_finally关键字如何使用
- HDOJ 1339 A Simple Task(简单数学题,暴力)
- 键盘回收
- Sublime 快捷键
- 深入理解javascript原型和闭包系列 深入理解javascript原型和闭包(6)——继承
- 记一次ASP.NET MVC性能优化(实际项目中)
- 砝码称重V2
- NKOI 1006 护卫队
- 乘法逆元小结
- Linux学习笔记(三)
- 树状数组
- OC中weak/assign/strong