Wednesday, July 30, 2008

Diz catz is so seriuz

This kitten's picture is taken at the backyard of my inlaw's house using my Nokia N71, isn't he serious. Look at his eyes...

Wednesday, July 16, 2008

Setting NULL to datawindow column

/*
If it an integer, string, etc, replace with a declaration of the appropriate datatype
*/
datetime ldt_nulldate //to contain null value

SetNull(ldt_nulldate)
if dwo.name = 'b_clear' then
   dw_1.setitem(row, 'mydate', ldt_nulldate)
end if

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

Monday, July 14, 2008

My Experience with Macromedia

Back in 1999, i was involved in projects that requires presentation using macromedia director and macromedia flash (now known as Adobe). Sharing with you some project screenshot i have done using director :-

All images are created and edited using Photoshop.

Thursday, July 10, 2008

Passing Parameter, CloseWithReturn

string ls_bookingno

//Open a response window w_find
open(w_find, parent) //CloseWithReturn(Parent, sle_1.Text), when closing w_find
ls_bookingno = message.stringparm //received string parameter from w_find

if isnull(ls_bookingno) = False and ls_bookingno <> '' then
   sle_id.text = ls_bookingno
   sle_id.triggerevent(Modified!)
end if

/*
message.stringparm :- passes a string or a string variable.
message.doubleparm :- passes a numeric or a numeric variable.
message.powerobjectparm :- passes PB object such as structure or datawindow
*/

Wednesday, July 9, 2008

Tuesday, July 8, 2008

TO_CHAR Formats

SELECT to_char(SYSDATE, 'dd/mm/yyyy HH:MI') FROM DUAL;
output character: 08/07/2008 04:54

select to_char(CURRENT_DATE, 'dd/mm/yyyy HH:MI') from dual;
output character : 08/07/2008 04:54

SELECT to_char(SYSDATE, 'day/mon/yyyy HH24:MI:SS') FROM DUAL;
output character : thursday/jul/2008 15:34:30

Sunday, July 6, 2008

UPDATEBLOB using Powerbuilder

// -------
// ------- usage :doubleclicked objek picture to add, change & update
// ------- thanks to original writer :tropicalbloom -------

integer fh, ret
string txtname, named
string defext = "JPG"
string Filter = "Jpeg Files (*.jpg), *.jpg"
integer li_FileNum, loops, i
long flen, bytes_read, new_pos
blob b, tot_b
string ls_curdir
ulong l_buf

l_buf = 100
ls_curdir = space(l_buf)
ls_curdir = GetCurrentDirectory( )

// Open File directory

ret = GetFileOpenName("Open Jpeg", txtname, named, defext, filter)

// select desired file to DataType BLOB gambar_sf
// Set a wait cursor

SetPointer(HourGlass!)

// Get the file length, and open the file

flen = FileLength(txtname)
li_FileNum = FileOpen(txtname, StreamMode!, Read!, LockRead!)

// Determine how many times to call FileRead

IF flen > 32765 THEN
   IF Mod(flen, 32765) = 0 THEN
      loops = flen/32765
   ELSE
      loops = (flen/32765) + 1
   END IF
ELSE
   loops = 1
END IF

// Read the file
new_pos = 1

FOR i = 1 to loops
   bytes_read = FileRead(li_FileNum, b)
   tot_b = tot_b + b
NEXT

FileClose(li_FileNum)

// blob gambar_sf ; Declare Instance Variables
gambar_sf = tot_b
p_1.SetPicture(gambar_sf)

//use updateblob to update into database

UPDATEBLOB pstaff SET pstaff.spic = :gambar_sf
WHERE pstaff.stafno = :ls_no_staf USING sqlca;

IF sqlca.SQLNRows > 0 THEN
   messagebox('Updated', ls_no_staf)
   COMMIT USING sqlca;
END IF

// returning to Default Directory"
ChangeDirectory (ls_dirname)

Thursday, July 3, 2008

SELECTBLOB into picture control

blob lb_pic

SELECTBLOB a.picturecol
INTO :lb_pic
FROM picturetbl a, biodatatbl b
WHERE a.ic = b.ic
AND a.ic = :as_icno using sqlca;

if sqlca.sqlcode = 0 then
   if p_pic.setpicture(lb_pic) = 1 then
      p_pic.visible = True
   else
      p_pic.visible = False
   end if
else
   p_pic.visible = false
end if


/*Above code will select blob from picturetbl and display it on a picture control in Powerbuilder (p_pic)
*/

DECODE and SUBSELECT in Oracle

//DECODE is like if statement if(column, equals, True, False)

SELECT a.bookid, a.warga_type, a.matrik,
decode(a.warga_type, 'S', (select b.nama from fasas b where b.matrik = a.matrik),
'P', (select c.nama from SUN.biodata c where c.matrik = a.matrik)) as nama
FROM BOOKING a
WHERE a.bookid = :as_id

One of my SQL codes (Modified), if WARGA_TYPE = 'S' it will select NAMA from FASAS table.
if WARGA_TYPE = 'P' it will select from table BIODATA for user SUN.

Wednesday, July 2, 2008

Using Object in Datawindow

To disable a column in datawindow, in PB script write, in open window event or suitable event :

1 - Make the control's disable for editing
0 - Enable for Editing
dw_1.object.objectname.protect = 1
example : dw_detd.object.matrix.protect = 1

To set column background:
0 - Make the control's background opaque.
1 - Make the control's background transparent.

dw_1.object.objectname.background.mode = 0
example : dw_1.object.matrix.background.mode = 0

To set background color dynamically :
dw_1.object.objectname.background.color = RGB(192, 192, 192)
example : dw_1.object.matrix.background.color = RGB(192, 192, 192)

To set text in datawindow :
dw_1.object.objectname.text = 'This is Text'

Using LIKE in SQL

SELECT D.NOSTAF_DRIVER,
D.NODETAIL,
D.TKH_PERGI,
D.TKH_PULANG,
V.VREGNUM,
T.LOC_CODE,
T.LOC_DESC
FROM DETAIL D,
VEHICLE V,
TEMPAHAN T
WHERE ( D.VHCLCODE = V.VCODE ) and
( D.IDTEMPAH = T.IDTEMPAH ) and
( ( D.NOSTAF_DRIVER LIKE '%' ) AND
( TO_CHAR(D.TKH_PERGI, 'YYYY') = '2008' ) AND
( TO_CHAR(D.TKH_PERGI, 'MM') like '01' ) )
ORDER BY D.TKH_PERGI ASC

This SQL will retrieve all data for DETAIL table where NOSTAF_DRIVER equal '%' (all data)

Tuesday, July 1, 2008

Row Counting Problem in Datawindow for Powerbuilder

Do you want your datawindow report looks like this :

/*
Header Row No :- cumulativesum(1 for all DISTINCT groupname)
Group Row No :- cumulativesum(1 for group 1)
*/

Stripe Color in Datawindow


in datawindow properties > general.color

if (mod (getrow(), 2) = 0, RGB(192,192,192), RGB(255, 255, 255))

or

put a coloured rectangle in datawindow band and send it to back, in visible properties of the rectangle put this code :

if (mod (getrow(), 2) = 0, 1, 0)

Connecting PB to Oracle 9 Database

sqlca.DBMS = "O90 Oracle9i (9.0.1)"
sqlca.ServerName = "server"
sqlca.LogId = "scott"
sqlca.LogPass = "tiger"
sqlca.AutoCommit = False
sqlca.DBParm = "ObjectMode='No',CommitOnDisconnect='No',PBCatalogOwner= 'scott'"

connect using sqlca;

Date Format in SQL for Oracle Database

SELECT TO_CHAR(SYSDATE, 'DD/MM/YYYY') FROM DUAL;

output sample: 01/07/2008

SELECT TO_CHAR(SYSDATE, 'MMM/YYYY') FROM DUAL;

output sample: JUL/2008

SELECT TO_CHAR(SYSDATE, 'Dy') FROM DUAL;

output : Sun

SELECT TO_CHAR(SYSDATE, 'Day') FROM DUAL;

output : Sunday

Manual Retrieving DatawindowChild

datawindowchild dwc_year

dw_1.insertrow(0)
dw_1.getchild('year', dwc_year)
dwc_year.settransobject(sqlca)
dwc_year.retrieve('%')

My Story with Powerbuilder

Welcome...

Me & Powerbuilder...

I have been using Powerbuilder for quite sometime since version 5, 8, 9, 10.2 and now 12.1
Well, i am not an expert in Powerbuilder but i just love PB (yup it's a rapid application development -RAD language). For me, i'm just another regular PB programmer. Now i am using PB with Appeon 5, (2011 - now Dec.2012)

These are some of projects i involved/done since i knew Powerbuilder :

1. Attendance System
2. Student Information System
3. Staff Information System

4. Dynamic MenuTree and Security Level Access
5. University Account System
6. Student Account System
7. Budget Information System
8. Vehicle Booking System
9. Bla bla blah...

I will upload my codes in Powerbuilder, SQL from time to time, if have time :)
All the codes are either inspired from my experience or of course PB examples,community,etc. doesn't represent PowerBuilder or other application(s), company or such as if mentioned in this blog. The script maybe correct and it could be errors. I am using it as reference and for sharing.

Regards.