Hola a todos
Necesito hacer operaciones con fechas en ADO, búsqueda blanda (tipo SoftSeek), fitros de un campo y dos fechas, etc.
Alguno de ustedes podría tirarme un cable?
Les quedaría muy agradecido
Local cSql2 := "SELECT FECHA,FACTURA,CODIGO,NOMBRE,VENCTO,IMPORTE, FROM VENCTOS WERE VENCTO BETWEEN "+Dtoc(dInicio)+" AND "+Dtoc(dFinal)
Local dFIni := "#"+PADL(Month(dInicio),2,"0")+"/"+PADL(Day(dInicio),2,"0")+"/"+STR(YEAR(dInicio))+"#"
Local dFEnd := "#"+PADL(Month(dFinal),2,"0")+"/"+PADL(Day(dFinal),2,"0")+"/"+STR(YEAR(dFinal))+"#"
Local cSql1 := "SELECT FECHA,FACTURA,CODIGO,NOMBRE,VENCTO,IMPORTE FROM VENCTOS WERE VENCTO BETWEEN '"+dFIni+"'"+" AND '"+dFEnd+"'"+" ORDER BY VENCTO"
Local cSql2,dFIni,dFEnd
// make sure century is on ( in your main startup )
// SET Century On
// added ctod() to match dtoc() in query
dFIni := ctod(PADL(Month(dInicio),2,"0")+"/"+PADL(Day(dInicio),2,"0")+"/"+STR(YEAR(dInicio,4)) )
dFEnd := ctod(PADL(Month(dFinal),2,"0")+"/"+PADL(Day(dFinal),2,"0")+"/"+STR(YEAR(dFinal,4)) )
// verify dates look correct
MsgInfo( dFIni )
MsgInfo( dFEnd )
cSql2 := "SELECT FECHA,FACTURA,CODIGO,NOMBRE,VENCTO,IMPORTE "
cSql2 += "FROM VENCTOS WERE VENCTO "
cSql2 += "BETWEEN #"+Dtoc(dFIni)+"# AND #"+Dtoc(dFEnd)+"#"
//--------------------------
Function TtoDate( tDate )
If empty( tDate)
Return( ctod("00/00/00"))
Endif
If ValType( tDate ) = "D"
Return(tDate )
Endif
Return( stod( substr( ttos( tDate ), 1, 8 ) ))
cQuery := "SELECT FECHA,FACTURA,CODIGO,NOMBRE,VENCTO,IMPORTE, FROM VENCTOS WERE VENCTO >= '"+DtoS( dInicio )+"' AND VENCTO <= '"+DtoS( dFinal ) + "'"
*-------------------------------------------------------------------------------
Function REPLISVTO(nOption,dInicio,dFinal,oRsVctos)
*-------------------------------------------------------------------------------
Local nReg := oRsVctos:BookMark()
Local aVtos := {}
Local dFIni := Ctod(PADL(Month(dInicio),2,"0")+"/"+PADL(Day(dInicio),2,"0")+"/"+STR(YEAR(dInicio)))
Local dFEnd := Ctod(PADL(Month(dFinal),2,"0")+"/"+PADL(Day(dFinal),2,"0")+"/"+STR(YEAR(dFinal)))
Local cSql1
Local cSql2
Local cSql
Local oRsLisVto
cSql1 := "SELECT FECHA,FACTURA,CODIGO,NOMBRE,VENCTO,IMPORTE "
cSql1 += "FROM VENCTOS WERE VENCTO "
cSql1 += "BETWEEN #"+Dtoc(dFIni)+"# AND #"+Dtoc(dFEnd)+"#"
cSql2 := "SELECT FECHA,FACTURA,CODIGO,NOMBRE,VENCTO,IMPORTE,FPAGO,TIPOPAGO "
cSql2 += "FROM VENCTOS WERE VENCTO "
cSql2 += "BETWEEN #"+Dtoc(dFIni)+"# AND #"+Dtoc(dFEnd)+"#"
If Dtos(dInicio)> Dtos(dFinal)
MsgStop("Parámetros de fechas incorrectos","ATENCION")
Return nil
EndIf
IIf(nOption== 1, cSql := cSql1, cSql := cSql2)
oRsLisVto := FW_OpenRecordSet(oConex,cSql,3) //<------------(Parametros, oConex = Conexión, cSql = Fuente de datos, 3 = LockType) Esta función está en fwh/source/functions/olefuncs.prg
Msginfo(oRsLisVto) //<-----------------( oRsLisVto --> Nil)
........
select * from facturas where factura.emision between '20130101' AND '20130131'
Function main()
Local oAdoConnector := adoConnector()
Local cQuery := "select * from facturas where factura.emision between '20130101' AND '20130131'"
//memoedit( cQuery ) //para cortar y pegar en el manejador sql
adorecordset( oAdoConnector, cQuery )
Return nil
Function ADOConnector()
Local cStr := "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Port=3306;Database=" + "BASE_DE_DATOS" + ";User=" + "USUARIO" + ";Password=" + "12345"+ ";Option=3;"
Local oReturn := tOleAuto():New("ADODB.connection")
oReturn:ConnectionSTring := cStr
try
oReturn:Open()
catch
oReturn := nil
end try
Return oReturn
Function ADORecordSet( oConnect, cSql, lConnect )
Local oRs
Local cError := "No se ha podido crear el objeto contenedor RECORDSET !"
try
oRs := CreateObject("ADODB.RecordSet")
oRs:CursorLocation := 3
oRs:LockType := 4
oRs:ActiveConnection:= oConnect
oRs:source := cSql
oRs:Open()
lConnect := .t.
catch
//MsgStop( cError + CRLF + CRLF + "Query : " + cSql,"Error de Datos (ADO)" )
msadoerror( cSql, "Error de Conexion con servidor" )
return nil
end try
Return oRS
// Ms Access connection string
// place this in your top Main.prg
// modify xSource to your database name
Local xProvider,xSource,xPassword,cFile,mStart,cDefa
Public xConnect
// where .exe started from is default directory //
cFILE := GetModuleFileName( GetInstance() )
mSTART := RAT( "\", cFILE )
cDEFA := SUBSTR(cFILE,1,mSTART-1)
SET DEFA to ( cDEFA )
xPROVIDER := "Microsoft.Jet.OLEDB.4.0"
xSOURCE := cDEFA+"\Travel.mdb" // ms access table
xPASSWORD := "yourpassword"
xCONNECT := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Jet OLEDB:Database Password='+xPASSWORD
//--
Local oRs,cSql,oErr,dFIni,dFEnd
dFIni := Ctod(PADL(Month(dInicio),2,"0")+"/"+PADL(Day(dInicio),2,"0")+"/"+STR(YEAR(dInicio)))
dFEnd := Ctod(PADL(Month(dFinal),2,"0")+"/"+PADL(Day(dFinal),2,"0")+"/"+STR(YEAR(dFinal)))
//Open the recordset
oRs := TOleAuto():New( "ADODB.Recordset" )
oRs:CursorType := 1 // opendkeyset
oRs:CursorLocation := 3 // local cache
oRs:LockType := 3 // lockoportunistic
cSql := "SELECT FECHA,FACTURA,CODIGO,NOMBRE,VENCTO,IMPORTE "
cSql += "FROM VENCTOS WERE VENCTO "
cSql += "BETWEEN #"+Dtoc(dFIni)+"# AND #"+Dtoc(dFEnd)+"#"
TRY
oRs:Open( cSQL,xCONNECT )
CATCH oErr
MsgInfo( "Error in Opening table" )
RETURN(.f.)
END TRY
xBrowse( oRs )
oRs:CLose()
dDate := date()
cDate1 := "01/01/" + NTOC( str( year( dDate ) - 2, 4, 0 ), 4 )
cDate2 := NTOC( str( month( dDate ), 2, 0 ), 2 ) + "/" + NTOC( str( day( dDate ), 2, 0 ), 2) + "/" + NTOC( str( year( dDate ), 4, 0 ), 4 )
cQuery := "select checkinout.userid, userinfo.name, checkinout.checkTime, checkinout.checktype from checkinout " + CRLF + ;
"left join userinfo on checkinout.userid = userinfo.userid " + CRLF + ;
"where checkinout.checkTime >= #" + cDate1 + "# and checkinout.checkTime <= #" + cDate2 + "# " + CRLF + ;
"order by checkinout.userid, checkinout.checktime"
oDbf := Adorecordset( oApp:oAdoConnector, cQuery )
xbrowse( oDbf )
Function Main()
Local aCorH[2]
Local hDlib
Local oBtnBal1,oBtnBal2,oBtnBal3,oBtnBal4,oBtnBal5
Local oPopBal1,oPopBal2,oPopBal3,oPopBal4,oPopBal5
Public oWMain, oFont,oIcon,oConex
Public cAreaTemp, cArea := "", aDatEmp[0],cTrabajo,aIva[7,3]
...........................................
DEFINE WINDOW oWMain MDI FROM 02, 02 TO ( MaxRow() - 2 ), ( MaxCol() - 10 );
.............................................
ACTIVATE WINDOW oWMain MAXIMIZED ;
ON INIT (EscogeArea(),VerificaConfig()) ; //<-----------------EscogeArea is where you choose the work area
.........................................................
*===============================================================================
function EscogeArea()
*===============================================================================
....................................
DEFINE DIALOG oDlgEmp RESOURCE "INICIO";
COLOR RGB(0,0,0), RGB(153,204,255)
REDEFINE BITMAP oBmp ID 101 OF oDlgEmp ;
FILENAME ".\BMP\LOGO2.BMP" ;
ADJUST;
UPDATE;
TRANSPARENT
REDEFINE BUTTONBMP ID 301 OF oDlgEmp BITMAP "ACEPTAR" TEXTRIGHT;
ACTION lSeguir := PonArea(oDEmpr,oLbx,oDlgEmp)
oLbx := TXBrowse():New(oDlgEmp)
.....................................................
for nFor := 1 to len(aCols)
oLbx:aCols[ nFor ]:blDClickData := {|| (lSeguir := PonArea(oDEmpr,oLbx,oDlgEmp),oLbx:Refresh()) }
oLbx:aCols[ nFor ]:bRClickData := {|| (lSeguir := PonArea(oDEmpr,oLbx,oDlgEmp),oLbx:Refresh()) }
oLbx:aCols[ nFor ]:bRClickHeader := {|r,c,f,o| NIL }
next
.................................................................
//----------------------------------------------------------------------------//
function PonArea(oDEmpr,oLbx,oDlgEmp)
//----------------------------------------------------------------------------//
Local cCarpeta, cEstacion
Local cDir := cArea
Local cSitio,lSeguir
Sysrefresh()
ASIZE(aDatEmp, EMP->( FCOUNT() ) )
AFILL(aDatEmp,.T.)
EMP->( IniCampo(@aDatEmp) )
EMP->( TabCampo(@aDatEmp,0) )
cEstacion := NetName(.t.)
cCarpeta := cDir+"\"+cEstacion
cSitio := cDir+"\"+oDEmpr:Codigo+"\"
cArea := cSitio
cAreaTemp := cCarpeta
cNomArea := oDEmpr:Nombre+" "+Str(oDEmpr:Ejercicio)
cTrabajo := "[ "+oDEmpr:codigo+" "+oDEmpr:nombre+" ]"
oWMain:SetText("Gestión Comercial "+cTrabajo)
oWMain:Refresh()
Set Path to (cArea)
Set Default to (cArea)
cEjercicio := Str(oDEmpr:Ejercicio)
lSeguir := AbreTablas() //<<=========================Here
If lSeguir
CARGAIVA()
EndIf
oLbx:Destroy()
oDlgEmp:End()
Return( lSeguir )
*-------------------------------------------------------------------------------
FUNCTION AbreTABLAS()
*-------------------------------------------------------------------------------
Local cServer := "localhost"
Local cUser := "root"
Local cPass := ""
Local lConecta := .T.
Local cSource := cArea+"Datos.mdb"
* Para aplicaciones en MySQL
* oConex := TOLEAUTO():new("adodb.connection")
* oConex:ConnectionString:="Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=LBRINQUIS;User='root'; Password='';Option=3;"
* TRY
* oConex:Open()
* MSGINFO("CONECTADO")
* CATCH
* MSGSTOP("NO SE CONECTO")
* RETURN NIL
* END
* Para aplicaciones con ACCES
* oConex := TOLEAUTO():NEW("ADODB.connection")
oConex := CREATEOBJECT("ADODB.connection")
oConex:open("Provider= MicroSoft.Jet.OLEDB.4.0;Data Source="+cSource+";")
If Empty(oConex)
MsgAlert(" No se Pudo Establecer la Conexion Con La Base De Datos..","Atencion")
lConecta := .F.
EndIf
If lConecta
* AbreBrochas()
EndIf
Return(lConecta)
Simon wrote:ya lo encontre espero te sirva
- Code: Select all Expand view
dDate := date()
cDate1 := "01/01/" + NTOC( str( year( dDate ) - 2, 4, 0 ), 4 )
cDate2 := NTOC( str( month( dDate ), 2, 0 ), 2 ) + "/" + NTOC( str( day( dDate ), 2, 0 ), 2) + "/" + NTOC( str( year( dDate ), 4, 0 ), 4 )
cQuery := "select checkinout.userid, userinfo.name, checkinout.checkTime, checkinout.checktype from checkinout " + CRLF + ;
"left join userinfo on checkinout.userid = userinfo.userid " + CRLF + ;
"where checkinout.checkTime >= #" + cDate1 + "# and checkinout.checkTime <= #" + cDate2 + "# " + CRLF + ;
"order by checkinout.userid, checkinout.checktime"
oDbf := Adorecordset( oApp:oAdoConnector, cQuery )
xbrowse( oDbf )
en el ejemplo hay 2 tablas una checkinout donde se almacenan los registros de entrada/salida de los trabajadores y userinfo donde se almacena la informacion de los trabajadores en el ejemplo traigo todos los registros de los trabajadores del año en curso hasta la fecha.
Function ADOConnector()
Local cStr := "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Port=3306;Database=" + "BASE_DE_DATOS" + ";User=" + "USUARIO" + ";Password=" + "12345"+ ";Option=3;"
Local oReturn := tOleAuto():New("ADODB.connection")
oReturn:ConnectionSTring := cStr
try
oReturn:Open()
catch
oReturn := nil
end try
Return oReturn
Function ADORecordSet( oConnect, cSql, lConnect )
Local oRs
Local cError := "No se ha podido crear el objeto contenedor RECORDSET !"
try
oRs := CreateObject("ADODB.RecordSet")
oRs:CursorLocation := 3
oRs:LockType := 4
oRs:ActiveConnection:= oConnect
oRs:source := cSql
oRs:Open()
lConnect := .t.
catch
//MsgStop( cError + CRLF + CRLF + "Query : " + cSql,"Error de Datos (ADO)" )
msadoerror( cSql, "Error de Conexion con servidor" )
return nil
end try
Return oRS
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot] and 58 guests