第五章 体检项目

来源:互联网 发布:狼雨seo网络科技 编辑:程序博客网 时间:2024/03/29 02:00
using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using System.Windows.Forms;namespace Day05_体检套餐管理系统{    static class Program    {        /// <summary>        /// 应用程序的主入口点。        /// </summary>        [STAThread]        static void Main()        {            Application.EnableVisualStyles();            Application.SetCompatibleTextRenderingDefault(false);            Application.Run(new Form1());        }    }}using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Day05_体检套餐管理系统{    class HealthCheckSet    {        public List<HealthCheckItem> Items { get; set; }        public string  Name { get; set; }        public int  Price { get; set; }        public HealthCheckSet()        {        }        public  HealthCheckSet(string name,List<HealthCheckItem> items)//int price构两个函数        {            this.Items = items;            this.Name = name;           // this.Price = price;        }        public void CalcPrice()        {            int totalPrice = 0;            foreach(HealthCheckItem item in this.Items)            {                totalPrice += item.Price;            }            this.Price = totalPrice;        }           } }using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Day05_体检套餐管理系统{    class HealthCheckItem    {        public string Decription { get; set; }        public string Name { get; set; }        public int  Price { get; set; }        public  HealthCheckItem()        {        }        public  HealthCheckItem(string decription, string name, int price)        {            this.Decription = decription;            this.Name = name;            this.Price = price;        }    }}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 Day05_体检套餐管理系统{    public partial class Form1 : Form    {        //采用泛型集合List保存所有的体检项目        List<HealthCheckItem> AllItems = new List<HealthCheckItem>();        //采用泛型集合List保存套餐中的体检项目        List<HealthCheckItem> items = new List<HealthCheckItem>();        Dictionary<string, HealthCheckSet> HealthSet = new Dictionary<string, HealthCheckSet>();        public Form1()        {            InitializeComponent();        }            //选择"套餐列表"下拉列表事件        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)        {            string setName = this.cboSets.Text;            if (setName == "请选择")            {                this.dgvHealthList.DataSource = new BindingList<HealthCheckItem>();                lalSetName.Text = "";                lalSetPrice.Text = "";                return;            }            //设置套餐名称            lalSetName.Text=this.HealthSet[setName].Name;            //设置套餐价格            lalSetPrice.Text = this.HealthSet[setName].Price.ToString();            //更新套餐检查项目            UpdateSet(HealthSet[setName]);            //设置“删除”按钮为可用状态            this.btnDel.Enabled = true;        }        //更新套餐检查项目        private void UpdateSet(HealthCheckSet set)        {            this.dgvHealthList.DataSource = new BindingList<HealthCheckItem>(set.Items);        }        private void Button2_Click(object sender, EventArgs e)        {            string wantAdd = this.cboSets.Text;            int index = this.cboSetTex.SelectedIndex ;            MessageBox.Show(index.ToString());            //添加操作的关键代码            if (!this.HealthSet[wantAdd].Items.Contains(AllItems[index]))            {                //添加检查项目                this.HealthSet[wantAdd].Items.Add(AllItems[index]);                //重新计算总价格                this.HealthSet[wantAdd].CalcPrice();                //更新                UpdateSet(this.HealthSet[wantAdd]);                //刷新窗体集合A名称                this.lalSetName.Text = this.HealthSet[wantAdd].Name;                //刷新集合A价格                this.lalSetPrice.Text = this.HealthSet[wantAdd].Price.ToString();                MessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);            }            else            {                MessageBox.Show("该项目存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);            }        }        public void liebiao()        {            HealthCheckItem height = new HealthCheckItem("身高", "用于检查身高", 20);            HealthCheckItem weight = new HealthCheckItem("体重", "用于检查体重", 30);            HealthCheckItem vision = new HealthCheckItem("视力", "用于检查视力", 50);            HealthCheckItem hearing = new HealthCheckItem("听力", "用于检查听力", 50);            HealthCheckItem function = new HealthCheckItem("肝功能", "用于检查肝功能", 100);            HealthCheckItem Bultrasonography = new HealthCheckItem("B超", "用于检查B超", 200);            HealthCheckItem electrocardiogram = new HealthCheckItem("心电图", "用于检查心电图", 300);            items.Add(height);            items.Add(weight);            items.Add(vision);            items.Add(hearing);            items.Add(function);            items.Add(Bultrasonography);            items.Add(electrocardiogram);            foreach (HealthCheckItem item in this.items)            {                this.cboSetTex.Items.Add(item.Name);            }            this.cboSetTex.SelectedIndex = 0;        }        private void cboSets_SelectedIndexChanged(object sender, EventArgs e)        {            string setName = this.cboSets.Text;            if (setName == "请选择")            {                this.dgvHealthList.DataSource = new BindingList<HealthCheckItem>();                label5.Text = "";                label7.Text = "";                return;            }            else            {                label5.Text = this.HealthSet[setName].Name;                HealthSet[setName].CalcPrice();                label7.Text = this.HealthSet[setName].Price.ToString();                UpdateSet(HealthSet[setName]);                this.btnDel.Enabled = true;            }        }        public void Showruxue()        {            HealthCheckItem height = new HealthCheckItem("身高", "用于检查身高", 20);            HealthCheckItem weight = new HealthCheckItem("体重", "用于检查体重", 30);            HealthCheckItem vision = new HealthCheckItem("视力", "用于检查视力", 50);            AllItems.Add(height);            AllItems.Add(weight);            AllItems.Add(vision);            HealthCheckSet health = new HealthCheckSet("入学体检", AllItems);            HealthSet.Add("入学体检", health);            this.cboSets.Items.Add("请选择");            this.cboSets.SelectedIndex = 0;            foreach (var item in HealthSet)            {                this.cboSets.Items.Add(item.Key);            }        }        private void Form1_Load(object sender, EventArgs e)        {            //启动            liebiao();            Showruxue();        }        //删除按键        private void btnDel_Click(object sender, EventArgs e)        {            string sename = this.cboSets.Text;            if (MessageBox.Show("确认删除吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)            {                int index = this.dgvHealthList.SelectedRows[0].Index;                if (this.dgvHealthList.SelectedRows.Count > 0)                {                    this.HealthSet[sename].Items.RemoveAt(index);                    label5.Text = this.HealthSet[sename].Name;                    HealthSet[sename].CalcPrice();                    label7.Text = this.HealthSet[sename].Price.ToString();                    UpdateSet(HealthSet[sename]);                }                else                {                    MessageBox.Show("请选中一行", "提示");                }            }        }        private void button1_Click(object sender, EventArgs e)        {            string sename = this.textBox1.Text;            int count = this.cboSets.Items.Count;            if (!HealthSet.Keys.ToList().Contains(sename))            {                List<HealthCheckItem> health = new List<HealthCheckItem>();                HealthCheckSet hea = new HealthCheckSet(sename,health);                HealthSet.Add(sename,hea);                this.cboSets.Items.Add(sename);                this.cboSets.SelectedIndex = count;                UpdateSet(HealthSet[sename]);            }            else {                MessageBox.Show("该套餐已经存在","提示");            }        }    }        }    

0 0
原创粉丝点击