Key ideas of health check plan and health check plan
Ideas
Define several classes:
HealthCheckItem class: check items
Attribute:
public string Description { get; set; } public int Price { get; set; } public string Name { get; set; }
Methods In the HealthCheckItem class:
// When you select a package from the package drop-down list, all check items under the package are added to the dgvlist. public HealthCheckItem (string name, int price, string description) {Name = name; price = price; Description = description ;}
Main Interface:
// Define multiple check items HealthCheckItem m, hg, wg, sg, hr, lf, eg, ba, bp, bt; // define the system default check package "admission check "; healthCheckSet setA; // use a generic set List to save all health check item lists <HealthCheckItem> allitems = new List <HealthCheckItem> (); // use the generic set List to save the List of health check items in the package <HealthCheckItem> items = new List <HealthCheckItem> (); // use the double row set (dictionary) save the set public Dictionary <string, HealthCheckSet> hs = new Dictionary <string, HealthCheckSet> ();
HealthCheckSet: Health Check plan
Attribute:
Public int Price {get; set;} // public string Name {get; set;} public List <HealthCheckItem> Items {get; set ;} // Items is a set of HealthCheckItem,
Methods In the HealthCheckSet class:
public HealthCheckSet() { Items = new List<HealthCheckItem>(); } public HealthCheckSet(string name, List<HealthCheckItem> items) { Name = name; Items = items; }
How to get the price:
// Method for obtaining the price public void CalcPrice () {int tatolPrice = 0; foreach (HealthCheckItem item in Items) {tatolPrice = tatolPrice + item. price;} // The Package Price is equal to the Price of each health check item and the Price = tatolPrice ;}
Add a new package:
// Add a new package private void btnAdd_Click (object sender, EventArgs e) {if (txtName. Text. Equals ("") {MessageBox. Show ("Enter the package name! ");} Else {HealthCheckSet hc = new HealthCheckSet (); hs. add (txtName. text, hc); // call and load the package drop-down box information method InitiateHealthSetList (); cboList. selectedIndex = hs. count (); lblname. text = cboList. text; hc. name = cboList. text; MessageBox. show ("added successfully! ");}}
Load package drop-down box information:
Private void InitiateHealthSetList () {// load the package drop-down list information // clear the drop-down list cboList first. items. clear (); // select cboList for adding. items. add ("select"); // bind the key value of the dictionary to the drop-down box as the value displayed in the drop-down box foreach (string k in hs. keys) {cboList. items. add (k);} // by default, the first item is selected cboList. selectedIndex = 0 ;}
Initialize check items:
Hg = new HealthCheckItem ("height", 15, "used for height check"); wg = new HealthCheckItem ("weight", 25, "used for weight check"); allitems. add (hg); allitems. add (wg );
Add check items:
// Add the check project private void btnOk_Click (object sender, EventArgs e) {if (cboProject. text. equals ("select") | cboProject. text. equals ("") {MessageBox. show ("select project"); return;} if (cboList. text = "select") {MessageBox. show ("select package"); return;} // List <T>. contains (object) can determine whether an object is in the set if (! Hs [cboList. text]. items. contains (allitems [cboProject. selectedIndex]) {// Add check item hs [cboList. text]. items. add (allitems [cboProject. selectedIndex]); // recalculates the total price of hs [cboList. text]. calcPrice (); // update UpdateSet (hs [cboList. text]); // refresh the form set name lblname. text = hs [cboList. text]. name; // refresh the price of the form set lblprice. text = hs [cboList. text]. price. toString (); MessageBox. show ("added successfully");} else {MessageBox. show ("this project already exists ");}}
Delete health check package information:
// Delete information private void btnDelete_Click (object sender, EventArgs e) {if (this. dgvInfo. selectedRows. count = 0) {MessageBox. show ("select the row to be deleted"); return;} // index int index = dgvInfo. selectedRows [0]. index; // check the deleted project data // The method for deleting a project from a generic set: RemoveAt (); hs [cboList. text]. items. removeAt (index); // recalculate the price hs [cboList. text]. calcPrice (); // update dgvlist data UpdateSet (hs [cboList. text]); lblname. text = setA. name; string choS = cboList. text; lblprice. text = hs [choS]. price. toString ();}
Fill in the dgvlist of the package and update the package check item
// Fill in the dgvlist of the package. Update the package check item private void UpdateSet (HealthCheckSet set) {dgvInfo. DataSource = new BindingList <HealthCheckItem> (set. Items );}