zoukankan
html css js c++ java
从XML中读取数据到内存的实例
public
clsSimuResultByOneGoods GetOneGoodsSimulationXML(
string
PathAndFileName)
{
clsSimuResultByOneGoods OneGoods
=
new
clsSimuResultByOneGoods();
//
自己定义的一个类
Hashtable AllLocationResult
=
new
Hashtable();
System.Xml.XmlTextReader r
=
new
XmlTextReader(PathAndFileName);
string
LocationID
=
""
;
DataTable LocationTable
=
null
;
while
(r.Read())
{
if
(r.NodeType
==
XmlNodeType.Element)
{
switch
(r.LocalName)
{
case
"
Result
"
:
OneGoods.GoodsCode
=
r.GetAttribute(
"
GoodsCode
"
);
OneGoods.From
=
Convert.ToDateTime(r.GetAttribute(
"
FromDate
"
));
OneGoods.To
=
Convert.ToDateTime(r.GetAttribute(
"
ToDate
"
));
break
;
case
"
Location
"
:
LocationID
=
r.GetAttribute(
"
ID
"
);
LocationTable
=
new
DataTable();
LocationTable.Columns.Add(
"
Date
"
,
typeof
(DateTime));
LocationTable.Columns.Add(
"
SafetyStock
"
,
typeof
(
decimal
));
LocationTable.Columns.Add(
"
ForecastDemand
"
,
typeof
(
decimal
));
LocationTable.Columns.Add(
"
FinalOutput
"
,
typeof
(
decimal
));
LocationTable.Columns.Add(
"
FinalInput
"
,
typeof
(
decimal
));
LocationTable.Columns.Add(
"
SimuStock
"
,
typeof
(
decimal
));
LocationTable.Columns.Add(
"
SimuStockTime
"
,
typeof
(
decimal
));
LocationTable.Columns.Add(
"
ImportWorkDay
"
,
typeof
(
bool
));
LocationTable.Columns.Add(
"
ImportWorkDay
"
,
typeof
(
bool
));
break
;
case
"
Record
"
:
if
(LocationTable
!=
null
)
{
DataRow dr
=
LocationTable.NewRow();
dr[
"
Date
"
]
=
Convert.ToDateTime(r.GetAttribute(
"
Date
"
));
if
(r.GetAttribute(
"
SafetyStock
"
)
!=
null
&&
r.GetAttribute(
"
SafetyStock
"
)
!=
""
)
dr[
"
SafetyStock
"
]
=
Convert.ToDecimal(r.GetAttribute(
"
SafetyStock
"
));
if
(r.GetAttribute(
"
ForecastDemand
"
)
!=
null
&&
r.GetAttribute(
"
ForecastDemand
"
)
!=
""
)
dr[
"
ForecastDemand
"
]
=
Convert.ToDecimal(r.GetAttribute(
"
ForecastDemand
"
));
if
(r.GetAttribute(
"
FinalInput
"
)
!=
null
&&
r.GetAttribute(
"
FinalInput
"
)
!=
""
)
dr[
"
FinalInput
"
]
=
Convert.ToDecimal(r.GetAttribute(
"
FinalInput
"
));
if
(r.GetAttribute(
"
FinalOutput
"
)
!=
null
&&
r.GetAttribute(
"
FinalOutput
"
)
!=
""
)
dr[
"
FinalOutput
"
]
=
Convert.ToDecimal(r.GetAttribute(
"
FinalOutput
"
));
if
(r.GetAttribute(
"
SimuStock
"
)
!=
null
&&
r.GetAttribute(
"
SimuStock
"
)
!=
""
)
dr[
"
SimuStock
"
]
=
Convert.ToDecimal(r.GetAttribute(
"
SimuStock
"
));
if
(r.GetAttribute(
"
SimuStockTime
"
)
!=
null
&&
r.GetAttribute(
"
SimuStockTime
"
)
!=
""
)
dr[
"
SimuStockTime
"
]
=
Convert.ToDecimal(r.GetAttribute(
"
SimuStockTime
"
));
if
(r.GetAttribute(
"
ImportWorkDay
"
)
!=
null
&&
r.GetAttribute(
"
ImportWorkDay
"
)
!=
""
)
dr[
"
ImportWorkDay
"
]
=
Convert.ToBoolean(r.GetAttribute(
"
ImportWorkDay
"
));
if
(r.GetAttribute(
"
ExportWorkDay
"
)
!=
null
&&
r.GetAttribute(
"
ExportWorkDay
"
)
!=
""
)
dr[
"
ExportWorkDay
"
]
=
Convert.ToBoolean(r.GetAttribute(
"
ExportWorkDay
"
));
LocationTable.Rows.Add(dr);
}
break
;
default
:
break
;
}
}
else
if
(r.NodeType
==
XmlNodeType.EndElement)
{
switch
(r.LocalName)
{
case
"
Location
"
:
if
(LocationTable
!=
null
)
{
LocationTable.AcceptChanges();
AllLocationResult.Add(LocationID,LocationTable);
LocationID
=
""
;
LocationTable
=
null
;
}
break
;
default
:
break
;
}
}
}
OneGoods.AllLocationResult
=
AllLocationResult;
return
OneGoods;
}
查看全文
相关阅读:
PriorityQueue详解
Queue介绍
Dubbo面试踩坑
Java中Integer和ThreadLocal
Java中Deque特性及API
由ubuntu装好想到的
双系统试水上岸
终于意识到BIM确实火了
读阿里机器学习平台的一些总结
继续ubuntu和遇到的easybcd的坑
原文地址:https://www.cnblogs.com/yangyang8848/p/378004.html
最新文章
volley源码分析(1)
Android自定义控件之自定义属性的添加 -(2)
Android自定义控件-(1)
LRU原理与实现
Java
Spring Data JPA 简单查询
Spring Data JPA 实例查询
MyBatis拦截器:给参数对象属性赋值
Java架构必会几大技术点(转)
产品经理常用工具Axure、Visio、Mindmanager使用解析(摘)
热门文章
JS数值输入控制
Java工具类:获取long型唯一ID
软件的未来
功件与面向功件编程
通用删除查询语句存储过程
Direct Buffer介绍
Buffer
Java NIO
Mysql系列(六)—— MySQL索引介绍
ArrayDeque详解
Copyright © 2011-2022 走看看