Hyderabad Jobs Book Website FREE PowerBuilder Training I Love Hyderabad Hyderabad Colleges
Home Business Emails Hyderabad Classifieds Contact Us
7 Wonders of Hyderabad Web Hosting Yellow Pages Our Network

 
Webpowerbuilder.hyderabad-colleges.com

Mastering PowerBuilder

HomePrevious Lesson: Monitoring Connection Information From the Server Console
Next Lesson: Testing Distributed Applications

Connecting from Client App to Middle Tier App

In the client application, i.e., the application located in product.pbl, we have created a connection object, but we haven't coded anything to connect to the middle tier application.

Open the application object and declare a global variable as shown below:
nuo_connection g_connection

In the application Open event, append the following code.
// Object: pms Application Object
// Event: Open
IF not IsValid( g_Connection ) THEN
   g_Connection = CREATE nuo_Connection
End IF
IF g_Connection.of_ConnectToServer() <> 1 THEN
	HALT CLOSE
END IF	
w_mdi_frame.SetMicroHelp( "Connected to DPB Server " )

Now, add ncst_product_master instance variable to w_product_master window.
ncst_product_master incst_product_master

Comment any code that is referring to any DataWindow in the w_product_master Open event and add the following code.
// Object: w_product_master
// Event: Open
IF g_Connection.CreateInstance(incst_product_master) <> 0 THEN
   MessageBox("Error", "Unable to create instance of " + &
              " Product master service object!")
   Return
END IF

Replace ue_retrieve event code with the following:
// Object: w_product_master
// Event: ue_retrieve
long ll_rowCount
Blob lbl_data
ll_rowCount = incst_product_master.of_retrieve(lbl_data)
dw_product1.SetFullState(lbl_data)
// Error Handling

In the above code, we are calling of_retrieve() function that is declared in ncst_product_master. You may recall that ncst_product_master is residing in product-server.pbl which will eventually be moved to another machine. However, you have the proxy for ncst_product_master sitting in product-proxy.pbl, which is in your current application library list. Later, we are making using of DataWindow synchronization functions.

Replace ue_save event code with the following.
// Object: w_product_master
// Event: ue_retrieve
BLOB lblob_changes
long ll_rc
int lUserAnswer, lUpdateStatus
lUserAnswer = MessageBox( "Update", &
                 "Apply Changes ?", Question!,YesNo!,2)
if lUserAnswer = 1 then 
   SetPointer( HourGlass! )
	dw_product1.getChanges(lblob_changes)
	ll_rc = incst_product_master.of_Update( lblob_changes )
	if ll_rc = 1 then 
		dw_product1.ResetUpdate()
   else
      SetPointer( Arrow! ) 
      MessageBox( "Update", "Error while " + &
		        "applying changes to the database" )
      return 0
   end if
end if
SetPointer( Arrow! )

The logic here is similar to ue_retrieve event. Here we are calling ue_update instead of of_retrieve. We are reading the changes into the BLOB variable and sending to the middle-tier object by calling of_update(). Later, we are resetting the status flags for dw_product.
HomePrevious Lesson: Monitoring Connection Information From the Server Console
Next Lesson: Testing Distributed Applications

Copyright © 1996 - 2006 HamaraShehar.com Pvt. Ltd. All Rights Reserved.
Domain Registration, Website Design, Website Hosting by HamaraShehar.com