Health Check package system, health check package
Using System;
Using System. Collections. Generic;
Using System. Text;
Namespace ExaminationList
{
Public class HealthCheckItem
{
Public HealthCheckItem (string name, int price, string description)
{
This. Name = name;
This. Price = price;
This. Description = description;
}
Public HealthCheckItem ()
{
}
Private string name;
Public string Name
{
Get {return name ;}
Set {name = value ;}
}
Private string description;
Public string Description
{
Get {return description ;}
Set {description = value ;}
}
Private int price;
Public int Price
{
Get {return price ;}
Set {price = value ;}
}
}
}
Using System;
Using System. Collections. Generic;
Using System. Text;
Namespace ExaminationList
{
Public class HealthCheckSet
{
Public HealthCheckSet ()
{
Items = new List <HealthCheckItem> ();
}
Public HealthCheckSet (string name, List <HealthCheckItem> items)
{
This. Name = name;
This. items = items;
}
Private string name;
Public string Name
{
Get {return name ;}
Set {name = value ;}
}
Private List <HealthCheckItem> items;
Public List <HealthCheckItem> Items
{
Get {return items ;}
Set {items = value ;}
}
Private int price;
Public int Price
{
Get {return price ;}
}
Public void CalcPrice ()
{
Int totalPrice = 0;
Foreach (HealthCheckItem item in items)
{
TotalPrice + = item. Price;
}
This. price = totalPrice;
}
}
}
Using ExaminationList;
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Linq;
Using System. Text;
Using System. Threading. Tasks;
Using System. Windows. Forms;
Namespace js
{
Public partial class Form1: Form
{
HealthCheckItem height, weight, sight, hearing, liverFun, ekg;
HealthCheckSet setA;
Public Form1 ()
{
InitializeComponent ();
}
List <HealthCheckItem> AllItem = new List <HealthCheckItem> ();
List <HealthCheckItem> items = new List <HealthCheckItem> ();
Public Dictionary <string, HealthCheckSet> healthset = new Dictionary <string, HealthCheckSet> ();
Private void Form1_Load (object sender, EventArgs e)
{
LblSetName. Text = "";
LblSetPrice. Text = "";
This. btnAdd. Enabled = false;
This. btnDel. Enabled = false;
InitItems ();
InitSets ();
InitHealthSetList ();
}
Public void InitItems ()
{
Height = new HealthCheckItem ("height", 5, "used to check height ");
Weight = new HealthCheckItem ("weight", 8, "used for weight check ");
Sight = new HealthCheckItem ("vision", 10, "used to check vision ");
Hearing = new HealthCheckItem ("hearing", 10, "used to check hearing ");
LiverFun = new HealthCheckItem ("liver function", 50, "used to check liver function ");
Ekg = new HealthCheckItem ("ECG", 100, "used to check ECG ");
AllItem. Add (height );
AllItem. Add (weight );
AllItem. Add (sight );
AllItem. Add (hearing );
AllItem. Add (liverFun );
AllItem. Add (ekg );
}
Public void InitSets ()
{
Items = new List <HealthCheckItem> ();
Items. Add (height );
Items. Add (weight );
Items. Add (sight );
SetA = new HealthCheckSet ("admission exam", items );
SetA. CalcPrice ();
This. healthset. Add ("admission exam", setA );
}
Public void InitHealthSetList ()
{
This. cboSets. Items. Clear ();
This. cboSets. Items. Add ("select ");
Foreach (string key in this. healthset. Keys ){
This. cboSets. Items. Add (key );
}
This. cboSets. SelectedIndex = 0;
}
Private void UpdateSet (HealthCheckSet set)
{
This. dgvHealthList. DataSource = new BindingList <HealthCheckItem> (this. items );
}
Private void cboSets_SelectedIndexChanged (object sender, EventArgs e)
{
String setName = this. cboSets. Text;
If (setName = "select "){
This. dgvHealthList. DataSource = new BindingList <HealthCheckItem> ();
LblSetName. Text = "";
LblSetPrice. Text = "";
Return;
}
LblSetName. Text = this. healthset [setName]. Name;
LblSetPrice. Text = this. healthset [setName]. Price. ToString ();
UpdateSet (healthset [setName]);
This. btnDel. Enabled = true;
}
Private void btnDel_Click (object sender, EventArgs e)
{
String setName = this. cboSets. Text;
If (this. dgvHealthList. SelectedRows. Count = 0 ){
MessageBox. Show ("You have not selected the delete item", "friendly prompt", MessageBoxButtons. OK, MessageBoxIcon. Error );
Return;
}
Int index = this. dgvHealthList. SelectedRows [0]. Index;
This. healthset [setName]. Items. RemoveAt (index );
This. healthset [setName]. CalcPrice ();
UpdateSet (healthset [setName]);
This. lblSetName. Text = setA. Name;
This. lblSetPrice. Text = setA. Price. ToString ();
MessageBox. Show ("deleted successfully! "," Friendly Reminder ", MessageBoxButtons. OK, MessageBoxIcon. Information );
}
Private void cboItems_SelectedIndexChanged (object sender, EventArgs e)
{
If (this. cboItems. Text! = "Select ")
{
This. btnAdd. Enabled = true;
}
Else
{
This. btnAdd. Enabled = false;
}
}
Private void btnAdd_Click (object sender, EventArgs e)
{
If (this. cboItems. SelectedIndex = 0 ){
MessageBox. Show ("select a project ");
Return;
}
String cboSetText = this. cboSets. Text;
If (cboSetText = "select "){
MessageBox. Show ("select package ");
Return;
}
Int index = this. cboItems. SelectedIndex-1;
If (! This. healthset [cboSetText]. Items. Contains (AllItem [index])
{
This. healthset [cboSetText]. Items. Add (AllItem [index]);
This. healthset [cboSetText]. CalcPrice ();
UpdateSet (this. healthset [cboSetText]);
This. lblSetName. Text = this. healthset [cboSetText]. Name;
This. lblSetPrice. Text = this. healthset [cboSetText]. Price. ToString ();
MessageBox. Show ("added successfully! "," Friendly Reminder ", MessageBoxButtons. OK, MessageBoxIcon. Information );
}
Else
{
MessageBox. Show ("this project already exists! "," Friendly Reminder ", MessageBoxButtons. OK, MessageBoxIcon. Error );
}
}
Private void btnOK_Click (object sender, EventArgs e)
{
If(string.IsNullOrEmpty(this.txt HealthName. Text. Trim ())){
MessageBox. Show ("Enter the package name", "tip", MessageBoxButtons. OK, MessageBoxIcon. Information );
}
HealthCheckSet Hch = new HealthCheckSet ();
This.healthset.Add(this.txt HealthName. Text. Trim (), Hch );
This. InitHealthSetList ();
This. cboSets. SelectedIndex = this. healthset. Count;
MessageBox. Show ("added successfully! "," Friendly Reminder ", MessageBoxButtons. OK, MessageBoxIcon. Information );
}
}
}