| Hyderabad Jobs | Book Website | ![]() |
I Love Hyderabad | Hyderabad Colleges |
| Home | Business Emails | Hyderabad Classifieds | Contact Us | |
| 7 Wonders of Hyderabad | Web Hosting | Yellow Pages | Our Network | |
Mastering PowerBuilder
Interactive DataWindow Sort UtilityWe are sure that you know how to sort the data in the DataWindow. You just need to call Sort() function. Then, why we are developing this utility? When we call Sort() function, PowerBuilder displays all the columns in the DataWindow in the sort criteria dialog box. As you know, the database names and the headings in the DataWindow may not be exactly same. In the column names there are a lot of restrictions, and, typically, the names would be cryptic for the end user. What we are going to do in this utility is that, let the user click on the DataWindow column interactively and let's take care of sorting the data. Paint a tabular style DataWindow with an external data source. Define the result set for the DataWindow as follows:
Change the edit style for the sort_order column as RadioButton. The allowed values for the sort_order column should be "A" (Asc), "D" (Dsc) and save the DataWindow as d_sort.
Paint a window as shown in the following picture. There are four controls in the window. A DataWindow dw_sort, the three other controls are CommandButtons. Those are cb_sort, cb_delete and cb_close from left to right. Save this window as w_sort. Make sure to set the window type as Child window. Disable all window options expect visible, boarder and title. Set the title to "Sort". Associate d_sort DataWindow to the dw_sort DataWindow control.
Declare two instance variables: iWindow as a Window, and iDw as a DataWindow:
The purpose of iDw is to store the DataWindow that the user wants to sort on, while iWindow stores the window. Actually, storing the window isn't necessary, but if we do, it allows the sort window to be more flexible. For example, suppose that two sheets are open and the user invoked the sort window from Sheet2. As you know, we are allowing the user to select the column by clicking on the appropriate sheet, so if the user clicks on a column from Sheet1, we won't be able to find the column name. Sending both the Window and the DataWindow overcomes this problem. We need to declare a function wf_initialize() at this window level. The purpose of this window is to initialize the instance variables. We can't hard code the DataWindow name to sort, since we are creating a general purpose utility. After opening this window, let the user of this utility call this function saying which DataWindow to sort and in which window the DataWindow is in.
This function assigns the Window and DataWindow to instance variables and determines the existing sort order by calling Describe(). If there is any problem, Describe() will return either '!' or '?'. The following loop parses the sort order string returned by Describe() and inserts each column name and sort order in the dw_sort DataWindow. Okay, in the above function, we know which DataWindow to sort. But, we don't know the sort criteria. We need know each column the user clicks and add it to the sort criteria. We need one more function wf_add_to_sort_cols. Declare the following function at the window level.
This function checks that the DataWindow and Window are valid and then adds the column name to the dw_sort DataWindow control and enable the Sort and Delete buttons. The final thing to do is to apply the sort criteria when the user clicks on the Sort button. Write the following code for the clicked event of the cb_Sort button:
This sets the values from each row in the dw_sort DataWindow control and prepares the sort strings with a loop. Before we actually sort the DataWindow, we call SetSort() with the new sort criteria. We then change the pointer to an hourglass, and call the Sort() function, before changing the pointer back. As a final touch, allow the user to delete a sort criteria by clicking on the Delete button:
Now, we are done with developing the utility. Let's use it. Open the w_product_master window and comment all the code in the ue_sort event for the window and type the following code:
As explained above, we are opening the window and calling the initialize function with the window and DataWindow names. Now we have to allow the user to select a column by clicking on it. The following code has to be written for the clicked event for the DataWindow control on w_product_master:
This code checks whether or not the w_sort is open using the Handle() function. If the return value is greater than zero, the window is open and we call another function to add the column to the sort list.
Want to see this in action? Run the application and test it. Working? Hey Guys, take it and use it in your real applications. You pay No royalties to us.
|
| Copyright © 1996 - 2006 HamaraShehar.com Pvt. Ltd. All Rights Reserved.
Domain Registration, Website Design, Website Hosting by HamaraShehar.com |