FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour check existing first and last on customer - RESOLVED !!!
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: check existing first and last on customer
Posted: Tue Jun 15, 2021 03:37 PM
I didn't find the Lookup() method in TDatabase because I was looking a the sorted methods in my editor and the actual method name is TD_LOOKUP, so it was under the T's not the L's.


Method LookUp exists:
Code (fw): Select all Collapse
   METHOD LookUp( uSeek, cOrder, bcExpr, lTrigger ) INLINE ( ::cAlias )->( ::td_LookUp( uSeek, cOrder, bcExpr, lTrigger ) )


The original question in the first post was how to find if a combination of two fields already exists in the table. I provided a simple and straight answer for that which works irrespective of the indexes.
Regards



G. N. Rao.

Hyderabad, India
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: check existing first and last on customer
Posted: Tue Jun 15, 2021 04:06 PM
Nages,

The original question in the first post was how to find if a combination of two fields already exists in the table. I provided a simple and straight answer for that which works irrespective of the indexes
.

Sorry, I never meant to imply otherwise.

I was just pointing out that using primary keys solves this and many other problems Silvio has been having. When using primary keys, Silvio won't need to do this lookup. However, your technique will be useful in other situations. Thanks for providing it--I already have it in my notes file.

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: check existing first and last on customer
Posted: Tue Jun 15, 2021 06:32 PM

cNomeintero was only a test.
I wish use the same fields i pubblish
clicognome as First
clinome as last
of 20 characters

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: check existing first and last on customer
Posted: Wed Jun 16, 2021 09:37 AM
James Bott wrote:Nages,

The original question in the first post was how to find if a combination of two fields already exists in the table. I provided a simple and straight answer for that which works irrespective of the indexes
.

Sorry, I never meant to imply otherwise.

I was just pointing out that using primary keys solves this and many other problems Silvio has been having. When using primary keys, Silvio won't need to do this lookup. However, your technique will be useful in other situations. Thanks for providing it--I already have it in my notes file.

James


But which primaries should I use?
the clienti.dbf file has these indexes

INDEX ON UPPER(CLICOGNOME) TAG CLICOGNOME
INDEX ON UPPER(CLINOME) TAG CLINOME
INDEX ON UPPER(CLIFISCALE) TAG CLIFISCALE
INDEX ON UPPER(CLIPARTIVA) TAG CLIPARTIVA
INDEX ON UPPER(CLIINDIRIZ) TAG CLIINDIRIZ
INDEX ON UPPER(CLIPAESE) TAG CLIPAESE
INDEX ON UPPER(CLICAP) TAG CLICAP
INDEX ON UPPER(CLIPROV) TAG CLIPROV
INDEX ON UPPER(CLIREGIONE) TAG CLIREGIONE
INDEX ON UPPER(CLITELEF1) TAG CLITELEF1
INDEX ON UPPER(CLITELEF2) TAG CLITELEF2
INDEX ON UPPER(CLIEMAIL) TAG CLIEMAIL
INDEX ON UPPER(CLISITOWEB) TAG CLISITOWEB
INDEX ON UPPER(CLIAPPUNTI) TAG CLIAPPUNTI
INDEX ON DELETED() TAG DELETED


and the fields are these
Code (fw): Select all Collapse
local aFields := { { "CLICOGNOME", "C", 20, 0 },;
                   { "CLINOME", "C", 20, 0 },;
                   { "CLIFISCALE", "C", 16, 0 },;
                   { "CLIPARTIVA", "C", 11, 0 },;
                   { "CLIINDIRIZ", "C", 30, 0 },;
                   { "CLIPAESE", "C", 30, 0 },;
                   { "CLICAP", "C", 5, 0 },;
                   { "CLIPROV", "C", 2, 0 },;
                   { "CLIREGIONE", "C", 20, 0 },;
                   { "CLITELEF1", "C", 14, 0 },;
                   { "CLITELEF2", "C", 14, 0 },;
                   { "CLIEMAIL", "C", 40, 0 },;
                   { "CLISITOWEB", "C", 40, 0 },;
                   { "CLIAPPUNTI", "C", 200, 0 } }



the idea of using only one field (FULLNAME) was just a test I did but in reality I need a field for the Surname and a field for the name.
There are many customers with the same surname just think that entire families go to the sea. There is the possibility of having the same surname and the same name

nages suggestion only works on the first try i.e:
1) I enter the surname and then the name for example "Vitali" "Pietro"
I only put control on the name
2) the procedure tells me that the name "Peter" already exists so I 3) deletes the contents of the get control and sets focus on the get, so the cusor is stopped on the get control of the name
3) I insert in place of "Pietro", my name "Silvio" which in reality is not in the archive, the procedure does not make me go ahead to enter the other fields and makes a error

this error
Code (fw): Select all Collapse
 Error description: Error BASE/1066  Argument error: conditional
   Args:
     [   1] = U   

Stack Calls
===========
   Called from: test.prg => CLCLAVE( 305 )
   Called from: test.prg => (b)CLEDITA( 206 )
   Called from: .\source\classes\TGET.PRG => TGET:LVALID( 2282 )


is there a solution please?
I'll post the valid function I made

@ 26, 10 SAY "Nome :" OF oDlg SIZE 22, 8 PIXEL FONT oFont
@ 24, 67 GET aGet[2] VAR oCliente:Clinome OF oDlg SIZE 100, 12 PIXEL FONT oFont ;
VALID CLClave( oCliente:Clicognome, aGet[2], 1,oDbf,oCliente:Clinome )


Code (fw): Select all Collapse
function CLClave( cCognome, oGet, nMode,oDbf,cNome )
   local lreturn  := .f.
   local nRecno   := oDbf:RecNo()
   local nOrder   := oDbf:OrdNumber()
   local nArea    := Select()


 if Empty( cNome )
      if nMode == 4
         return .t.
      else
         MsgStop("E' obbligatorio questo campo.")
         return .f.
      endif
   endif

*oDbf:SetOrder( 1 )  //CLICOGNOME
*   oDbf:GoTop()

 IF  oDbf:LookUp( UPPER( PADR( cCognome, 20 ) + PADR( cNome, 20 ) ), ;
                   "UPPER(CLICOGNOME+CLINOME)", { || FOUND() } )


 DO CASE
         Case nMode == 1 .OR. nMode == 3   // new or duplicate
            lreturn := .f.
            MsgStop("Nominativo esistente.")
         Case nMode == 2   // modify
            if oDbf:Recno()  == nRecno
               lreturn := .t.
            else
               lreturn := .f.
               MsgStop("Nominativo esistente.")
            endif
         Case nMode == 4     //selection dialog
            lreturn := .t.
         END CASE

 ELSE

      if nMode < 4
         lreturn := .t.
      else
         if MsgYesNo("Nominativo inesistente. ¿ Desideri inserirlo ora? ")   // on selection dialog ask to add the new record
            lreturn := ClEdita( , 1, , , @cCognome )
         else
            lreturn := .f.
         endif
      endif
   endif



 if lreturn == .f.
    oGet:cText( space(20) )
   endif

  oDbf:SetOrder( nOrder )
  oDbf:GoTo( nRecno )

   Select (nArea)

   return lreturn
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: check existing first and last on customer
Posted: Wed Jun 16, 2021 05:32 PM
Please change this line
Code (fw): Select all Collapse
IF  oDbf:LookUp( UPPER( PADR( cCognome, 20 ) + PADR( cNome, 20 ) ), ;
                   "UPPER(CLICOGNOME+CLINOME)", { || FOUND() } )


AS

Code (fw): Select all Collapse
IF  oDbf:LookUp( UPPER( PADR( cCognome, 20 ) + PADR( cNome, 20 ) ), ;
                   "UPPER(CLICOGNOME+CLINOME)", { || FOUND() } ) == .T.
Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: check existing first and last on customer
Posted: Wed Jun 16, 2021 06:15 PM

thanks Rao , run good!!!

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: check existing first and last on customer - RESOLVED !!!
Posted: Wed Jun 16, 2021 07:18 PM

Offtopic:

Is it a practice or tradition in your country to name children after their grandfather/grandmother's name?

I am curious because it is a tradition to give the first son his paternal grandfather's name and the first daughter her paternal grandmother's name in our region of our country. Same way, the second son and daughter get maternal grandfather and grandmothers' names. Of course, the present generation is mostly ignoring the tradition.

Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: check existing first and last on customer - RESOLVED !!!
Posted: Thu Jun 17, 2021 08:47 AM
nageswaragunupudi wrote:Offtopic:

Is it a practice or tradition in your country to name children after their grandfather/grandmother's name?

I am curious because it is a tradition to give the first son his paternal grandfather's name and the first daughter her paternal grandmother's name in our region of our country. Same way, the second son and daughter get maternal grandfather and grandmothers' names. Of course, the present generation is mostly ignoring the tradition.


I am the first child so my name is my grandfather.

My brother is called Massimiliano and now he has a son who bears the name of the father of my brother's wife.

Generally the first child is called by the same name, but this custom is no longer fashionable.

In my city there are many people who are called like me (name and surname) but we are not relatives,
one in particular is the same age as me but was born the day before me, so even the tax code is almost the same
and a few weeks ago his grandfather died who was named like us and everyone thought he was my grandfather and everyone gave me condolences
but my grandfather died 35 years ago when i was 19.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: check existing first and last on customer - RESOLVED !!!
Posted: Thu Jun 17, 2021 03:41 PM

Thanks for the information. We have similar traditions.

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion