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;
}
查看全文
相关阅读:
localtime 和 localtime_r 的区别
mysql1130远程连接没有权限的解决方法
pthread_create
GDB Core,gdb 调试大全,core文件调试
非root用户 如何将cscope安装到指定目录,vim74安装
linux查看网络链接状况命令netstat
在Linux系统如何让程序开机时自动启动
Linux开机启动程序详解
u盘出现大文件无法复制的解决
用JSON报的一个错误java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeExcep
原文地址:https://www.cnblogs.com/yangyang8848/p/378004.html
最新文章
洛谷1251餐巾纸问题
洛谷1343地震逃生
bzoj4514
bzoj2127
bzoj3894
bzoj2039
bzoj1927
停课集训 11.29
算法复习——欧拉回路(uoj117)
算法复习——迭代加深搜索(骑士精神bzoj1085)
热门文章
刷题总结——魔术球问题(ssoj最小路径覆盖+网络流)
刷题总结——奇怪的游戏(scoi2012)
刷题总结——蜥蜴(ssoj网络流)
刷题总结——太空飞行计划(最大权闭合子图用最大流解决)
刷题总结——bzoj1725(状压dp)
刷题总结——art2(ssoj)
刷题总结——mayan游戏(NOIP2011提高组day2T3)
刷题总结——选课(ssoj树形dp+记忆化搜索+多叉树转二叉树)
Shell参数
php 正则表达式
Copyright © 2011-2022 走看看