Thursday 27 February 2014

Developing apps using PowerBuilder

PowerBuilder is an integrated development environment owned by Sybase, a division of SAP. It is the fastest tool for creating high-performance applications at less cost and less time.
Pre-requisite :- Power Builder should be installed.
go to following link to install powerbuilder trial.

 http://www.sybase.com/products/modelingdevelopment/powerbuilder?htab=Technical+Info&vtab=Product+Manuals&hid=80395&vid=80383 

Getting started with development of an application using PowerBuilder :-

I am taking the example of employee management application :-
Steps :-
  1. Create a workspace by clicking on file->new->workspace in powerbuilder ,  say empManagement. As shown in figure :-                                        

                                   

Workspace will create as :-                  
                                                                         


             

 Next step is to create application .Right click on workspace , Click on new as shown in figure :-
                                                        

 

   then click on application as shown :-
                                                   
        
 
 
 Give it a name say empmgt , and save it .it'll be shown as :-

                                                    




                               

 As for creating an application ,first need is database and tables .
 For database :-
  •  go to file -> new 
  •  a window will open 
  • go to its database tab and 
  • select database painter as shown in figure :-

                                      
                                                             
 Next step is to create tables in database . as shown in figure .
  •  go to tools and 
  • click database painter.

                                                    


 Database painter will open .Create tables by right click on tables and select new table as shown in figure :-
                                         

  
 I created a table say emp having columns as shown in figure :-
            
                                     
and another table dept having column dept_id and name.
dept_id is foreign key in emp table. i.e. it is master table for emp table . I am directly inserting some department values into this table by insert queries.

Next step is to create connectservice from where connection information is obtained.
For connection information we have 3 options :-
  • ini file
  • Registry file
  • Script
i am using script option
 To create connectservice :-
  • go to file->new
  • click on PB object tab
  • click on connection object wizard.
                                       



connectservice(n_empmgt_connectservice) will create as shown in figure :-

                                                
    
Go to edit source of empmgt file (i.e. main application file) , connect db through n_empmgt_connectservice by writing following code snippet at the end of file :-
              
                                                                                                                                                                                                                       
 where gnv_connect is a global variable of type n_empmgt_connectservice . don't forget to declare it .

In above code snippet there is a code open(login_page) that means when i'll run ma app first page that will open will be the login_page.

 So next step is to create application pages :-

 I am creating a master page and will inherit other pages from master page by using inheritance feature of powerbuilder so that all the pages in application have same look and feel. 
steps to create a page:-
  • Click on file->new
  • go to PB object tab and click on window
  • a window will create
  • save it as master page as shown in figure :-
                            


 For better UI iadd a picture on master_page .
 Click on insert->control->picture as shown in figure :-

                            

 Picture control will show at window . Give it name and path of the picture as shown in figure :-
                            

Next i'll create login page inherited from master_page.
steps are :-
  • click on file->inherit
  • a window will be open
  • choose the master_page in window, click ok as shown in figure:-
                           
  • page will be create, name it as login_page .as shown in figure :-
                                          
  Login page having the image as in master page because of it is inherited from master_page. Take static text , singlelineedit control and buttons on login_page.
As shown in figure :-
                             
         
 Next step is to create Welcome page and register page. also inherit these pages from master_page .
As shown in figure My register page is :-
              
                                                 
 Now i want , when register page is opened , then supervisor and department dropdownlistbox values should come from database tables emp and dept respectively.
   
 For this , Go to :-
  •     open tab of register page
  •     write code to connect to database and then add following code snippet :-
                             
  where supervisor_value and department_value is tha name of dropdownlistbox respectively.

   After Register into app ,  
   Next step is to login to application with these username and password values. so write code at click event of login button. steps are:-
  •    write code to connect to db
  •    and then add following code snippet :-
              

Now i login to application by these username and password . As shown in figure :-                                                                           

      and redirected to welcome page  as shown in figure :-

                                            
  Next main feature of powerbuilder is its datawindow control :-
 DataWindow Control :- it is the container of datawindow objects in PowerBuilder and used to display the data or in other words , we use datawindow control for reporting.
 Here i am using datawindowcontrol for showing the list of employees.
 First make a employee_list page that is inherited from master_page and take a datawindow control at this page . As shown in figure :-
                
                         

 
 Next step is to add dataobject for datawindow control .
steps to create dataobject :-
  • go to file->new
  • go to datawindow tab of opened window. 
  • select grid at ths tab
  • click ok
  • then select quickselect
  • click next
  • then select the table for which you want to show the data on datawindow . i select emp table. (When i select emp then dept table can also select because both table have relationship)
  • as shown in below  fig , at right hand sight there is columns window , select columns that you want to show in datawindow..
  • click ok 
You'll see something like this :-
                                                                                                                                                                                              
   
  • click next->finish
  • dataobject will create.
Next step is to add dataobject in datawindow control. 
  • Go to data window property.
  • select dataobject.
  • as shown in fig :-
                            

i want datawindow to be updated or refresh every time when i go to employee_list page for this write  dw_1.Retrieve( )  at open event of datawindow control. 
When i run this page data will be shown in datawindow control as shown in fig :-                                                                                                                                                                                                                                                                  
This is my small app that i developed using PowerBuilder .
Enjoy developing application using PowerBuilder . :-)