首页 > 开发 > 综合 > 正文

实现一个客户端的DataSet-----index.htm

2024-07-21 02:16:42
字体:
来源:转载
供稿:网友
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
<head>
<meta name=vs_targetschema content="http://schemas.microsoft.com/intellisense/ie5">
<title>客户端dataset</title>
<script>
var irowidx = 0;

function init()
{
    services.useservice("clientdatasetdataprovider.asmx?wsdl", "clientdatasetdataprovider");
    loaddata();
}
function loaddata()
{
    services.clientdatasetdataprovider.callservice(loadresult, "getpubs");
}
function loadresult(result)
{
    if (result.error) {
        alert(result.errordetail.string);
    }
    else {
        dspubs.readxml(result.value);
        irowidx = 0;
        updatebuttons();
        databind();
    }
}
function databind()
{
    var otable = dspubs.gettable("authors");
    if (otable) {
        var orow = otable.getrow(irowidx);
        if (orow) {
            txtauthorid.value    = orow.getvalue("au_id");
            txtfirstname.value    = orow.getvalue("au_fname");
            txtlastname.value    = orow.getvalue("au_lname");
            txtphone.value        = orow.getvalue("phone");
            txtaddress.value    = orow.getvalue("address");
            txtcity.value        = orow.getvalue("city");
            txtstate.value        = orow.getvalue("state");
            txtzip.value        = orow.getvalue("zip");
            chkcontract.checked    = (orow.getvalue("contract") == "true") ? true : false;
            return;
        }
    }

    txtauthorid.value    = "";
    txtfirstname.value    = "";
    txtlastname.value    = "";
    txtphone.value        = "";
    txtaddress.value    = "";
    txtcity.value        = "";
    txtstate.value        = "";
    txtzip.value        = "";
    chkcontract.value    = false;
}
function text_onblur()
{
    var sdatafld = event.srcelement.getattribute("datafld");
    var otable = dspubs.gettable("authors");
    if (otable) {
        var orow = otable.getrow(irowidx);
        if (orow) {
            orow.setvalue(sdatafld, event.srcelement.value);
        }
    }
}
function checkbox_onblur()
{
    var sdatafld = event.srcelement.getattribute("datafld");
    var otable = dspubs.gettable("authors");
    if (otable) {
        var orow = otable.getrow(irowidx);
        if (orow) {
            orow.setvalue(sdatafld, event.srcelement.checked.tostring().tolowercase());
        }
    }
}
function updatebuttons()
{
    var otable = dspubs.gettable("authors");
    if (otable) {
        var crows = otable.getrowcount();
        if (irowidx == 0 || crows == 0) {
            btnfirst.disabled = true;
            btnprev.disabled = true;
        }
        else {
            btnfirst.disabled = false;
            btnprev.disabled = false;
        }
        
        if (irowidx < crows-1) {
            btnnext.disabled = false;
            btnlast.disabled = false;
        }
        else {
            btnnext.disabled = true;
            btnlast.disabled = true;
        }
        
        if (crows > 0) {
            btndelete.disabled = false;
        }
        else {
            btndelete.disabled = true;
        }
    }
    else {
        btnfirst.disabled = true;
        btnprev.disabled = true;
        btnnext.disabled = true;
        btnlast.disabled = true;
        btnadd.disabled = true;
        btndelete.disabled = true;
    }
}
function btnsave_onclick()
{
    var dschanges = dspubs.getchanges();
    services.clientdatasetdataprovider.callservice(saveresult, "savechanges", dschanges);
}
function saveresult(result)
{
    if (result.error) {
        alert(result.errordetail.string);
        dspubs.rejectchanges();
    }
    else {
        alert("数据已保存!");
        dspubs.acceptchanges();
    }
    
    updatebuttons();
    databind();
}
function btnfirst_onclick()
{
    irowidx = 0;
    updatebuttons();
    databind();
}
function btnprev_onclick()
{
    irowidx--;
    if (irowidx < 0) irowidx = 0;
    updatebuttons();
    databind();
}
function btnnext_onclick()
{
    var otable = dspubs.gettable("authors");
    if (otable) {
        var crows = otable.getrowcount();
        irowidx++;
        if (irowidx >= crows) irowidx = crows - 1;
        updatebuttons();
        databind();
    }
}
function btnlast_onclick()
{
    var otable = dspubs.gettable("authors");
    if (otable) {
        var crows = otable.getrowcount();
        irowidx = crows - 1;
        updatebuttons();
        databind();
    }
}
function btnadd_onclick()
{
    var otable = dspubs.gettable("authors");
    if (otable) {
        var orow = otable.addrow();
        irowidx = otable.getrowcount()-1;
        updatebuttons();
        databind();
    }
}

function btndelete_onclick()
{
    var otable = dspubs.gettable("authors");
    if (otable) {
        otable.getrow(irowidx).delete();
        otable = dspubs.gettable("authors");
        var crows = otable.getrowcount();
        if (irowidx >= crows) irowidx = crows - 1;
        updatebuttons();
        databind();
    }
}

function btngetchanges_onclick()
{
    var odoc = dspubs.getchanges();
    var odiff = odoc.selectsinglenode("//diffgr:diffgram");
    txtdebug.value = odiff.xml;
}

function btnacceptchanges_onclick()
{
    dspubs.acceptchanges();
    txtdebug.value = dspubs.xmldata.xml;
}

function btnrejectchanges_onclick()
{
    dspubs.rejectchanges();
    txtdebug.value = dspubs.xmldata.xml;
}

window.attachevent("onload", init);
</script>
</head>
<body>

<table cellspacing=0 cellpadding=10 border=0>
<tr>
    <td align=left valign=top>
        <b>author id:</b><br>
        <input id=txtauthorid type=text datafld="au_id" onblur="text_onblur()"><br><br>

        <b>first name:</b><br>
        <input id="txtfirstname" type=text datafld="au_fname" onblur="text_onblur()"><br><br>

        <b>last name:</b><br>
        <input id="txtlastname" type=text datafld="au_lname" onblur="text_onblur()"><br><br>
    </td>
    <td align=left valign=top>
        <b>phone:</b><br>
        <input id="txtphone" type=text datafld="phone" onblur="text_onblur()"><br><br>

        <b>address:</b><br>
        <input id="txtaddress" type=text datafld="address" onblur="text_onblur()"><br><br>

        <b>city:</b><br>
        <input id="txtcity" type=text datafld="city" onblur="text_onblur()"><br><br>
    </td>
    <td align=left valign=top>
        <b>state:</b><br>
        <input id="txtstate" type=text datafld="state" onblur="text_onblur()"><br><br>

        <b>zip:</b><br>
        <input id="txtzip" type=text datafld="zip" onblur="text_onblur()"><br><br>

        <b>contract:</b><input id="chkcontract" type=checkbox datafld="contract" onblur="checkbox_onblur()"><br><br>
    </td>
</tr>
</table>

<hr>

<table width="100%">
<tr>
    <td align=left valign=top>
        <input id="btnfirst" type=button value="first" onclick="btnfirst_onclick()">
        <input id="btnprev" type=button value="prev" onclick="btnprev_onclick()">
        <input id="btnnext" type= button value="next" onclick="btnnext_onclick()">
        <input id="btnlast" type= button value="last" onclick="btnlast_onclick()">
        <input id="btnadd" type=button value="add" onclick="btnadd_onclick()">
        <input id="btndelete" type=button value="delete" onclick="btndelete_onclick()">
    </td>
    <td align=right valign=top>
        <input id="btngetchanges" type=button value="getchanges" onclick="btngetchanges_onclick()">
        <input id="btnacceptchanges" type=button value="acceptchanges" onclick="btnacceptchanges_onclick()">
        <input id="btnrejectchanges" type=button value="rejectchanges" onclick="btnrejectchanges_onclick()">
        <input id="btnsave" type=button value="save" onclick="btnsave_onclick()">
    </td>
</tr>
</table>

<hr>

<textarea id=txtdebug rows=20 style="width:100%;">
</textarea>

<div id="services" style="behavior:url(webservice.htc)" showprogress=true></div>
<div id="dspubs" style="behavior:url(clientdataset.htc)"></div>

</body>
</html>注册会员,创建你的web开发资料库,
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表