#include "FiveWin.Ch"
#include "Ado.ch"
#include "FileIO.ch"
#define cBorde NOBORDER
#define nIcono 1
STATIC oWindow
STATIC oError
STATIC aVars := {NIL,NIL,NIL}
#xtranslate aBtns = > aVars\[ 1\]
#xtranslate aMenu = > aVars\[ 2\]
#xtranslate aSubM = > aVars\[ 3\]
MEMVAR oApp
// Para que los acentos se vean bien
REQUEST HB_LANG_ES
REQUEST HB_CODEPAGE_ESWIN
FUNCTION Main()
LOCAL oIcono, oCursor, oCasilla, oBmp , oBrush
LOCAL lStatus := ( .T. )
LOCAL hWnd
SET CENTURY ON
SET DATE TO FRENCH
SET DELETED ON
SET OPTIMIZE ON
SETBALLOON(.T.)
HB_CDPSELECT("ESWIN")
HB_LangSelect( "ESWIN" )
FWSetLanguage( 2 ) // Para poner el PREVIEW en Español
// Para que los acentos se vean bien
SET( _SET_CODEPAGE, "ESWIN" )
SETHELPFILE( "ParCre.Hlp" )
// Para cambiar el color del get con foco
TGet():lClrFocus := (.T.)
TGet():nClrFocus := nRGB( 213, 219, 255 ) // Lila claro
oApp := TAplicacion()
LeeIni() // Lee parametros
hWnd := FindWindow( 0, oApp:cAplicacion + " " + oApp:cVersion + " " + oApp:cServer)
IF hWnd != 0 .AND. ! oApp:lInstancia
ShowWindow( hWnd, 3) //SW_MAXIMIZE=3 SW_NORMAL=1 SW_MINIMIZE=6
QUIT
ENDIF
IF ! Conecta()
QUIT
ENDIF
aBtns := ARRAY(05)
aMenu := ARRAY(10)
aSubM := ARRAY(05)
// LeeEmpresa( )
DEFINE ICON oIcono RESOURCE "AppLogo"
DEFINE BRUSH oBrush COLOR CLR_WHITE
DEFINE WINDOW oWindow MDI FROM 0, 0 TO 22, 75 TITLE oApp:cAplicacion + " " + oApp:cVersion + " " + oApp:cServer;
MENU HazMenu() ICON oIcono BRUSH oBrush PIXEL MENUINFO 8
SET MESSAGE OF oWindow TO oApp:cRazonSocial KEYBOARD CLOCK 2007
IF ! EMPTY( oApp:cUsuario )
DEFINE MSGITEM oCasilla OF oWindow:oMsgBar SIZE 120 ;
PROMPT ALLTRIM( oApp:cUsuario ) COLOR CLR_BLACK, CLR_BLUE
ENDIF
DEFINE MSGITEM oCasilla OF oWindow:oMsgBar ;
SIZE 85 ;
PROMPT Date2Txt( DATE( ) )
DEFINE MSGITEM oCasilla OF oWindow:oMsgBar ;
SIZE 175 ;
PROMPT oApp:cCopyRight
oBmp = TImage():Define(,cFilePath(GetModuleFileName(GetInstance())) + "AppFondo.Jpg")
oWindow:bPainted := {|hDC| PalBmpDraw( hDC, 0, 0,oBmp:hBitmap,, oWindow:nWidth, oWindow:nHeight,, (.T.)) }
ACTIVATE WINDOW oWindow MAXIMIZED VALID Salir() ON INIT (LaBarra(oWindow), oWindow:Refresh())
oIcono:End()
oCasilla:End()
oBmp:End()
oBrush:End()
RETURN(.T.)
/*
* ---------------------------------------------------------------------------- *
*/
STATIC FUNCTION LaBarra( oWindow )
LOCAL oBarra
LOCAL oCursor
DEFINE CURSOR oCursor RESOURCE "Dedo"
DEFINE BUTTONBAR oBarra SIZE 45, 45 OF oWindow CURSOR oCursor 2007
oBarra:bClrGrad = { | lInvert | If( ! lInvert,;
{ { 0.25, nRGB( 068, 097, 176 ), nRGB( 068, 097, 176 ) },;
{ 0.75, nRGB( 068, 097, 176 ), nRGB( 068, 097, 176 ) } },;
{ { 0.25, nRGB( 255, 255, 255 ), nRGB( 255, 255, 255 ) },;
{ 0.75, nRGB( 255, 255, 255 ), nRGB( 255, 255, 255 ) } } ) }
oBarra:nClrText = { | lInvert | IF( ! lInvert, nRGB( 235, 160, 86 ), nRGB( 20, 20, 20 ) ) }
* ------------------------------------------------------------------------- *
DEFINE BUTTON aBtns[01] OF oBarra RESOURCE "Brw32" cBorde ;
ACTION Test(oWindow )
aBtns[01] :cToolTip := { "Test", "Test button", nIcono, oApp:cClrForTol, oApp:cClrBakTol }
DEFINE BUTTON aBtns[02] OF oBarra RESOURCE "Exi32" cBorde ;
GROUP ;
ACTION oWindow:END( ) ;
MESSAGE "Abandona el programa y retorna a windows"
aBtns[02] :cToolTip := { "Salir", "Exit button", nIcono, oApp:cClrForTol, oApp:cClrBakTol }
RETURN (.T.)
/*
* ---------------------------------------------------------------------------- *
*/
STATIC FUNCTION HazMenu( )
LOCAL oMenu
MENU oMenu 2007
MENUITEM aMenu[01] PROMPT "&Test xBrowse"
MENU
MENUITEM aSubM[01] PROMPT "&Test";
RESOURCE "Brw16" ;
ACTION Test(oWindow )
SEPARATOR
MENUITEM aSubM[02] PROMPT "Salir ALT-F4" ;
RESOURCE "Exi16" ;
ACTION oWindow:END( )
ENDMENU
ENDMENU
RETURN(oMenu)
/*
* ---------------------------------------------------------------------------- *
*/
STATIC FUNCTION Salir( )
IF MsgNoYes( "Seguro desea salir de la aplicación ?", oApp:cAplicacion )
oApp:oCon:Close()
ELSE
RETURN ( .F. )
ENDIF
RETURN ( .T. )
/*
* ---------------------------------------------------------------------------- *
*/
STATIC FUNCTION LeeEmpresa( )
LOCAL oRsEmp, oError
oRsEmp := FW_OpenRecordSet(oApp:oCon,"SELECT " +;
"* " +;
"FROM " +;
"Empresa",adLockOptimistic,adOpenDynamic,0)
IF oRsEmp == nil
MsgStop("No pude abrir la tabla EMPRESA !",oApp:cAplicacion)
FW_ShowAdoError(oApp:oCon)
RETURN(.F.)
ENDIF
IF oRsEmp:BOF( ) .AND. oRsEmp:EOF( )
oApp:cRazonSocial := "Empresa no registrada, s.a. de c.v."
ELSE
oApp:cRazonSocial := oRsEmp:Fields( "EMP_NOM" ) :Value
ENDIF
IF oRsEmp <> NIL
IF oRsEmp:State( ) = adStateOpen
oRsEmp:Close( )
ENDIF
ENDIF
RETURN( .T. )
/*
* ---------------------------------------------------------------------------- *
*/
FUNCTION Alinea( oReporte, Izq, Der, lTitle )
DEFAULT lTitle := ( .T. )
IF lTitle
oReporte:oTitle:aRow[ Izq ] := oReporte:oTitle:aRow[ Der ]
ELSE
oReporte:oHeader:aRow[ Izq ] := oReporte:oHeader:aRow[ Der ]
ENDIF
RETURN ( NIL )
/*
* ---------------------------------------------------------------------------- *
*/
FUNCTION OverFlow( oReporte )
IF ( oReporte:nRow + ( oReporte:nStdLineHeight * 2 ) ) >= oReporte:nBottomRow
oReporte:EndPage( )
oReporte:StartPage( )
ENDIF
RETURN NIL
/*
* ---------------------------------------------------------------------------- *
*/
CLASS TAplicacion
DATA cUsuario INIT ""
DATA cRazonSocial INIT "EMPRESA NO REGISTRADA, S.A. DE C.V."
DATA cAplicacion INIT "© " + STR( YEAR( DATE( ) ), 4, 0 ) + " XBrowse Test"// + SPACE(2) + FWVERSION
DATA cAppAlias INIT "© " + STR( YEAR( DATE( ) ), 4, 0 ) + " ParCre"
DATA cCopyRight INIT "© 2021-" + STR( YEAR( DATE( ) ), 4, 0 ) + " by S.O.I., s.a. de c.v."
DATA cVersion INIT "Versión 1.0M18"
DATA nLineStyle INIT 4
DATA cPath INIT ""
DATA cPathExe INIT cFilePath(GetModuleFileName(GetInstance())) // C:\ParCre\
DATA cCrypt INIT "XrypT2023"
// Estos parámetros son para el servidor de MySql
DATA oCon INIT NIL
DATA oDsn INIT NIL
DATA cDsn INIT NIL
DATA cDescription INIT NIL
DATA cServer INIT NIL
DATA cDBName INIT NIL
DATA cDataBase INIT NIL
DATA cUser INIT NIL
DATA cPass INIT NIL
DATA nPort INIT NIL
DATA cStmt INIT ""
DATA cDriveName INIT ""
DATA nRowsInt INIT 3
// Colores del dialogo
DATA cBrush INIT "Brush"
// Colores de la pijama
DATA nRowNonClr INIT RGB( 255, 255, 255 )
DATA nRowParClr INIT RGB( 238, 246, 255 )
// Colores para encabezados del browse
DATA nHdrForClr INIT RGB( 255, 255, 255 ) // Blanco
DATA nHdrBckClr INIT RGB( 000, 000, 000 ) // Negro
DATA nFClrFocus INIT RGB( 000, 000, 000 ) // Negro
DATA nBClrFocus INIT RGB( 000, 191, 255 ) // Azúl, se ve bien
DATA cClrForTol INIT CLR_WHITE
DATA cClrBakTol INIT CLR_HBLUE
ENDCLASS
/*
* ------------------------------------------------------------------------ *
* ------------------------------------------------------------------------ *
*/
STATIC FUNCTION LeeIni()
LOCAL oIni
INI oIni FILE ".\ParCre.Ini"
GET oApp:cDsn SECTION "MYSQL" ENTRY "Dsn" OF oIni DEFAULT "TestXbrw"
GET oApp:cDescription SECTION "MYSQL" ENTRY "Description" OF oIni DEFAULT "XBrowse Test"
GET oApp:cServer SECTION "MYSQL" ENTRY "Server" OF oIni DEFAULT "localhost"
GET oApp:cDataBase SECTION "MYSQL" ENTRY "DataBase" OF oIni DEFAULT ""
GET oApp:cUser SECTION "MYSQL" ENTRY "User" OF oIni DEFAULT "root"
GET oApp:cPass SECTION "MYSQL" ENTRY "PassWord" OF oIni DEFAULT "91502127"
GET oApp:nPort SECTION "MYSQL" ENTRY "Port" OF oIni DEFAULT 3306
GET oApp:cDriveName SECTION "MYSQL" ENTRY "DriveName" OF oIni DEFAULT "Driver={MySQL ODBC 5.1 Driver}"
GET oApp:cPath SECTION "MYSQL" ENTRY "Path" OF oIni DEFAULT "C:\Program Files\MySQL\MySQL Server 5.1\bin\"
GET oApp:cStmt SECTION "MYSQL" ENTRY "Statement" OF oIni DEFAULT ""
GET oApp:cDBName SECTION "DATABASE" ENTRY "DBName" OF oIni DEFAULT "TestXBrw"
ENDINI
RETURN( NIL )
/*
* ---------------------------------------------------------------------------- *
*/
STATIC FUNCTION Conecta( )
LOCAL oError
TRY
oApp:oCon := TOleAuto( ) :new( "adodb.connection" )
CATCH oError
MsgStop( "No se ha podido crear la conexión al servidor !", oApp:cAplicacion )
RETURN( .F. )
END
oApp:oCon:ConnectionString := ALLTRIM( oApp:cDriveName ) + ;
";Server=" + ALLTRIM( oApp:cServer ) + ;
";Port=" + STR( oApp:nPort ) + ;
";Database=" + ALLTRIM( oApp:cDataBase ) + ;
";User=" + ALLTRIM( oApp:cUser ) + ;
";Password=" + ALLTRIM( oApp:cPass ) + ;
";Option=3;"
oApp:oCon:CommandTimeout := 1800 // 30 Minutos * 60 segundos
oApp:oCon:ConnectionTimeout := 28800 // 8 horas * 360 segundos
TRY
oApp:oCon:Open()
oApp:oCon:Execute( "SET SESSION wait_timeout = 86400;" )
CATCH oError
MsgInfo( "No se pudo lograr la conexión al servidor, REVISE LA CONEXION DE SU RED O LA CONEXION A INTERNET !" + CRLF +;
oApp:oCon:ConnectionString, oApp:cAplicacion )
FW_ShowAdoError(oApp:oCon)
RETURN( .F. )
END
RETURN( .T. )
#Include "FiveWin.ch"
#Include "Ado.ch"
#Include "xbrowse.ch"
MEMVAR oApp
STATIC oWnd
STATIC oRsHdr
STATIC oBtns
FUNCTION Test(oWindow)
LOCAL oDlg,oBrw,oFont
oBtns := ARRAY(05)
CreateDB()
OpenTable()
DEFINE FONT oFont NAME "MS Sans Serif" SIZE 0,-10
DEFINE ICON oIcono RESOURCE "AppLogo"
DEFINE WINDOW oWnd MDICHILD OF oWindow FROM 0,0 TO 10,10;
TITLE "Relación de movimientos de almacén" ICON oIcono
oWnd:bGotFocus = { || oBrw:SetFocus() }
DEFINE DIALOG oDlg RESOURCE "BrwVda" OF oWnd FONT oFont ICON oIcono
REDEFINE BUTTONBAR oBar ID 100 OF oDlg SIZE 56,42 2007
DEFINE BUTTON oBtns[01] OF oBar ;
RESOURCE "Add16" TOP NOBORDER;
PROMPT "&Agregar";
ACTION InsertMovs(oBrw)
DEFINE BUTTON oBtns[04] OF oBar ;
ACTION oWnd:End();
RESOURCE "Exi16" TOP NOBORDER;
PROMPT "&Salir";
GROUP
REDEFINE XBROWSE oBrw ID 200 OF oDlg;
DATASOURCE oRsHdr;
COLUMNS "HDR_FOL","HDR_FDM","HDR_REF","","","","","","SUC_NOM","HDR_CAN";
HEADERS "Folio","Fecha","Referencia","Tipo","Unidades","Costos","Unidades","Costos","Sucursal","Can";
COLSIZES 50,80,80,60,70,75,70,75,110,32;
PICTURES "@Z 9999999","dd/mmm/yyyy",Nil,Nil,"@Z 9,999,999","@Z 99,999,999.99","@Z 9,999,999","@Z 99,999,999.99",Nil,Nil;
JUSTIFY {AL_RIGHT,AL_RIGHT,AL_LEFT,AL_LEFT,AL_RIGHT,AL_RIGHT,AL_RIGHT,AL_RIGHT,AL_LEFT,AL_CENTER};
FOOTERS AUTOSORT //BACKGROUND oApp:cBrush
WITH OBJECT oBrw
:l2007 := (.F.)
:lHScroll := (.F.)
:lVScroll := (.F.)
:nMarqueeStyle := MARQSTYLE_HIGHLROW
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:nRowDividerStyle := LINESTYLE_LIGHTGRAY
:SetGroupHeader( "E N T R A D A S",05,06 )
:SetGroupHeader( "S A L I D A S",07,08 )
:nHeaderHeight := 25
:nRowHeight := 22
:nFooterHeight := 25
:bClrHeader := { || {CLR_WHITE,CLR_BLACK} }
:bClrFooter := { || {CLR_WHITE,CLR_BLACK} }
:bClrSel := { || IF( oBrw:KeyNo % oApp:nRowsInt == 0 ,{ CLR_BLACK, oApp:nRowParClr },{ CLR_BLACK, oApp:nRowNonClr }) }
:bClrSelFocus := { || {oApp:nFClrFocus,oApp:nBClrFocus} }
:bClrStd := { || IF( oBrw:KeyNo % oApp:nRowsInt == 0 ,{ CLR_BLACK, oApp:nRowParClr },{ CLR_BLACK, oApp:nRowNonClr }) }
:nRecSelColor := oApp:nRowParClr
:lDisplayZeros := (.F.)
WITH OBJECT :Folio
:cOrder := "A"
END
WITH OBJECT :Tipo
:bStrData := { || IF(oRsHdr:RecordCount() > 0 .AND.;
oRsHdr:Fields("HDR_EOS"):Value == 1,;
"Entrada","Salida")}
:nHeadStrAlign := AL_LEFT
END
WITH OBJECT :aCols[05]
:bStrData := { || IF(oRsHdr:RecordCount() > 0 .AND.;
oRsHdr:Fields("HDR_EOS"):Value == 1,;
Transform(oRsHdr:Fields("HDR_TOU"):Value,"@Z 9,999,999"),"")}
:nHeadStrAlign := AL_RIGHT
END
WITH OBJECT :aCols[06]
:bStrData := { || IF(oRsHdr:RecordCount() > 0 .AND.;
oRsHdr:Fields("HDR_EOS"):Value == 1,;
Transform(oRsHdr:Fields("HDR_TOC"):Value,"@Z 99,999,999.99") ,"")}
:nHeadStrAlign := AL_RIGHT
END
WITH OBJECT :aCols[07]
:bStrData := { || IF(oRsHdr:RecordCount() > 0 .AND.;
oRsHdr:Fields("HDR_EOS"):Value == 2,;
Transform(oRsHdr:Fields("HDR_TOU"):Value,"@Z 9,999,999"),"")}
:nHeadStrAlign := AL_RIGHT
END
WITH OBJECT :aCols[08]
:bStrData := { || IF(oRsHdr:RecordCount() > 0 .AND.;
oRsHdr:Fields("HDR_EOS"):Value == 2,;
Transform(oRsHdr:Fields("HDR_TOC"):Value,"@Z 99,999,999.99") ,"")}
:nHeadStrAlign := AL_RIGHT
END
WITH OBJECT :aCols[10]
:SetLogical()
:SetCheck(NIL,(.T.))
END
END
ACTIVATE DIALOG oDlg NOWAIT ON INIT oDlg:MOVE(0,0) VALID ! GetASyncKey(VK_ESCAPE)
ACTIVATE WINDOW oWnd ON INIT (oWnd:SETSIZE(oDlg:nWidth+15,oDlg:nHeight+29),oBrw:SetFocus) VALID CloseTable()
oFont:END()
oIcono:END()
RETURN(.T.)
* ---------------------------------------------------------------------------- *
STATIC FUNCTION CreateDB()
LOCAL cCmdSql := NIL
oApp:oCon:Execute("USE Test")
cCmdSql := "CREATE TABLE IF NOT EXISTS HdrVda (" +;
"HDR_FOL INTEGER(03) NOT NULL AUTO_INCREMENT COMMENT 'Folio'," +;
"HDR_EOS DECIMAL(01,0) NOT NULL DEFAULT 0 COMMENT 'E=Entrada y S=Salida'," +;
"HDR_SUC DECIMAL(03,0) NULL COMMENT 'Número de sucursal'," +;
"HDR_FDM DATE NOT NULL DEFAULT '0000-00-00' COMMENT 'Fecha del movimiento'," +;
"HDR_REF VARCHAR(15) NOT NULL DEFAULT '' COMMENT 'Referencia'," +;
"HDR_TOU DECIMAL(05,0) NOT NULL DEFAULT 0 COMMENT 'Total de unidades'," +;
"HDR_TOC DECIMAL(11,2) NOT NULL DEFAULT 0.00 COMMENT 'Total de costos'," +;
"HDR_CAN BIT NOT NULL DEFAULT 0 COMMENT 'Cancelado ?'," +;
"HDR_MOT VARCHAR(50) NOT NULL DEFAULT '' COMMENT 'Motivo de la cancelación'," +;
"PRIMARY KEY(HDR_FOL))" +;
"ENGINE = InnoDB COMMENT 'Encabezado de vales de almacén';"
oApp:oCon:Execute(cCmdSql)
RETURN(.T.)
* ---------------------------------------------------------------------------- *
STATIC FUNCTION OpenTable()
oRsHdr := FW_OpenRecordSet(oApp:oCon,"SELECT " +;
"*," +;
"SUC_NOM " +;
"FROM " +;
"HdrVda " +;
"LEFT JOIN " +;
"Sucursales " +;
"ON " +;
"HDR_SUC = Sucursales.SUC_NUM",adLockOptimistic,adOpenDynamic,0)
IF oRsHdr == nil
MsgStop("I can't open the table HDRVDA !",oApp:cAplicacion)
FW_ShowAdoError(oApp:oCon)
RETURN(.F.)
ENDIF
IF oRsHdr:BOF() .AND. oRsHdr:EOF()
ELSE
oRsHdr:MoveFirst()
ENDIF
RETURN(.T.)
* ---------------------------------------------------------------------------- *
STATIC FUNCTION InsertMovs(oBrw)
oRsHdr:AddNew()
oRsHdr:Fields("HDR_EOS"):Value := 1 // In
oRsHdr:Fields("HDR_SUC"):Value := AdoNull() // Only out movs has value
oRsHdr:Fields("HDR_FDM"):Value := Date()
oRsHdr:Fields("HDR_TOU"):Value := 10
oRsHdr:Fields("HDR_TOC"):Value := 175.25
oRsHdr:UpDate()
oRsHdr:AddNew()
oRsHdr:Fields("HDR_EOS"):Value := 2 // Out
oRsHdr:Fields("HDR_SUC"):Value := 1 // Only out movs has value
oRsHdr:Fields("HDR_FDM"):Value := Date()
oRsHdr:Fields("HDR_REF"):Value := "F-254"
oRsHdr:Fields("HDR_TOU"):Value := 150
oRsHdr:Fields("HDR_TOC"):Value := 15000.00
oRsHdr:UpDate()
oRsHdr:ReQuery()
oBrw:Refresh()
oBrw:SetFocus()
RETURN(.T.)
* ---------------------------------------------------------------------------- *
*/
STATIC FUNCTION CloseTable()
oWnd := NIL
IF oRsHdr <> NIL
IF oRsHdr:State() = adStateOpen
oRsHdr:Close()
ENDIF
ENDIF
RETURN(.T.)
Error description: (DOS Error -2147352567) WINOLE/1007 El identificador de fila se refirió a una fila eliminada o a una fila marcada para eliminar. (0x80040E23): Microsoft Cursor Engine
Stack Calls
===========
Called from: => TOLEAUTO:VALUE( 0 )
Error description: (DOS Error -2147352567) WINOLE/1007 The row identifier referred to a deleted row or a row marked for deletion. (0x80040E23): Microsoft Cursor Engine
local oCn, oRs, oField
oCn := FW_MSSQLDB()
oRs := FW_OpenRecordSet( oCn, "states" )
oRs:Delete()
oField := oRs:Fields( 0 )
? oField:Value // error 1007
Error description: (DOS Error -2147352567) WINOLE/1007 Row handle referred to a deleted row or a row marked for deletion. (0x80040E23): Microsoft Cursor Engine
Stack Calls
===========
Called from: => TOLEAUTO:VALUE( 0 )
oApp:oCon:Execute("USE Test")
Armando wrote:Mr. Rao:
Yes, USE is a mysql command, after this command all commands affect tables in TEST database
Best regards
Oh Sorry, yes. Pardon my forgetfulness.
It selects TEST as current database.
I am now copying your program with minor changes and trying to execute at my end.
BTW, it is now about 10:30 pm in Toluca. Are you still awake?
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 44 guests