zoukankan      html  css  js  c++  java
  • 体验套餐管理系统

    ///1.显示指定项目的项目明细2.向指定套餐添加检查项目信息3.删除套餐中的项目信息4.新建套餐

    做项目之前得有自己的思路,不要着急写,先把这个项目理清楚了就好,之后该怎么写就明白了!

    //1.1实现窗体的搭建

    1.2初始化默认套餐

    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;
            }
    
        }

         ////刚加载窗体时

    ////查看下拉列表框中的内容

    ///当选择一个套餐时默认加载三个项目,价格为3个项目之和

    ///当添加项目时,作出判断

    ///相应的价格和项目明细也作出改变

    ///当删除不需要的项目时

    ///删除成功时价格和项目明细也作出改变

    ///添加另一个套餐

    ///添加项目

  • 相关阅读:
    LOJ #2196「SDOI2014」LIS
    LOJ#2249 Luogu P2305「NOI2014」购票
    LOJ #6268 分拆数
    Luogu P3700「CQOI2017」小Q的表格
    LOJ #2527 Luogu P4491「HAOI2018」染色
    knockout 学习使用笔记-----event绑定传参ko属性
    bootstrap select 学习使用笔记-------选中赋值及change监听丢失
    knockout 学习使用笔记------绑定值时赋值失败
    js 数组判断是否包含某元素 或 数组去重
    bootstrap-select 使用笔记 设置选中值及手动刷新
  • 原文地址:https://www.cnblogs.com/wl0000-03/p/5813384.html
Copyright © 2011-2022 走看看