<html>
<head>
<title>Employee Information</title>
</head>
<body>
<div>
<button align="middle" id="btnAdd" onclick="addEmployee()">新建员工</button>
<div align="right">
<a href="javascript:languageChange('zh')">中文版</a>|<a href="javascript:languageChange('en')">English Version</a>
</div>
</div>
<div id="divContent" align="center">
</div>
<script language="javascript" type="text/javascript">
var lngg = new ActiveXObject("MSXML2.DOMDocument");
var langg = "zh";
var scending = "ascending";
lngg.load("language.xml");
function languageChange(str)
{
lnggRoot = lngg.selectSingleNode("//" + str);
btnAdd.value = lnggRoot.selectSingleNode("btnAdd").childNodes[0].xml;
langg=str;
showTable();
}
//全局变量
var currentPage = 1;
var pageSize = 5;
var order = "name";
//初始化
var xml = new ActiveXObject("MSXML2.DOMDocument");
xml.load("employee.xml");
var root=xml.documentElement;
var xsl = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
xsl.load("employee.xsl");
var xslTemplate = new ActiveXObject("MSXML2.XSLTemplate");
xslTemplate.stylesheet = xsl;
var xslProcessor = xslTemplate.createProcessor();
xslProcessor.input = xml;
//总记录数
function GetTotleEmplyee()
{
return xml.documentElement.childNodes.length;
}
//总页数
function GetTotlePage()
{
return Math.ceil(GetTotleEmplyee()/pageSize);
}
//增
function addEmployee()
{
var tmpObj = new Object();
tmpObj.XML = xml;
var lgg = new ActiveXObject("MSXML2.DOMDocument");
lgg.load(langg+".xml");
tmpObj.language = lgg;
window.showModalDialog("add.html",tmpObj,
"dialogHeight: 300px; dialogWidth:300px;center:resizable: No; status:No");
showTable();
}
//删
function delEmployee(str)
{
var node=xml.selectSingleNode("//employee[name='"+str+"']");
var lgg = new ActiveXObject("MSXML2.DOMDocument");
lgg.load(langg+".xml");
var del = lgg.documentElement.selectSingleNode('del');
if(!confirm(del.selectSingleNode('Text1').childNodes[0].xml
+ str + del.selectSingleNode('Text2').childNodes[0].xml))
{
return;
}
root.removeChild(node);
try
{
xml.save("employee.xml")
}catch(E)
{
alert(E.description);
}
showTable();
}
function sort(str)
{
order = str;
if(scending == "ascending")
{
scending = "descending";
}
else
{
scending = "ascending";
}
showTable();
}
function showTable()
{
xslProcessor.addParameter("currentPage", currentPage);
xslProcessor.addParameter("totelPage", GetTotlePage());
xslProcessor.addParameter("totelEmployee", GetTotleEmplyee());
xslProcessor.addParameter("pageSize", pageSize);
//定义要读取的Employee记录的范围
xslProcessor.addParameter("startEmployee", (currentPage-1)*pageSize);
xslProcessor.addParameter("endEmployee", currentPage*pageSize);
//排序
xslProcessor.addParameter("order", order);
xslProcessor.addParameter("scending", scending);
//语言切换
xslProcessor.addParameter("langg", langg);
xslProcessor.transform();
divContent.innerHTML = xslProcessor.output;
}
showTable();
function Edit(str)
{
var tmpObj = new Object();
tmpObj.XML = xml;
tmpObj.Ename = str;
var lgg = new ActiveXObject("MSXML2.DOMDocument");
lgg.load(langg+".xml");
tmpObj.lgg = lgg;
window.showModalDialog("edit.html",tmpObj,
"dialogHeight: 300px; dialogWidth:300px;center:resizable: No; status:No");
showTable();
}
function firstPage()
{
currentPage = 1;
showTable();
}
function nextPage()
{
currentPage=currentPage+1;
showTable();
}
function prevPage()
{
currentPage=currentPage-1;
showTable();
}
function lastPage()
{
currentPage=GetTotlePage();
showTable();
}
</script>
</body>
</html>