File: pwd_ds_contact.sru
Size: 2424
Date: Sat, 08 Dec 2007 15:38:31 +0100
$PBExportHeader$pwd_ds_contact.sru
$PBExportComments$Contact List and Detail
forward
global type pwd_ds_contact from pwd_ds_base
end type
end forward

global type pwd_ds_contact from pwd_ds_base
string dataobject = "pwd_d_contact_list"
string #listdataobject = "pwd_d_contact_list"
string #detaildataobject = "pwd_d_contact_detail"
end type
global pwd_ds_contact pwd_ds_contact

on pwd_ds_contact.create
call super::create
end on

on pwd_ds_contact.destroy
call super::destroy
end on

event pbw_setdetailretrievearguments;call super::pbw_setdetailretrievearguments;this.of_setArgument(1,Long(CGIEnv.of_getParam( 'id')))

end event

event updatestart;call super::updatestart;long ll_row
long ll_rowcount
long ll_max_id = 0
// This has to be done because of the ID is not autoincement
ll_rowcount = This.RowCount()
FOR ll_row = 1 to ll_rowcount
   if This.getitemStatus ( ll_row, 0 , Primary!) = NewModified! then
      if ll_max_id = 0 then 
         select max(id)  into :ll_max_id from contact using SQLCA;
         log.of_addmessage( 3,'Updatestart max_id is ' + String(ll_max_id)+ "for row" )
      end  if
      ll_max_id ++
      This.SetItem ( ll_row , "id" , ll_max_id )
   end if
NEXT

end event

event pbw_setdetailinitialvalues;call super::pbw_setdetailinitialvalues;/*
Set inital values 
*/
long ll_row , ll_rowcount

ll_rowcount = This.RowCount()
For ll_row = 1 To ll_rowcount
   Choose Case This.getitemStatus ( ll_row, 0 , Primary!)
      Case NewModified! , New!
      This.SetItem ( ll_row , 'phone' ,'123456789')
      This.SetItem ( ll_row , 'fax' ,'123456789')
      This.SetItem ( ll_row ,'zip' , '12345')
      This.SetItem ( ll_row ,'state' , 'FL')
   End Choose
Next
end event

event pbw_prelisthtmlgen;call super::pbw_prelisthtmlgen;// Scroll to a page with submitted id (PK of Data)
// This is brute force..

long ll_rowfound
long ll_rowsperpage
long ll_lastrow
long ll_id

ll_id = Long(CGIEnv.of_getParam( 'id'))
if ll_id > 0 then
   ll_rowfound = This.Find ('id='+string(ll_id), 1,This.RowCount())
   log.of_addmessage( 1, "Scrolling to "+String(ll_rowfound))
   if ll_rowfound > 0 then 
      ll_rowsperpage = Long(This.Object.DataWindow.HTMLGen.PageSize)
      if ll_rowsperpage > 0 then
         ll_lastrow = ll_rowsperpage
         do while ll_lastrow <= ll_rowfound
            this.sethtmlaction( "PageNext", "")
            ll_lastrow += ll_rowsperpage
         loop  
      end if
   end if   
end if


end event