• Welcome to SQLitening Support Forum.
 

News:

Welcome to the SQLitening support forums!

Main Menu

SQLitening and MLG

Started by Fredrick Ughimi, May 21, 2011, 10:35:02 AM

Previous topic - Next topic

Fredrick Ughimi

Hello,

Is there any one using SQLitening with MLG? I am thinking of changing from Listview to MLG. I don't even know if I should.

Wonder what advantage(s) MLG has over Listview.

I would appreciate your contributions.

Kind regards,
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

I am considering switching from using a multiline textbox to MLG.
Anyone have an example using My Little Grid?
It looks like a perfect combination with slSelAry.

Fredrick Ughimi

Here...


#PBFORMS CREATED V1.51
#COMPILE EXE
#DIM ALL

#PBFORMS BEGIN INCLUDES
#IF NOT %DEF(%WINAPI)
    #INCLUDE "WIN32API.INC"
#ENDIF
#PBFORMS END INCLUDES

#PBFORMS BEGIN CONSTANTS
%IDC_GRID1   = 1001
%IDD_DIALOG1 =  101
#PBFORMS END CONSTANTS

DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
#PBFORMS DECLARATIONS

#INCLUDE "MLG_DLLPB.INC"

FUNCTION PBMAIN()
    ShowDIALOG1 %HWND_DESKTOP
END FUNCTION

CALLBACK FUNCTION ShowDIALOG1Proc()

    SELECT CASE AS LONG CBMSG
        CASE %WM_INITDIALOG

        CASE %WM_NCACTIVATE
            STATIC hWndSaveFocus AS DWORD
            IF ISFALSE CBWPARAM THEN
                hWndSaveFocus = GetFocus()
            ELSEIF hWndSaveFocus THEN
                SetFocus(hWndSaveFocus)
                hWndSaveFocus = 0
            END IF

        CASE %WM_COMMAND
            SELECT CASE AS LONG CBCTL
                 CASE 101
                 DIM s(5,5) AS STRING
                 DIM hGrid AS DWORD
                 CONTROL HANDLE CBHNDL, %IDC_GRID1 TO hGrid
                 MLG_GetEx hGrid,BYREF s()
                 MSGBOX s(1,1)
            END SELECT
    END SELECT
END FUNCTION

FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    LOCAL lRslt AS LONG
    LOCAL grid1 AS LONG


#PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
    LOCAL hDlg  AS DWORD

    DIALOG NEW hParent, "MLG Test", 70, 70, 301, 121, %WS_POPUP OR %WS_BORDER _
        OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR _
        %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
        %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
        %WS_EX_RIGHTSCROLLBAR, TO hDlg
    CONTROL ADD "MYLITTLEGRID", hDlg, %IDC_GRID1, "r7/c4", 15, 10, 155, _
        100, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER, %WS_EX_LEFT OR _
        %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR

   CONTROL ADD BUTTON ,hDlg, 101, "Test", 230, 70, 40, 20

#PBFORMS END DIALOG

CONTROL HANDLE hDlg,%IDC_GRID1 TO grid1

LOCAL MyHeaderFont,MyFontSize AS LONG

myfontsize =14

MyHeaderFont = CreateFont(0 - myfontsize, 0, 0, 0, %FW_NORMAL, 0, 0, 0, _
                       %ANSI_CHARSET, %OUT_TT_PRECIS, %CLIP_DEFAULT_PRECIS, _
                       %DEFAULT_QUALITY, %FF_SWISS, "Arial")



MLG_Put(grid1,1,1,"Fredrick",0)



    DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt

#PBFORMS BEGIN CLEANUP %IDD_DIALOG1
#PBFORMS END CLEANUP

    FUNCTION = lRslt
END FUNCTION
                               
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

#3
SlSelAry is in col,row order while mlg expects row,col order arrays.
Might  add a function slSelAry2 to reverse the order.
In this demo sArray is copied to sArray2 and sent to the grid

#PBFORMS CREATED V2.01
#COMPILE EXE
#DIM ALL
GLOBAL global_hDlg,global_hgrid1 AS DWORD

#PBFORMS BEGIN INCLUDES
%USEMACROS = 1
#INCLUDE ONCE "WIN32API.INC"

#PBFORMS END INCLUDES

#PBFORMS BEGIN CONSTANTS
%IDC_GRID1   = 1001
%IDD_DIALOG1 =  101
%Button1     =  102
#PBFORMS END CONSTANTS

#PBFORMS DECLARATIONS

#INCLUDE "SQLITENING.INC"
#INCLUDE "MLG.INC"

FUNCTION PBMAIN()
  ShowDIALOG1 %HWND_DESKTOP
END FUNCTION

CALLBACK FUNCTION ShowDIALOG1Proc()

  SELECT CASE AS LONG CB.MSG

     CASE %WM_INITDIALOG
      FillGrid
     CASE %WM_NCACTIVATE
        STATIC hWndSaveFocus AS DWORD
        IF ISFALSE CB.WPARAM THEN
          hWndSaveFocus = GetFocus()
        ELSEIF hWndSaveFocus THEN
          SetFocus(hWndSaveFocus)
          hWndSaveFocus = 0
         END IF

    CASE %WM_COMMAND
      SELECT CASE AS LONG CB.CTL
        CASE %IDC_GRID1
        CASE %BUTTON1
          IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
            FillGrid
          END IF
      END SELECT

    CASE %WM_SIZE
      DIALOG SEND CB.HNDL, %WM_SETREDRAW, 0,0 'prevent flickering
      LOCAL TheWidth,TheHeight AS LONG
      DIALOG GET SIZE CB.HNDL TO TheWidth,TheHeight
      CONTROL SET SIZE CB.HNDL,%IDC_GRID1, TheWidth -10,TheHeight * .5
      CONTROL SET LOC CB.HNDL, %BUTTON1, 0,TheHeight-50
      DIALOG SEND CB.HNDL, %WM_SETREDRAW, 1,0 'prevent flickering
      DIALOG REDRAW CB.HNDL
  END SELECT
END FUNCTION

FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    LOCAL lRslt AS LONG
    LOCAL grid1 AS LONG

#PBFORMS BEGIN DIALOG %IDD_DIALOG1->->
  LOCAL hDlg  AS DWORD

  DIALOG NEW hParent, "MLG Test", 69, 147, 600, 180, %WS_POPUP OR %WS_BORDER _
    OR %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
    %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_CLIPSIBLINGS OR _
    %WS_CLIPCHILDREN OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _
    %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _
    %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
  CONTROL ADD "MYLITTLEGRID", hDlg, %IDC_GRID1, "r5/c5", 0, 10, 570, 100, _
    %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER, %WS_EX_LEFT OR %WS_EX_LTRREADING _
    OR %WS_EX_RIGHTSCROLLBAR
  CONTROL ADD BUTTON, hDlg, %Button1, "Test", 555, 155, 40, 20
#PBFORMS END DIALOG
  global_hDlg = hDlg
  CONTROL HANDLE global_hDlg, %IDC_GRID1 TO global_hGrid1
  DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
#PBFORMS BEGIN CLEANUP %IDD_DIALOG1
#PBFORMS END CLEANUP
    FUNCTION = lRslt
END FUNCTION

SUB FillGrid
  LOCAL cols,rows,op,refresh,x,ROW,COL AS LONG
  DIM sArray() AS STRING
  op = 1
  refresh = 0
  slOpen "sample.db3","C"
  slSelAry "select rowid,* from parts",sArray()
  cols = UBOUND(sArray(1))
  rows = UBOUND(sArray(2))
  IF cols < 0 THEN BEEP:EXIT SUB

  DIM sArray2(rows,cols) AS STRING     'move data to another array
  FOR ROW = 0 TO rows
    FOR COL = 1 TO cols
     sArray2(ROW,COL) = sArray(COL,ROW)
    NEXT
  NEXT
  MLG_ArrayRedim global_hGrid1,rows,cols,rows,cols
MLG_PutEx global_hGrid1,sArray2(),op,refresh
  FOR x = 1 TO cols
    MLG_SetColMaxLen global_hGrid1, x
  NEXT
END SUB

Fredrick Ughimi

Hello CJ,

Very nice demo. I haven't gotten around using MLG and SQLitening for my real applications. I still use Listview. It would be a nice idea to start using MLG. MLG is growing by the day with features added and maintained by James Klutho. Let us know how you progress.

We might ask James Klutho to chip in one or two ideas here.

Best regards,
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

James Klutho

MLG_PutEx global_hGrid1,sArray2(),refresh,1    'refresh must be 1

needs to be

MLG_PutEx global_hGrid1,sArray2(),op,refresh    'op needs to be 1 for your needs


Jim

cj

#6
Thank you James!
Sure makes filling a grid easy.
Modified my code above.

Added this note later:
%WS_CLIPCHILDREN when creating dialog may dramatically reduce flicker.  Not a MLG issue.

Fredrick Ughimi

Thank you James for popping in.  :)
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

Hello,

Its pretty straight forward saving records from MLG to SQLitening using MLG_Get:


sUsername = MLG_Get(hUsersGrid, 1, 1)
sPassword = MLG_Get(hUsersGrid, 1, 2)
sStatus = MLG_Get(hUsersGrid, 1, 3)

slExe "Begin"
    Errorcode& = slExe(slBuildInsertOrUpdate("tblUsers", sUsername & $Nul & sPassword & $Nul & sStatus),"E")
slExe "End"
   
If Errorcode& = 19 Then
     MsgBox "Username Already Exists ", %MB_TASKMODAL Or %MB_ICONINFORMATION, VD_App.Title 
     Exit Function
End If

? "Record Saved!", %MB_TASKMODAL Or %MB_ICONINFORMATION, VD_App.Title



Is there an example some where using MLG_GetEx to save multiple records at once?

Best regards.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet


Fredrick Ughimi

Hello,

I posted this question on Powerbasic yesterday, but I can't seems to connect to the Powerbasic website this morning.

How can I read SQLitening Field into the MLG column formatted as Combobox?

Psedo:


slSelAry "SELECT Name FROM tblChartOfAccounts LIMIT 10", a(), "Q9"
MLG_FormatColCombo hGrid,2, a()
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

Hello Mike,

Here, I am trying to get multiple rows from MLG and saving it into SQLitening:


Dim sUsersArray() As String
MLG_GetEx hUsersGrid, sUsersArray()   
Local cols,rows,refresh,x,ROW,COL As Long
Dim sUsersArray2(rows,cols) As String     'move data to another array
  For ROW = 0 To rows
    For COL = 1 To cols
     sUsersArray2(ROW,COL) = sUsersArray(COL,ROW)
    Next
  Next   
slExeBind "Insert into tblUsers values(?" + Repeat$(2, ",?" ) + ")", Join$( sUsersArray2( ), "" ), "V3"   


I get error -19 invalid string or request. Wonder what I have done wrong here.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

Hello,

As per the MLG ComboBox. This snippet really worked for placing items in the Combobox. Thanks Mike.


slSelAry "select Status from tblUsers",sUsersArray(),"Q9c"
sUsers = JOIN$(sUsersArray(),",")
mlg_FormatColCombo hGrid,3,sUsers ' Column 3 only


See Post #25 of http://www.powerbasic.com/support/pbforums/showthread.php?t=59781&page=2
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Mike Doty

#13
http://www.powerbasic.com/support/pbforums/showthread.php?t=59781

FUNCTION PBMAIN() AS LONG  'mlg4.bas
  LOCAL hDlg,hGrid,r,c,rows,cols AS LONG
  LOCAL sb AS ISTRINGBUILDERA
  LOCAL RowStart,RowEnd,ColStart,ColEnd AS LONG
  LOCAL RowsCols(),sResult() AS STRING
  sb = CLASS "StringBuilderA"
'------------------------------------------------------------------------------
  DIALOG NEW 0, "MLG4",,, 520, 370, %WS_SYSMENU OR %WS_THICKFRAME TO hDlg
  CONTROL ADD "MYLITTLEGRID",hDlg,%GridID,"",0,0,520,370,%MLG_STYLE OR %WS_TABSTOP
  CONTROL HANDLE hDlg,%GridID TO hGrid
  DIALOG SHOW MODELESS hDlg
'------------------------------------------------------------------------------
  rows = 20
  cols  =5
  DIM RowsCols(1 TO rows,1 TO cols) AS STRING 'create sample data array
  FOR r = 1 TO rows
    FOR c = 1 TO cols
      RowsCols(r,c) = USING$("r#c#",r,c)
    NEXT
  NEXT
  Mlg_PutEx hGrid,RowsCols(),-4,1             'put array to MLG
'------------------------------------------------------------------------------
  RowStart=6    'select first row from mlg
  RowEnd=10     'select last  row from mlg
  ColStart=1    'need entire record
  ColEnd=cols
  REDIM FromGrid(RowStart TO RowEnd,ColStart TO ColEnd) AS STRING 'dim array
  MLG_GETEx hGrid,FromGrid()                                      'fill array
  FOR r = RowStart TO RowEnd
    FOR c = colStart TO colEnd
      sb.add slbuildbindDat(FromGrid(r,c),"T") 'be sure to bind as text
    NEXT
  NEXT
'------------------------------------------------------------------------------
  slOpen "sample.db3","C"
  slexe  "drop table if exists t1"
  slexe  "create table if not exists t1(c1,c2,c3,c4,c5)"
  slexe "begin exclusive"
  slexebind "insert into t1 values(?,?,?,?,?)",sb.string,"V" + FORMAT$(cols)
  slexe "end"
  slSelAry "select rowid,* from t1",sResult(),"Q9"
  ? JOIN$(sResult(),$CR),,USING$("Inserted rows # to #",RowStart,RowEnd)
END FUNCTION

Mike Doty

If no valid modchar is passed to slBuildBindDat the default is binary.
Need to look into this more because SQlitening will read the columns, but others may not.
Simple solution is to pass "T", "TN", "TC" or "TNC"  when working with text, encrypted/compressed or both.
sb.add slbuildbindDat(FromGrid(r,c),"T") 'be sure to bind as text

Archive site showing when  PowerBASIC forum is reported to be down.
http://www.garybeene.com/powerbasic/