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.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10
11 namespace 体检套餐
12 {
13 public partial class TiJian : Form
14 {
15 public TiJian()
16 {
17 InitializeComponent();
18 }
19 #region 定义..
20 //定义几个检查项目
21 HealIte height, weight, sight, hearing, liverFun, ekg, bwaves, bloodpressure, bloodTest;
22 //定义几个检查项目
23 //HealIte height, weight, singht, hearing, liveFun, ekg, bwaves, bloodpressure, bloodTest;
24
25
26 //定义一个系统默认检查套餐"入学体检"
27 HealtSet setA;
28 //保存所有体检项目
29 List ALLItems = new List();
30 //保存套餐中的体检项目
31 List ltems = new List();
32
33 //使用字典保存套餐集合
34 public Dictionary<string, HealtSet> healtset = new Dictionary<string, HealtSet>();
35
36 #endregion
37
38 #region 保存套餐列表
39 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
40 {
41
42 //采用泛型集合List保存所有的体检项目
43 List AllItems = new List();
44 //采用反省集合List保存套餐中的体检项目
45 List item = new List();
46
47 }
48 #endregion
49
50 #region 添加事件 套餐
51 private void btntianjia_Click(object sender, EventArgs e)
52 {
53 if (string.IsNullOrEmpty(txtname.Text))
54 {
55 MessageBox.Show("请输入套餐名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
56 return;
57
58 }
59 else
60 //else
61 {
62 //声明数组
63 HealtSet hs = new HealtSet();
64 this.healtset.Add(this.txtname.Text, hs);
65 this.iInitHealthSetList();
66
67
68
69
70 //向下拉框添加内容
71 this.comb.SelectedIndex = this.healtset.Count;
72 lilruxue.Text = comb.Text;
73 hs.Name = comb.Text;
74 lilruxue.Show();
75 MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
76
77
78
79 }
80 }
81 #endregion
82
83 #region iInitHealthSetList方法
84 private void iInitHealthSetList()
85 {
86 //清空下拉列表
87 //this.comb.Items.Clear();
88 this.comb.Items.Clear();
89 //this.comb.Items.Add("请选择");
90 this.comb.Items.Add("您请选择");
91
92 //foreach (string key in this.healtset.Keys)
93 //{
94 // this.comb.Items.Add(key);
95 //}
96 //this.comb.SelectedIndex = 0;
97
98
99 foreach (string key in this.healtset.Keys)
100 {
101 this.comb.Items.Add(key);
102 }
103 this.comb.SelectedIndex = 0;
104
105
106 }
107 #endregion
108
109 #region load事件
110 private void TiJian_Load(object sender, EventArgs e)
111 {
112 lilruxue.Hide();
113 lblmaoey.Hide();
114 this.lilruxue.Text = "";
115 //设置套餐总价的值为空
116 this.lblmaoey.Text = "";
117 btntianjia1.Enabled = false;
118 btnsanchu.Enabled = false;
119 //默认初始化所有检查项目
120 Initems();
121 //默认初始化套餐
122 Initems();
123 //加载下拉列表
124 iInitHealthSetList();
125 dataGridView1.AutoGenerateColumns = false;
126
127
128 }
129 #endregion
130
131 #region 下拉列表功能 为数组赋值
132 public void Initems()
133 {
134 height = new HealIte("身高", 5, "用于检查身高");
135 weight = new HealIte("体重", 5, "用于检查体重");
136 sight = new HealIte("视力", 10, "用于检查视力");
137 hearing = new HealIte("听力", 20, "用于检查听力");
138 liverFun = new HealIte("肝功能", 100, "用于检查肝功能");
139 ekg = new HealIte("B超", 200, "用于检查B超");
140 bwaves = new HealIte("心电图", 50, "用于检查心电图");
141 bloodpressure = new HealIte("血压", 20, "用于检查血压");
142 bloodTest = new HealIte("血常规", 88, "用于检查血常规");
143
144 ALLItems.Add(height);
145 ALLItems.Add(weight);
146 ALLItems.Add(sight);
147 ALLItems.Add(hearing);
148 ALLItems.Add(liverFun);
149 ALLItems.Add(ekg);
150 ALLItems.Add(bwaves);
151 ALLItems.Add(bloodpressure);
152 ALLItems.Add(bloodTest);
153
154 }
155 #endregion
156
157 #region InitSets方法
158 //默认套餐数据
159 private void InitSets()
160 {
161 ltems = new List();
162 ltems.Add(height);
163 ltems.Add(weight);
164 ltems.Add(liverFun);
165
166 setA = new HealtSet("入学体检", ltems);
167 setA.Calcprice();
168 this.healtset.Add("入学体检", setA);
169
170 }
171
172
173 #endregion
174
175 #region 下拉列表
176 private void UpdateSet(HealtSet set)
177 {
178 dataGridView1.DataSource = new BindingList(set.Items);
179 }
180
181 #endregion
182
183 #region 设置套餐总价 更新 删除
184 private void comb_SelectedIndexChanged(object sender, EventArgs e)
185 {
186 string setName = this.comb.Text;
187 if (setName == "请选择")
188 {
189 this.dataGridView1.DataSource = null;
190 lilruxue.Text = "";
191 lblmaoey.Text = "";
192 return;
193 }
194 //设置套餐名称
195 lilruxue.Text = this.healtset[setName].Name;
196 //设置套餐总价
197 lblmaoey.Text = this.healtset[setName].Price.ToString();
198 //更新套餐检查项目
199 UpdateSet(healtset[setName]);
200 //删除按钮为可用状态
201 btnsanchu.Enabled = true;
202
203 }
204 #endregion
205
206 #region if循环 盒子2号
207 private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
208 {
209 if (this.comboBox2.Text != "选择")
210 {
211 this.btntianjia1.Enabled = true;
212 }
213 else
214 {
215 this.btntianjia1.Enabled = false;
216 }
217 }
218 #endregion
219
220 #region 添加按钮全部功能
221 private void btntianjia1_Click(object sender, EventArgs e)
222 {
223 if (this.comboBox2.SelectedIndex == 0)
224 {
225
226 MessageBox.Show("请选择一个项目");
227 return;
228 }
229 string comboBox2Text = this.comboBox2.Text;
230 if (comboBox2Text == "请选择")
231 {
232 MessageBox.Show("请选择一个套餐");
233 return;
234 }
235 int index = this.comboBox2.SelectedIndex - 1;
236
237 string mc = txtname.Text;
238 if (!this.healtset[mc].Items.Contains(ALLItems[index]))
239 {
240 //this.healtset
241
242
243 this.healtset[mc].Items.Add(ALLItems[index]);
244 this.healtset[mc].Calcprice();
245 UpdateSet(this.healtset[mc]);
246 this.lilruxue.Text = this.healtset[mc].Name;
247 this.lblmaoey.Text = this.healtset[mc].Price.ToString();
248 MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
249
250 }
251 else
252 {
253 MessageBox.Show("该项目已经选择过", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
254 }
255
256
257 }
258
259 #endregion
260
261 #region 删除按钮全部功能
262 private void btnsanchu_Click(object sender, EventArgs e)
263 {
264 //删除项目
265 string setName = txtname.Text;// this.comboBox2.Text;
266 if (this.dataGridView1.SelectedRows.Count == 0)
267 {
268 MessageBox.Show("请选择删除项", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
269 return;
270 }
271
272 //获取选中的项目索引
273 int index = this.dataGridView1.SelectedRows[0].Index;
274 //删除检查项
275 this.healtset[setName].Items.RemoveAt(index);
276 //重新计算价格
277 this.healtset[setName].Calcprice();
278 //更新dgv显示
279 UpdateSet(healtset[setName]);
280 //重设标签显示
281 lilruxue.Text = setName;// setA.Name;
282 string comboBox2Text = this.comboBox2.Text;
283
284 string mc = txtname.Text;
285 lblmaoey.Text = healtset[mc].Price.ToString();
286 MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
287
288
289 }
290
291 #endregion
292
293
294
295
296
297
298
299 }
300
301
302
303
304
305 }
306
307
308
309