Health Check package management system and package management system

Source: Internet
Author: User

Health Check package management system and package management system

This article is a Dictionary <K, V> double-row collection development project. If you need List <T> Single-Column Collection Development for this project, please search

Blog: http://www.cnblogs.com/lsy131479/

 

Form

      

 

 

I. first create a project class

Public class HealthCheckItem {// project description private string description; // project name private string name; // project price private int price; // public HealthCheckItem () constructed without Parameters () {}// public HealthCheckItem (string description, string name, int price) {this. description = description; this. name = name; this. price = price;} public string Description {get => description; set => description = value;} public string Name {get => name; set => name = value ;} public int Price {get => price; set => price = value ;}}

Ii. Create a meal set

/// <Summary> /// package class /// </summary> public class HealthCheckSet {// package name private string name; // total package price private int price; // private Dictionary <string, HealthCheckItem> items = new Dictionary <string, HealthCheckItem> (); // construct public HealthCheckSet () without Parameters () {}// public HealthCheckSet (string name) {this. name = name;} public string Name {get => name; set => name = value;} public int Price {get => price; set => price = value ;} public Dictionary <string, HealthCheckItem >{get => items; set => items = value ;}}

 

Iii. Main form code

/// <Summary> /// check Plan Management System -- Dictionary <K, V> double row set /// </summary> public partial class FrmMain: Form {public FrmMain () {InitializeComponent ();} private void FrmMain_Load (object sender, EventArgs e) {// Delete extra columns this. dataGridView1.AutoGenerateColumns = false; // clear unnecessary rows this. dataGridView1.AllowUserToAddRows = false;/** package drop-down box initialization **/HealthCheckSet set0 = new HealthCheckSet ("select"); HealthCheckSet set1 = New HealthCheckSet ("admission exam"); set. add (set0.Name, set0); set. add (set1.Name, set1); AddExamCbo () ;}// refresh the public void AddExamCbo () {BindingSource source = new BindingSource (); source. dataSource = set. keys; this. cboExams. dataSource = source;} // set Dictionary <string, HealthCheckSet> set = new Dictionary <string, HealthCheckSet> (); // initialize the project set Dictionary <string, healthCheckItem> allItems = new Di Ctionary <string, HealthCheckItem> (); public void AddPhyCbo () {/** initialize (refresh) Project drop-down box **/allItems. clear (); HealthCheckItem item1 = new HealthCheckItem ("is used to check height. "," Height ", 5); HealthCheckItem item2 = new HealthCheckItem (" is used to check the weight. "," Weight ", 5); HealthCheckItem item3 = new HealthCheckItem (" used to check liver function. "," Liver function ", 50); HealthCheckItem item4 = new HealthCheckItem (" is used to check eyesight. "," Eyesight ", 5); HealthCheckItem item5 = new HealthCheckItem (" is used to check hearing. "," Hearing ", 5); HealthCheckItem item6 = new HealthCheckItem (" is used to check B ultrasound. "," B ultrasound ", 80); HealthCheckItem item7 = new HealthCheckItem (" is used to check ECG. "," ECG ", 100); allItems. add (item1.Name, item1); allItems. add (item2.Name, item2); allItems. add (item3.Name, item3); allItems. add (item4.Name, item4); allItems. add (item5.Name, item5); allItems. add (item6.Name, item6); allItems. add (item7.Name, item7); this. cboPhy. displayMember = "name"; BindingSource source = new BindingSource (); source. dataSource = allItems. keys; this. cboPhy. dataSource = source;} priv Ate void cboExams_SelectedIndexChanged (object sender, EventArgs e) {/** change the subscript in the drop-down box and determine the subscript. Change status **/this. lblNames. text = this. cboExams. text; RenovateDgv (); Btn (); if (this. cboExams. selectedIndex> 0) {this. btnAdd. enabled = true; AddPhyCbo ();} else {this. btnAdd. enabled = false; this. cboPhy. dataSource = null;} private void btnNew_Click (object sender, EventArgs e) {// if (txtNewName. text = "" | txtNewName. text = null) {MessageBox. show ("Enter the package name! "); Return;}/** set to add package name * and refresh the drop-down box **/HealthCheckSet set3 = new HealthCheckSet(this.txt NewName. text); set. add (set3.Name, set3); AddExamCbo (); this. cboExams. text = set3.Name; MessageBox. show ("added successfully! ");} Public void AddDgv () {// ToList () convert the double row set into a single column set // Contains () in a single column set, find whether the item if (set [cboExams. text]. items. keys. toList (). contains (this. cboPhy. text) {MessageBox. show ("You have added this item! "); Return;}/** add project to the package **/set [cboExams. text]. items. add (cboPhy. text, allItems [cboPhy. text]); Btn (); MessageBox. show ("added successfully! ");} Public void RenovateDgv () {/** refresh the datagridview **/BindingSource source = new BindingSource (); source. dataSource = set [cboExams. text]. items. values; dataGridView1.DataSource = source;} private void btnAdd_Click (object sender, EventArgs e) {/** add package project **/AddDgv (); RenovateDgv ();} public void Btn () {/** indicates whether an element exists in the set to change the status of the delete button. **/if (set [cboExams. text]. items. count> 0) {this. btnDel. ena Bled = true;} else {this. btnDel. enabled = false;}/** calculate the total package amount * and refresh the control **/set [cboExams. text]. price = 0; foreach (KeyValuePair <string, HealthCheckItem> it in set [cboExams. text]. items) {set [cboExams. text]. price + = it. value. price;} this. lblPrices. text = set [cboExams. text]. price. toString ();} private void btnDel_Click (object sender, EventArgs e) {/** remove the specified set element by the key * and refresh the value and status displayed by the control */set [cboEx Ams. text]. items. remove (this. dataGridView1.SelectedRows [0]. cells [0]. value. toString (). trim (); RenovateDgv (); Btn (); MessageBox. show ("deleted successfully! ");}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.