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 No5
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
HealthCheckItem height, weight, eyes, listen, liver, b, heart;
public List<HealthCheckItem> AllItems = new List<HealthCheckItem>();
Dictionary<string, HealthCheckItem> items = new Dictionary<string, HealthCheckItem>();
public List<HealthCheckSet> healthset=new List<HealthCheckSet>();
public void iitems() {
HealthCheckItem height = new HealthCheckItem();
height.Name = "身高";
height.Description = "用于检查身高.";
height.Price = 5;
HealthCheckItem weight = new HealthCheckItem();
weight.Name = "体重";
weight.Description = "用于检查体重.";
weight.Price = 5;
HealthCheckItem eyes = new HealthCheckItem();
eyes.Name = "视力";
eyes.Description = "用于检查视力.";
eyes.Price = 5;
HealthCheckItem listen = new HealthCheckItem();
listen.Name = "听力";
listen.Description = "用于检查听力.";
listen.Price = 5;
HealthCheckItem liver = new HealthCheckItem();
liver.Name = "肝功能";
liver.Description = "用于检查肝功能.";
liver.Price = 5;
HealthCheckItem b = new HealthCheckItem();
b.Name = "B超";
b.Description = "用于检查B超.";
b.Price = 5;
HealthCheckItem heart = new HealthCheckItem();
heart.Name = "心电图";
heart.Description = "用于检查心电图.";
heart.Price = 5;
AllItems.Add(height);
AllItems.Add(weight);
AllItems.Add(eyes);
AllItems.Add(listen);
AllItems.Add(liver);
AllItems.Add(b);
AllItems.Add(heart);
items.Add(height.Name,height);
items.Add(weight.Name,weight);
items.Add(liver.Name,liver);
}
public void sitems() {
HealthCheckSet student = new HealthCheckSet();
student.Name = "入学体检";
student.Items = items;
student.CalcPrice();
this.healthset.Add(student);
}
private void button3_Click(object sender, EventArgs e)
{
foreach (HealthCheckItem i in AllItems)
{
if (dataGridView1.SelectedRows[0].Cells["项目名"].Value.ToString().Equals(i.Name))
{
items.Remove(i.Name);
sitems();
foreach (HealthCheckSet item in healthset)
{
if (item.Name.Equals(this.comboBox1.Text))
{
label7.Text = item.Price.ToString();
this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(items.Values.ToList());
}
}
}
}
}
private void button2_Click(object sender, EventArgs e)
{
foreach (HealthCheckItem i in AllItems) {
if (comboBox2.Text.Equals(i.Name))
{
items.Add(i.Name, i);
HealthCheckSet student = new HealthCheckSet();
student.Name = label5.Text;
student.Items = items;
student.CalcPrice();
this.healthset.Add(student);
foreach (HealthCheckSet item in healthset)
{
if (item.Name.Equals(this.comboBox1.Text))
{
label7.Text = item.Price.ToString();
this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(items.Values.ToList());
}
}
}
}
}
public void com1() {
this.comboBox1.Items.Clear();
this.comboBox1.Items.Add("请选择");
foreach (HealthCheckSet name in healthset) {
this.comboBox1.Items.Add(name.Name);
}
this.comboBox1.SelectedIndex = 0;
}
private void FrmMain_Load(object sender, EventArgs e)
{
iitems();
sitems();
com1();
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
items.Clear();
HealthCheckSet student = new HealthCheckSet();
student.Name = textBox1.Text.ToString();
student.Items = items;
student.CalcPrice();
this.healthset.Add(student);
com1();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text == "请选择") {
label5.Text = "";
label7.Text = "";
this.dataGridView1.DataSource = new BindingList<HealthCheckItem>();
return;
}
foreach (HealthCheckSet item in healthset) {
if (item.Name.Equals(this.comboBox1.Text)) {
label5.Text = item.Name;
label7.Text = item.Price.ToString();
this.dataGridView1.DataSource = new BindingList<HealthCheckItem>(items.Values.ToList());
}
}
this.button2.Enabled = true;
this.button3.Enabled = true;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace No5
{
public class HealthCheckItem
{
public HealthCheckItem(string name, double price, string description)
{
this.Name = name;
this.Description = description;
this.Price = price;
}
public HealthCheckItem()
{
}
private string description;
public string Description { get { return description; } set { description=value;} }
private string name;
public string Name { get { return name; } set { name = value; } }
private double price;
public double Price { get { return price; } set { price = value; } }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace No5
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMain());
}
}
}