第五章项目 体检套餐管理系统
生活随笔
收集整理的這篇文章主要介紹了
第五章项目 体检套餐管理系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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<HealIte> ALLItems = new List<HealIte>();
30 //保存套餐中的體檢項目
31 List<HealIte> ltems = new List<HealIte>();
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<HealIte> AllItems = new List<HealIte>();
44 //采用反省集合List保存套餐中的體檢項目
45 List<HealIte> item = new List<HealIte>();
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<HealIte>();
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<HealIte>(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
?
轉載于:https://www.cnblogs.com/LJN520/p/5372197.html
總結
以上是生活随笔為你收集整理的第五章项目 体检套餐管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java中类的初始化顺序
- 下一篇: 20145237第六周学习总结