国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

C#第五章 套餐體檢

2019-11-08 02:05:05
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

using System;  using System.Collections.Generic;  using System.Linq;  using System.Text;    namespace 體檢項(xiàng)目  {     public class CheckSet      {          public string Name { get; set; }          public int PRice { get; set; }          public List<Health> items { get; set; }          public CheckSet()          {              items = new List<Health>();          }          public CheckSet(string name,List<Health> item)          {              this.Name = name;              this.items = item;          }          public void CalPrice()           {              int total = 0;              foreach (Health h in items)              {                  total = total + h.Price;              }              this.Price = total;          }      }  }  [csharp] view plain copy 在CODE上查看代碼片派生到我的代碼片using System;  using System.Collections.Generic;  using System.Linq;  using System.Text;    namespace 體檢項(xiàng)目  {      //檢查項(xiàng)目類(lèi)    public  class Health      {          public string Name { get; set; }          public string Description { get; set; }          public int Price { get; set; }          public Health()          {            }          public Health(string name,string ds,int price)          {              this.Name = name;              this.Description = ds;              this.Price = price;          }      }  }  [csharp] view plain copy 在CODE上查看代碼片派生到我的代碼片using System;  using System.Collections.Generic;  using System.ComponentModel;  using System.Data;  using System.Drawing;  using System.Linq;  using System.Text;  using System.Windows.Forms;    namespace 體檢項(xiàng)目  {      public partial class Form1 : Form      {          public Form1()          {              InitializeComponent();          }          //采用泛型集合保存 所有 的體檢項(xiàng)目          List<Health> AllItems = new List<Health>();          //采用泛型集合保存 套餐 中的的體檢項(xiàng)目          List<Health> items = new List<Health>();         //使用字典保存套餐集合      public  Dictionary<string, CheckSet> HealthSet = new Dictionary<string, CheckSet>();          Health sg, ti, gan, B,shili;            CheckSet set = new CheckSet();          private void Form1_Load(object sender, EventArgs e)          {              this.label5.Text = "";              this.label7.Text = "";              ADD();              Student();          }          public void ADD()           {                              sg = new Health("身高", "用于檢查身高", 5);                  ti = new Health("體重", "用于檢查體重", 5);                  gan = new Health("肝功能", "用于檢查肝功能", 50);                  B = new Health("B超", "用于檢查B超", 30);                  shili = new Health("視力", "用于檢查視力", 50);                  AllItems.Add(sg);                  AllItems.Add(ti);                  AllItems.Add(gan);                  AllItems.Add(B);                  AllItems.Add(shili);              //    this.dataGridView1.DataSource = new BindingList<Health>(AllItems);                   this.comboBox2.Items.Add("請(qǐng)選擇");                  foreach (Health item in AllItems)                  {                      comboBox2.Items.Add(item.Name);                  }                  this.comboBox2.SelectedIndex = 0;                     }          //設(shè)置入學(xué)套餐          public void Student()           {              items = new List<Health>();              items.Add(sg);              items.Add(ti);              items.Add(gan);              set = new CheckSet("入學(xué)體檢",items);              //計(jì)算套餐價(jià)格              set.CalPrice();              this.HealthSet.Add("入學(xué)體檢",set);              //清空套餐下拉列表              this.comboBox1.Items.Clear();              //添加請(qǐng)選擇              this.comboBox1.Items.Add("請(qǐng)選擇");              //將 Dictionary的Key值 綁定到COMBOX1              foreach (string key in HealthSet.Keys)              {                  this.comboBox1.Items.Add(key);              }              //默認(rèn)選擇第一項(xiàng)              this.comboBox1.SelectedIndex = 0;             // this.dataGridView1.DataSource = new BindingList<Health>(items);          }          public void UpdateSet(CheckSet set)           {              this.dataGridView1.DataSource = new BindingList<Health>(set.items);          }            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)          {              string sNAME = this.comboBox1.Text;              if (sNAME == "請(qǐng)選擇")              {                  this.dataGridView1.DataSource = null;                  this.label5.Text = "";                  this.label7.Text = "";                  return;              }              //設(shè)置套餐名稱(chēng)              this.label5.Text = this.HealthSet[sNAME].Name;              //設(shè)置套餐總價(jià)              this.label7.Text = this.HealthSet[sNAME].Price.ToString();              UpdateSet(HealthSet[sNAME]);          }          /// <summary>          /// 添加 套餐 檢查的項(xiàng)目 方法          /// </summary>          /// <param name="sender"></param>          /// <param name="e"></param>          private void button2_Click(object sender, EventArgs e)          {              if (this.comboBox2.SelectedIndex==0)              {                  MessageBox.Show("請(qǐng)選擇一個(gè)項(xiàng)目");                return;              }              //聲明一個(gè)套餐來(lái)接受  套餐 列表的文字              string CBO = comboBox1.Text;              if (CBO=="請(qǐng)選擇")              {                  MessageBox.Show("請(qǐng)選擇套餐!");                  return;              }             // 判斷現(xiàn)有套餐是否存在              int index = this.comboBox2.SelectedIndex-1;              if (! this.HealthSet[CBO].items.Contains(AllItems[index]))              {                  this.HealthSet[CBO].items.Add(AllItems[index]);                  this.HealthSet[CBO].CalPrice();                  UpdateSet(this.HealthSet[CBO]);                  //刷新窗體集合名稱(chēng)                  this.label5.Text = this.HealthSet[CBO].Name;                  //刷新窗體集合的 價(jià)格                  this.label7.Text = this.HealthSet[CBO].Price.ToString();                  MessageBox.Show("添加成功!!!","提示");              }              else              {                  MessageBox.Show("該項(xiàng)目已存在","提示");              }          }          //刪除項(xiàng)目          private void button3_Click(object sender, EventArgs e)          {              string setName = this.comboBox1.Text;              if (this.dataGridView1.SelectedRows.Count==0)              {                  MessageBox.Show("沒(méi)有選擇刪除項(xiàng)");                  return;              }              //獲取選中的索引             int index =this.dataGridView1.SelectedRows[0].Index;              this.HealthSet[setName].items.RemoveAt(index);              //重新計(jì)算價(jià)格              this.HealthSet[setName].CalPrice();              UpdateSet(HealthSet[setName]);              this.label5.Text=set.Name;              this.label7.Text=set.Price.ToString();              MessageBox.Show("刪除成功");            }          /// <summary>          /// 添加套餐          /// </summary>          /// <param name="sender"></param>          /// <param name="e"></param>          private void button1_Click(object sender, EventArgs e)          {              if (this.textBox1.Text=="")              {                  MessageBox.Show("請(qǐng)輸入要添加的套餐名稱(chēng)");                  return;              }              CheckSet se = new CheckSet();              this.HealthSet.Add(this.textBox1.Text, se);              this.AddSet();             // this.comboBox1.Items.Clear();             //this.comboBox1.Items.Add("請(qǐng)選擇");             // foreach (string item in HealthSet.Keys)             // {             //     this.comboBox1.Items.Add(item);             // }             this.comboBox1.SelectedIndex = this.HealthSet.Count;              MessageBox.Show("添加成功");          }          public void AddSet()           {              this.comboBox1.Items.Clear();              this.comboBox1.Items.Add("請(qǐng)選擇");              foreach (string item in HealthSet.Keys)              {                  this.comboBox1.Items.Add(item);              }              this.comboBox1.SelectedIndex = 0;          }          }      }  


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 石狮市| 承德市| 屏东县| 凤阳县| 大宁县| 莱州市| 德惠市| 巴东县| 额济纳旗| 赣州市| 黔南| 秀山| 九寨沟县| 沙坪坝区| 平阳县| 宁城县| 定日县| 资阳市| 山东省| 天津市| 拉孜县| 离岛区| 胶州市| 德格县| 苍南县| 北安市| 嘉祥县| 禄劝| 响水县| 乐山市| 济南市| 讷河市| 黎川县| 金昌市| 赤壁市| 将乐县| 北流市| 沾化县| 卢湾区| 卓尼县| 大化|