體檢套餐管理系統


       體檢套餐管理系統

          1.任務描述

                 1.加載默認體檢套餐

                    

              2.維護體檢套餐

                    

                    維護功能主要有以下幾個方面

                    1.顯示指定套餐的項目明細

                    2.向指定套餐添加檢查項目信息

                    3.刪除套餐中的項目信息

                    4.新建套餐

         

          2.實現代碼      

              1.搭建體檢套餐管理系統的主窗體

                          

              2.創建體檢套餐項目維護中的檢查項目類,體檢套餐類

                 

              3.系統默認提供一種套餐“入學套餐”填充檢查項目對象到窗體

                 

 1   //套餐類
 2    public class HealthCheckSet  3  {  4         private string name;  5 
 6         public string Name  7  {  8             get { return name; }  9             set { name = value; } 10  } 11 
12         private int price; 13 
14         public int Price 15  { 16             get { return price; } 17             set { price = value; } 18  } 19 
20         private Dictionary<string, HealthCheckItem> item; 21 
22         public Dictionary<string, HealthCheckItem> Item 23  { 24             get { return item; } 25             set { item = value; } 26  } 27 
28         public HealthCheckSet() 29  { 30             item = new Dictionary<string, HealthCheckItem>(); 31  } 32 
33         public HealthCheckSet(string name,Dictionary<string,HealthCheckItem> item) 34  { 35             this.Name = name; 36             this.Item = item; 37  } 38 
39         public void GetPrice() 40  { 41             int sum = 0; 42             foreach (HealthCheckItem i in item.Values) 43  { 44                 sum += i.Price; 45  } 46             this.price = sum; 47  } 48     }

 

 1   //項目類
 2    public class HealthCheckItem  3  {  4         private string name;  5 
 6         public string Name  7  {  8             get { return name; }  9             set { name = value; } 10  } 11         private int price; 12 
13         public int Price 14  { 15             get { return price; } 16             set { price = value; } 17  } 18         private string description; 19 
20         public string Description 21  { 22             get { return description; } 23             set { description = value; } 24  } 25         public HealthCheckItem(string name, int price, string description) 26  { 27             this.Name = name; 28             this.Price = price; 29             this.Description = description; 30  } 31     }

 

 1 //窗體中主要實現代碼
 2         public frmMain()  3  {  4  InitializeComponent();  5  }  6         //用於保存單個項目
 7  HealthCheckItem h1, h2, h3, h4, h5, h6, h7, h8;  8         //單個項目集合
 9         Dictionary<string, HealthCheckItem> allItem = new Dictionary<string, HealthCheckItem>(); 10         //一個套餐所包含的項目
11         Dictionary<string, HealthCheckItem> items = new Dictionary<string, HealthCheckItem>(); 12         //套餐集合
13         Dictionary<string, HealthCheckSet> allSet = new Dictionary<string, HealthCheckSet>(); 14         //定義一個初始化套餐
15         HealthCheckSet set; 16         //向初始化的套餐添加各個項目
17         public void GetItems() 18  { 19             h1 = new HealthCheckItem("身高",5,"用於檢查身高"); 20             h2 = new HealthCheckItem("體重", 5, "用於檢查體重"); 21             h3 = new HealthCheckItem("視力", 5, "用於檢查視力"); 22             h4 = new HealthCheckItem("聽力", 5, "用於檢查聽力"); 23             h5 = new HealthCheckItem("B超", 30, "用於檢查B超"); 24             h6 = new HealthCheckItem("肝功能", 30, "用於檢查肝功能"); 25             h7 = new HealthCheckItem("心電圖", 50, "用於檢查心電圖"); 26             h8 = new HealthCheckItem("血常規", 50, "用於檢查血常規"); 27  allItem.Add(h1.Name, h1); 28  allItem.Add(h2.Name, h2); 29  allItem.Add(h3.Name, h3); 30  allItem.Add(h4.Name, h4); 31  allItem.Add(h5.Name, h5); 32  allItem.Add(h6.Name, h6); 33  allItem.Add(h7.Name, h7); 34  allItem.Add(h8.Name, h8); 35 
36  } 37         //添加一個套餐
38         public void GetSet() 39  { 40  items.Add(h1.Name,h1); 41  items.Add(h3.Name, h3); 42  items.Add(h4.Name, h4); 43             set = new HealthCheckSet("入學體檢",items); 44             set.GetPrice(); 45             allSet.Add("入學體檢",set); 46  } 47         //綁定下拉框 
48         public void GetCbo() 49  { 50  cboSetList.Items.Clear(); 51             cboSetList.Items.Add("請選擇"); 52             foreach (string a in allSet.Keys) 53  { 54  cboSetList.Items.Add(a); 55  } 56             this.cboSetList.SelectedIndex = 0; 57 
58  cbolitemsList.Items.Clear(); 59             cbolitemsList.Items.Add("請選擇"); 60             foreach (string a in allItem.Keys) 61  { 62  cbolitemsList.Items.Add(a); 63  } 64             this.cbolitemsList.SelectedIndex = 0; 65  } 66         //窗體加載時調用各個方法
67         private void frmMain_Load(object sender, EventArgs e) 68  { 69 
70  GetItems(); 71  GetSet(); 72  GetCbo(); 73         }

 

          實現效果:

      

     4.實現刪除體檢套餐信息

         

 //刪除
        private void btnDelete_Click(object sender, EventArgs e) { string name = this.dgvList.SelectedRows[0].Cells[0].Value.ToString(); string Setname = this.cboSetList.Text; MessageBox.Show(string.Format("確定要刪除"+name+"這一項嗎?","提示")); allSet[Setname].Item.Remove(name); UpdateSet(allSet[Setname]); }

實現效果:

 

5.向套餐中添加檢查項目

//向套餐中添加項目
        private void btnItemAdd_Click(object sender, EventArgs e) { if(this.cbolitemsList.SelectedIndex==0) { MessageBox.Show("請選擇要添加的項目"); return; } string name=this.cboSetList.Text; if(name=="請選擇") { MessageBox.Show("請選擇套餐"); return; } if (!allSet[name].Item.Keys.ToList().Contains(this.cbolitemsList.Text)) { allSet[name].Item.Add(this.cbolitemsList.Text, allItem[this.cbolitemsList.Text]); this.lblName.Text = name; GetPrice(); UpdateSet(allSet[name]); } else { MessageBox.Show("已有該項目"); } }

實現效果:

 

6.新建套餐

 1 //添加套餐
 2         private void btnSetAdd_Click(object sender, EventArgs e)  3  {  4             string setName=this.txtSetName.Text;  5             if (this.txtSetName.Text.Trim() != null && this.txtSetName.Text.Trim() != "")  6  {  7                 HealthCheckSet set = new HealthCheckSet();  8                 allSet.Add(txtSetName.Text, set);  9  GetCbo(); 10                 this.cboSetList.SelectedIndex = allSet.Count(); 11  } 12             else 
13  { 14                 MessageBox.Show("請輸入套餐名稱"); 15  } 16  } 17         //下拉框中套餐名字改變時DataGridView里面所綁定的項目也改變
18         private void cboSetList_SelectedIndexChanged(object sender, EventArgs e) 19  { 20             string name = this.cboSetList.Text; 21             if (name == "請選擇") 22  { 23                 this.dgvList.DataSource = new BindingList<HealthCheckItem>(); 24                 this.lblName.Text = ""; 25                 this.lblPrice.Text = ""; 26                 return; 27  } 28             this.lblName.Text = name; 29  GetPrice(); 30  UpdateSet(allSet[name]); 31         }

實現效果:

 

項目基本功能實現,希望對你有所幫助

請關注我,Call_迪迦


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM