Page 1 of 1
3 levels categories
Posted:
Sun Apr 21, 2013 4:25 pm
by Silvio.Falconi
I'm thinking to create 3 levels of categories for a store
Level 1 : 2 Characters (es. 11)
Level 2 : 2 Characters (es. 1122)
Level 3 : 4 Characters (es. 11223333)
sample :
cCodice:= 01020001
cDesc := Italian keyboard black
I have some problems to build valid at get when the user insert a new record because the valid function must to control if there is the higher-level of the code he inserted
Isample : if the user insert the code := 01020001
he must insert before 01 keyboard, 0102 Italian Keyboard and then he can insert the new category
Any help please to build the valid function
Re: 3 levels categories
Posted:
Sun Apr 21, 2013 4:44 pm
by ADutheil
You can split the get into 3 gets so you can validate them separately.
Re: 3 levels categories
Posted:
Sun Apr 21, 2013 5:11 pm
by Silvio.Falconi
sorry I have allready the dbf, and I must use this (from customer) look this :
Re: 3 levels categories
Posted:
Sun Apr 21, 2013 6:12 pm
by Antonio Mart.
Silvio,
Here at the levels we call families of items.
So you should have your stored configuration in a field the levels of your families of items.
Example:
If your levels are 2,2,4 you can store "020408"
To find that there are higher levels of hierarchy you can use:
- Code: Select all Expand view
FUNCTION lExistLevels(cItem)
Local lExist:= .f.
Local cLevels:= "020408" // From config field
Local nMaxItem:= Val(Right(cLevels, 2))
Local nI, nAt:= At(StrZero(Len(cItem), 2), cLevels)- 2
Local nLevel, cSubItem
FOR nI:= 1 TO nAt STEP 2
nLevel:= SubStr(cLevels, nI, 2)
cSubItem:= Left(cItem, nLevel)
SELECT Items
SEEK PadR(cSubItem, nMaxItem)
IF Eof()
lExist:= .f.
EXIT
ENDIF
lExist:= .t.
NEXT
RETURN lExist
Regards
Re: 3 levels categories
Posted:
Sun Apr 21, 2013 7:27 pm
by Silvio.Falconi
perhaps it is that I'm searching... I must make some tests
Re: 3 levels categories
Posted:
Sun Apr 21, 2013 8:14 pm
by Silvio.Falconi
Antonio Mart.,
the function can run ok only when I digit a string of 8 Cr the function run ok
if I digit a string of 6 cr it is bad code I can have only 3 levels
for sample
aa
aabb
aabbcccc
the function must return a string aabbcc as right ...
Re: 3 levels categories
Posted:
Mon Apr 22, 2013 12:04 am
by FranciscoA
Silvio.
You can do this:
Static nLenCode := 8
Redefine get oget var cvar id 4000 of odlg Valid cCodeOk(cvar)
Function cCodeOK(cVar)
if !MyCatal->(dbseek(cVar)) .or. len(alltrim(cVar)) != nLenCode
Stop("Bad code inserted")
return .f.
endif
Return .t.
This is only for transactions validations.
I hope it helps you.
Regards.
Re: 3 levels categories
Posted:
Mon Apr 22, 2013 12:30 am
by ADutheil
The DBF does not matter.
get var1 valid ...
get var2 valid ...
get var3 valid ...
read
field_to_save := var1 +var2 + var3