Main()
Local cProvider,xSource,xPassword
Public oCN
xPROVIDER := "Microsoft.Jet.OLEDB.4.0"
xSOURCE := cDEFA+"\Billing.mdb"
xPASSWORD := "password"
xDatabase := "A" // access "S" for Sql Server
IF xDATABASE = "A"
oCN := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Jet OLEDB:Database Password='+xPASSWORD
ELSE
oCn := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD
ENDIF
// global connection string
oCn := CREATEOBJECT( "ADODB.Connection" )
TRY
oCn:Open( xString )
CATCH oErr
lOk := .f.
END TRY
....
....
...
....
...
// your program menu and code
// end main
#INCLUDE "XBROWSE.CH"
//----------------------------
FUNCTION _ItBrow( oWnd )
LOCAL SAYING,oRsType,oErr,cSQL
LOCAL oICO,oBTN1,oBTN2,oBTN3,oBTN4,oBTN5
LOCAL cTITLE,oLBX,oDLG,oWndChild,cDEFA
Local lOk,oCol
lOK := .F.
cDEFA := SET(7)
oRsType := TOleAuto():New( "ADODB.Recordset" )
oRsType:CursorType := 1 // opendkeyset
oRsType:CursorLocation := 3 // local cache
oRsType:LockType := 3 // lockoportunistic
cSql := "Select * From [InvoiceType] "
cSql += "Order by [InvoiceType]"
TRY
oRsType:Open( cSQL,oCn )
CATCH oErr
MsgInfo( "Error in Opening INVOICETYPE table" )
RETURN(.F.)
END TRY
cTITLE := "Invoice Type Information"
DEFINE ICON oICO RESOURCE "CROWN"
DEFINE WINDOW oWndChild ;
MDICHILD ;
FROM 0,1 to 27,47 ;
NOMINIMIZE ;
ICON oICO ;
OF oWnd ;
TITLE cTitle
DEFINE DIALOG oDlg RESOURCE "ITBROW" of oWndChild
REDEFINE xBROWSE oLBX ;
RECORDSET oRsType ;
COLUMNS "INVOICETYPE" ;
COLSIZES 150 ;
HEADERS "Invoice Type" ;
ID 111 of oDlg ;
AUTOSORT AUTOCOLS LINES CELL
* oLbx:nMarqueeStyle := MARQSTYLE_HIGHLROW
oLbx:lRecordSelector := .f.
oLbx:lHScroll := .f. // turn off horiz scroll bar
// yesno checkbox
ADD oCol to oLbx at 2 HEADER 'Letter' size 60 //60
oLbx:aCols[ 2 ]:addbmpfile( "off" )
oLbx:aCols[ 2 ]:addbmpfile( "on" )
oLbx:aCols[ 2 ]:bBmpData := { | lValue | If(oRsType:eof, ,If( (empty(oRsType:Fields("Letter"):Value) .or.;
oRsType:Fields("Letter"):Value = " "), 1, 2 )) }
oLbx:aCols[ 2 ]:lBtnTransparent := .t.
oLbx:aCols[ 2 ]:nHeadStrAlign := AL_CENTER
_BrowColor( oLbx )
* oLbx:aCols[4]:nDataStrAlign := AL_RIGHT
* oLbx:aCols[4]:nHeadStrAlign := AL_RIGHT
oLbx:bLDblClick := { |nRow,nCol | _ITView( "V",oRsType,oBtn1,oBtn2,oBtn3,oBtn4,oBtn5 ),oLbx:SetFocus() }
REDEFINE BTNBMP oBTN1 ID 113 ;
RESOURCE "ADD16","DADD16","DADD16" ;
PROMPT "&Add" LEFT 2007;
ACTION ( _ITView("A",oRsType,oBtn1,oBtn2,oBtn3,oBtn4,oBtn5 ),; // add
oLBX:ReFresh(),( oLbx:SetFocus(), .F. ) )
REDEFINE BTNBMP oBTN2 ID 114 ;
RESOURCE "EDIT16","DEDIT16","DEDIT16" ;
PROMPT "&Edit" LEFT 2007;
ACTION ( _ITView("E",oRsType,oBtn1,oBtn2,oBtn3,oBtn4,oBtn5 ),; // edit
oLBX:ReFresh(), (oLbx:SetFocus(),.f.) )
REDEFINE BTNBMP oBTN3 ID 115 ;
RESOURCE "VIEW16","DVIEW16","DVIEW16" ;
PROMPT "&View" LEFT 2007;
ACTION ( _ITView("V",oRsType,oBtn1,oBtn2,oBtn3,oBtn4,oBtn5 ),; // edit
oLBX:ReFresh(), oLbx:SetFocus() )
REDEFINE BTNBMP oBTN4 ID 116 ;
RESOURCE "DELETE16","DDELETE16","DDELETE16" ;
PROMPT "&Delete" LEFT 2007;
ACTION ( ITDel( oRsType,oLbx ), ;
oLBX:ReFresh(),( oLbx:SetFocus(), .F. ) )
REDEFINE BTNBMP oBTN5 ID 112 ;
RESOURCE "CANCEL","DCANCEL","DCANCEL" ;
PROMPT "&Quit" LEFT 2007;
ACTION ( lOK1 := .F., oWndChild:END() )
ACTIVATE DIALOG oDlg NOWAIT ;
VALID (!GETKEYSTATE( 27 )) // do not allow esc key here
ACTIVATE WINDOW oWndChild ;
ON INIT ( oDlg:Move( 0,0, oWndchild:nWidth, oWndchild:nHeight, .T. ),oLbx:SetFocus(), ;
oWndChild:bResized := {|| _ReSizeUm( oDlg,oWndChild,oLbx) }, ;
oDlg:refresh(.t.),oLbx:SetFocus());
VALID ( IIF( !lOK, ExitPgm(.T., oRsType,oWndChild,@lOk ), .F. ))
RETURN( .T. )
//------------------------------
Static Func _ReSizeUm( oDlg,oWndChild,oLbx )
oDlg:SetSize( oWndChild:nWidth, oWndChild:nHeight, .t. ) // frame and dialog link
// dialog controls
oDlg:bResized = { | nSizeType, nWidth, nHeight | ResizeControls( nSizeType, nWidth, nHeight, oDlg ) }
oLbx:SetFocus()
Return(nil)
//-------------------------
Static Func ResizeControls( nSizeType, nWidth, nHeight, oDlg )
*xBrowse(oDlg:aControls)
if nSizeType = 0 //SIZE_MAXIMIZED
// 100 100
oDlg:aControls[ 1 ]:SetSize( nWidth - 140, nHeight - 68 ) //txbrowse
endif
Return(nil)
//-----------------------
Static FUNCTION ExitPgm( lCLEAN , oRsType, oWndchild,lOk )
LOCAL aDIR, cFILE, cDEFA, lOK1, nNUM
cDEFA := SET(7)
lOK1 := .F.
nNUM := 0
IF lCLEAN = .T.
lOK := .T.
lOK1 := lOK
try
oRsType:CLose()
catch
end try
oWndChild:End()
ENDIF
RETURN( lOK1 )