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

来源:互联网 发布:淘宝上营业执照是外地 编辑:程序博客网 时间:2024/06/16 02:07
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<!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>
<

实现一个客户端的DataSet-----index.htm';return true">
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击