// Structures used by the services // Customer Information // This structure matches the structure of the Customer table struct tCustomerInfo integer iCustNumber string sName string sCustAddress string sCity string sState string sZip string sPhoneNumber string sFaxNumber string sEmailAddress real rCreditLimit real rPurchases real rBalance string sComments string sStatus end_struct // These next two structures do not match the structure of the Customer table exactly // It is an example of structures that could have been determined by some other source (e.g. an industry group) // Customer Address struct tCustAddress string sCustAddress string sCity string sState string sZip end_struct // New Customer struct tNewCustomer string sFirstName string sMiddleName string sLastName tCustAddress Address string sPhoneNumber string sFaxNumber string sEmailAddress end_struct // Order Detail struct tOrderDet string sItemID integer iQty real rUnitPrice real rPrice end_struct // Order struct tOrder integer iOrderNumber integer iCustNumber date dOrdDate string sTerms string sShipVia string sOrderedBy string sSalesPerson real rOrderTotal tOrderDet[] ArrayOfDetails end_struct // Order Summary struct tOrderSummary integer iOrderNumber date dOrderDate real rOrderTotal end_struct Use cWebService.pkg Use DataDict.pkg Use VENDOR.DD Use INVT.DD Use CUSTOMER.DD Use SALESP.DD Use OrderHea.DD Use ORDERDTL.DD Object oCustOrderWebService is a cWebService // psDocumentation provides high level documentation of your web service. Clients using // this service will see and use this documentation. set psDocumentation to ; ("This Visual DataFlex Web Service provides information on Customers " +; "and their orders. You can also use this service to update Customer information, " +; "create new Customers and retrieve a list of Customers.") Set psServiceName to "CustomerAndOrderInfo" Set psServiceURI to "http://tempuri.org/" Set psServiceTitle to "Customer and Order Information Service" Object Vendor_DD is a Vendor_DataDictionary Send DefineAllExtendedFields End_Object // Vendor_DD Object Invt_DD is a Invt_DataDictionary Set DDO_Server to Vendor_DD Send DefineAllExtendedFields End_Object // Invt_DD Object Customer_DD is a Customer_DataDictionary Send DefineAllExtendedFields End_Object // Customer_DD Object Salesp_DD is a Salesp_DataDictionary Send DefineAllExtendedFields End_Object // Salesp_DD Object OrderHea_DD is a OrderHea_DataDictionary Set DDO_Server to Customer_DD Set DDO_Server to Salesp_DD Set Constrain_File to Customer.File_Number Send DefineAllExtendedFields End_Object // OrderHea_DD Object OrderDtl_DD is a OrderDtl_DataDictionary Set DDO_Server to OrderHea_DD Set DDO_Server to Invt_DD Set Constrain_File to OrderHea.File_Number Send DefineAllExtendedFields End_Object // OrderDtl_DD Set Main_DD to Customer_DD // Function GetOrdersForCustomer: // Searches for order number in the OrderHea file for specified customer number and returns order numbers // // This demonstrates how to build and return data in an Array based on a fundamental datatype (array of integers) // // iCustNum - Customer number // iArrayOfOrderNumbers - Array containing Order numbers for iCustNum { Published = True } { Description = "Searches for order number in the OrderHea file for specified customer number and returns order numbers." } Function GetOrdersForCustomer integer iCustNum returns Integer[] integer[] iArrayOfOrderNumbers handle hoCustomerDD hoOrderHeaDD integer iCount iOldConstraint iNewConst move 0 to iCount // Validate Customer Number move Customer_DD to hoCustomerDD send clear of hoCustomerDD move iCustNum to Customer.Customer_number send find of hoCustomerDD EQ 1 // Find Orders for iCustNum if (found) begin move OrderHea_DD to hoOrderHeaDD send find of hoOrderHeaDD first_record 1 while (found) move OrderHea.Order_number to iArrayOfOrderNumbers[iCount] send find of hoOrderHeaDD GT 1 increment iCount loop end else begin send WebServiceException "Customer number not found." Function_Return end Function_Return iArrayOfOrderNumbers End_Function // GetOrdersForCustomer // Function ChangeCustomerAddress: // Change address for customer // // This demonstrates how to pass in and use simple struct data // // NewCustomerAddress - New Customer Address // bSuccess - Boolean indicating if the new address was changed successfully or not { Published = True } { Description = "Change address for customer." } Function ChangeCustomerAddress integer iCustNum tCustAddress NewCustomerAddress returns Boolean boolean bSuccess handle hDD move False to bSuccess move Customer_DD to hDD send clear of hDD move iCustNum to Customer.Customer_number send find of hDD EQ 1 if (found) begin // Move values from structure to DD buffer set field_changed_value of hDD FIELD Customer.Address to NewCustomerAddress.sCustAddress set field_changed_value of hDD FIELD Customer.City to NewCustomerAddress.sCity set field_changed_value of hDD FIELD Customer.State to NewCustomerAddress.sState set field_changed_value of hDD FIELD Customer.Zip to NewCustomerAddress.sZip // Save record send Request_Save of hDD move (not(Err)) to bSuccess end Function_Return bSuccess End_Function // ChangeCustomerAddress // Function CreateNewCustomer: // Add new customer to Customer file // // This demonstrates how to pass in and use more complex struct data where // the struct contains an element that is itself another struct // // NewCustomer - New Customer // iSuccess - Integer containing the customer number, if the new customer was added successfully // or -1 if customer not added { Published = True } { Description = "Add new customer to Customer file." } Function CreateNewCustomer tNewCustomer NewCustomer returns Integer integer iSuccess handle hDD string sName move Customer_DD to hDD send clear of hDD // Move values from structure to DD buffer move (NewCustomer.sFirstName * NewCustomer.sMiddleName * NewCustomer.sLastName) to sName set field_changed_value of hDD FIELD Customer.Name to sName set field_changed_value of hDD FIELD Customer.Address to NewCustomer.Address.sCustAddress set field_changed_value of hDD FIELD Customer.City to NewCustomer.Address.sCity set field_changed_value of hDD FIELD Customer.State to NewCustomer.Address.sState set field_changed_value of hDD FIELD Customer.Zip to NewCustomer.Address.sZip set field_changed_value of hDD FIELD Customer.Phone_number to NewCustomer.sPhoneNumber set field_changed_value of hDD FIELD Customer.Fax_number to NewCustomer.sFaxNumber set field_changed_value of hDD FIELD Customer.Email_address to NewCustomer.sEmailAddress // note that the default for Credit_limit is already set in the data dictionary set field_changed_value of hDD FIELD Customer.Purchases to 0 set field_changed_value of hDD FIELD Customer.Balance to 0 set field_changed_value of hDD FIELD Customer.Comments to "New Customer" set field_changed_value of hDD FIELD Customer.Status to "Y" // Active by default // Save record send request_save of hDD if (not(Err)) move Customer.Customer_Number to iSuccess else move -1 to iSuccess Function_Return iSuccess End_Function // CreateNewCustomer // Function GetCustomerInfo: // Searches for customer number in the Customer file and returns customer details // // This demonstrate how to build and return data in a simple struct // // iCustNum - Customer number // OneCustomer - Structure containing Customer Information in Customer File { Published = True } { Description = "Searches for customer number in the Customer file and returns customer details." } Function GetCustomerInfo integer iCustNum returns tCustomerInfo tCustomerInfo OneCustomer handle hDD move Customer_DD to hDD send clear of hDD move iCustNum to Customer.Customer_number send find of hDD EQ 1 if (found) begin move Customer.Customer_Number to OneCustomer.iCustNumber move Customer.Name to OneCustomer.sName move Customer.Address to OneCustomer.sCustAddress move Customer.City to OneCustomer.sCity move Customer.State to OneCustomer.sState move Customer.Zip to OneCustomer.sZip move Customer.Phone_number to OneCustomer.sPhoneNumber move Customer.Fax_number to OneCustomer.sFaxNumber move Customer.Email_address to OneCustomer.sEmailAddress move Customer.Credit_limit to OneCustomer.rCreditLimit move Customer.Purchases to OneCustomer.rPurchases move Customer.Balance to OneCustomer.rBalance move Customer.Comments to OneCustomer.sComments move Customer.Status to OneCustomer.sStatus end else begin send WebServiceException "Customer number not found." Function_Return end Function_Return OneCustomer End_Function // GetCustomerInfo // Function GetCustomerInfoList: // Reads customer file and returns an array with a list of customers // // This demonstrates how to build and return data in an Array of structs // // ArrayOfCustomers - Array containing Customer from Customer File { Published = True } { Description = "Reads customer file and returns an array with a list of customers." } Function GetCustomerInfoList returns tCustomerInfo[] tCustomerInfo[] ArrayOfCustomers handle hoCustomerDD integer iCount move 0 to iCount move Customer_dd to hoCustomerDD // now go through all customer records send clear of hoCustomerDD send find of hoCustomerDD GE 2 while (found) move Customer.Customer_Number to ArrayOfCustomers[iCount].iCustNumber move Customer.Name to ArrayOfCustomers[iCount].sName move Customer.Address to ArrayOfCustomers[iCount].sCustAddress move Customer.City to ArrayOfCustomers[iCount].sCity move Customer.State to ArrayOfCustomers[iCount].sState move Customer.Zip to ArrayOfCustomers[iCount].sZip move Customer.Phone_number to ArrayOfCustomers[iCount].sPhoneNumber move Customer.Fax_number to ArrayOfCustomers[iCount].sFaxNumber move Customer.Email_address to ArrayOfCustomers[iCount].sEmailAddress move Customer.Credit_limit to ArrayOfCustomers[iCount].rCreditLimit move Customer.Purchases to ArrayOfCustomers[iCount].rPurchases move Customer.Balance to ArrayOfCustomers[iCount].rBalance move Customer.Comments to ArrayOfCustomers[iCount].sComments move Customer.Status to ArrayOfCustomers[iCount].sStatus send find of hoCustomerDD GT 2 increment iCount Loop Function_Return ArrayOfCustomers End_Function // CustomerList // Function GetOrderSummaryForCustomer: // Searches for order number in the OrderHea file for specified customer number and returns order numbers, // date and total. // // This demonstrates how to build and return data in an Array of structs // // iCustNum - Customer number // ArrayOfOrdersSum - Array containing OrderSummary for iCustNum { Published = True } { Description = "Searches for order number in the OrderHea file for specified customer number and returns order numbers, date and total." } Function GetOrderSummaryForCustomer integer iCustNum returns tOrderSummary[] tOrderSummary[] ArrayOfOrdersSum handle hDD integer iCount iOldConstraint move 0 to iCount // Validate Customer Number move Customer_DD to hDD send clear of hDD move iCustNum to Customer.Customer_number send find of hDD EQ 1 // Find Orders for iCustNum if (found) begin move OrderHea_DD to hDD send find of hDD first_record 1 while (found) move OrderHea.Order_number to ArrayOfOrdersSum[iCount].iOrderNumber move OrderHea.Order_Date to ArrayOfOrdersSum[iCount].dOrderDate move OrderHea.Order_Total to ArrayOfOrdersSum[iCount].rOrderTotal send find of hDD GT 1 increment iCount loop end else begin send WebServiceException "Customer number not found." Function_Return end Function_Return ArrayOfOrdersSum End_Function // GetOrderSummaryForCustomer // Function GetOrderInfo: // Searches for order number in the OrderHea file and returns order header and details // // This demonstrates how to build and return data in complex structs. // This struct contains a member that is an array of structs // // iOrdNum - Order number // OneOrder - Structure containing Order header and details { Published = True } { Description = "Searches for order number in the OrderHea file and returns order header and details." } Function GetOrderInfo integer iOrdNum returns tOrder tOrder OneOrder handle hDD integer iCount iOldConstraint boolean bHasRecord move 0 to iCount move OrderHea_DD to hDD // OrderHea_DD is constrained by Customer. In order to find all orders, // not only the ones belonging to the current Customer in the DD buffer, // we need to remove the constraint. Here we: // save the current constraint get constrain_file of hDD to iOldConstraint // remove the constraint set constrain_file of hDD to 0 // enforce the new rule i.e. no constraint send rebuild_constraints of hDD send clear of hDD move iOrdNum to OrderHea.Order_number send find of hDD EQ 1 // restore the default constraint to whatever it was set constrain_file of hDD to iOldConstraint send rebuild_constraints of hDD get HasRecord of hDD to bHasRecord if (bHasRecord) begin move OrderHea.Order_Number to OneOrder.iOrderNumber move OrderHea.Customer_Number to OneOrder.iCustNumber move OrderHea.Order_Date to OneOrder.dOrdDate move OrderHea.Terms to OneOrder.sTerms move OrderHea.Ship_Via to OneOrder.sShipVia move OrderHea.Ordered_By to OneOrder.sOrderedBy move OrderHea.Salesperson_ID to OneOrder.sSalesPerson move OrderHea.Order_Total to OneOrder.rOrderTotal move OrderDtl_DD to hDD send find of hDD first_record 1 while (found) move OrderDtl.Item_id to OneOrder.ArrayOfDetails[iCount].sItemID move OrderDtl.Qty_ordered to OneOrder.ArrayOfDetails[iCount].iQty move OrderDtl.Price to OneOrder.ArrayOfDetails[iCount].rUnitPrice move OrderDtl.Extended_price to OneOrder.ArrayOfDetails[iCount].rPrice send find of hDD GT 1 increment iCount loop end else begin send WebServiceException "Order number not found." Function_Return end Function_Return OneOrder End_Function // GetOrderInfo End_Object // oCustOrderWebService