zoukankan      html  css  js  c++  java
  • 体检套餐系统

    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("身高",5,"用于检查身高");
                weight = new HealthCheckItem("体重",8,"用于检查体重");
                sight = new HealthCheckItem("视力",10,"用于检查视力");
                hearing = new HealthCheckItem("听力",10,"用于检查听力");
                liverFun = new HealthCheckItem("肝功能",50,"用于检查肝功能");
                ekg = new HealthCheckItem("心电图",100,"用于检查心电图");
               
                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("入学体检",items);
                setA.CalcPrice();
                this.healthset.Add("入学体检",setA);
            }

            public void InitHealthSetList()
            {
                this.cboSets.Items.Clear();
                this.cboSets.Items.Add("请选择");
                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=="请选择"){
                    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("您没有选中删除项","友情提示",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("删除成功!","友情提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }

            private void cboItems_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (this.cboItems.Text != "请选择")
                {
                    this.btnAdd.Enabled = true;
                }
                else
                {
                    this.btnAdd.Enabled = false;
                }
            }

            private void btnAdd_Click(object sender, EventArgs e)
            {
                if(this.cboItems.SelectedIndex==0){
                    MessageBox.Show("请选择一个项目");
                    return;
                }
                string cboSetText = this.cboSets.Text;
                if(cboSetText=="请选择"){
                    MessageBox.Show("请选择套餐");
                    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("添加成功!", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Information);


                }
                else
                {
                    MessageBox.Show("该项目已存在!","友情提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
                }
            }

            private void btnOK_Click(object sender, EventArgs e)
            {
                if(string.IsNullOrEmpty(this.txtHealthName.Text.Trim())){
                    MessageBox.Show("请输入套餐名称","友情提示",MessageBoxButtons.OK,MessageBoxIcon.Information);

                }
                HealthCheckSet Hch = new HealthCheckSet();
                this.healthset.Add(this.txtHealthName.Text.Trim(),Hch);
                this.InitHealthSetList();
                this.cboSets.SelectedIndex = this.healthset.Count;
                MessageBox.Show("添加成功!","友情提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }

        }
    }

  • 相关阅读:
    “epoll errno (EINTR)4” —— epoll遭遇EINTR(Interrupted system call)
    linux普通用户无法登录mysql,管理员用户却不用密码就能登录
    三小时快速入门Python第五篇--异常处理与迭代器
    三小时快速入门Python第四篇--函数与对象
    三小时快速入门Python第三篇--控制流分支与循环
    三小时快速入门Python第二篇--变量与集合
    三小时快速入门Python第一篇--原始数据类型与操作
    Go语言学习笔记十八-练习篇-Go语言版学生信息管理系统
    Go语言学习笔记十七--Go语言面向对象struct的基本使用
    Go语言学习笔记十六-Go语言init函数
  • 原文地址:https://www.cnblogs.com/wangbenqing/p/6564297.html
Copyright © 2011-2022 走看看