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

    体检套餐管理系统

    首先搭建一个窗体

    创建体检项目的两个类一个是检查项目类(HealthCheckItem),另一个是套餐类(HealthCheckSet)

    在HealthCheckItem类 中有

    项目描述(Description)

    项目名称(Name)

    项目价格(Price)

    在HealthCheckSet类中有

    Items:为HealthCheckItem的集合,采用泛型集合list<T>作为存储HealthCheckItem的数据结构

    Price:套餐价格,Items属性中检查项目的价格之和

    Name:套餐的名称;

    //定义一个集合存放所有的体检项目
    List<HealthCheckItem> allItems = new List<HealthCheckItem>();
    //定义一个集合存放套餐中的体检项目
    List<HealthCheckItem> items = new List<HealthCheckItem>();
    //保存套餐集合
    Dictionary<string, HealthCheckSet> healthSet = new Dictionary<string, HealthCheckSet>();
    //定义一个默认套餐
    HealthCheckSet setA;
    //定义几个体检项目
    HealthCheckItem height, weight, shi, ting, gan, chao, tu;

    要先绑定检查项目的下拉列表

    代码如下:

    public void InilSet()
    {
    height = new HealthCheckItem("身高","用来检查身高",5);
    weight = new HealthCheckItem("体重", "用来检查体重", 15);
    shi = new HealthCheckItem("视力", "用来检查视力", 25);
    ting = new HealthCheckItem("听力", "用来检查听力", 25);
    gan = new HealthCheckItem("肝功能", "用来检查肝功能", 85);
    chao = new HealthCheckItem("B超", "用来检查B超", 45);
    tu = new HealthCheckItem("心电图", "用来检查心电图", 75);

    allItems.Add(height);
    allItems.Add(weight);
    allItems.Add(shi);
    allItems.Add(ting);
    allItems.Add(gan);
    allItems.Add(chao);
    allItems.Add(tu);

    comItems.DataSource = allItems;
    comItems.DisplayMember = "name";
    comItems.ValueMember = "money";
    }

    在套餐列表中的默认一个“入学体检”

    并给此套餐设置制定的检查项目

    代码如下:

    public void MoRen()
    {
    items = new List<HealthCheckItem>();
    items.Add(height);
    items.Add(weight);
    items.Add(gan);

    setA = new HealthCheckSet("入学体检",items);
    setA.AddMoney();
    this.healthSet.Add("入学体检",setA);

    }
    //体检套餐下拉列表
    public void InitHealthSet()
    {
    //清空下拉列表
    this.comSet.Items.Clear();
    //添加请选择
    this.comSet.Items.Add("请选择");
    foreach (string key in healthSet.Keys)
    {
    this.comSet.Items.Add(key);
    }
    this.comSet.SelectedIndex = 0;
    }

    把数据绑定到DataGridView中显示套餐的检查项目 

    代码如下:

    public void dgvAdd(HealthCheckSet set)
    {
        dataGridView1.DataSource = new BindingList<HealthCheckItem>(set.Items);
    }

    选择“套餐列表”下拉列表事件

    private void comSet_SelectedIndexChanged(object sender, EventArgs e)
    {
    if (result)
    {
    string setName = this.comSet.Text;
    if (setName=="请选择")
    {
    this.dataGridView1.DataSource = null;
    lblSetMoney.Text = "";
    lblSetName.Text = "";
    return;
    }
    else
    {
    //设置套餐名称
    lblSetName.Text = this.healthSet[setName].Name;
    //设置套餐总价
    lblSetMoney.Text=this.healthSet[setName].Price.ToString();
    //更新套餐项目
    dgvAdd(healthSet[setName]);
    //设置删除按钮为可用状态
    btnShanChu.Enabled = true;
    }
    }
    }

    点击添加按钮可以在数据列表中显示出来你

    代码如下:

    private void btnTianJia_Click(object sender, EventArgs e)
    {

    if (this.comItems.SelectedIndex==0)
    {
    MessageBox.Show("请选择一个项目","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    return;
    }
    string newName = this.comSet.Text;
    if (newName=="请选择")
    {
    MessageBox.Show("请选择一个套餐","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    return;
    }
    int index = this.comItems.SelectedIndex;
    if (!this.healthSet[newName].Items.Contains(allItems[index]))
    {
    this.healthSet[newName].Items.Add(allItems[index]);
    this.healthSet[newName].AddMoney();
    dgvAdd(healthSet[newName]);

    //刷新窗体中显示套餐名称
    this.lblSetName.Text = this.healthSet[newName].Name;

    //刷新窗体中显示套餐价格
    this.lblSetMoney.Text = this.healthSet[newName].Price.ToString();
    MessageBox.Show("添加成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }
    else
    {
    MessageBox.Show("该项目已经存在","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }
    }

    点击删除按钮将选中项从套餐中删除

    先从泛型集合中删除项目,然后从新绑定数据,从新计算套餐总价

    private void btnShanChu_Click(object sender, EventArgs e)
    {
    string setName = this.comSet.Text;
    if (this.dataGridView1.SelectedRows.Count==0)
    {
    MessageBox.Show("请选择一项删除","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    return;
    }
    else
    {
    //获得所删除项的索引
    int index = this.dataGridView1.SelectedRows[0].Index;
    //删除所选中的项
    this.healthSet[setName].Items.RemoveAt(index);
    //重新计算价格
    this.healthSet[setName].AddMoney();
    //更新数据
    dgvAdd(healthSet[setName]);
    lblSetName.Text = setA.Name;
    string cboSetText = this.comSet.Text;
    lblSetMoney.Text = this.healthSet[cboSetText].Price.ToString();
    MessageBox.Show("删除成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }

    }

    添加套餐检查项目

    点击添加按钮时将新建的套餐添加到套餐集合中

    private void btnOK_Click(object sender, EventArgs e)
    {
    //添加
    if (string.IsNullOrEmpty(txtHealthName.Text))
    {
    MessageBox.Show("请输入套餐名称", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    return;//结束方法
    }
    else
    {
    //声明一个套餐对象
    HealthCheckSet Hch = new HealthCheckSet();
    //将套餐对对象添加到Dictionary中
    this.HealthSet.Add(this.txtHealthName.Text, Hch);
    this.InitHealthSetList();
    //下拉框显示刚添加的内容
    this.cboSets.SelectedIndex = this.HealthSet.Count;
    lblSetName.Text = cboSets.Text;
    Hch.Name = cboSets.Text;

    MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    }

  • 相关阅读:
    形象理解ERP(转)
    禁用windows server 2008 域密码复杂性要求策略
    How to adding find,filter,remove filter on display method Form
    Windows Server 2008 R2激活工具
    How to using bat command running VS development SSRS report
    Creating Your First Mac AppGetting Started
    Creating Your First Mac AppAdding a Track Object 添加一个 Track 对象
    Creating Your First Mac AppImplementing Action Methods 实现动作方法
    Creating Your First Mac AppReviewing the Code 审查代码
    Creating Your First Mac AppConfiguring the window 设置窗口
  • 原文地址:https://www.cnblogs.com/yhsj/p/4620067.html
Copyright © 2011-2022 走看看