Processing the Purchase Order Confirmation

[Previous] [Next]

Back at Toi Carz, an ASP application named poConfirm.asp is waiting to receive confirmation of our purchase order. This program is acting as a BizTalk server in that it reads a BizTalk document and does processing based on the body element type and the contents of the payload. The purchase order confirmation program is shown in Listing 11-14.

Listing 11-14. The poConfirm.asp program processes the purchase order confirmation.

 

poConfirm.asp

<%@language=vbscript%> <% Function ymdhms2mdy(ymdhms) strYear = mid(ymdhms, 1, 4) strMonth = mid(ymdhms, 5, 2) strDay = mid(ymdhms, 7, 2) ymdhms2mdy = strMonth & "/" & strDay & "/" & strYear End Function Function closeReq(reqID, datePromised, qtyPromised) Set dbPurchaseOrders = Server.CreateObject("ADODB.Connection") Set rsPORequests = Server.CreateObject ("ADODB.Recordset") rsPORequests.CursorType = 2 rsPORequests.LockType = 2 dbPurchaseOrders.Open "dbTC-PurchaseOrders" txtSQL = "SELECT PORequests.reqID, vendors.vendorName, " _ & "PORequests.itemPrice, PORequests.needBefore, " _ & "PORequests.needAfter, PORequests.itemQty, " _ & "PORequests.qtyPromised, PORequests.datePromised, " _ & "PORequests.itemNum, PORequests.requestorID, " _ & "catalog.description, PORequests.itemPrice, " _ & "PORequests.itemQty FROM [catalog] " _ & "INNER JOIN (vendors INNER JOIN PORequests " _ & "ON vendors.vendorID = PORequests.vendorID) " _ & "ON catalog.itemNum = PORequests.itemNum " _ & "WHERE (((PORequests.reqID)=" & reqID & "));" rsPORequests.Open txtSQL, dbPurchaseOrders rsPORequests("datePromised") = ymdhms2mdy(datePromised) rsPORequests("qtyPromised") = qtyPromised rsPORequests.Update Set dbEmployees = Server.CreateObject("ADODB.Connection") dbEmployees.Open "dbTC-Employees" Set rsEmployees = dbEmployees.Execute( _ "SELECT * FROM Employees where empID=" _ & rsPORequests("requestorID")) If Not rsEmployees.EOF Then Set exchangeMail = CreateObject("CDONTS.NewMail") strFrom = "biztalk_robot@toicarz.com" strTarget = rsEmployees("EMail") strSubject = "Purchase requisition confirmation" strMsg = "The purchase requisition for your order has " _ "been confirmed" _ & vbCrLf & " Item: " & rsPORequests("itemNum") _ & vbCrLf & " Description: " & rsPORequests("description") _ & vbCrLf & " Vendor: " & rsPORequests("vendorName") _ & vbCrLf & " Qty Ordered: " & rsPORequests("itemQty") _ & vbCrLf & " Qty Promised: " & rsPORequests("qtyPromised") _ & vbCrLf & " Date Required: " & rsPORequests("needBefore") _ & vbCrLf & " Date Promised: " & rsPORequests("datePromised") Response.Write(vbCrLf & "Message to " _ & rsEmployees("FName") & " " & rsEmployees("LName") _ & " <" & rsEmployees("Email") & ">" _ & vbCrLf & vbCrLf & strMsg) exchangeMail.Send strFrom, strTarget, strSubject, strMessage Set exchangeMail = Nothing End If rsPORequests.Close Set rsPORequest = Nothing dbEmployees.Close Set dbEmployees = Nothing dbPurchaseOrders.close Set dbPurchaseOrders = Nothing End Function Function closePO(poNum) Set dbPOSent = Server.CreateObject("ADODB.Connection") dbPOSent.Open "dbTC-PurchaseOrders" txtSQL = "UPDATE POSent SET confReceived=#" & CDate(date) _ & "# WHERE poNum= " & poNum dbPOSent.Execute txtSQL', intrecs, adcmdtext dbPOSent.Close Set dbPOSent = Nothing End Function HTTPSize = Request.TotalBytes HTTPBody = Request.BinaryRead(HTTPSize) strXML = "" For i = 1 To HTTPSize strXML = strXML & Chr(AscB(MidB(HTTPBody,i,1))) Next strXML = Replace (strXML, "%3C", "<") strXML = Replace (strXML, "%3E", ">") strXML = Replace (strXML, "%20", " ") strXML = Replace (strXML, "%2F", "/") strXML = Replace (strXML, "%3D", "=") strXML = Replace (strXML, "%0A", vbCrLf) Set oXMLDoc = Server.CreateObject("Microsoft.XMLDOM") oXMLDoc.loadXML(strXML) If oXMLDoc.parseError.errorcode <> 0 Then Response.Write("Error, Reason: " & oXMLDoc.parseError.reason _ & ", Code: " & oXMLDoc.parseError.errorcode _ & ", Line: " & oXMLDoc.parseError.line) End If poNum = oXMLDoc.selectSingleNode_ ("//purchaseOrder_Confirm_Chapter11_1.0").attributes.getNamedItem_ ("PONum").nodeValue Set collItem = oXMLDoc.selectNodes("//item") For i = 0 To collItem.length - 1 reqID = collItem.item(i).attributes.getNamedItem("reqID").nodeValue datePromised = collItem.item(i).selectSingleNode("datePromised").text qtyPromised = collItem.item(i).selectSingleNode("qtyPromised").text Response.Write("reqID: " & reqID _ & ", datePromised: " & datePromised _ & ", qtyPromised: " & qtyPromised) closeReq reqID, datePromised, qtyPromised Next closePO(poNum) %>

The poConfirm.asp program must perform three tasks. First it must close out each purchase requisition by updating the PORequests table with the delivery date and quantity promised by Toy Car Parts. It does this using the closeReq function. This function also performs the second task, notifying the person who placed the purchase requisition, by using the Collaboration Data Objects library CDONTS. CDONTS provides an interface for e-mail by using Microsoft Exchange Server.

The third task poConfirm.asp must perform is to close the purchase order by marking the record in the POSent table. It does this using the closePO function.

The program then sends a response to the OmniMark BizTalk server, which passes the message back to the purchase order generation program that started the process.

This is a very basic system showing the minimum requirements of a BizTalk server environment by using two different operating system/language platforms. It is, of course, more difficult to implement systems like this when many possible variables exist, but open standards such as BizTalk, SOAP, and XML make it much easier to build and deploy such systems.

One of the interesting challenges we overcame in building the system was getting use out of an existing application that has been working for years. The PlaceOrder system had been completely debugged and had worked well with our environment, so why should we change it? Because we were able to use state-of-the-art tools and open standards, we could breathe new life into a legacy application. The lesson here is that you don't necessarily need to discard working systems just because they aren't written using the newest tools and technologies.

Some really cool tools are coming along to help developers deploy systems that can communicate between you and your trading partners. The SOAP Toolkit for Visual Studio 6.0 is one such tool that allows developers to get beyond the XML syntax to deploy systems that leverage the entire Web. This is really powerful stuff! Other vendors have announced that they are supporting SOAP with tools similar to Microsoft's toolkit.

Other tools are being developed to work with BizTalk servers. In Chapter 12, I show you an early release of some tools built into the Microsoft BizTalk Server 2000 Technology Preview. These tools also allow the business programmer to get the most out of XML through useful utilities such as the BizTalk Editor, which allows you to create schemas, and the BizTalk Mapper, which creates transformations between different schemas. When Microsoft BizTalk Server 2000 is released, it will have other developer tools to help integrate business transactions into your enterprise systems.



XML and SOAP Programming for BizTalk Servers
XML and SOAP Programming for BizTalk(TM) Servers (DV-MPS Programming)
ISBN: 0735611262
EAN: 2147483647
Year: 2000
Pages: 150

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net