博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#实现体验套餐管理系统
阅读量:5261 次
发布时间:2019-06-14

本文共 4632 字,大约阅读时间需要 15 分钟。

体验套餐类!!

/// <summary>

/// 体验套餐类!!
/// </summary>
public class HealthCheckSet
{
private List<HealthCheckItem> _items; //HealthCheckItem的集合!
internal List<HealthCheckItem> Items
{
get { return _items; }
set { _items = value; }
}
private int _price; //套餐价格!!
public int Price
{
get { return _price; }
set { _price = value; }
}
private string _name; //套餐名称!!
public string Name
{
get { return _name; }
set { _name = value; }
}
//采用泛型集合List保存所有的体验项目!!
List<HealthCheckItem> _AllItems = new List<HealthCheckItem>();

//采用泛型集合List保存套餐中的体验项目!!

List<HealthCheckItem> items = new List<HealthCheckItem>();

/// <summary>

/// 套餐价格计算方法!!
/// </summary>
public void CalcPrice()
{
int totalPrice = 0;
foreach (HealthCheckItem item in this.Items)
{
totalPrice += item.Price;
}
this.Price = totalPrice;
}

}

 

检查项目类!

/// <summary>

/// 检查项目类!!
/// </summary>
public class HealthCheckItem
{
/// <summary>
/// 带参构造方法!!
/// </summary>
public HealthCheckItem(string name,string desc,int price)
{
this.Description = desc;
this.Name = name;
this.Price = price;
}

private string _description; //项目描述!!

public string Description
{
get { return _description; }
set { _description = value; }
}

private string _name; //项目名称!!

public string Name
{
get { return _name; }
set { _name = value; }
}

private int _price; //项目价格!!

public int Price
{
get { return _price; }
set { _price = value; }
}
}

 

主窗体!

 

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 Chapter05

{
public partial class FrmMain : Form
{
public HealthCheckSet healthset;

 

//采用泛型集合List保存所有的体验项目!!

public List<HealthCheckItem> AllItem = new List<HealthCheckItem>();

 

//保存套餐中的体验项目!!

public List<HealthCheckItem> Item = new List<HealthCheckItem>();

 

//字典存套餐!!

public Dictionary<string, HealthCheckSet> HealthSet = new Dictionary<string, HealthCheckSet>();

 

public FrmMain()

{
InitializeComponent();
}

 

#region 初始化信息!!

/// <summary>
/// 初始化信息!!
/// </summary>
public void Init()
{
HealthCheckItem hci = new HealthCheckItem( "身高","用于检查身高", 5);
HealthCheckItem hci1 = new HealthCheckItem( "体重","用于检查体重", 5);
HealthCheckItem hci2 = new HealthCheckItem("肝功能","用于检查肝功能", 30);
HealthCheckItem hci3 = new HealthCheckItem("B超","用于B超检查", 50);
HealthCheckItem hci4 = new HealthCheckItem( "视力","用于检查眼睛", 5);
HealthCheckItem hci5 = new HealthCheckItem( "听觉","用于检查听觉", 5);
HealthCheckItem hci6 = new HealthCheckItem( "11","肝功能", 30);
HealthCheckItem hci7 = new HealthCheckItem( "B213","B超检查", 50);

 

AllItem.Add(hci);

AllItem.Add(hci1);
AllItem.Add(hci2);
AllItem.Add(hci3);
AllItem.Add(hci4);
AllItem.Add(hci5);
AllItem.Add(hci6);
AllItem.Add(hci7);

 

healthset = new HealthCheckSet();

healthset.Name = "请选择";
healthset.Name = "入学体验";
//healthset.Items.Add(hci4);
//healthset.Items.Add(hci5);
//healthset.Items.Add(hci6);
//healthset.Items.Add(hci7);
//healthset.CalcPrice();
HealthSet.Add("请选择", healthset);
HealthSet.Add("入学体验", healthset);
}
#endregion

 

#region 刷新方法!!

/// <summary>
/// 刷新方法!!
/// </summary>
/// <param name="set"></param>
public void Update(HealthCheckSet set)
{
this.dgvHealthList.DataSource = new BindingList<HealthCheckItem>(set.Items);
set.CalcPrice();
}
#endregion

 

#region 套餐列表下拉事件!!

/// <summary>
/// 套餐列表下拉事件!!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cboLiebiao_SelectedIndexChanged(object sender, EventArgs e)
{
string setName = this.cboLiebiao.SelectedItem.ToString();
if(setName == "请选择")
{
this.dgvHealthList.DataSource = new BindingList<HealthCheckItem>();

 

lblTaoCanM.Text = "";

lblJiaGe.Text = "";
//控件:删除为不可用状态!!
this.btnQuXiao.Enabled = false;
return;
}
else
{
//设置套餐名称!!
lblTaoCanM.Text = this.HealthSet[setName].Name;
//设置套餐总价!!
lblJiaGe.Text = this.HealthSet[setName].Price.ToString();
//控件:删除为可用状态!!
this.btnQuXiao.Enabled = true;
//绑定DataGirlView!!
this.dgvHealthList.DataSource = new BindingList<HealthCheckItem>(AllItem);
}
}
#endregion

 

#region 窗体加载事件!

/// <summary>
/// 窗体加载事件!
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmMain_Load(object sender, EventArgs e)
{
//初始化信息!!
Init();

 

//项目绑定!!

this.cboPgriom.DisplayMember = "name";
this.cboPgriom.DataSource = AllItem;

 

//套餐循环绑定!

foreach (string key in HealthSet.Keys)
{
this.cboLiebiao.Items.Add(key);
}
//默认选中一行!!
this.cboLiebiao.SelectedIndex = 0;
}
#endregion

 

private void btnQuXiao_Click(object sender, EventArgs e)

{
//获取选中的项!!
string _key = this.dgvHealthList.SelectedRows[0].Cells[0].Value.ToString();

 

}

 

}

}

 

转载于:https://www.cnblogs.com/wenlonghui/p/8452884.html

你可能感兴趣的文章
TCP为什么需要3次握手与4次挥手(转载)
查看>>
IOC容器
查看>>
Windows 2003全面优化
查看>>
URAL 1002 Phone Numbers(KMP+最短路orDP)
查看>>
web_day4_css_宽度
查看>>
electron入门心得
查看>>
格而知之2:UIView的autoresizingMask属性探究
查看>>
我的Hook学习笔记
查看>>
js中的try/catch
查看>>
寄Android开发Gradle你需要知道的知识
查看>>
简述spring中常有的几种advice?
查看>>
整理推荐的CSS属性书写顺序
查看>>
ServerSocket和Socket通信
查看>>
css & input type & search icon
查看>>
源代码的下载和编译读后感
查看>>
Kafka学习笔记
查看>>
Octotree Chrome安装与使用方法
查看>>
Windows 环境下基于 Redis 的 Celery 任务调度模块的实现
查看>>
趣谈Java变量的可见性问题
查看>>
C# 强制关闭当前程序进程(完全Kill掉不留痕迹)
查看>>