在平时开发系统功能的时候,我们经常会碰到一些需求需要经常性的发生变化,比如 系统版本、更新日志 等等。这个时候用一个XML文件来替代数据库,就会变的简便很多。

前段时候我也正好需要改个需求,是关于客户公司年假的设置,大致需求是这样的:

年假规定:公司员工入职满一年后,方可享受带薪年假,具体如下:
1档: 连续服务满1年以上不满2年,每年可享受2个工作日。
2档:连续服务满2年以上不满5年, 每年可享受3个工作日。
3档:连续服务满5年以上不满8年, 每年可享受6个工作日。
4档:连续服务满8年以上,每年可享受10个工作日。
 
需求很简单,但以上条件很有可能会变化, 所以我就想到了用读取XML文件的方式去存储这些“条件”。
废话少说,直接上代码:
 
1、YearLeaveConfig.xml(特别注意:XML文件里的标签首字母必须是大写的)
<?xml version="1.0"?>
<YearLeaveConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--下列标签首字母必须大写-->
<LeaveItems>
<LeaveItem>
<YearStart>0</YearStart>
<YearEnd>1</YearEnd>
<LeaveDay>0</LeaveDay>
</LeaveItem> <LeaveItem>
<YearStart>1</YearStart>
<YearEnd>2</YearEnd>
<LeaveDay>2</LeaveDay>
</LeaveItem> <LeaveItem>
<YearStart>2</YearStart>
<YearEnd>5</YearEnd>
<LeaveDay>3</LeaveDay>
</LeaveItem> <LeaveItem>
<YearStart>5</YearStart>
<YearEnd>8</YearEnd>
<LeaveDay>6</LeaveDay>
</LeaveItem> <LeaveItem>
<YearStart>8</YearStart>
<YearEnd>100</YearEnd>
<LeaveDay>10</LeaveDay>
</LeaveItem> </LeaveItems>
</YearLeaveConfig>

2、实体类

public class LeaveItem
{
public int YearStart { get; set; }
public int YearEnd { get; set; }
public int LeaveDay { get; set; }
} public class YearLeaveConfig
{
public LeaveItem[] LeaveItems { get; set; }
}

3、读取XML

static void Main(string[] args)
{
string strPth = Environment.CurrentDirectory;
YearLeaveConfig yearLeave = (YearLeaveConfig)new XmlSerializer(typeof(YearLeaveConfig)).Deserialize(new FileStream(strPth + @"\YearLeaveConfig.xml", FileMode.Open)); foreach (LeaveItem item in yearLeave.LeaveItems)
{
Console.WriteLine(string.Format("年假设置:{0}~~{1}年的享受年假:{2}天",item.YearStart,item.YearEnd,item.LeaveDay)); }
Console.Read(); }

DEMO下载

最新文章

  1. 『.NET Core CLI工具文档』(九)dotnet-run
  2. 【leetcode】Min Stack -- python版
  3. iOS的内购
  4. Linux Linux程序练习九
  5. c语言参数类型
  6. python--str的几个方法
  7. 《Cocos2d-x实战 C++卷》上线了-源码-样章-感谢大家的支持
  8. Android中Application类用法
  9. css笔记:如何将一个页面平均分成四个部分?
  10. 创建Sencha touch第一个应用
  11. VS2012及VS2013连接SQL2008提示 Could not load file or assembly &#39;Microsoft.SqlServer.Management.Sdk.Sfc&#39;
  12. 十大经典排序算法详细总结(含JAVA代码实现)
  13. (predicted == labels).sum().item()作用
  14. CF 833B
  15. 开车旅行 [NOIP 2012]
  16. django中的中间件机制和执行顺序
  17. AES算法在Python中的使用
  18. web前端小数点位数处理
  19. Python 实现画一个小猪佩奇
  20. ROS+L2TP+IPSEC

热门文章

  1. 【转】LoadRunner监控 -- Linux的17个指标
  2. 释怀我的诺亚尔 不用EF框架,完成完美实体映射,且便于维护!(AutoMapper,petapoco)
  3. hive计算网页停留时长
  4. Ubuntu 14.04正式公布,一个不眠之夜
  5. centos7 rpm 安装MySQL5.6
  6. myecplise、ecplise项目空间优化
  7. HTML的DOM和浏览器的BOM
  8. java反射(1)
  9. Apache Flink 1.5.0 Release Announcement
  10. C++不能在栈上申请动态内存,而只能依靠指针