Moderador: Moderadores
* Treatment of ADO Date and DateTime fields/values
XBrowse, TDataRow, TRecSet and function FWAdoStruct( oRs )
In many databases like MSAccess, MSSQL, Oracle only DateTime field type is
avaiable for storing both simple dates and date-time values. Whether a
particular field is to be treated as Date or DateTime field mostly depends
on the usage. Accordingly FWH libraries treat fields containing pure Date
values (without any time-part) as Date fields and fields containing DateTime
values are treated as DateTime fields. While this approach works satisfactorily
in most cases, there could be exceptions and the programmer needs to have
the facility to override the default behavior.
#include "fivewin.ch"
#include "xbrowse.ch"
#include "hbcompat.ch" // required
REQUEST DBFCDX
static cMdb := "tutor01.mdb"
static oCn
//----------------------------------------------------------------------------//
function Main()
SET DELETED ON
SET DATE ITALIAN
SET CENTURY ON
XbrNumFormat( 'A', .t. )
ferase( cmdb )
if .not. File( cMdb )
FW_CreateMDB( cMdb )
endif
CreateTable()
CopyFromDBF()
BrowseTable()
oCn:Close()
return nil
//----------------------------------------------------------------------------//
static function CreateTable()
local cSql, c
oCn := FW_OpenAdoConnection( cMdb )
TRY
oCn:Execute( "DROP TABLE CUSTSMAL" )
CATCH
END
TEXT INTO cSql
CREATE TABLE CUSTSMAL (
ID AUTOINCREMENT PRIMARY KEY,
CUSTNAME VARCHAR( 30 ),
MARRIED BIT,
AGE BYTE,
SALARY MONEY
)
ENDTEXT
oCn:Execute( cSql )
return nil
//----------------------------------------------------------------------------//
static function CopyFromDBF()
local oRs
oRs := FW_OpenRecordSet( oCn, "CUSTSMAL" )
USE CUSTOMER NEW ALIAS CUST SHARED READONLY VIA 'DBFCDX'
do while ! eof() .and. RecNo() < 6
oRs:AddNew( { "CUSTNAME", "MARRIED", "AGE", "SALARY" }, ;
{ Left( Trim( CUST->FIRST ) + ' ' + Trim( CUST->LAST ), 30 ), ;
CUST->MARRIED, CUST->AGE, CUST->SALARY } )
SKIP
enddo
CLOSE CUST
oRs:Close()
return nil
//----------------------------------------------------------------------------//
static function BrowseTable()
local oRs, oBrw, oFont, oDlg
oRs := FW_OpenRecordSet( oCn, "CUSTSMAL" )
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 800,400 PIXEL TITLE "ADO: SAMPLE" FONT oFont
@ 30,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg DATASOURCE oRs ;
AUTOCOLS AUTOSORT ;
PICTURES "999", nil, nil, "99", "9,999,999.99" ;
CELL LINES NOBORDER FASTEDIT
WITH OBJECT oBrw
:nEditTypes := EDIT_GET
:nStretchCol := STRETCHCOL_WIDEST
:Married:SetCheck()
//
:bKeyDown := { |nKey| If( nKey == VK_DELETE, DeleteRow( oBrw ), ;
If( nKey == VK_INSERT, AddEditDlg( oBrw ), nil ) ) }
//
:CreateFromcode()
END
@ 10, 10 BUTTON "Add" SIZE 40,12 PIXEL OF oDlg ACTION AddEditDlg( oBrw, .t. )
@ 10, 55 BUTTON "Edit" SIZE 40,12 PIXEL OF oDlg ACTION AddEditDlg( oBrw )
@ 10,100 BUTTON "Delete" SIZE 40,12 PIXEL OF oDlg ACTION DeleteRow( oBrw )
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
oRs:Close()
return nil
//----------------------------------------------------------------------------//
static function AddEditDlg( oBrw, lAdd )
local oRs := oBrw:oRs
local aFldNames := { "CUSTNAME", "MARRIED", "AGE", "SALARY" }
local aVals
local oDlg, oFont, nRow, lOK := .f.
DEFAULT lAdd := ( oBrw:nLen == 0 )
if lAdd
aVals := { Space( 30 ), .f., 0, 0.00 }
else
aVals := oRs:GetRows( 1, 0, aFldNames )[ 1 ]
oRs:MovePrevious() // IMPORTANT: After Get Rows we need to go back
endif
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 420,210 PIXEL FONT oFont ;
TITLE If( lAdd, "ADD NEW CUSTOMER", "EDIT CUSTOMER" )
nRow := 10
@ nRow+1, 10 SAY "Customer Name : " SIZE 60,10 PIXEL OF oDlg RIGHT
@ nRow, 75 GET aVals[ 1 ] SIZE 115,12 PIXEL OF oDlg VALID ! Empty( aVals[ 1 ] )
nRow += 14
@ nRow+1, 10 SAY "Married : " SIZE 60,10 PIXEL OF oDlg RIGHT
@ nRow, 75 CHECKBOX aVals[ 2 ] PROMPT "" SIZE 12,12 PIXEL OF oDlg
nRow += 14
@ nRow+1, 10 SAY "Age : " SIZE 60,10 PIXEL OF oDlg RIGHT
@ nRow, 75 GET aVals[ 3 ] PICTURE "99" SIZE 30,12 PIXEL OF oDlg RIGHT ;
VALID aVals[ 3 ] > 0
nRow += 14
@ nRow+1, 10 SAY "Salary : " SIZE 60,10 PIXEL OF oDlg RIGHT
@ nRow, 75 GET aVals[ 4 ] PICTURE "9,999,999.99" SIZE 70,12 PIXEL ;
OF oDlg RIGHT VALID aVals[ 4 ] > 0
nRow += 30
@ nRow, 115 BUTTON "Cancel" SIZE 40,12 PIXEL OF oDlg CANCEL ACTION ( lOK := .f., oDlg:End() )
@ nRow, 160 BUTTON "OK" SIZE 40,12 PIXEL OF oDlg ACTION ( lOK := .t., oDlg:End() )
ACTIVATE DIALOG oDlg CENTERED
if lOK
aVals[ 1 ] := AllTrim( aVals[ 1 ] )
TRY
if lAdd
oRs:AddNew( aFldNames, aVals )
else
oRs:Update( aFldNames, aVals )
endif
oBrw:Refresh()
CATCH
oRs:CancelUpdate()
MsgAlert( "Error writing" )
END
oBrw:SetFocus()
endif
return lOk
//----------------------------------------------------------------------------//
static function DeleteRow( oBrw )
local oRs := oBrw:oRs
local nPos
if !( oRs:Eof .or. oRs:Bof )
nPos := oRs:AbsolutePosition
oRs:Delete()
oRs:AbsolutePosition := Max( 1, Min( nPos, oRs:RecordCount() ) )
oBrw:Refresh()
endif
oBrw:SetFocus()
return nil
//----------------------------------------------------------------------------//
sygecom escreveu:1-No xHarbour rodar com MT(Mult theread), hoje tenho contornado com .EXE separado sistema que não é ruim e, até tenho .EXE que roda como serviço no servidor dos clientes.
PROCEDURE Main
PARAMETERS x
IF x = "SEGUNDOEXE"
RotinaSegundoExe()
QUIT
ENDIF
Kapiaba escreveu:Se eu estivesse na Itália, conseguiria, já que lá, a porta 25 está ativa. Aqui o gobierno de mierda desligou a porta 25 e pela outras portas não vai
Usuários vendo este fórum: Nenhum usuário registrado online e 5 visitantes