Tuesday, July 15, 2008

Using GetSQLSelect( ) & SetSQLSelect( )

//on the event of itemfocuschanged
//declare instance string oldSQL, datawindowchild dwc_dsr

string ls_kw, ls_pt, ls_sp, ls_ak, ls_am, ls_sb, ls_kol, ls_uol
integer li_dasar, li_digit, ret
string whereSQL, newSQL

this.setrow(row)

if dwo.name = 'dasar_id' then
   ls_kw = this.getitemstring(row, "kwg")
   ls_pt = this.getitemstring(row, "ptj")
   ls_sp = this.getitemstring(row, "sptj")
   ls_ak = this.getitemstring(row, "aktv")
   ls_am = this.getitemstring(row, "obam")
   ls_sb = this.getitemstring(row, "obsb")
   ls_kol = this.getitemstring(row, 'kol')
   ls_uol = this.getitemstring(row, 'uol')

   this.getchild('dasar_id', dwc_dsr)
   dwc_dsr.settransobject(sqlca)

   if isnull(oldSQL) or oldSQL = '' then oldSQL = dwc_dsr.getsqlselect();
   whereSQL = '~rAND "BLJ1"."KWG" = ' + "'" + ls_kw + "'"
   whereSQL += '~r AND "BLJ1"."PTJ" = ' + "'" + ls_pt + "'"
   whereSQL += '~r AND "BLJ1"."SPTJ" = ' + "'" + ls_sp + "'"
   whereSQL += '~r AND "BLJ1"."AKTV" = ' + "'" + ls_ak + "'"

   SELECT "KWG"."DIGIT"
   INTO :li_digit
   FROM "KWG"
   WHERE "KWG"."WC01KWG" = :ls_kw using sqlca;

   if sqlca.sqlcode = 0 then
      if li_digit >= 5 then
         whereSQL += '~r AND "BLJ1"."OBAM" = ' + "'" + '0' + "'"
         whereSQL += '~r AND "BLJ1"."OBSB" = ' + "'" + '0' + "'"
         whereSQL += '~r AND "BLJ1"."KOL" = ' + "'" + '0' + "'"
         whereSQL += '~r AND "BLJ1"."UOL" = ' + "'" +'00' + "'"
         whereSQL += '~r AND "BLJ1"."THNBLJ" = ' + string(ii_tahun)

         dwc_dsr.modify( "kodproj.visible=1" )
         dwc_dsr.modify( "vot.visible=0" )
         dwc_dsr.modify( "ptj.visible=0" )
         dwc_dsr.modify( "sptj.visible=0" )
      else
         whereSQL += '~r AND "FIBLJ1"."OBAM" = ' + ls_am
         whereSQL += '~r AND "FIBLJ1"."OBSB" = ' + ls_sb
         whereSQL += '~r AND "FIBLJ1"."THNBLJ" = ' + string(ii_tahun)

         dwc_dsr.modify( "kodproj.visible=0" )
         dwc_dsr.modify( "vot.visible=1" )
         dwc_dsr.modify( "ptj.visible=1" )
         dwc_dsr.modify( "sptj.visible=1" )
      end if
   else
      messagebox('Fail', 'At retrieve digit', StopSign!)
      return
   end if

   newSQL = oldSQL + whereSQL
   ret = dwc_dsr.SetSQLSelect(newSQL)
   dwc_dsr.retrieve()
end if

No comments: