Selasa, 14 April 2015

Membatasi Aplikasi yang Running hanya satu

Berikut ini adalah tips untuk membatasi user dalam menjalankan aplikasi, Hal ini guna mencegah agar user hanya menjalankan aplikasi cuma satu saja.

Berikut step by stepnya :

  • Klik "NEW
  • Pilih Tab "Pb Object" kemudian pilih "CUSTOM CLASS"
Custom Class
  • Set Properties AutoInstantiate menjadi TRUE

  • Deklarasikan  Win32 API modul pada  UserObject  -> Local External Functions
Function Long GetLastError () Library 'kernel32.dll'
Function ULong CreateMutex (ULong lpsa, Boolean fInitialOwner, String lpszMutexName) Library 'kernel32.dll' Alias for CreateMutexA
  • Buat UserObject Function seperti dibawah ini :

String ls_name
If Handle(GetApplication()) > 0 Then
   ls_name = GetApplication().AppName + Char(0)
   CreateMutex(0, True, ls_name)
   If GetLastError() = 183 Then Return True
End If
Return False
  • Simpan user object yang dibuat dengan nama uo_limitrun (sebagai contoh)
  • Untuk mengunakan object tersebut, copy script dibawah ini pada event open pada form aplikasi.

uo_limitrun lou_limitrun
If lou_limitrun.uf_isrunning() Then
  MessageBox ('Warning', 'Application is already running', StopSign!)
  HALT CLOSE
End If
//...
// Your next line code
//...

Senin, 14 April 2014

Konversi Hexadecimal to Decimal

Wah Sudah lama tidak nulis2 diblog...

Kali ini saya akan menulis sebuah function untuk mengkonversi bilangan Hexadecimal ke Decimal
berikut ini adalah langkah2nya :

1. Buat New Function dengan function name "F_Hex2Dec "
2. Isi Return Type dengan "long"
3. Isi Argument Type dengan "string" dan Argument Name dengan "as_Hex "
4. Tuliskan powerscript dibawah ini
5. Selamat mencoba...

/**********************************************/
/*  public long F_Hex2Dec ( string as_Hex )  */
/**********************************************/

CONSTANT STRING ls_HexSet = "0123456789ABCDEF"

STRING  ls_Hex, ls_Bit
LONG    ll_RetVal = 0
INTEGER li_C, li_Len, li_Pos
BOOLEAN lb_Error = FALSE

ls_Hex = Upper( as_Hex )

IF NOT IsNull( ls_Hex ) AND ls_Hex <> "" THEN
   
    li_Len = Len( ls_Hex )
   
    FOR li_C = 1 TO li_Len
        ls_Bit = Mid( ls_Hex, li_C, 1 )
        li_Pos = Pos( ls_HexSet, ls_Bit )
       
        IF li_Pos = 0 THEN
            lb_Error = TRUE
        ELSE
            ll_RetVal += ( ( li_Pos - 1 ) * ( 16 ^ ( li_Len - li_C ) ) )
        END IF
    NEXT
    IF lb_Error THEN ll_RetVal = 0
END IF

RETURN ll_RetVal


Minggu, 02 Juni 2013

Membuat Koneksi Powerbuilder ke Database SQLITE

Singkat saja, dalam tulisan ini saya mencoba membuat koneksi POWERBUILDER ke database SQLITE, berikut script yang ditulis didalam event open :

//===============================================
string ls_dbparm, ls_dbfile, ls_exepath, ls_file[]

ls_dbfile = 'sqlite_db_test.db3'

IF Fileexists(ls_dbfile) THEN
    // do nothing
ELSE
    IF GetFileOpenName('Select Data File',ls_dbfile, ls_file,'db3','SQLite files (*.db3),*.db3') < 1 THEN
        Messagebox('No Data File Chosen','Application will close')
        HALT CLOSE
    END IF
END IF
// SQLite connection
ls_dbparm = "ConnectString='"
// Driver installed with SQLite2009 Pro Enterprise Manager
ls_dbparm = ls_dbparm + "DRIVER=SQLite3 ODBC Driver;"
ls_dbparm = ls_dbparm + "Database=" + ls_dbfile + "'"
ls_dbparm = ls_dbparm + "UID=" + "admin" + ";PWD="
ls_dbparm = ls_dbparm +  "'"
sqlca.DbParm=ls_dbparm

sqlca.DBMS = "ODBC"

CONNECT USING SQLCA;

IF sqlca.sqlcode <> 0 then
MessageBox('Connect', 'Transaction not connect..'+sqlca.sqlerrtext,stopsign!)
Return
End IF

//============================================
Sekian dulu tulisan saya, semoga bisa membantu

Terima Kasih.

Rabu, 16 Januari 2013

Konversi Hex Ke Binary

Kali ini saya ingin membuat beberapa FUNCTION untuk mengkonversi bilangan HEX ke dalam bentuk Binary secara sederhana

1. Buat New Function dengan function name "f_hex_to_bin"
2. Isi Return Type dengan "string"
3. Isi Argument Type dengan "string" dan Argument Name dengan "as_param_hex"
4. Tuliskan powerscript dibawah ini
5. Selamat mencoba...

integer i,li_length
string ls_param_hex,ls_hex,ls_binary,ls_huruf

ls_param_hex = trim(as_param_hex)

li_length = len(ls_param_hex)

for i = 1 to li_length

ls_huruf = Mid(ls_param_hex, i,1)

choose case ls_huruf
case '0'
ls_binary = '0000'
case '1'
ls_binary = '0001'
case '2'
ls_binary = '0010'
case '3'
ls_binary = '0011'
case '4'
ls_binary = '0100'
case '5'
ls_binary = '0101'
case '6'
ls_binary = '0110'
case '7'
ls_binary = '0111'
case '8'
ls_binary = '1000'
case '9'
ls_binary = '1001'
case 'A'
ls_binary = '1010'
case 'B'
ls_binary = '1011'
case 'C'
ls_binary = '1100'
case 'D'
ls_binary = '1101'
case 'E'
ls_binary = '1110'
case 'F'
ls_binary = '1111'
end choose

ls_hex = ls_hex + ls_binary

next

return ls_hex

Lain kali saya akan coba untuk membuat function2 yang semoga bisa bermanfaat untuk para penggemar PB.

Rabu, 17 Oktober 2012

Kumpulan Script Membuat 3D di PB 12.5 .NET dengan HELIX 3D TOOLKIT

Berikut kumpulan2 script dalam membuat aplikasi WPF 3D di Powerbuilder 12.NET, sebelum membuatnya ada baiknya anda download dulu komponen helix 3D toolkit disini
Selanjutnya add Reference file2 dll nya :
1. 3DTools.dll
2. HelixToolkit.Wpf.dll
3. HelisToolkit.Wpf.Input.dll

XAML :

 xmlns:helix="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf"


<helix:HelixViewport3D Name="viewport3D"
InfoBackground="White"
Background="Transparent"
IsHeadLightEnabled="True"
InfiniteSpin="True"
CameraRotationMode="Turnball">
          <helix:HelixViewport3D.Camera>
                  <PerspectiveCamera Position="40,0,0"
LookDirection="-40,0,0"
UpDirection="0,0,9"
FieldOfView="61"
NearPlaneDistance="0.125"
FarPlaneDistance="Infinity" />
        </helix:HelixViewport3D.Camera>
            <helix:SunLight />
      </helix:HelixViewport3D>

       

SCRIPT :
1. Create Viewport3D dari Script
HelixToolkit.Wpf.HelixViewport3D viewport3D
viewport3D = create HelixToolkit.Wpf.HelixViewport3D
viewport3D.InfoBackground = System.Windows.Media.Brushes.Transparent
viewport3D.ZoomExtentsWhenLoaded = True
viewport3D.IsHeadLightEnabled = True
viewport3D.InfiniteSpin = True
viewport3D.Background = System.Windows.Media.Brushes.Transparent
viewport3D.CameraRotationMode = HelixToolkit.Wpf.CameraRotationMode.Turnball!

1. Memanggil File 3DS

HelixToolkit.Wpf.FileModelVisual3D iFile3D
iFile3D = Create HelixToolkit.Wpf.FileModelVisual3D
iFile3D.Source = "Files3D\heart.3DS"
viewport3D.Children.Add(iFile3D)

2. Rotate Object 3DS

System.Nullable lnull1,lnull2

lnull1 = create System.Nullable(1)
lnull2 = create System.Nullable(361)

System.Windows.Media.Animation.DoubleAnimation myAnimation
myAnimation = create System.Windows.Media.Animation.DoubleAnimation
myAnimation.From = lnull1
myAnimation.To = lnull2
myAnimation.Duration = create System.Windows.Duration(System.TimeSpan.FromMilliseconds(5000))
myAnimation.RepeatBehavior = System.Windows.Media.Animation.RepeatBehavior.Forever

System.Windows.Media.Media3D.Vector3D lvector3D
lvector3D = Create System.Windows.Media.Media3D.Vector3D(0, 0, 1)

System.Windows.Media.Media3D.AxisAngleRotation3D AxisAR3D
AxisAR3D = Create System.Windows.Media.Media3D.AxisAngleRotation3D(lvector3D,1)

System.Windows.Media.Media3D.RotateTransform3D myRotateTransform
myRotateTransform = Create System.Windows.Media.Media3D.RotateTransform3D(AxisAR3D)

myRotateTransform.Rotation.BeginAnimation(System.Windows.Media.Media3D.AxisAngleRotation3D.AngleProperty, myAnimation)

iFile3D.Transform = myRotateTransform

3. Menghentikan Rotate
System.Windows.Media.Media3D.RotateTransform3D myRotateTransform
myRotateTransform = Create System.Windows.Media.Media3D.RotateTransform3D

myRotateTransform.Rotation.Freeze()

iFile3D.Transform = myRotateTransform

4. Converting Warna

string ls_warna

ls_warna = '1'

choose case ls_warna
CASE '1'
ls_warna = '#2F3699'
CASE '2'
ls_warna = '#9DDA4E'
case '3'
ls_warna ='#00B7EF'
case '4'
ls_warna = '#000000'
case '5'
ls_warna = '#ED1C24'
case else
ls_warna = '#FFFFFF'
end choose

System.Windows.Media.BrushConverter lconverter
lconverter = create System.Windows.Media.BrushConverter

System.Windows.Media.Brush lbrush
lbrush = lconverter.ConvertFromString(ls_warna)

4. Menambahkan Object ke Viewport

HelixToolkit.Wpf.SphereVisual3D Sphere3D[1]
Sphere3D[1] = create HelixToolkit.Wpf.SphereVisual3D
Sphere3D[1].Radius = 2
Sphere3D[1].Center = p3
Sphere3D[1].Fill = lbrush
viewport3D.Children.Add(Sphere3D[1])

5. Merubah posisi Camera
System.Windows.Media.Media3D.PerspectiveCamera myPCamera
myPCamera = create System.Windows.Media.Media3D.PerspectiveCamera
myPCamera.NearPlaneDistance = 1
myPCamera.FieldOfView = 61
myPCamera.Position = Create System.Windows.Media.Media3D.Point3D(180,0,0)
myPCamera.LookDirection = Create System.Windows.Media.Media3D.Vector3D(-180,0,0)
myPCamera.UpDirection = create System.Windows.Media.Media3D.Vector3D(0, 0, 9)
viewport3D.Camera = myPCamera

6. Mencapture Viewport ke dalam Picture

System.Windows.Rect rect
rect = create System.Windows.Rect

rect.Height = view_3D.Viewport.ActualHeight
rect.Width  = view_3D.Viewport.ActualWidth

// Scale dimensions from 96 dpi to 600 dpi.
double scale

scale = 600 / 96

integer li_pixelWidth,li_pixelHeight

li_pixelWidth = integer(scale * (rect.Width + 1))
li_pixelHeight= integer(scale * (rect.Height + 1))

System.Windows.Media.Imaging.RenderTargetBitmap renderbitmap
renderbitmap = create System.Windows.Media.Imaging.RenderTargetBitmap(li_pixelWidth,li_pixelHeight,scale * 96,scale * 96, System.Windows.Media.PixelFormats.Default)
 
renderbitmap.Render(viewport3D)
 
    // set ke picture

p_1.Source = renderbitmap

//Jika ingin save ke File sekalian buat directorynya

string l_directori

l_directori = "C:\Temp_image\"

if System.IO.Directory.Exists(l_directori) then
l_directori = "C:\Temp_image\"
else
System.IO.Directory.CreateDirectory(l_directori)
end if

System.Windows.Media.Imaging.PngBitmapEncoder image
image = create System.Windows.Media.Imaging.PngBitmapEncoder

image.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(renderbitmap))

System.IO.Stream fs
fs = System.IO.File.Create(l_directori+"NamaFile.png")
image.Save(fs)


7. Save Viewport3D ke File
System.Windows.Controls.PrintDialog dlg
dlg  = create System.Windows.Controls.PrintDialog

if dlg.ShowDialog().GetValueOrDefault() = true then
dlg.PrintVisual(viewport3D.Viewport,"TEST")
end if