码迷,mamicode.com
首页 > 其他好文 > 详细

体检套餐主代码

时间:2017-04-09 23:23:21      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:rate   namespace   foreach   class   button   tostring   else   身高   string   

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 HealthCheckItem
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //全部体检项目
        List<HealthCheckItems> alllist = new List<HealthCheckItems>();

        //套餐
        List<HealthCheckItemSet> taoCanList = new List<HealthCheckItemSet>();

        private void label2_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 套餐名称
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            dgvname.AutoGenerateColumns = false;

            HealthCheckItems item = new HealthCheckItems();
            item.Name = "身高";
            item.Description = "用于检查身高";
            item.Price = "12";
            HealthCheckItems item2 = new HealthCheckItems();
            item2.Name = "肝功能";
            item2.Description = "由于检查肝功能";
            item2.Price = "16";
            HealthCheckItems item3 = new HealthCheckItems();
            item3.Name = "听力";
            item3.Description = "由于检查听力";
            item3.Price = "15";
            HealthCheckItems item4 = new HealthCheckItems();
            item4.Name = "视力";
            item4.Description = "由于检查视力";
            item4.Price = "15";
            HealthCheckItems item5 = new HealthCheckItems();
            item5.Name = "B超";
            item5.Description = "由于检查B超";
            item5.Price = "15";
            alllist.Add(item);
            alllist.Add(item2);
            alllist.Add(item3);
            alllist.Add(item4);
            alllist.Add(item5);
            for (int i = 0; i < alllist.Count; i++)
            {
                cmbname.Items.Add(alllist[i].Name);
            }
            ff();
            d();
            Bang();
        }
        /// <summary>
        /// 套餐列表
        /// </summary>
        public void ff() 
        {
            
            HealthCheckItemSet item = new HealthCheckItemSet();
            item.Name = "请选择";
            HealthCheckItemSet item2 = new HealthCheckItemSet();
            item2.Name = "入学体检";
            taoCanList.Add(item);
            taoCanList.Add(item2);
            cmbbiao.DataSource = new List<HealthCheckItemSet>(taoCanList);
            cmbbiao.DisplayMember = "Name";
        }
        public void d()
        {
            //List<HealthCheckItems> list = new List<HealthCheckItems>();
            //HealthCheckItems item = new HealthCheckItems();
            //item.Name = "身高";
            //item.Description = "用于检查身高";
            //item.Price = "12";
            //HealthCheckItems item2 = new HealthCheckItems();
            //item2.Name = "肝功能";
            //item2.Description = "由于检查肝功能";
            //item2.Price = "16";
            //HealthCheckItems item3 = new HealthCheckItems();
            //item3.Name = "听力";
            //item3.Description = "由于检查听力";
            //item3.Price = "15";
            //list.Add(item);
            //list.Add(item2);
            //list.Add(item3);
            //dgvname.DataSource = new List<HealthCheckItems>(list);
        }
       public  List<HealthCheckItems> list = new List<HealthCheckItems>();

        /// <summary>
        /// 绑定入学体检套餐项目
        /// </summary>
       public void Bang()
       {
           foreach (var item in alllist)
           {
               if (item.Name.Equals("肝功能"))
               {
                   list.Add(item);
               }
               if (item.Name.Equals("身高"))
               {
                   list.Add(item);
               }
               if (item.Name.Equals("视力"))
               {
                   list.Add(item);
               }
           }
       }
       private void cmbbiao_SelectedValueChanged(object sender, EventArgs e)
       {
           foreach (var item in taoCanList)
           {
               if (cmbbiao.Text == item.Name)
               {
                   show();
               }
               else
               {
                   if (cmbbiao.Text.Equals("请选择"))
                   {
                       dgvname.DataSource = null;
                       lblj.Text = "";
                       lblname.Text = "";
                   }
               }
           }


       }
        public void show(){
              int a = 0;
            dgvname.DataSource = new List<HealthCheckItems>(list);
                //加载事件
                for (int i = 0; i < list.Count; i++)
                {
                    a +=int.Parse( list[i].Price);
                }
                lblj.Text =a.ToString();
            }
    
    
        //套餐名
        private void cmbbiao_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (var item in taoCanList)
            {
                if (cmbbiao.Text == cmbbiao.Text)
                {
                    lblname.Text = cmbbiao.Text;
                }
            }
            
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            if(dgvname.SelectedRows.Count!=1)
            {
                return;
            }
         
            string a = dgvname.SelectedRows[0].Cells[0].Value.ToString();
       
            for (int i = 0; i < list.Count; i++)
            {
                if(a.Equals(list[i].Name)){
                   
                    list.RemoveAt(i);
                    show();
                }
                
            }
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            //循环判断是哪个项目
            foreach (var item in alllist)
            {
                if (item.Name.Equals(cmbname.Text)) {
                    //判断该套餐是否有重复项目
                    foreach (var li in list)
                    {
                        if (li.Name.Equals(cmbname.Text))
                        {
                            MessageBox.Show("重复了");
                            return;
                        }
                    }
                  list.Add(item);
                    show();
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            HealthCheckItemSet hcis = new HealthCheckItemSet();

            hcis.Name = txtname.Text;
            taoCanList.Add(hcis);
            //重新绑定组合框数据源
            cmbbiao.DataSource = new List<HealthCheckItemSet>(taoCanList);
            cmbbiao.DisplayMember = "Name";
        }

      
    }
}

 

体检套餐主代码

标签:rate   namespace   foreach   class   button   tostring   else   身高   string   

原文地址:http://www.cnblogs.com/nancheng/p/6686913.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!