gambas

Aku tidak akan diskon Gambas atau ScriptBasic hanya karena mereka penerjemah. Keduanya ditulis dalam C dan sangat cepat dan extensible. Aku menulis utilitas untuk menghapus foto-foto lama dari pencarian real estat yang saya host di PowerBASIC dan diperlukan untuk memindahkan operasi untuk server Linux. Aku menulis ulang program dalam ScriptBasic dan selesai dalam satu menit versi PB dikompilasi saya. Sebelum memberikan Gambas jempol ke bawah, saya akan memberikan spin dan kemudian memberitahu saya apa yang Anda pikirkan. VB sekarang bebas (VS2005 / VS2008) dan Windows dibanjiri wantabe (Delphi, PowerBASIC konversi proyek, …) bahasa. Saya kira ada kesempatan besar untuk aplikasi bisnis di Linux dan saya berencana untuk mengisi beberapa dari mereka niche dengan solusi asli Linux. (Gambas & ScriptBasic) john Berikut adalah salah satu contoh database di Gambas.

berikut scripnya:

' Gambas class file

PRIVATE $hConn AS Connection

PUBLIC SUB btnConnect_Click()

  DIM sName AS String
  DIM hTable AS Table

  TRY $hConn.Close
  '$hConn = NEW Connection

  sName = txtName.Text

  WITH $hConn
    .Type = cmbType.Text
    .Host = txtHost.Text
    .Login = txtUser.Text
    .Password = txtPassword.Text
    .Name = ""
  END WITH

  IF chkCreate.Value THEN

    $hConn.Open
    IF NOT $hConn.Databases.Exist(sName) THEN
      $hConn.Databases.Add(sName)
    ENDIF
    $hConn.Close

  ENDIF

  $hConn.Name = sName
  $hConn.Open

  'FOR EACH hTable IN $hConn.Tables
  '  PRINT hTable.Type
  'NEXT

  frmDatabase.Enabled = TRUE
  frmRequest.Enabled = TRUE

CATCH

  Message.Error(DConv(Error.Text))

END

PUBLIC SUB btnCreate_Click()

  DIM hTable AS Table

  hTable = $hConn.Tables.Add("test")

  hTable.Fields.Add("id", db.Long)
  hTable.Fields.Add("color", db.Integer,, 1)
  hTable.Fields.Add("firstname", gb.String, 16)
  hTable.Fields.Add("name", gb.String, 32)
  hTable.Fields.Add("birth", gb.Date)
  hTable.Fields.Add("active", gb.Boolean)
  hTable.Fields.Add("salary", gb.Float)
  hTable.Fields.Add("comment", gb.String)

  hTable.PrimaryKey = ["id"]

  hTable.Update

  hTable = $hConn.Tables.Add("color")

  hTable.Fields.Add("color", db.Serial)
  hTable.Fields.Add("name", gb.String, 32)
  hTable.Fields.Add("french", gb.String, 32)

  hTable.PrimaryKey = ["color"]

  hTable.Update

CATCH

  Message.Error(DConv(Error.Text))

END

PUBLIC SUB btnDelete_Click()

  TRY $hConn.Tables.Remove("test")
  TRY $hConn.Tables.Remove("color")

END

PUBLIC SUB btnFill_Click()

  DIM iInd AS Integer
  DIM rTest AS Result
  DIM rColor AS Result
  DIM sColor AS String
  DIM aName AS String[] = ["Paul", "Pierre", "Jacques", "Antoine", "Mathieu", "Robert", "Stéphane", "Yannick", "Frédéric"]
  DIM aFrench AS String[] = ["Noir", "Blanc", "Rouge", "Vert", "Bleu", "Jaune", "Transparent"]
  INC Application.Busy

  $hConn.Begin

  rColor = $hConn.Create("color")

  FOR EACH sColor IN ["Black", "White", "Red", "Green", "Blue", "Yellow", "Transparent"]

    rColor!name = sColor
    rColor!french = aFrench[iInd]
    INC iInd
    rColor.Update

  NEXT

  rTest = $hConn.Create("test")

  FOR iInd = 1 TO txtCount.Value

    rTest!id = iInd
    rTest!color = Int(Rnd(6)) + 1
    rTest!firstname = aName[Int(Rnd(aName.Count))]
    rTest!name = "Name #" & iInd
    rTest!birth = CDate("01/01/1970") + Int(Rnd(10000))
    rTest!active = Int(Rnd(2))
    rTest!salary = Round(Rnd(1000, 10000), -2)

    rTest.Update

  NEXT

  $hConn.Commit

FINALLY

  DEC Application.Busy

CATCH

  $hConn.Rollback
  Message.Error(DConv(Error.Text))

END

PUBLIC SUB btnRun_Click()

  DIM rData AS Result
  DIM hForm AS FRequest

  rData = $hConn.Exec(txtRequest.Text)
  hForm = NEW FRequest($hConn, rData)
  hForm.Show

CATCH

  Message.Error(DConv(Error.Text))

END

PUBLIC SUB Form_Open()

  $hConn = NEW Connection

END

PUBLIC SUB Form_Close()

  $hConn.Close

END

PUBLIC SUB chkDebug_Click()

  DB.Debug = chkDebug.Value

END

PUBLIC SUB btnTest_Click()

  FTest.Show

END

This slideshow requires JavaScript.

' Gambas class file

PRIVATE $hConn AS Connection
PRIVATE $rData AS Result
fine AS Boolean
cur AS Integer


PUBLIC SUB _new(hConn AS Connection, rData AS Result)

  $hConn = hConn
  $rData = rData

  RefreshTitle

  ReadData

  ME.Move(Int(Rnd(Desktop.W - ME.W)), Int(Rnd(Desktop.H - ME.H)))

END


PRIVATE SUB RefreshTitle()

  DIM sTitle AS String

  sTitle = ("SQL request") & " - " & $hConn.Name

  ME.Title = sTitle

END


PRIVATE SUB ReadData()

  DIM hTable AS Table
  DIM hField AS ResultField
  DIM sField AS String
  DIM iInd AS Integer
  DIM iLen AS Integer

  INC Application.Busy

  tbvData.Rows.Count = 0

  tbvData.Columns.Count = $rData.Fields.Count

  FOR EACH hField IN $rData.Fields

    WITH hField

      'PRINT .Name; ": "; .Type; " "; .Length

      tbvData.Columns[iInd].Text = .Name
      tbvData.Columns[iInd].Width = WidthFromType(tbvData, .Type, .Length, .Name)

    END WITH

    INC iInd
  NEXT
' ODBC Changes
  IF $rData.Count = -1 THEN
    tbvData.Rows.Count = rowcount()
'      $rData.Count

  ELSE
  tbvData.Rows.Count = $rData.Count
  ENDIF

FINALLY

  DEC Application.Busy

CATCH

  Message.Error("Cannot exec request." & "\n\n" & DConv(Error.Text))

END


PUBLIC SUB tbvData_Data(Row AS Integer, Column AS Integer)

  $rData.MoveTo(Row)

  tbvData.Data.Text = Str($rData[tbvData.Columns[Column].Text])
  tbvData.Data.Background = Color.RGB((Row MOD 31) * 8, (Row MOD 17) * 15, (Row MOD 13) * 21)
  tbvData.Data.Foreground = Color.White

END


PRIVATE FUNCTION WidthFromType(hCtrl AS control, iType AS Integer, iLength AS Integer, sTitle AS String) AS Integer

  DIM iWidth AS Integer

  SELECT CASE iType

    CASE gb.Boolean
      iWidth = hCtrl.Font.Width(Str(FALSE)) + 32

    CASE gb.Integer
      iWidth = hCtrl.Font.Width("1234567890") + 16

    CASE gb.Long
      iWidth = hCtrl.Font.Width("12345678901234567890") + 16

    CASE gb.Float
      iWidth = hCtrl.Font.Width(CStr(Pi) & "E+999") + 16

    CASE gb.Date
      iWidth = hCtrl.Font.Width(Str(Now)) + 16

    CASE gb.String
      IF iLength = 0 THEN iLength = 255
      iLength = Min(32, iLength)
      iWidth = hCtrl.Font.Width("X") * iLength + 16

  END SELECT

  iWidth = Max(iWidth, hCtrl.Font.Width(sTitle) + 8)

  RETURN iWidth

END

PRIVATE FUNCTION rowcount() AS Integer

  DIM rows AS Integer

  rows = 0
  DO
    $rData.MoveTo(rows)
   INC rows
  LOOP

CATCH

  RETURN rows

END
jkdsf
' Gambas class file

'PRIVATE $hConn AS NEW Connection

PUBLIC SUB Form_Open()

  WITH DataBrowser2.GridView
    .Columns[0].Text = "Color"
  END WITH

  WITH DataBrowser1.GridView
    .Columns[0].Text = "Id"
    .Columns[0].Width = 48
    .Columns[1].Text = "Active"
    .Columns[2].Text = "Name"
  END WITH

END

PUBLIC SUB DataControl6_Validate(Value AS Variant)

  IF IsNull(Value) THEN RETURN
  IF Value < 0 OR Value > 10000 THEN
    STOP EVENT
  ENDIF

END

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s