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;
}
查看全文
相关阅读:
TSQL 中游标应用示例
[转]浅谈数据库设计技巧(上)、(下)
ASP.NET页面打印技术的总结(转)
深入理解RIA(转)
三层架构的bussiness层没用?
ASP.NET中常用的26个优化性能方法(转)
基于MapX的GIS动态操作与实现
web项目经理手册项目经理的工作内容(转)
ASP.NET中上传文件到数据库
学习.net中I/O的心得第一篇 初探I/O(转)
原文地址:https://www.cnblogs.com/yangyang8848/p/378004.html
最新文章
在sql server里,日期字段按天数进行group by查询的方法
DataTable的AcceptChange方法为什么不能在Update之前?
SQL Server 2008使用自定义表类型
C#如何快速高效地导出大量数据?
浅谈如何在C#Winform程序中正确使用登录窗体
SQL Server数据库row_number() over() 来自动产生行号
DataTable 最大容量
执行SQL语句,返回新插入的主键值
SQL Server数据库获取TEXT字段的内容长度的方法
SQL Server中行列转换 Pivot UnPivot 转
热门文章
Delphi TcxTreeList表格 中的汇总金额起作用
投资金条如何回购
sql server convert函数的用法
Delphi TcxTreeList 总结
价格半小时变一次投资金条半小时就可套现
Sql CAST 函数的用法
PHP如何解决网站大流量与高并发的问题(四)
PHP如何解决网站大流量与高并发的问题(二)
PHP如何解决网站大流量与高并发的问题(三)
git 删除文件 、只删除远程仓库文件、更换远程仓库
Copyright © 2011-2022 走看看