体验套餐管理系统

复制代码
1.3///

 //定义几个检查项目
        CheckItem sg, tz, sl, tl, ggn, bc, xdt;

        //定义一个系统默认的检查套餐“入学体检”
        CheckSet cset;

        //记录套餐中的体检项目
        List<CheckItem> list = new List<CheckItem>();

        //记录所有体检项目
        Dictionary<String, CheckItem> Items = new Dictionary<string, CheckItem>();

        //使用字典保存项目套餐
        Dictionary<string, CheckSet> set = new Dictionary<string, CheckSet>();

1.4///创建一个存储数据的方法

  // 初始化体检项目
        private void InsertItems()
        {


            sg = new CheckItem("身高", "用于检查身高", 5);
            tz = new CheckItem("体重", "用于检查体重", 5);
            sl = new CheckItem("视力", "用于检查视力", 10);
            tl = new CheckItem("听力", "用于检查听力", 50);
            ggn = new CheckItem("肝功能", "用于检查肝功能", 50);
            bc = new CheckItem("B超", "用于检查B超", 30);
            xdt = new CheckItem("心电图", "用于检查心电图", 50);

            Items.Add(sg.Name, sg);
            Items.Add(tz.Name, tz);
            Items.Add(sl.Name, sl);
            Items.Add(tl.Name, tl);
            Items.Add(ggn.Name, ggn);
            Items.Add(bc.Name, bc);
            Items.Add(xdt.Name, xdt);

        }

1.5///

 // 初始化体检项目列表
        private void InsertItemsList()
        {
            cbo02.Items.Clear();
            cbo02.Items.Add("请选择");
            foreach (string key in Items.Keys)
            {
                cbo02.Items.Add(key);
            }
            cbo02.SelectedIndex = 0;
        }

 1.6      //初始化套餐
        private void InitSets()
        {
            list.Add(sg);
            list.Add(tz);
            list.Add(ggn);
            cset = new CheckSet("入学体检", list);
            cset.CalcPrice();
            set.Add("入学体检", cset);

        }
  1.7      // 添加套餐下拉列表
        private void InitSetsList()
        {
            cbo01.Items.Clear();
            cbo01.Items.Add("请选择");
            foreach (string key in set.Keys)
            {
                cbo01.Items.Add(key);
            }
            cbo01.SelectedIndex = 0;
        }
  1.8    //显示方法
        private void UpdateSet(CheckSet set)
        {
            //判断套餐中检查项目集合为空的时候DataGridView就不显示信息
            if (set.list == null)
            {
                dgvList.DataSource = new BindingList<CheckItem>();
            }
            else
            {
                dgvList.DataSource = new BindingList<CheckItem>(set.list);
            }
        }

1.9///在主窗体load事件里加载

  private void FrmMain_Load(object sender, EventArgs e)
        {
           
            InsertItems(); //初始化体检项目
            InsertItemsList(); //初始化体检项目列表
            InitSets(); //初始化套餐
            InitSetsList();  //添加套餐下拉列表
        }

2.0///

 private void btn02_Click(object sender, EventArgs e)
        {
            
            //判断套餐是否存在要添加的体检项目
            if (!set[cbo01.Text].list.Contains(Items[cbo02.Text]))
            {
                set[cbo01.Text].list.Add(Items[cbo02.Text]);
                MessageBox.Show("添加成功");
                //绑定dgvList
                dgvList.DataSource = new BindingList<CheckItem>(set[cbo01.Text].list);
                set[cbo01.Text].CalcPrice(); //计算套餐价格
                lbl000.Text = set[cbo01.Text].Prices.ToString();
            }
            else
            {
                MessageBox.Show("已经有该项目的存在了", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
        }

2.1

  private void cbo01_SelectedIndexChanged(object sender, EventArgs e)
        {

            //套餐列表等于请选择的时候删除按钮Enabled就为false
            if (cbo01.Text == "请选择")
            {
                this.btn03.Enabled = false;
            }
            else
            {
                this.btn03.Enabled = true;
                lbl00.Text = this.set[cbo01.Text].Name;
                lbl000.Text = this.set[cbo01.Text].Prices.ToString();
                if (set[cbo01.Text] != null)
                {
                    UpdateSet(set[cbo01.Text]); //调用显示方法
                }
            }
        }

2.2

 private void btn01_Click(object sender, EventArgs e)
        {
            string name = txt01.Text;
            if (!txt01.Text.Equals(string.Empty))
            {
                //判断是否在体检套餐中存在
                if (set.Keys.Contains(name))
                {
                    MessageBox.Show("已经有该套餐了", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    //添加新的体检项目
                    list = new List<CheckItem>();
                    cset = new CheckSet(name, list);
                    cset.CalcPrice(); //体检套餐价格
                    set.Add(name, cset);
                    InitSetsList(); //刷新体检套餐下拉列表
                    cbo01.Text = name; //体检套餐下拉列表等于新添加的套餐名称
                    txt01.Text = "";
                }
            }
            else
            {
                MessageBox.Show("添加条件不能为空!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
        }

2.3///删除按钮的事件里

   private void btn03_Click(object sender, EventArgs e)
        {
            //判断是否选中一行
            if (dgvList.SelectedRows.Count == 1)
            {

                string key = dgvList.SelectedRows[0].Cells[1].Value.ToString();
                set[cbo01.Text].list.Remove(Items[key]);
                MessageBox.Show("删除成功!");
                UpdateSet(set[cbo01.Text]);
                set[cbo01.Text].CalcPrice();
                lbl000.Text = set[cbo01.Text].Prices.ToString();
            }
            else
            {
                MessageBox.Show("请选择选中一行!");
            }
        }

  2.4///在下拉列表框里判断

      private void cbo02_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbo02.Text == "请选择")
            {
                this.btn02.Enabled = false;
            }
            else
            {
                btn02.Enabled = true;
            }
        }

2.5///创建CheckItem类

public  class CheckItem
    {
        public string Description { get; set; }

        public string Name { get; set; }

        public int Price { get; set; }

 

//创建无参构造

 public CheckItem() 

{ 

}

//创建有参构造

       public CheckItem(string name, string description, int price)
        {
            this.Description = description;
            this.Name = name;
            this.Price = price;
        }

}

2.6///创建CheckSet类

public  class CheckSet
    {
        //检查项目的集合
        public List<CheckItem> list { get; set; }

        public int Prices { get; set; }

        public string Name { get; set; }

  //无参构造
        public CheckSet()
        {
            list = new List<CheckItem>();
        }
        //带参构造
        public CheckSet(string name, List<CheckItem> list)
        {
            this.Name = name;
            this.list = list;
        }

        //套餐价格计算
        public void CalcPrice()
        {
            int StratPrice = 0;
            foreach (CheckItem item in list)
            {
                StratPrice += item.Price;
            }
            Prices = StratPrice;
        }

    }
复制代码
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值