Files
comun/clase/_cb_base.vc2

844 lines
27 KiB
Plaintext

*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.21" SourceFile="_cb_base.vcx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
DEFINE CLASS _cbautofill AS _combobox OF "_baza.vcx"
*< CLASSDATA: Baseclass="combobox" Timestamp="" Scale="Pixels" Uniqueid="" />
*<DefinedPropArrayMethod>
*p: acstyle
*p: cpk && Numele campului cheie primara ( PK ) din cursorul atasat
*p: lastdisplayvalue
*p: lastsellength
*p: lastselstart
*p: npk && Valoarea campului cheie primara ( PK ) corespunzator valorii afisate
*</DefinedPropArrayMethod>
*<PropValue>
acstyle = 2
BorderStyle = 1
cpk =
FontCharSet = 238
Format = "!"
Height = 24
lastdisplayvalue =
lastsellength = 0
lastselstart = 0
Name = "_cbautofill"
npk = 0
RowSourceType = 2
SelectOnEntry = .T.
Style = 0
Width = 240
*</PropValue>
PROCEDURE InteractiveChange
*!* modificare adrese parteneri 12.2013
If This.Style = 0
*!* modificare adrese parteneri 12.2013 ^
Local lnStyle, lnLastKey, lcDisplayValue
lnLastKey=Lastkey()
lnStyle = This.Style
*!* modificare adrese parteneri 12.2013
*!* If This.Style = 2
*!* This.Style = 0
*!* Endif
*!* modificare adrese parteneri 12.2013 ^
If (lnLastKey>=32 And lnLastKey<=126)
If This.SelStart>=1
lcDisplayValue=Substr(This.DisplayValue,1,This.SelStart-1)+(Chr(lnLastKey))
Else
lcDisplayValue=(Chr(lnLastKey))+Allt(This.DisplayValue)
Endif
If Empty(lcDisplayValue)
lcDisplayValue=Allt(Chr(lnLastKey))
Endif
For i = 1 To This.ListCount
If Upper(lcDisplayValue)=Upper(Substr(This.List(i),1,Len(lcDisplayValue)))
This.DisplayValue=This.List(i)
If Len(Allt(This.DisplayValue))>Len(lcDisplayValue)
This.SelStart=Len(lcDisplayValue)
This.SelLength=Len(Allt(This.DisplayValue))-Len(lcDisplayValue)
Endif
This.lastdisplayvalue = This.DisplayValue
This.lastselstart = This.SelStart
This.lastsellength = This.SelLength
Return
Endif
Endfor
*&& Removed the next for line to allow for the DisplayValue to be added to the table.
*!* if this.acStyle = 2
*!* this.displayvalue = this.lastdisplayvalue
*!* this.selstart = this.lastselstart
*!* this.sellength = this.lastsellength
*!* endif
Endif
*!* modificare adrese parteneri 12.2013
Else
DoDefault()
Endif
*!* modificare adrese parteneri 12.2013 ^
ENDPROC
PROCEDURE Requery
This.Value = This.DisplayValue && Just to reset the display value
ENDPROC
PROCEDURE Valid
*!* 09.03.2014
*!* marius.mutu
*!* in caz ca sunt mai multe campuri delimitate prin virgula, iau primul camp
*!* modificare adrese parteneri 12.2013
Local cTableName,cFieldName,nAnswer,cValue,cPK
cTableName = Substr(This.RowSource,1,At('.',This.RowSource)-1)
If This.Style = 0
*!* modificare adrese parteneri 12.2013 ^
If !Empty(This.DisplayValue)
*Store substr(This.RowSource,1,at('.',This.RowSource)-1) To cTableName &&Won't work for VFP5.0
*Store substr(This.RowSource,at('.',This.RowSource)+1) To cFieldName && This is normally used for 3 character extension, but it works for any lenght. Won't work for VFP5.0
cFieldName = Substr(This.RowSource,At('.',This.RowSource)+1)
cFieldName = GETWORDNUM(m.cFieldName,1, ',') && in caz ca sunt mai multe campuri delimitate prin virgula, iau primul camp
Select (cTableName)
Locate For &cFieldName = This.DisplayValue
If !Found()
*nAnswer = Messagebox("Aceasta valoare nu exista in baza de date,"+Chr(13)+"Doriti sa o adaugati?",36,"")
*If nAnswer = 6
Insert Into &cTableName (&cFieldName) Values (This.DisplayValue)
If CursorGetProp("Buffering") > 1 && Check to see if we should use tableupdate
Tableupdate(1,.T.,cTableName)
Endif
This.Requery() && To reset the display value
*!* Else
*!* Store '' To This.DisplayValue
*!* Endif
Endif
Endif
*!* modificare adrese parteneri 12.2013
Else
DoDefault()
Endif
cPK = This.cpk
If !EMPTY(cPK)
Select (cTableName)
This.npk = &cPK
Endif
*!* modificare adrese parteneri 12.2013 ^
ENDPROC
ENDDEFINE
DEFINE CLASS _cbbase AS _combobox OF "_baza.vcx"
*< CLASSDATA: Baseclass="combobox" Timestamp="" Scale="Pixels" Uniqueid="" />
#INCLUDE "c:\program files\microsoft visual foxpro 8\foxpro.h"
*<PropValue>
FontCharSet = 238
Name = "_cbbase"
*</PropValue>
ENDDEFINE
DEFINE CLASS _cbsearch AS _combobox OF "_baza.vcx"
*< CLASSDATA: Baseclass="combobox" Timestamp="" Scale="Pixels" Uniqueid="" />
*<DefinedPropArrayMethod>
*p: acstyle
*p: lastdisplayvalue
*p: lastsellenght
*p: lastselstart
*p: sellenght
*</DefinedPropArrayMethod>
*<PropValue>
acstyle = 2
lastdisplayvalue =
lastsellenght = 0
lastselstart = 0
Name = "_cbsearch"
sellenght = 0
Style = 0
_memberdata = <VFPData>
<memberdata name="lastselstart" display="lastSelStart"/>
<memberdata name="lastsellenght" display="lastSelLenght"/>
<memberdata name="lastdisplayvalue" display="lastDisplayValue"/>
<memberdata name="sellenght" display="selLenght"/>
</VFPData>
*</PropValue>
PROCEDURE InteractiveChange
Local lnStyle, lnLastKey, lcDisplayValue
lnLastKey=Lastkey()
lnStyle = This.Style
If This.Style = 2
This.Style = 0
Endi
If (lnLastKey>=32 And lnLastKey<=126)
If This.SelStart>=1
lcDisplayValue=Substr(This.DisplayValue,1,This.SelStart-1)+(Chr(lnLastKey))
Else
lcDisplayValue=(Chr(lnLastKey))+Allt(This.DisplayValue)
Endi
If Empty(lcDisplayValue)
lcDisplayValue=Allt(Chr(lnLastKey))
Endi
For i = 1 To This.ListCount
If Upper(lcDisplayValue) == Upper(Substr(This.List(i),1,Len(lcDisplayValue)))
This.DisplayValue=This.List(i)
This.SelStart=Len(lcDisplayValue)
nlLength=Len(Allt(This.DisplayValue))-Len(lcDisplayValue)
This.SelLength=Iif(nlLength <0,0,nlLength)
This.lastdisplayvalue = This.DisplayValue
This.lastselstart = This.SelStart
This.lastsellenght = This.sellenght
Return
Endi
Endfor
Endif
ENDPROC
ENDDEFINE
DEFINE CLASS _cbsql AS _combobox OF "_baza.vcx"
*< CLASSDATA: Baseclass="combobox" Timestamp="" Scale="Pixels" Uniqueid="" />
*<DefinedPropArrayMethod>
*m: findrow
*m: log
*m: resettext
*p: csearchstring
*p: isclick
*p: llimittolist
*p: pcursorname
*p: pfieldactiv
*p: prowsource
*p: secondfield
*p: secondsearchfield
*</DefinedPropArrayMethod>
*<PropValue>
csearchstring =
Height = 24
isclick = .F.
llimittolist = .T.
Name = "_cbsql"
pcursorname =
pfieldactiv =
prowsource =
secondfield =
secondsearchfield =
SelectOnEntry = .T.
Style = 0
Width = 97
_memberdata = <VFPData>
<memberdata name="resettext" display="ResetText"/>
<memberdata name="isclick" display="isClick"/>
<memberdata name="findrow" display="FindRow"/>
<memberdata name="pfieldactiv" display="pFieldActiv"/>
<memberdata name="secondfield" display="SecondField"/>
<memberdata name="csearchstring" display="cSearchString"/>
<memberdata name="prowsource" display="pRowSource"/>
<memberdata name="pcursorname" display="pCursorName"/>
<memberdata name="secondsearchfield" display="SecondSearchField"/>
<memberdata name="llimittolist" display="lLimitToList"/>
<memberdata name="selstart" display="SelStart"/>
</VFPData>
*</PropValue>
PROCEDURE Click
This.Log('Click')
this.isclick = .T.
this.sellength = MAX(LEN(RTRIM(NVL(this.displayvalue,''))) - this.selstart, 0)
this.csearchstring = LEFT(NVL(this.displayvalue,''), this.selstart)
This.Log('Click ^')
ENDPROC
PROCEDURE findrow
This.Log('FindRow')
LOCAL lcExact
lcExact = SET("Exact")
SET EXACT OFF
LOCATE FOR UPPER(EVALUATE(this.pfieldactiv)) = UPPER(this.csearchstring)
IF !FOUND()
IF !EMPTY(this.secondfield)
LOCATE FOR EVALUATE(this.secondfield) = UPPER(this.csearchstring) + " " OR EVALUATE(this.secondfield) = "RO" + UPPER(this.csearchstring) + " "
IF !FOUND()
LOCATE FOR EVALUATE(this.secondfield) = UPPER(this.csearchstring) OR EVALUATE(this.secondfield) = "RO" + UPPER(this.csearchstring)
ENDIF
SET EXACT &lcExact
IF FOUND()
RETURN 3
ELSE
RETURN 2
ENDIF
ELSE
SET EXACT &lcExact
RETURN 2
ENDIF
ELSE
SET EXACT &lcExact
RETURN 1
ENDIF
ENDPROC
PROCEDURE GotFocus
LOCAL lcDisplayValue
This.Log('GotFocus')
lcDisplayValue = NVL(this.displayvalue, '')
IF this.selectonentry AND !this.isClick AND INLIST(LASTKEY(), 13, 5, 24, 4, 19, 9) AND !ISNULL(this.displayvalue)
FOR iii = 1 TO LEN(ALLTRIM(this.displayvalue))
KEYBOARD '{SHIFT + rightarrow}'
ENDFOR
ENDIF
this.selstart = 0
this.sellength = LEN(RTRIM(m.lcDisplayValue))
this.csearchstring = ""
this.isclick = .F.
This.Log('GotFocus ^')
ENDPROC
PROCEDURE InteractiveChange
This.Log('InteractiveChange')
this.csearchstring = ""
This.Log('InteractiveChange ^')
ENDPROC
PROCEDURE KeyPress
LPARAMETERS nkeycode, nshiftaltctrl
LOCAL lnrecno, msearchstring, mselstart, lcDisplayValue
This.Log('KeyPress')
lcDisplayValue = NVL(this.DisplayValue, '')
SELECT (this.pcursorname)
IF (EMPTY(this.csearchstring) OR (m.lcDisplayValue <> this.csearchstring AND m.lcDisplayValue <> "RO" + this.csearchstring)) AND !EMPTY(m.lcDisplayValue)
this.resettext()
IF nkeycode = 13
this.findrow()
ENDIF
ENDIF
msearchstring = this.csearchstring
mselstart = 0
IF BITAND(4, nshiftaltctrl) == 4
RETURN
ENDIF
IF (nkeycode = 54 .AND. ;
nshiftaltctrl = 1) .OR. ;
(nshiftaltctrl = 2 .AND. ;
nkeycode = 97)
this.resettext()
ENDIF
IF this.rowsourcetype = 3 AND !INLIST(nkeycode, 5, 24, 13, 54, 160, 152)
IF !EMPTY(this.prowsource)
this.rowsource = ""
this.requery()
this.rowsource = this.prowsource
this.prowsource = ""
this.requery()
this.refresh()
this.csearchstring = ""
ELSE
IF nkeycode = 10
IF !EMPTY(this.secondsearchfield)
mfieldactiv = this.secondsearchfield
ELSE
mfieldactiv = this.pfieldactiv
ENDIF
mQuery="SELECT * FROM (This.pCursorName) WHERE ALLTRIM(This.DisplayValue)$ UPPER(&mFieldActiv) INTO CURSOR (This.pCursorName)"
IF this.rowsource <> mquery
NODEFAULT
this.prowsource = this.rowsource
this.rowsource = mquery
this.requery()
this.resettext()
KEYBOARD '{ALT + DNARROW}'
RETURN
ENDIF
ENDIF
ENDIF
ENDIF
IF INLIST(nkeycode, 6) OR (INLIST(nkeycode, 52, 54) AND BITAND(1, nshiftaltctrl) == 1) .OR. (INLIST(2, 26) .AND. BITAND(2, nshiftaltctrl) == 2)
RETURN
ENDIF
SELECT (this.pcursorname)
lnrecno = RECNO()
DO CASE
CASE nkeycode = 4
this.csearchstring = LEFT(this.csearchstring, this.selstart) + SUBSTR(m.lcDisplayValue, this.selstart + 1, 1)
mselstart = this.selstart + 1
CASE nkeycode = 19
this.csearchstring = LEFT(this.csearchstring, this.selstart - 1)
mselstart = this.selstart - 1
this.sellength = MAX(LEN(RTRIM(m.lcDisplayValue)) - mselstart, 0)
IF mselstart < 0
RETURN
ENDIF
CASE nkeycode = 7
IF this.selstart = 0
this.csearchstring = ""
this.displayvalue = ""
ELSE
this.csearchstring = LEFT(this.csearchstring, this.selstart) + RIGHT(this.csearchstring, LEN(this.csearchstring) - this.selstart - 1)
this.displayvalue = this.csearchstring
ENDIF
mselstart = LEN(this.csearchstring)
CASE nkeycode = 127
IF this.selstart = 0
this.csearchstring = ""
this.displayvalue = ""
ELSE
this.csearchstring = LEFT(this.csearchstring, this.selstart - 1) + RIGHT(this.csearchstring, LEN(this.csearchstring) - this.selstart)
this.displayvalue = this.csearchstring
mselstart = LEN(this.csearchstring)
ENDIF
CASE nkeycode = 24
IF .NOT. EOF()
SKIP
ENDIF
IF EOF()
GOTO BOTTOM
ENDIF
CASE nkeycode = 5
IF .NOT. BOF()
SKIP -1
ENDIF
IF BOF()
GOTO TOP
ENDIF
CASE BETWEEN(nkeycode, 32, 126) OR BETWEEN(nkeycode, 97, 122) OR BETWEEN(nkeycode, 48, 57)
IF this.selstart = 0 AND this.sellength > 1
this.csearchstring = UPPER(CHR(nkeycode))
ELSE
this.csearchstring = LEFT(this.csearchstring, this.selstart) + UPPER(CHR(nkeycode)) + RIGHT(this.csearchstring, LEN(this.csearchstring) - this.selstart)
ENDIF
mselstart = this.selstart + 1
OTHERWISE
RETURN
ENDCASE
NODEFAULT
msemafor = 0
IF nkeycode <> 4 AND nkeycode <> 19 AND nkeycode <> 5 AND nkeycode <> 24 AND !EMPTY(this.csearchstring)
msemafor = this.findrow()
ENDIF
IF nkeycode <> 7 AND nkeycode <> 127 AND nkeycode <> 4 AND nkeycode <> 19
IF (EMPTY(this.csearchstring) OR msemafor = 2) AND nkeycode <> 5 AND nkeycode <> 24
IF lnrecno > RECCOUNT()
GOTO TOP
ELSE
GOTO lnrecno
ENDIF
IF !this.lLimitToList
this.displayvalue = this.csearchstring
ELSE
this.csearchstring = msearchstring
ENDIF
ELSE
IF msemafor = 1 OR nkeycode = 5 OR nkeycode = 24
this.displayvalue = EVALUATE(this.pfieldactiv)
IF nkeycode = 5 OR nkeycode = 24
this.resettext()
RETURN
ENDIF
ENDIF
IF msemafor = 3
this.displayvalue = EVALUATE(this.secondfield)
ENDIF
ENDIF
ENDIF
this.selstart = MAX(mselstart, 0)
IF TXTWIDTH(RTRIM(NVL(this.DisplayValue,'')), this.fontname, this.fontsize) * FONTMETRIC(6, this.fontname, this.fontsize) < this.width - 15
this.sellength = MAX(LEN(RTRIM(NVL(this.DisplayValue,''))) - LEN(RTRIM(this.csearchstring)), 0)
ELSE
this.sellength = 0
ENDIF
This.Log('KeyPress ^')
ENDPROC
PROCEDURE log
LPARAMETERS tcEvent
lcText = TRANSFORM(tcEvent) + ' ' + ttoc(DATETIME()) + ' selstart ' + TRANSFORM(this.SelStart) + CHR(13)
STRTOFILE(m.lcText, "e:\selstart.txt", .T.)
ENDPROC
PROCEDURE LostFocus
IF .NOT. EMPTY(this.prowsource)
SELECT (this.pcursorname)
mcamp = ALLTRIM(this.pcursorname) + ;
"." + ;
this.pfieldactiv
mCurrentValue=&mCamp
mthisvalue = this.value
this.rowsource = this.prowsource
this.prowsource = ""
this.requery()
SELECT (this.pcursorname)
LOCATE FOR &mCamp=mCurrentValue
this.value = mthisvalue
ENDIF
IF .NOT. EMPTY(this.secondfield)
SELECT (this.pcursorname)
IF this.displayvalue = ;
EVALUATE(this.secondfield) ;
.OR. "RO" + ;
this.displayvalue = ;
EVALUATE(this.secondfield)
this.displayvalue = EVALUATE(this.pfieldactiv)
ENDIF
ENDIF
this.csearchstring = ""
this.selstart = 0
ENDPROC
PROCEDURE MouseMove
LPARAMETERS nButton, nShift, nXCoord, nYCoord
this.isclick = .T.
ENDPROC
PROCEDURE resettext
This.Log('ResetText')
this.csearchstring = ALLTRIM(NVL(this.displayvalue,''))
this.selstart = 0
this.sellength = LEN(RTRIM(NVL(this.displayvalue,'')))
This.Log('ResetText ^')
ENDPROC
ENDDEFINE
DEFINE CLASS combosql AS combobox
*< CLASSDATA: Baseclass="combobox" Timestamp="" Scale="Pixels" Uniqueid="" />
*<DefinedPropArrayMethod>
*m: getdata && Retrieves data from the OLE drag and drop DataObject object.
*m: refreshdata
*m: selectdata
*p: csearchstring
*p: csourceorder && Ordinea pentru SourceSql
*p: csourcesql && Select SQL fara where si order
*p: csourcewhere && Conditia Where pentru cSourceSql
*p: isclick
*p: llimittolist
*p: ncharcountbegin && Dupa cate caractere incepe cautarea pe server. Implicit 0
*p: pcursorname && Numele cursorului
*p: pfieldactiv && Campul dupa care se face cautarea
*p: prowsource && Camp intern
*p: psecondfield && Al doilea camp de cautare (optional)
*p: _memberdata && XML Metadata for customizable properties
*</DefinedPropArrayMethod>
*<PropValue>
BackColor = 252,252,225
BorderStyle = 0
csearchstring =
csourceorder =
csourcesql =
csourcewhere =
Format = "K"
Height = 24
isclick = .F.
llimittolist = .F.
Name = "combosql"
ncharcountbegin = 0
pcursorname =
pfieldactiv =
prowsource =
psecondfield =
RowSourceType = 3
SpecialEffect = 1
Width = 100
_memberdata = <VFPData>
<memberdata name="pfieldactiv" display="pFieldActiv"/>
<memberdata name="pcursorname" display="pCursorName"/>
<memberdata name="llimittolist" display="lLimitToList"/>
<memberdata name="prowsource" display="pRowSource"/>
<memberdata name="csearchstring" display="cSearchString"/>
<memberdata name="isclick" display="isClick"/>
<memberdata name="csourcesql" display="cSourceSql"/>
<memberdata name="csourcewhere" display="cSourceWhere"/>
<memberdata name="csourceorder" display="cSourceOrder"/>
<memberdata name="refreshdata" display="RefreshData"/>
<memberdata name="getdata" display="GetData"/>
<memberdata name="selectdata" display="SelectData"/>
<memberdata name="psecondfield" display="pSecondField"/>
<memberdata name="ncharcountbegin" display="nCharCountBegin"/>
</VFPData>
*</PropValue>
PROCEDURE Click
This.isclick = .T.
This.SelLength = Max(Len(Rtrim(This.DisplayValue)) - this.SelStart, 0)
This.csearchstring = Left(This.DisplayValue, This.SelStart)
ENDPROC
PROCEDURE getdata && Retrieves data from the OLE drag and drop DataObject object.
ENDPROC
PROCEDURE Init
Local lcCursor, lcCursorS, lcSourceSql, lcSql, lcSqlRowSource, llSucces
lcSourceSql = This.cSourceSql
lcCursor = This.pCursorName
lcCursorS= 's' + m.lcCursor
lcSql = m.lcSourceSql + " where 1=2"
lcSqlRowSource = "select * from " + m.lcCursorS + " into cursor " + m.lcCursor
llSucces = This.RefreshData(0)
If m.llSucces
Select (m.lcCursorS)
Append Blank
TABLEUPDATE()
Endif
This.RowSource = m.lcSqlRowSource
ENDPROC
PROCEDURE InteractiveChange
This.csearchstring = ""
ENDPROC
PROCEDURE KeyPress
Lparameters nkeycode, nshiftaltctrl
Local lnrecno, lcSearchString, m.lnSelStart, llQueried
llQueried = .F.
lcSearchString = This.csearchstring
lnSelStart = 0
*!* IF nkeycode = 24
*!* SET STEP ON
*!* ENDIF
If Bitand(4, nshiftaltctrl) == 4
Return
Endif
If nkeycode = 54 .And. nshiftaltctrl = 1
This.SelStart = 0
This.SelLength = Len(Rtrim(This.DisplayValue))
This.csearchstring = ""
ENDIF
*** CAUTARE "CONTINE" DACA SE APASA CTRL+ENTER
If This.RowSourceType = 3 .And. .Not. Inlist(nkeycode, 5, 24, 13, 54) && FARA SAGETI
*!* If .Not. Empty(This.prowsource)
*!* This.RowSource = This.prowsource
*!* This.prowsource = ""
*!* This.Requery()
*!* Endif
If nkeycode = 10 && CTRL+ENTER => SELECTIA CONTINE CUVANTUL CHEIE IN LOC DE INCEPE CU
Nodefault
This.prowsource = This.RowSource
this.RowSource = ""
This.RefreshData(2) && cautare contine
llQueried = .T.
this.RowSource = This.prowsource
This.prowsource = ""
This.csearchstring = ""
Keyboard '{ALT + DNARROW}'
Return
Endif
Endif
If Inlist(nkeycode, 6) .Or. (Inlist(nkeycode, 52, 54) .And. Bitand(1, nshiftaltctrl) == 1) .Or. (Inlist(2, 26) .And. Bitand(2, nshiftaltctrl) == 2)
Return
Endif
Select (This.pcursorname)
lnrecno = Recno()
*** TRATARE SAGETI, DEL, BACKSPACE
Do Case
Case nkeycode = 4 && RIGHT ARROW
This.csearchstring = Left(This.csearchstring, This.SelStart) + Substr(This.DisplayValue, This.SelStart + 1, 1)
m.lnSelStart = This.SelStart + 1
Case nkeycode = 19 && LEFT ARROW
This.csearchstring = Left(This.csearchstring, This.SelStart - 1)
m.lnSelStart = This.SelStart - 1
This.SelLength = Max(Len(Rtrim(This.DisplayValue)) - m.lnSelStart, 0)
If m.lnSelStart < 0
Return
Endif
Case nkeycode = 7 && DEL
If This.SelStart = 0
This.csearchstring = ""
This.DisplayValue = ""
Else
This.csearchstring = Left(This.csearchstring, This.SelStart) + Right(This.csearchstring, Len(This.csearchstring) - This.SelStart - 1)
This.DisplayValue = This.csearchstring
Endif
m.lnSelStart = Len(This.csearchstring)
Case nkeycode = 127 && BACKSPACE
If This.SelStart = 0
This.csearchstring = ""
This.DisplayValue = ""
Else
This.csearchstring = Left(This.csearchstring, This.SelStart - 1) + Right(This.csearchstring, Len(This.csearchstring) - This.SelStart)
This.DisplayValue = This.csearchstring
m.lnSelStart = Len(This.csearchstring)
Endif
Case nkeycode = 24 && DOWN ARROW
If .Not. Eof()
Skip
Endif
If Eof()
Goto Bottom
Endif
Case nkeycode = 5 && UP ARROW
If .Not. Bof()
Skip -1
Endif
If Bof()
Goto Top
Endif
Case Between(nkeycode, 32, 126) .Or. Between(nkeycode, 97, 122) .Or. Between(nkeycode, 48, 57)
If This.SelStart = 0 .And. This.SelLength > 1
This.csearchstring = Upper(Chr(nkeycode))
Else
This.csearchstring = Left(This.csearchstring, This.SelStart) + Upper(Chr(nkeycode)) + Right(This.csearchstring, Len(This.csearchstring) - This.SelStart)
Endif
m.lnSelStart = This.SelStart + 1
Otherwise
Return
Endcase
NODEFAULT
*** CAUTARE "INCEPE CU"
msemafor = 0
If nkeycode <> 4 .And. nkeycode <> 19 .And. nkeycode <> 5 .And. nkeycode <> 24 .And. .Not. Empty(This.csearchstring)
* Execut cautarea INCEPE CU pe serverul baza de date, daca nu cumva am facut cautarea deja CONTINE la CTRL+ENTER This.Requery(2)
IF !m.llQueried && AND m.lcSearchString <> this.cSearchString
This.prowsource = This.RowSource
this.RowSource = ""
This.RefreshData(1) && cautare incepe cu...
this.RowSource = this.pRowSource
This.prowsource = ""
ENDIF
* Verific daca textul cautat este in inregistrarile selectate (daca am rezultate in cursor)
SELECT (this.pCursorName)
Locate For Upper(Evaluate(This.pfieldactiv)) = Upper(This.csearchstring)
If .Not. Found()
If .Not. Empty(This.pSecondField)
Locate For Evaluate(This.pSecondField) = Upper(This.csearchstring) + " " .Or. Evaluate(This.pSecondField) = "RO" + Upper(This.csearchstring) + " "
If .Not. Found()
Locate For Evaluate(This.pSecondField) = Upper(This.csearchstring) .Or. Evaluate(This.pSecondField) = "RO" + Upper(This.csearchstring)
Endif
If Found()
msemafor = 3
Else
msemafor = 2
Endif
Else
msemafor = 2
Endif
Else
msemafor = 1
Endif
ENDIF
SELECT (this.pCursorName)
If nkeycode <> 7 .And. nkeycode <> 127 .And. nkeycode <> 4 .And. nkeycode <> 19
If (Empty(This.csearchstring) .Or. msemafor = 2) .And. nkeycode <> 5 .And. nkeycode <> 24
If lnrecno > Reccount()
Goto Top
Else
Goto lnrecno
Endif
If .Not. This.llimittolist
This.DisplayValue = This.csearchstring
Else
This.csearchstring = m.lcSearchString
Endif
Else
If msemafor = 1 .Or. nkeycode = 5 .Or. nkeycode = 24
This.DisplayValue = Evaluate(This.pfieldactiv)
Endif
If msemafor = 3
This.DisplayValue = Evaluate(This.pSecondField)
Endif
Endif
Endif
This.SelStart = Max(m.lnSelStart, 0)
If Txtwidth(Rtrim(This.DisplayValue), This.FontName, This.FontSize) * Fontmetric(6, This.FontName, This.FontSize) < This.Width - 15
This.SelLength = Max(Len(Rtrim(This.DisplayValue)) - Len(Rtrim(This.csearchstring)), 0)
Else
This.SelLength = 0
Endif
ENDPROC
PROCEDURE LostFocus
*!* If .Not. Empty(This.prowsource)
*!* This.RowSource = This.prowsource
*!* This.prowsource = ""
*!* This.Requery()
*!* Endif
If .Not. Empty(This.pSecondField)
Select (This.pcursorname)
If This.DisplayValue = EVALUATE(This.pSecondField) .Or. "RO" + this.DisplayValue = EVALUATE(This.pSecondField)
This.DisplayValue = Evaluate(This.pfieldactiv)
Endif
Endif
This.csearchstring = ""
This.SelStart = 0
ENDPROC
PROCEDURE refreshdata
Lparameters tnTip
Local lnTip, lcSourceOrder, lcSourceSql, lcSourceWhere, lcSql, lnHandle, llSucces, lcCursor
Private pcValue
pcValue = ''
lnTip = Iif(Type('tnTip') = 'N', m.tnTip, 0)
If m.lnTip <> 0 AND Len(Alltrim(This.cSearchString)) <= This.nCharCountBegin
Return
Endif
lcSourceSql = This.cSourceSql
lcWhereFirst = This.pFieldActiv + " like ?pcValue"
lcWhereSecond = Iif(!Empty(This.pSecondField), This.pSecondField + " like ?pcValue", "")
lcSourceWhere = [ where ] + Iif(!Empty(This.cSourceWhere), [(] + This.cSourceWhere + [)], []) + [ and (] + m.lcWhereFirst + Iif(!Empty(m.lcWhereSecond), [ or ] + m.lcWhereSecond, []) + [)]
lcSourceOrder = " order by " + Iif(!Empty(This.cSourceOrder), This.cSourceOrder, This.pFieldActiv)
Do Case
Case m.lnTip = 0 && INIT
lcSourceWhere = [ where 1=2]
lcSourceOrder = ""
Case m.lnTip = 1 && CAUTARE INCEPE CU
pcValue = This.cSearchString + '%'
Case m.lnTip = 2 && CAUTARE CONTINE
pcValue = '%' + This.cSearchString + '%'
ENDCASE
lcCursor = 's' + This.pCursorName
lcSql = m.lcSourceSql + m.lcSourceWhere + m.lcSourceOrder
WAIT WINDOW 'RefreshData ' + m.lcSql NOWAIT
llSucces = This.SelectData(m.lcSql, m.lcCursor)
Return m.llSucces
ENDPROC
PROCEDURE selectdata
Lparameters tcSql, tcCursor
Local llSucces
WAIT WINDOW 'Sql: ' + m.tcSql + ' cursor: ' + m.tcCursor + IIF(TYPE('pcValue') = 'C', ' pcValue: ' + m.pcValue, '') NOWAIT
llSucces = goExecutor.oExecuta(m.tcSql, m.tcCursor)
Return m.llSucces
ENDPROC
ENDDEFINE