第五章上机代码

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());
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值