A small project written with a generic collection
1. To achieve a new medical checkup plan, and if you already have the medical plan can not be created again,
2. To implement the package list dynamic update, not add a health checkup package, in the package list will automatically add an item;
3. Add a check item to the current package list, there is no duplicate medical examination item in a medical examination plan;
4. Dynamic calculation plan current price;
5. Dynamic Dgvlist of the current package of the package list in the program;
6. Implementation of the removal of physical examination items:
Here is the implementation:
New Checkup Package:
Add a physical examination to the health plan and calculate the package price:
To delete a selected medical item:
Select a health plan in the package list to view specific items and package prices:
Cannot add duplicate packages, each plan cannot have duplicate medical items:
Here's the code:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceMedical Package System { Public classHC {//Physical Examination Item category PublicHC () {}//The surrogate constructor method is used to initialize member variables PublicHC (stringNamestringDescintPrice ) { This. Name =name; This. Price =Price ; This. Desc =desc; } Public stringName {Get;Set; } Public stringDesc {Get;Set; } Public intPrice {Get;Set; } }}
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespaceMedical Package System { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } //declare a collection of HC types, save the initial health check itemListNewList() { NewHC ("Height","for height check", A), NewHC ("Weight","for weight checking",Ten), NewHC ("liver function","used to check liver function", -), NewHC ("B-Super","used to check the inside of the body", -), NewHC ("ECG","for ECG examination", Max), NewHC ("Hearing","used to check hearing", -), }; //declare a double-column collection, which is used to save the checkup plan, the package name is key, and the physical examination item is value;dictionary<string, listNewdictionary<string, list(); Private voidForm1_Load (Objectsender, EventArgs e) { //bind the name of the medical item in the drop-down list Cbo2 foreach(HC IteminchHC1) {Cbo2. Items.Add (item. Name); } } //Bind the name of the medical plan to the drop -down list cbo1 Private voidinfo () {Cbo1. Items.clear (); foreach(stringIteminchHC2. Keys) {Cbo1. Items.Add (item); } } //How to create a new medical checkup plan Private voidNew _click (Objectsender, EventArgs e) { intError =0; foreach(stringIteminchHC2. Keys) {if(Item = =txt1. Text) {Error=1; } } if(Txt1. text!=""&&error!=1) {hc2. ADD (txt1. Text,NewList()); info (); MessageBox.Show ("Add Success","Tips", MessageBoxButtons.OK, Messageboxicon.asterisk); } Else if(Error = =1) {MessageBox.Show ("The package is already available and cannot be added again","Tips", MessageBoxButtons.OK, Messageboxicon.asterisk); } Else{MessageBox.Show ("The package name cannot be empty","Tips", MessageBoxButtons.OK, Messageboxicon.asterisk); } } //How to add a physical examination item to a selected health plan Private voidButton2_Click (Objectsender, EventArgs e) { intError =0; foreach(stringIteminchHC2. Keys) {if(Item = =Cbo1. Text) { for(inti =0; I < Hc2[item]. Count; i++) { if(Hc2[item][i]. Name = =Cbo2. Text) {Error=1; }}}} HC H=NewHC (); if(Cbo1. Text! =""&& Cbo2. Text! =""&&error==0) { foreach(HC IteminchHC1) { if(item. Name = =Cbo2. Text) {h=item; } } foreach(stringIteminchHC2. Keys) {if(Item = =Cbo1. Text) {Hc2[item]. ADD (h); } } } Else if(Error = =1) {MessageBox.Show ("there can be no duplicate medical items.","Tips", MessageBoxButtons.OK, Messageboxicon.asterisk); } Else{MessageBox.Show ("please fill in the whole package information","Tips", MessageBoxButtons.OK, Messageboxicon.asterisk); } info1 (); } Private voidCbo1_selectionchangecommitted (Objectsender, EventArgs e) {info1 (); } //How to update the physical examination plan dynamically Private voidInfo1 () {intMoney =0; foreach(stringIteminchHC2. Keys) {if(Cbo1. selecteditem.tostring () = =Item) { for(inti =0; I ) { money+=Hc2[item][i]. Price; } Datagridview1.datasource=NewBindinglist(Hc2[item]); LB1. Text=Cbo1. Selecteditem.tostring (); Lb2. Text=Money . ToString (); } } } //method of deletion Private voidButton3_Click (Objectsender, EventArgs e) { foreach(stringIteminchHC2. Keys) {if(Item = =Cbo1. Selecteditem.tostring ()) {if(DataGridView1.SelectedRows.Count >=0) { for(inti =0; I < Hc2[item]. Count; i++) { if(Hc2[item][i]. Name = = datagridview1.selectedrows[0]. cells[0]. Value.tostring ()) {DialogResult Dr= MessageBox.Show ("whether to delete","Tips", Messageboxbuttons.yesno, Messageboxicon.asterisk); if(dr = =dialogresult.yes) {Hc2[item]. RemoveAt (i); Info1 (); MessageBox.Show ("Delete succeeded","Tips", MessageBoxButtons.OK, Messageboxicon.asterisk); } } } } } } } Private voidTxt1_textchanged (Objectsender, EventArgs e) { } Private voidDatagridview1_cellcontentclick (Objectsender, DataGridViewCellEventArgs e) { } }}
C # Health Package program