Thursday, May 10, 2007

Validasi untuk Requeired Column

// function : f_cek_required( datawindow dw )
// deskripsi : Untuk mencek column-column yang harus diisi (required)
// dan menampilkan pesan jika column tsb tidak diisi.
// Required column tsb harus diberi sesuai dengan
// label column tsb.
// return : 1 (success) , -1 (ada column yg tidak diisi)

string sTemp
long lRowCount, lColCount, i, j
dwitemstatus l_status
SetPointer(HourGlass!)
lRowCount = dw.RowCount()
lColCount = long(dw.Describe("DataWindow.Column.Count"))
if dw.AcceptText() = -1 then return -1

// Cek setiap column untuk setiap row
For i = 1 to lRowCount
l_status = dw.GetItemStatus(i,0,Primary!)
IF l_status <> NotModified! THEN
FOR j = 1 TO lColCount
sTemp = Trim(String(dw.object.data[i,j]))
IF isNull(sTemp) THEN sTemp = ""
IF sTemp <> "" THEN CONTINUE
sTemp = dw.Describe("#" + String(j) + ".tag")
IF sTemp <> "" THEN
IF sTemp <> "?" THEN
MessageBox("Validation Error","Sorry! " +sTemp + " cannot be Empty.")
sTemp = dw.Describe("#" + String(j) + ".name")
dw.SetFocus()
dw.ScrollToRow(i)
dw.SetColumn(sTemp)
RETURN -1
END IF
END IF
NEXT
END IF
Next

RETURN 1

Cari nama parent window pada suatu object (Powerbuilder)

///////////////////////////////////////////////////////////////////////////////////////
//
// function : uf_parentwindow
// Purpose : return parent window
// Scope : Public
// Arguments : graphicobject - ao_grapobj
// Returns : window
//
// Modification Log
// ================
// NAME VER DATE DESCRIPTION
//
//------------------ ---------------------------------------------
// setiawanthea 1.0
//
//////////////////////////////////////////////////////////
/////////////////////////////
//--------------------------Start of declarations----------------------------//

graphicobject lgr
window lwin

lgr = ao_grapobj
if isnull(lgr) or not(isvalid(lgr)) then
return lwin
end if

do until lgr.typeof() = window!
lgr = lgr.getparent()
if isnull(lgr) or not(isvalid(lgr)) then
//have no parent window
return lwin
end if
loop

lwin = lgr

return lwin

validasi time (Powerbuilder)

//////////////////////////////////////////////////////////////////////////////////
//
// Purpose : validasi time (hh:mm:ss:ff)
// Scope : Public
// Arguments : as_time - strring
// Returns : long
//
//////////////////////////////////////////////////////////////////////////////////

//*****************Start of Code****************//


if isnull(as_time) then
return true
end if

if len(as_time) = 8 then
else
return false
end if

if isnumber(as_time) then
else
return false
end if

if mid(as_time,3,2) > '59' then return false // cek menit
if mid(as_time,5,2) > '59' then return false // cek detik
if mid(as_time,7,2) > '24' then return false // cek frame

if mid(as_time,3,2) < '00' then return false // cek menit if mid(as_time,5,2) < '00' then return false // cek detik if mid(as_time,7,2) < '00' then return false // cek frame return true //*****************End of Code****************// Cara Pake nya masukan syntak dibawah kedalam datawindow - Validation Expression di kolom yang akan di validasi f_time_valid( gettext())

Status Baris Data (Powerbuilder)

////////////////////////////////////////////////////////
// Purpose : Cek Status Kolom
//
// Scope :
// Arguments :
// Returns :
//
///////////////////////////////////////////////////////
//*****************Start of Code****************//

dwitemstatus ldw_st
ldw_st = nama_dw.getitemstatus(nama_dw.getrow(),0,Primary!)
if ldw_st = new! then
messagebox("check",'new')
elseif ldw_st = newmodified! then
messagebox("check",'newmodified')
elseif ldw_st = datamodified! then
messagebox("check",'datamodified')
elseif ldw_st = notmodified! then
messagebox("check",'notmodified')
else
messagebox("check",'others')
end if

//*****************End of Code****************//

Fungsi Terbilang (Powerbuilder)

//-----
num = truncate(num,0)
//------

double a, b
double c, d
boolean suff, done
string abjad[9]
string str_milyar, str_juta, str_ribu, str_satuan, str
double e1,e2,e3, tmp, tmp2, ix, jx

if num = 0 then
return('Nol')
end if

suff = true
str = ''
str_milyar = ''
str_juta = ''
str_ribu = ''
str_satuan = ''

abjad[1] = 'satu'
abjad[2] = 'dua'
abjad[3] = 'tiga'
abjad[4] = 'empat'
abjad[5] = 'lima'
abjad[6] = 'enam'
abjad[7] = 'tujuh'
abjad[8] = 'delapan'
abjad[9] = 'sembilan'


// ************************************* JUTAAN / MILLION*************************************
c = 100000000
d = 1000000

a = 100000
b = 1000000
ix = c * d
done = false
do while (not done)
// first
e1 = int(num / ix)
tmp = mod(num, ix)
num = num - (e1 * ix)

// second
e2 = int(tmp/ (ix/10) )
tmp2 = mod(tmp, (ix/10) )
num = num - (e2 * (ix/10))

// third
e3 = int(tmp2/ (ix/100) )
num = num - (e3 * (ix/100))

if e1=1 then
str = str + 'seratus '
else
if (e1 > 1 and e1 <= 9) then
str = str + abjad[e1] + ' ratus '
end if
end if

if (e2=1 and e3 = 0) then
str = str + 'sepuluh '
//suff = false
else
if (e2=1 and e3 = 1) then
str = str + 'sebelas '
//suff = false
else
if (e2=1 and e3 >= 2) then
str = str + abjad[e3] + ' belas '
else
if (e2>1 and e2<=9) then
str = str + abjad[e2] + ' puluh '
end if
end if
end if
end if

if (e3=1) and (ix=100000) and (e1=0) and (e2=0) then //RIBUAN => SERIBU
str = str + 'se'
else
if (e3>=1 and e3<=9 and e2<>1) then
str = str + abjad[e3] + ' '
end if
end if
// end if

if ( str<> '' ) then
choose case (ix)
case (c * d)
if str <> '' then
str = str + 'trilyun '
end if
case (a * b)
if str <> '' then
str = str + 'milyar '
end if
case 100000000
if str <> '' then
str = str + 'juta '
end if
case 100000
if str <> '' then
str = str + 'ribu '
end if
case 100
end choose

end if
e1=0
e2=0
e3=0
ix = ix/1000
if num<1>
done = true
end if

loop

// Decimal Handling
// See The Algorithm
integer num_koma

// Manipulate The Value
num_koma = num * 100

if num_koma > 0 then
if str = '' then
return gf_prop('Nol koma ' + gf_prop(gf_angka(num_koma)) +'Sen') // make it nice
else
return gf_prop(str + ' koma ' + gf_prop(gf_angka(num_koma)) + 'Sen') // make it nice
end if
else
return gf_prop(str) // make it nice
end if

Expand All Treeview (Powerbuilder)

//////////////////////////////////////////////////////////////////////////////////
//
// Purpose : expand all item on tree
// Scope : Public
// Arguments : none
// Returns : none
//
// Modification Log
// ================
// NAME VER DATE DESCRIPTION
//------------------ -----------------------------------------------------------
// setiawanthea 1.0 01/03/2006 Initial version
//
//////////////////////////////////////////////////////////////////////////////////

//--------------------------------------Start of Code------------------------------//

TreeViewItem ltvi_root
TreeViewItem ltvi_NextTreeViewItem
TreeViewItem ltvi_CurrentTreeViewItem

long ll_root, ll_next
long ll_Current

//Get tree Root
ll_root = tv_1.FindItem( RootTreeItem!, 0)
tv_1.GetItem( ll_root, ltvi_root )
tv_1.SelectItem(ll_root)
//MessageBox( "Root Item", ltvi_root.Label )



// Returns the next tree item in the same branch level
do
//Get current tree
ll_current = tv_1.FindItem( CurrentTreeItem!, 0 )
tv_1.ExpandItem( ll_current )

//Get current tree data information
tv_1.GetItem( ll_current, ltvi_CurrentTreeViewItem )
// MessageBox( "Current Tree Item", ltvi_CurrentTreeViewItem.Label )

//Get next tree
ll_next = tv_1.FindItem( NextTreeitem!, ll_current )
tv_1.GetItem( ll_next, ltvi_NextTreeViewItem )
//select and make it current
tv_1.SelectItem(ll_next)
// MessageBox( "Next Tree Item", ltvi_NextTreeViewItem.Label )
if ll_next <= 0 then exit loop while true //--------------------------------------End of Code------------------------------//

Collapse All on Treeview (Powerbuilder)

//////////////////////////////////////////////////////////////////////////////////
//
// Purpose : Collapse all item on tree
//
// Scope : Public
//
// Arguments : none
//
// Returns : none
//
// Modification Log
// ================
// NAME VER DATE DESCRIPTION
//------------------ -----------------------------------------------------------
// setiawanthea 1.0 01/03/2006 Initial version
//
//////////////////////////////////////////////////////////////////////////////////

//--------------------------------------Start of Code------------------------------//

TreeViewItem ltvi_root
TreeViewItem ltvi_NextTreeViewItem
TreeViewItem ltvi_CurrentTreeViewItem

long ll_root, ll_next
long ll_Current

//Get tree Root
ll_root = tv_1.FindItem( RootTreeItem!, 0)
tv_1.GetItem( ll_root, ltvi_root )
tv_1.SelectItem(ll_root)

//tv_1.CollapseItem( ll_current )

//MessageBox( "Root Item", ltvi_root.Label )


// Returns the next tree item in the same branch level
do

//Get current tree
ll_current = tv_1.FindItem( CurrentTreeItem!, 0 )
tv_1.CollapseItem( ll_current )

//Get current tree data information
tv_1.GetItem( ll_current, ltvi_CurrentTreeViewItem )
// MessageBox( "Current Tree Item", ltvi_CurrentTreeViewItem.Label )

//Get next tree
ll_next = tv_1.FindItem( NextTreeitem!, ll_current )
tv_1.GetItem( ll_next, ltvi_NextTreeViewItem )

//select and make it current
tv_1.SelectItem(ll_next)
// MessageBox( "Next Tree Item", ltvi_NextTreeViewItem.Label )

if ll_next <= 0 then exit loop while true //--------------------------------------End of Code------------------------------//

Monday, May 7, 2007

Fungsi untuk ngebuat unik id

///////////////////////////////////////////////////////////////////////////////////////
//
// function : f_getrowid
// Purpose : Ngebuat unik id
// Scope : Public
// Arguments : none
// Returns : unik id
//
// Modification Log
// ================
// NAME VER DATE DESCRIPTION
//
//------------------ ---------------------------------------------
// setiawanthea 1.0
//
//////////////////////////////////////////////////////////
/////////////////////////////
//--------------------------Start of declarations----------------------------//

decimal ldec_10, ldec_int
string ls_temp
string ls_62 = ''
char ic_simbol[]
string ls_simbol = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
integer ii

// Prepare string Array for row id
// prepare lambangan bilangan untuk row_id
for ii=1 to 62
ic_simbol[ii] = mid(ls_simbol,ii,1)
next


ldec_10 = dec(string(datetime(today(),now()),'yyyymmddhhmmssffff'))
// generates a unique rowid based on time
// convert ke bilangan basis 62
do until ldec_10 = 0
ls_temp = string(ldec_10 / 62)
ldec_int = dec(mid(ls_temp,1,pos(ls_temp,'.')))
//ldec_int = int(ls_temp)
if ldec_int = 0 then ldec_int = dec(mid(ls_temp,1,pos(ls_temp,',')))
ls_62 = ic_simbol[ldec_10 - 62 * ldec_int + 1] + ls_62
ldec_10 = ldec_int
loop

// Counter for Unique Guarantee
// counter untuk menjamin unique
if gl_cc > 99999 then gl_cc = 0
ls_62 += gs_id +string(gl_cc,'00000')
gl_cc ++
if isnull(ls_62) or Trim(ls_62) = "" then
ls_62 = string(gf_serverdate(),'yyyymmddhhmmssffff')
Messagebox("Error","Cannot Generate Row ID")
end if
return ls_62

Fungsi untuk menimpa teks

// Access: public
//
// Arguments:
// as_Source The string being searched.
// as_Old The old string being replaced.
// as_New The new string.
// ab_IgnoreCase A boolean stating to ignore case sensitivity.
//
// Returns: string
// as_Source with all occurrences of as_Old replaced with as_New.
// If any argument's value is NULL, function returns NULL.
//
// Description: Replace all occurrences of one string inside another with
// a new string.

Long ll_Start
Long ll_OldLen
Long ll_NewLen
String ls_Source

//Check parameters
If IsNull(as_source) or IsNull(as_old) or IsNull(as_new) or IsNull(ab_ignorecase) Then
string ls_null
SetNull(ls_null)
Return ls_null
End If

//Get the string lenghts
ll_OldLen = Len(as_Old)
ll_NewLen = Len(as_New)

//Should function respect case.
If ab_ignorecase Then
as_old = Lower(as_old)
ls_source = Lower(as_source)
Else
ls_source = as_source
End If

//Search for the first occurrence of as_Old
ll_Start = Pos(ls_Source, as_Old)

Do While ll_Start > 0
// replace as_Old with as_New
as_Source = Replace(as_Source, ll_Start, ll_OldLen, as_New)

//Should function respect case.
If ab_ignorecase Then
ls_source = Lower(as_source)
Else
ls_source = as_source
End If

// find the next occurrence of as_Old
ll_Start = Pos(ls_Source, as_Old, (ll_Start + ll_NewLen))
Loop

Return as_Source

Powerbuilder Linkage

/************ Setting Linkage ************/

dw_name.of_SetLinkage(True)
child_dw.inv_linkage.of_SetMaster(master_dw)
child_dw.inv_linkage.of_SetStyle(2)
child_dw.inv_linkage.of_Register('child_col_name','master_col_name')


/************ Setting Calendar ************/
dw_name.of_setdropdowncalendar(true)
dw_name.iuo_calendar.of_Register('col_name',dw_name.iuo_calendar.DDLB_WITHARROW)


/*********** Setting setrowfocus ***********/
dw_name.of_SetRowmanager(true)
dw_name.of_SetRowSelect(true)
dw_name.inv_rowselect.of_setstyle(0)


/************ Setting Dropdown ************/
dw_name.of_setdropdownsearch(true)
dw_name.inv_DropDownSearch.of_register('col_name')

Menampilkan data sebanyak 14 baris per halaman

Dalam Powerbuilder kita bisa menampilkan data sebanyak yang kita mau, contoh menampilkan 14 baris per halaman.. caranya :
1. Buat compute field diberinama misalnya "c_baris" yang ekspresinya :
int((getrow() - 1)/14)
(catatan : 14 adalah jumlah baris yang diinginkan )
2. Buat group berdasarkan "c_baris" itu
3. Aktifkan properties "NEW PAGE ON GROUP BREAK"

Cari tanggal terakhir disuatu bulan

/*
Description:
pencarian tanggal terakhir suatu bulan

Arguments:
ad_parm - tanggal acuan

Returns:
date - tanggal terakhir suatu bulan

contoh - cari tanggal terkahir di bulan ini :
ld_last = f_last_date_in_month ( today() )
*/
date ld_last_date_in_previous_month
date ld_date_in_next_month


ld_last_date_in_previous_month = RelativeDate ( ad_parm, -day ( ad_parm ) )
ld_date_in_next_month = RelativeDate ( ld_last_date_in_previous_month, 35 )

return RelativeDate ( ld_date_in_next_month, &
-day ( ld_date_in_next_month ) )