zoukankan      html  css  js  c++  java
  • 体检套餐管理系统的综合版

    步骤:

    定义几个类:

    HealthCheckItem类:检查项目

    属性:

       public string Description { get; set; }
            public int Price { get; set; }
            public string Name { get; set; }

    HealthCheckItem类中的方法:

      //当选择套餐下拉框中的套餐时,套餐下所有检查项目都添加到dgvlist中显示
            public HealthCheckItem(string name, int price, string description)
            {
                Name = name;
                Price = price;
                Description = description;
            }

    主界面:

       //定义多个检查项目
            HealthCheckItem m,hg, wg, sg, hr, lf, eg, ba, bp, bt;
            //定义系统默认检查套餐"入学体检";
            HealthCheckSet setA;
            //采用泛型集合List保存所有的体检项目
            List<HealthCheckItem> allitems = new List<HealthCheckItem>();
            //采用泛型集合List保存套餐中的体检项目
            List<HealthCheckItem> items = new List<HealthCheckItem>();
            //使用双列集合(字典)保存套餐集合
            public Dictionary<string, HealthCheckSet> hs = new Dictionary<string, HealthCheckSet>();

    HealthCheckSet类:体检套餐

    属性:

      public int Price { get; set; }//Item属性中检查项目的价格之和
            public string Name { get; set; }
            public List<HealthCheckItem> Items { get; set; }//Items是HealthCheckItem的集合,

    HealthCheckSet类中的方法:

      public HealthCheckSet()
            {
                Items = new List<HealthCheckItem>();
            }
            public HealthCheckSet(string name, List<HealthCheckItem> items)
            {
                Name = name;
                Items = items;
    
            }

    获取价格的方法:

       // 获取价格的方法
            public void CalcPrice()
            {
                int tatolPrice = 0;
                foreach (HealthCheckItem item in Items)
                {
                    tatolPrice = tatolPrice + item.Price;
                }
                //套餐的价格等于每个体检项目价格的和
                Price = tatolPrice;
    
            }

    添加新套餐:

      //添加新套餐
            private void btnAdd_Click(object sender, EventArgs e)
            {
                if (txtName.Text.Equals(""))
                {
                    MessageBox.Show("请输入套餐名称!");
                }
                else
                {
                    HealthCheckSet hc = new HealthCheckSet();
                    hs.Add(txtName.Text, hc);
                    // 调加载套餐下拉框信息方法
                    InitiateHealthSetList();
                    cboList.SelectedIndex = hs.Count();
                    lblname.Text = cboList.Text;
                    hc.Name = cboList.Text;
                    MessageBox.Show("添加成功!");
                }
            }

    加载套餐下拉框信息:

     private void InitiateHealthSetList()
            {
                 //加载套餐下拉框信息
                //先清空下拉框列表
                cboList.Items.Clear();
                //添加请选择
                cboList.Items.Add("请选择");
                //将dictionary的key值绑定到下拉框中,作为下拉框显示的值
                foreach (string k in hs.Keys)
                {
                    cboList.Items.Add(k);
                }
                //默认第一项被选中
                cboList.SelectedIndex = 0;
            }

    初始化检查项目:

    hg = new HealthCheckItem("身高", 15, "用于检查身高");
    wg = new HealthCheckItem("体重", 25, "用于检查体重");
     allitems.Add(hg);
    allitems.Add(wg);

    添加检查项目:

      //添加检查项目
            private void btnOk_Click(object sender, EventArgs e)
            {
                if (cboProject.Text.Equals("请选择")||cboProject.Text.Equals(""))
                {
                      MessageBox.Show("请选择项目");
                    return;
                }        
                if (cboList.Text == "请选择")
                {
                    MessageBox.Show("请选择套餐");
                    return;
                }
                //List<T>.Contains(对象)可以判断某个对象是否在集合中
                if (!hs[cboList.Text].Items.Contains(allitems[cboProject.SelectedIndex]))
                {
                    //添加检查项目             hs[cboList.Text].Items.Add(allitems[cboProject.SelectedIndex]);
                    //重新计算总价格
                    hs[cboList.Text].CalcPrice();
                   //更新
                    UpdateSet(hs[cboList.Text]);
                    //刷新窗体集合名称
                    lblname.Text = hs[cboList.Text].Name;
                    // //刷新窗体集合价格
                    lblprice.Text = hs[cboList.Text].Price.ToString();
                    MessageBox.Show("添加成功");
                }
                else
                {
                    MessageBox.Show("该项目已经存在");
                }
            }

    删除体检套餐信息:

      //删除信息
            private void btnDelete_Click(object sender, EventArgs e)
            {
                if (this.dgvInfo.SelectedRows.Count == 0)
                {
                    MessageBox.Show("请选择要删除的一行");
                    return;
                }
                //找索引
                int index = dgvInfo.SelectedRows[0].Index;
                //删除的检查项目数据
                //泛型集合删除项目的方法:RemoveAt();
                hs[cboList.Text].Items.RemoveAt(index);
                //重新计算价格
                hs[cboList.Text].CalcPrice();
                //更新dgvlist数据
                UpdateSet(hs[cboList.Text]);
                lblname.Text = setA.Name;
                string choS = cboList.Text;
                lblprice.Text = hs[choS].Price.ToString();
            }

    填充套餐的dgvlist,更新套餐检查项目

      //填充套餐的dgvlist,更新套餐检查项目
            private void UpdateSet(HealthCheckSet set)
            {
                dgvInfo.DataSource = new BindingList<HealthCheckItem>(set.Items);
            }

    这样简单明了-----------------------------------

  • 相关阅读:
    求算个十百输出
    求算反弹高度
    九九乘法表
    等腰三角形字母
    动态数码管
    静态数码管
    出错的程序操作
    EPLAN
    robotstudio smart组件解释
    eclipse插件安装方法
  • 原文地址:https://www.cnblogs.com/weiguangyi/p/5227101.html
Copyright © 2011-2022 走看看