The form is built as follows:
One: the implementation of the functions are mainly the following aspects:
①: Displays project details for the specified plan
②: Add Check item information to the specified plan
③: Delete Item information from a package
④: New Package
Second: the establishment of physical examination project maintenance system in the Inspection Project category (Healthcheckitem), Physical examination Package Class (Healthcheckset)
The properties in the Healthcheckitem class are described below:
Description: Project Description
Name: Project names
Price: Project Prices
The properties in the Healthcheckset class are described below:
A collection of Items:healthcheckitem. Using generic collection list<t> as the data structure of storage Healthcheckitem
Price: Package price, which is the sum of the prices of items checked in the Items property
Name: Package names
The key code is as follows:
Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; namespace chapter05{ public class Healthcheckitem { //project name private string name; public string name { get {return Name;} set {name = value;} } Price private int prices; public int price { get {return price;} set {price = value;} } Description private string description; public string Description { get {return Description;} Set {description = value;} } Public Healthcheckitem (String name,int price,string description) {this . name = name; This. Price = Price; This. Description = Description;}} }
Using system;using system.collections.generic;using system.linq;using system.text;using System.Threading.Tasks; Namespace chapter05{public class Healthcheckset {//non-parametric constructs are instantiated in items public healthcheckset () { Items = new listThree: Use the collection to store the corresponding data, because the package, physical examination items have multiple. Define some containers to hold the data.
Define several inspection items healthcheckitem height, weight, sight, hearing, Liverfun, EKG, Bwaves, Bloodpressure, bloodtest; Define a system default check package "Entrance Examination" Healthcheckset SetA; Save all medical items list
IV: Initialize all medical items saved in AllItems
Initialize check item drop-down box value public void Inititems () {height = new Healthcheckitem ("Height", 5, "for height check"); Weight = new Healthcheckitem ("Weight", 5, "for weight checking."); Sight = new Healthcheckitem ("Vision", 10, "for examination of vision."); hearing = new Healthcheckitem ("Hearing", 10, "for examination of hearing."); Liverfun = new Healthcheckitem ("liver function", 50, "for the examination of liver function."); bwaves = new Healthcheckitem ("B-Super", 30, "for checking B-Ultrasound."); EKG = new Healthcheckitem ("ECG", 50, "for examination of electrocardiogram."); Bloodpressure = new Healthcheckitem ("blood pressure", 20, "used to check blood pressure."); Bloodtest = new Healthcheckitem ("Blood routine", 20, "used to check blood routine."); Allitems.add (height); Allitems.add (weight); Allitems.add (sight); Allitems.add (hearing); Allitems.add (Liverfun); Allitems.add (bwaves); Allitems.add (EKG); Allitems.add (bloodpressure); Allitems.add (bloodtest); Add Please select THIS.CBOITEMS.ITEMS.ADD ("Please select"); foreach (Healthcheckitem item in AllItems) {CBOITEMS.ITEMS.ADD (item. Name); }//Default first item is selected This.cboItems.SelectedIndex = 0; }
V: Generate default Plan data and add carrier check package drop-down list
Generate default plan data public void Initsets () { items = new list
Add Carrier Check Package drop-down list public void Inithealthsetlist () { //First empty Package drop-down list this.cboSets.Items.Clear (); Add Please select this.cboSets.Items.Add ("Please select"); Binds the key value of the dictionary to the ComboBox, as the value of the ComboBox display, foreach (string key in). Healthset.keys) { this.cboSets.Items.Add (key); } The default first item is checked this.cboSets.SelectedIndex = 0; }
Six: Calling methods in the Load event
private void Frmmain_load (object sender, EventArgs e) { this.lblSetName.Text = ""; This.lblSetPrice.Text = ""; Initialize all inspection items inititems (); Initialize default plan initsets (); Load drop-down list box inithealthsetlist (); btnadd.enabled = false; btndel.enabled = false; This.dgvHealthList.AutoGenerateColumns = false; }
Seven: When the package dropdown box selection changes, you need to load the corresponding medical items under the selected plan
Fill package DataGridView private void Updateset (Healthcheckset set) { Dgvhealthlist.datasource = new Bindinglist
Package list private void Cbosets_selectedindexchanged (object sender, EventArgs e) { string setName = This.cboSets.Text; if (SetName = = "Please select") { this.dgvHealthList.DataSource = null; Lblsetname.text = ""; Lblsetprice.text = ""; return; } Set the package name Lblsetname.text = this. Healthset[setname]. Name; Set Package Total Price Lblsetprice.text = this. Healthset[setname]. Price.tostring (); Update package Check item updateset (Healthset[setname]); Delete button is available status btndel.enabled = true; }
Eight: Add the item in DataGridView. Determine if the item you want to add already exists, and if it is not in the collection where you want to add the item, perform the add operation
Add private void btnAdd_Click (object sender, EventArgs e) {if (this.cboItems.SelectedIn dex==0) {MessageBox.Show ("Please select a project!) "); Return } string cbosettext = This.cboSets.Text; if (Cbosettext = = "Please select") {MessageBox.Show ("Please select the package!") "); Return }//To determine if the added physical examination item exists in the existing plan int index = THIS.CBOITEMS.SELECTEDINDEX-1; if (!this. Healthset[cbosettext]. Items.contains (Allitems[index])) {this. Healthset[cbosettext]. Items.Add (Allitems[index]); This. Healthset[cbosettext]. CalcPrice (); Updateset (this. Healthset[cbosettext]); Refreshes the form collection name This.lblSetName.Text = this. Healthset[cbosettext]. Name; Refreshes the form collection price This.lblSetPrice.Text = this. Healthset[cbosettext]. Price.tostring (); MessageBox.show ("added successfully! "," hint ", MessageBoxButtons.OK, MessageBoxIcon.Information); } else {MessageBox.Show ("the project already exists! "," hint ", messageboxbuttons.ok,messageboxicon.information); } }
IX: Implement DELETE health plan information
//delete item private void Btndel_click (object sender, EventArgs e) {string setnames = Thi S.cbosets.text; if (This.dgvHealthList.SelectedRows.Count = = 0) {MessageBox.Show ("Delete Item not selected!") "," hint ", messageboxbuttons.ok,messageboxicon.information); Return }//Gets the index of the selected item int index = This.dgvhealthlist.selectedrows[0]. Index; Delete Check item this. Healthset[setnames]. Items.removeat (index); Recalculate price this. Healthset[setnames]. CalcPrice (); Update DataGridView Display Updateset (Healthset[setnames]); Reset Label Display lblsetname.text = Seta.name; string cbosettext = This.cboSets.Text; Lblsetprice.text = this. Healthset[cbosettext]. Price.tostring (); MessageBox.Show ("Delete succeeded! "," hint ", MessageBoxButtons.OK, MessageBoxIcon.Information); }
Ten: Add a plan to the package list, add the package by adding the key value in the dictionary<k,v>, and refresh the drop-down list.
Add package private void Btnok_click (object sender, EventArgs e) { if (string. IsNullOrEmpty (Txthealthname.text)) { MessageBox.Show ("Please enter the package name", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { Healthcheckset Hch = new Healthcheckset (); This. Healthset.add (This.txtHealthName.Text, Hch); This. Inithealthsetlist (); The drop-down box adds the displayed content This.cboSets.SelectedIndex = this. Healthset.count; Lblsetname.text = Cboitems.text; Hch.name = Cbosets.text; MessageBox.Show ("added successfully! "," hint ", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
11: Add button is disabled when item is not added, when added is available
Check item private void Cboitems_selectedindexchanged (object sender, EventArgs e) { if (this.cboSets.Text! = " Please select ") { this.btnAdd.Enabled = true; } else { this.btnAdd.Enabled = false; } }
The fifth item: Medical Checkup Package