ASP.NET Podcast

ASP.NET Podcast is geared towards the Microsoft .NET Framework and ASP.NET.
The podcast is run by Wally McClure, David Penton, and Paul Glavich.
Welcome to ASP.NET Podcast Sign in | Join | Help
in Search

ASP.NET Podcast

The ASP.NET Podcast features, technical talks, interviews, news, reviews, and Wallyisms. Wallace B. (Wally) McClure, David Penton, and Paul Glavich are your hosts. We talk about ASP.NET, AJAX, Performance, Databases, WCF, Silverlight, Cloud Computing, Windows Azure, and whatever else we decide to talk about.

ASP.NET Podcast Show #114 - ADO.NET Data Services in .NET 3.5 Service Pack 1 Beta1 with ASP.NET AJAX

Subscribe to everything.

Subscribe to WMV.

Subscribe to M4V for iPod.

Subscribe to MP3.

Download WMV.

Download W4V for iPod.

Download MP3.

Show Notes:

  • ADO.NET Data Services Viewing DataSql Server Database .
  • ADO.NET Data Services.
  • Javascript.
  • No SQL.
  • Getting data.
  • Insert a record.
  • Update a record.
  • Metadata.
  • I had a snafu while recording, so some audio may sound clipped.

Source Code:

ADO.NET Data Services Editing Data<%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory" Service="OrderItemDataService" %>

Codebehind file:

using System;

using System.Data.Services;

using System.Collections.Generic;

using System.Linq;

using System.ServiceModel.Web;

 

public class OrderItemDataService : DataService< ADONETDataServicesModel.ADONETDataServicesEntities >

{

    // This method is called only once to initialize service-wide policies.

    public static void InitializeService(IDataServiceConfiguration config)

    {

        // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.

        // For testing purposes use "*" to indicate all entity sets/service operations.

        // "*" should NOT be used in production systems.

        // Example for entity sets (this example uses "AllRead" which allows reads but not writes)

        // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);

        config.SetEntitySetAccessRule("*", EntitySetRights.All);

        config.UseVerboseErrors = true;

        //config.SetEntitySetAccessRule("tbOrder", EntitySetRights.All);

        // Example for service operations

        // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);

  }

 

    // Query interceptors, change interceptors and service operations go here

}

Display Data:

<script language="javascript" type="text/javascript">

function pageLoad()

{

    var strOut;

    var Service = GetDataService();

 

    var QueryString = "/tbOrder";

    Service.query(QueryString, OnCompleteSuccess, OnCompleteFailure);

}

function GetDataService()

{

    return(new Sys.Data.DataService("WebDataService.svc"));

}

function OnCompleteSuccess(result) {

    var strReturn = "<br />";

    var Output = "On Complete Success Called." + strReturn;

    var i = 0;

    for (m in result)

    {

        Output += m + strReturn;

    }

 

    for (m in result[0]) {

        Output += m + strReturn;

    }

 

    Output += "<table>";

    Output += "<tr><th>Total Amount</th>" +

              "<th>Date of Order</th>" +

              "<th>Comment</th>" +

              "<th>Customer Name</th>" +

              "<th>Edit</th>" +

              "</tr>";

    for (i=0; i< result.length; i++)

    {

        Output += "<tr>" +

            "<td>" + result[i].TotalAmount + "</td>" +

            "<td>" + result[i].DateOrdered + "</td>" +

            "<td>" + result[i].Comment + "</td>" +

            "<td>" + result[i].CustomerName + "</td>" +

            "<td><a href='EditOrder.aspx?OrderID=" + result[i].OrderId + "'>Edit</td>" +

            "</tr>";

    }

    Output += "</table>";

    $get("OutputDiv").innerHTML = Output;

}

 

function OnCompleteFailure(result)

{

    alert("On Complete Failure Called.");

}

Add/Edit/Delete file:

        var OrderID=<%=Request.QueryString["OrderID"] %>;

       

        function pageLoad() {

            FillOrderData();

        }

        function FillOrderData()

        {

            var Service = GetDataService();

            var QueryString = "tbOrder(" + OrderID + ")?$expand=tbItem";

            Service.query(QueryString, OnCompleteSuccess, OnCompleteFailure);

        }

        function GetDataService()

        {

            return(new Sys.Data.DataService("OrderItemDataService.svc"));

        }

        function OnCompleteSuccess(result)

        {

            var i = 0;

            var Output = "<table><tr><th>Part</th><th>Price</th>" +

                "<th>Edit</th><th>Delete</th></tr>";

            for(i = 0; i < result.tbItem.length; i++)

            {

                Output += "<tr><td>" + result.tbItem[i].Part +

                    "</td><td>" + result.tbItem[i].Price + "</td>" +

                    "<td><a href='BLOCKED SCRIPTEditItem(" + result.tbItem[i].ItemId + ")'>Edit</a></td>" +

                    "<td><a href='BLOCKED SCRIPTDeleteItem(" + result.tbItem[i].ItemId + ")'>Delete</a></td>" +

                    "</tr>";

            }

            Output += "</table>";

            $get("OutputGrid").innerHTML = Output;

        }

       

        function OnCompleteFailure(result)

        {

            alert("OnCompleteFailure called.");

        }

       

        function DeleteItem( ItemId )

        {

            var Service = GetDataService();

           

            if ( window.confirm("Do you really want to delete this Item?" ) )

            {

                alert("Delete it.");

                Service.remove(null, "tbItem(" + ItemId + ")",

                    DeleteItemSucceed, DeleteItemFailure);

            }

        }

       

        function DeleteItemSucceed( result )

        {

            FillOrderData();

            alert("DeleteItemSucceed called.");

        }

       

        function DeleteItemFailure( result )

        {

            alert("DeleteItemFailure called.");

        }

       

        function EditItem( ItemId )

        {

            var Service = GetDataService();

            var QueryString = "tbItem(" + ItemId + ")";

            Service.query(QueryString, EditItemSucceed, EditItemFailure);

        }

       

        function EditItemSucceed( result )

        {

            $get("txtPrice").value = result.Price;

            $get("txtPart").value = result.Part;

            $get("hdItemId").value = result.ItemId;

            $get("OutputSpecifics").style.visibility = "visible";

            $get("OutputGrid").style.visibility = "hidden";

            FillOrderData();

        }

       

        function EditItemFailure( result )

        {

            alert("EditItemFailure called.");

        }

       

        function SaveItem()

        {

            var ThisItemId = $get("hdItemId").value;

            var Service = GetDataService();

           

            if (ThisItemId == "" )

            {

                var newProduct =

                {

                    Price:      $get("txtPrice").value,

                    Part:       $get("txtPart").value,

                    tbOrder:    { __metadata: {uri: "/tbOrder(" + OrderID + ")" }}

                };

                Service.insert(newProduct, "tbItem", InsertItemSucceed, InsertItemFailed);

            }

            else{

                var updateProduct=

                {

                    ItemId:     $get("hdItemId").value,

                    Price:      $get("txtPrice").value,

                    Part:       $get("txtPart").value,

                    tbOrder:    { __metadata: {uri: "/tbOrder(" + OrderID + ")" }}

                    //$get("hdOrderId").value

                }

                Service.update(updateProduct, "tbItem(" + $get("hdItemId").value + ")", UpdateItemSucceed, UpdateItemFailed, updateProduct);

            }

        }

        function InsertItemSucceed(result)

        {

            alert("InsertItemSucced called.");

            FillOrderData();

        }

        function InsertItemFailed(result)

        {

            alert("InsertItemFailed called.");

        }

        function UpdateItemSucceed(result)

        {

            alert("UpdateItemSucceed called.");

        }

        function UpdateItemFailed(result)

        {

            alert("UpdateItemFailed called.");

        }

        function BeginAdd()

        {

            $get("OutputGrid").style.visibility = "hidden";

            $get("OutputSpecifics").style.visibility = "visible";

            $get("txtPrice").value = "";

            $get("txtPart").value = "";

            $get("hdItemId").value = "";

        }

 

Published Saturday, May 31, 2008 1:03 AM by admin
Anonymous comments are disabled

This Blog

Syndication

Powered by Community Server, by Telligent Systems