Mediator / Listbox

Mediator / Listbox

Postby Jeff Barnes » Mon May 18, 2009 2:29 am

Hi Everybody,


After many failed attempts to connect and edit / modify records via MySql I have tried Mediator (http://www.otc.pl)
It seems to be working and was fairly simple to set up.
Also, they are providing a free unlimited Rdd to connect to MySql for harbour/xharbour.

I have come across a problem and was wondering if anyone else has see this...

I have a listbox that uses fields from a table opened via MEDNTX (their rdd) and I cannot use the mouse to click on the rows in the listbox (I can use the up/down arrow keys then double click the highlighted item but cannot use the mouse to select a row)

If I change the FIELDS clause to ITEMS and try I can click on the rows.

Example: (non-working)
Code: Select all  Expand view
  @ 7,1 LISTBOX oLbx ;
         FIELDS Patients->MRN,Patients->LastName,Patients->FirstName ;
         SIZE 780,350 ;
         of oSearch
 


Example: (working)
Code: Select all  Expand view
  aItems := { "One", "Two","Three" }
   @ 7,1 LISTBOX oLbx ;
         ITEMS aItems ;
         SIZE 780,350 ;
         of oSearch
 



Anyone seen this before? Anything I can do to get it working?
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Mediator / Listbox

Postby dutch » Mon May 18, 2009 7:24 am

Dear Jeff,

I try Mediator and able to read and write. I try listbox but it able to show only FIRST RECORD on the listbox only.
Code: Select all  Expand view
#include 'fivewin.ch'
#include 'mediator.ch'

static oWnd, oLbx

Function main
local numtabs, aTabNames
request medntx
rddsetdefault("MEDNTX")

numtabs := MedGetTabs()

Msginfo( numtabs )

aTabNames := array( numtabs )

MedGetTabs( aTabNames )

MsgList( aTabNames )

use rsvn alias rsvn

DEFINE WINDOW oWnd TITLE 'Test Mediator'

  @ 1, 1 LISTBOX oLbx FIELDS RSVN->ROOMNO, RSVN->FIRSTNAME, RSVN->LASTNAME ;
                 HEADERS 'Room', 'Firstname', 'Lastname' ;
                 SIZE 600,400 ;
                 OF oWNd

ACTIVATE WINDOW oWnd MAXIMIZED

use rsvn
close all
return nil


If you can do any forward, pls let me know. Thanks, bcos, I try to use MySql too.

Regards,
Dutch
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
User avatar
dutch
 
Posts: 1542
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: Mediator / Listbox

Postby Jeff Barnes » Mon May 18, 2009 11:22 pm

Hi Dutch,

I have it working now ... I think it was a table issue. I recreated a test table and all is ok.

Here is the code I used to create the test table:

Code: Select all  Expand view
#include "fivewin.ch"
#include "mediator.ch" 
request medntx     

Function Main()
   Local aDBF, i
   RDDSETDEFAULT("MEDNTX") 
   aDbf := {}
   AADD(aDbf, { "MRN",        "C", 30,   0 })
   AADD(aDbf, { "LastName",   "C", 30,   0 })
   AADD(aDbf, { "FirstName",  "C", 30,   0 })
   DBCREATE("Patients", aDbf, "MEDNTX")
   USE
   USE PATIENTS NEW alias "PAT"
   For i = 1 to 100
       APPEND BLANK
       Pat->MRN := STR(i)
       Pat->LastName := "Test"+str(i)
       Pat->FirstName := "Patient"+str(i)
   Next
   USE
   Msginfo("Patient Databasae Created")
Return Nil
 


As for my listbox code:

Code: Select all  Expand view
#include "FiveWin.ch"
#include "Mediator.ch"
request medntx     

Function Main()
   RDDSETDEFAULT("MEDNTX") 
   OpenFiles()
   Search()
Return Nil

Function OpenFiles()
  Use Patients Shared New
  GO TOP
Return Nil

Function Search()
   Define Window......

      @ 7,1  LISTBOX oLbx;
          FIELDS Patients->MRN,Patients->LastName,Patients->FirstName;
          HEAD "MRN","Last Name","First Name" ;
          SIZE 780,350 ;
          FIELDSIZES 150,150,150  ;
          ON DBLCLICK EditPatient() ;    
          of oSearch
      oLbx:Gotop()
   Activate Window.......
Return Nil
 


I hope this helps :-)
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Mediator / Listbox

Postby dutch » Tue May 19, 2009 2:49 am

Dear Jeff,

I try ADO from Daniel Garcia-Gil example. It doesn't too hard for starting.
The Mediator is good but I have to access the databae (MySql) share with WebBase Application (Third Party) and Mediator create and write database in thier way. If other application access and write in thier way too. The database will might be complete. The ADO is a pure connect from xHarbour+Fivewin, it is a good choice but if it is not easy Mediator will be better choice. I will try both (ADODB and Mediator) and let you know the testing.

Thanks a lot, I will try your code and it works ok now. I feel the Mediator will look at Command first. "Go Top"
Code: Select all  Expand view
/*
* test connection with ADODB
*/


#include "FiveWin.Ch"
#include "XBrowse.Ch"
#include "ado.Ch"


//----------------------------------------------------------------------------//

function main()

   execConnection()

return( 0 )

FUNCTION execConnection

LOCAL oCon, oRs, oError


oCon := MySQLConnect()

* MakeTable(oCon)

oRs  := MySQLRecordSet( oCon )

IF oRs:recordCount() > 0
   oRs:moveFirst()
ENDIF

TxBrowseShow( oRs )

oRs:close()

oCon:close()

RETURN( .T. )

/*
* --------------------------------------------------------------------------*
* --------------------------------------------------------------------------*
*/

FUNCTION MySQLConnect

LOCAL oError, oCon, cConnectionString


TRY

   oCon := TOleAuto():new( "ADODB.Connection" )

CATCH oError

   msgStop( "No se pudo crear la conexion" )
   RETURN( .F. )

END

cConnectionString := "Driver={MySQL ODBC 5.1 Driver}" + ;
                     ";Server=localhost"       + ;  //                      
             ";DefaultDatabase=php362"       + ;
                     ";Database=php362"            + ;
                     ";Port=3306"                     + ;
                     ";User=root"                  + ;
                     ";Password=pass"              + ;
                     ";Option=3;"

oCon:connectionString := cConnectionString

TRY

   oCon:open()
   ? "Connection ok!"

CATCH oError

   msgInfo( "No se pudo crear la conexion" )
   showError( oError )
   RETURN( .F. )

END

RETURN( oCon )

/*
* --------------------------------------------------------------------------*
* --------------------------------------------------------------------------*
*/

FUNCTION MySQLRecordSet( oCon )

LOCAL oRs, oError, cQuerySql


TRY
   oRs := TOleAuto():new( "ADODB.RecordSet" )

CATCH oError

   msgStop( "No hay RS" )
   showError( oError )
   oRs := NIL
   RETURN( .F. )

END

&& -- Realizando uma query no cadastro de empresas
cQuerySql := "SELECT * FROM RSVN"

oRs:cursorLocation := adUseClient // 3
oRs:lockType       := adLockOptimistic // 3
oRs:cursorType     := adOpenDynamic // 2

oRs:source         := cQuerySql

oRs:activeConnection( oCon )

TRY

   oRs:open()
   ? oRs:source,,, "oRs:recordCount()", oRs:recordCount()

CATCH oError

   msgStop( "No Query '" + cQuerySql + "'" )
   showError( oError )
   RETURN( .F. )

END

RETURN( oRs )

/*
* --------------------------------------------------------------------------*
* --------------------------------------------------------------------------*
*/

PROCEDURE showError( oError )

LOCAL cMensagemRetorno := ""

cMensagemRetorno := "[Subsystem]"         + CRLF + oError:SubSystem                 + CRLF + CRLF + ;
                    "[SubCode]"           + CRLF + alltrim( str( oError:SubCode ) ) + CRLF + CRLF + ;
                    "[Operacion]"         + CRLF + oError:Operation                 + CRLF + CRLF + ;
                    "[Descripcion]"       + CRLF + oError:Description               + CRLF + CRLF + ;
                    "[Argumentos]"        + CRLF + valToPrg( oError:Args )

msgStop( cMensagemRetorno )
RETURN

/*
* --------------------------------------------------------------------------*
* --------------------------------------------------------------------------*
*/

FUNCTION TxBrowseShow( oRs )

   local oWnd, oBrw, oCol

   DEFINE WINDOW ownd OF WndMain() TITLE "Test"

   @ 0,0 XBROWSE oBrw OF oWnd RECSET oRs AUTOCOLS AUTOSORT FOOTERS FASTEDIT ;
         LINES CELL

   oBrw:createFromCode()
   oWnd:oClient := oBrw

   ACTIVATE WINDOW oWnd ON INIT oBrw:setFocus()

return nil

function MakeTable( oCon )
local cCmdSql := "CREATE TABLE IF NOT EXISTS TEST ("+;
                 "ROW_ID INTEGER    NOT NULL AUTO_INCREMENT COMMENT 'LLAVE',"+;
                 "CODIGO CHAR(5)    NOT NULL COMMENT 'CODIGO CLIENTE',"+;
                 "NOMBRE CHAR(30)   NOT NULL COMMENT 'NOMBRE CLIENTE',"+;
                 "ACTIVO BIT        NOT NULL COMMENT 'ACTIVO',"+;
                 "PRIMARY KEY(ROW_ID))"+;
                 "ENGINE = InnoDB COMMENT 'Test';"
                 
oCon:Execute( cCmdSql )

cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('001','NOMBRE01',0);"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('002','NOMBRE02',1);"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('003','NOMBRE03',0);"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('004','NOMBRE04',1);"
oCon:Execute( cCmdSql )
return nil
 


Regards,
Dutch
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
User avatar
dutch
 
Posts: 1542
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: Mediator / Listbox

Postby dutch » Fri May 22, 2009 4:24 pm

Dear Jeff,

I've got good help from William Morales and Wang Shuming. Both guys are very kindness and helpful.
I can connect to MySql Server with TMySql (mysql.lib and libmysql.lib). It can connect without ODBC setup and without Mediator Server (Third party application).
It means xHarbour+FWH+(mysql.lib and libmysql.lib) only. I quite simple. If you are interesting, just add to library in your batch file before Fivehx.lib and Fivehc.lib.
Code: Select all  Expand view

(buildx.bat)
...
echo %hdirl%\mysql.lib + >> b32.bc
echo %hdirl%\libmysql.lib + >> b32.bc
echo %fwh%\lib\Fivehx.lib %fwh%\lib\FiveHC.lib + >> b32.bc
...
 

Example to connect to MySql
========================
Code: Select all  Expand view

#include 'fivewin.ch'

static oserver, odb1

Function Main

     LOCAL cHost := "localhost" // "incos...net"
     LOCAL cUser := "root"   // "dutch"
     LOCAL cPsw  := "nimda"  // "dutch"
     LOCAL cPort := "3306"

     oServer:= TMySQLServer():New( cHost, cUser, cPsw, cPort )
     if oServer:NetErr()
        MsgAlert (oServer:Error(),"MySQL Error")
        quit
     endif

     oserver:Selectdb("php362")
     IF oServer:lError
        ? "No used database"
        RETURN NIL
     ENDIF

     odb1:=oServer:Query("select * from rsvn")  // employee where name='Steven'")
     msginfo( odb1:fieldget( "lastname" ) )
     oserver:end()

return nil
 
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
User avatar
dutch
 
Posts: 1542
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: Mediator / Listbox

Postby Jeff Barnes » Fri May 22, 2009 11:09 pm

Thanks Dutch.
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Mediator / Listbox

Postby FranciscoA » Thu Jun 04, 2009 6:41 am

Dear Dutch:
I'm trying to start using MySql, and I'm very confused about the code below. I have two days without getting work it.
Can this code work only with MySql + xHarbour?, or other component I need?. Can you help?

I reviewed the class tmysql I have, and I do not see anywhere, the command :Execute (), but compiled without errors.
The problem is that it creates not the table, and the table do not exists, and the conection to the server is working well.

function MakeTable( oCon )
local cCmdSql := "CREATE TABLE IF NOT EXISTS TEST ("+;
"ROW_ID INTEGER NOT NULL AUTO_INCREMENT COMMENT 'LLAVE',"+;
"CODIGO CHAR(5) NOT NULL COMMENT 'CODIGO CLIENTE',"+;
"NOMBRE CHAR(30) NOT NULL COMMENT 'NOMBRE CLIENTE',"+;
"ACTIVO BIT NOT NULL COMMENT 'ACTIVO',"+;
"PRIMARY KEY(ROW_ID))"+;
"ENGINE = InnoDB COMMENT 'Test';"

oCon:Execute( cCmdSql )

cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('001','NOMBRE01',0);"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('002','NOMBRE02',1);"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('003','NOMBRE03',0);"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('004','NOMBRE04',1);"
oCon:Execute( cCmdSql )
return nil

Regards,
Francisco.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Mediator / Listbox

Postby nageswaragunupudi » Thu Jun 04, 2009 1:20 pm

Mr Duch

>>
TxBrowseShow( oRs )
>>

It is really not necessary to have this function written by yourself.

Simply,
Code: Select all  Expand view
xbrowse( oRs )

will do.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Mediator / Listbox

Postby dutch » Thu Jun 04, 2009 4:09 pm

Dear Francisco,

This function is used for ADO not for TMySql. If you need to use TMySql just add 2 library MYSQL.LIB and LIBMYSQL.LIB before FIVEHX.LIB and FIVEHC.LIB. Then try the sample. I just test to connect and read the database. You can search TMYSQL in the forum.

FranciscoA wrote:I reviewed the class tmysql I have, and I do not see anywhere, the command :Execute (), but compiled without errors.
The problem is that it creates not the table, and the table do not exists, and the conection to the server is working well.

function MakeTable( oCon )
local cCmdSql := "CREATE TABLE IF NOT EXISTS TEST ("+;
"ROW_ID INTEGER NOT NULL AUTO_INCREMENT COMMENT 'LLAVE',"+;
"CODIGO CHAR(5) NOT NULL COMMENT 'CODIGO CLIENTE',"+;
"NOMBRE CHAR(30) NOT NULL COMMENT 'NOMBRE CLIENTE',"+;
"ACTIVO BIT NOT NULL COMMENT 'ACTIVO',"+;
"PRIMARY KEY(ROW_ID))"+;
"ENGINE = InnoDB COMMENT 'Test';"

oCon:Execute( cCmdSql )

cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('001','NOMBRE01',0);"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('002','NOMBRE02',1);"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('003','NOMBRE03',0);"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('004','NOMBRE04',1);"
oCon:Execute( cCmdSql )
return nil

Regards,
Francisco.


Regards,
Dutch
Regards,
Dutch

FWH 19.01 / xHarbour Simplex 1.2.3 / BCC73 / Pelles C / UEStudio
FWPPC 10.02 / Harbour for PPC (FTDN)
ADS V.9 / MySql / MariaDB
R&R 12 Infinity / Crystal Report XI R2
(Thailand)
User avatar
dutch
 
Posts: 1542
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Re: Mediator / Listbox

Postby FranciscoA » Thu Jun 04, 2009 6:28 pm

Dutch: ¡Thanks!
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: jair, nageswaragunupudi and 84 guests