日期:2013-09-06  浏览次数:20474 次

<PUBLIC:COMPONENT lightWeight="true">
    <PUBLIC:PROPERTY name="Name" value="DataSet" />
    <PUBLIC:PROPERTY name="Namespace" value="http://tempuri.org" />
    <PUBLIC:PROPERTY name="XmlData" />
    <PUBLIC:PROPERTY name="XmlSchema" />
    
    <PUBLIC:METHOD name="ReadXml" />
    <PUBLIC:METHOD name="ReadXmlSchema" />
    <PUBLIC:METHOD name="GetTable" />
    <PUBLIC:METHOD name="AcceptChanges" />
    <PUBLIC:METHOD name="RejectChanges" />
    <PUBLIC:METHOD name="GetChanges" />

    <PUBLIC:EVENT name="ondatachanged" id="datachanged" />
</PUBLIC:COMPONENT>   

<SCRIPT>

//////////////////////////////////////////////////////////
// 实现一个客户端的DataSet
//////////////////////////////////////////////////////////

function DataRow(dt, oNode)
{
    this.DataTable        = dt;
    this.XmlNode        = oNode;
    this.GetValue        = DataRow_GetValue;
    this.SetValue        = DataRow_SetValue;
    this.Delete        = DataRow_Delete;
}

function DataRow_GetValue(vIndex)
{
    var oNode;
    switch (typeof(vIndex))
    {
        case "string":
            oNode = this.XmlNode.selectSingleNode(vIndex);
            break;
        default:
            throw "You must index into a DataRow using the string name.";
    }
    
    if (oNode != null)
    {
        return oNode.text;
    }
    
    return null;
}

function DataRow_SetValue(vIndex, vValue)
{
    var oNode;
    var oSchemaNode;
    
    switch (typeof(vIndex))
    {
        case "string":
            oNode = this.XmlNode.selectSingleNode(vIndex);
            oSchemaNode = this.DataTable.SchemaNode.selectSingleNode('xsd:complexType/xsd:sequence/xsd:element[@name="' + vIndex + '"]');
            if (oSchemaNode == null)
                throw "Invaid column index: " + vIndex;
            break;
        default:
            //oNode = this.XmlNode