Skip to content

Commit ebd7aa6

Browse files
author
Andrews Egas
committed
Versão 4.00 parametro no .INI
Essa versão faz o UTCTOOL ser executado de forma transparente com o parametro utctool=1 no .INI do server Tambem foi criado o parametro utcfiles=123456 para escolher quais dos tipos de arquivos deseja gerar agora o UTCTOOL pode ser utilizado normalmente junto com o protheus sem alterar o SmartClient.exe
1 parent d1651b8 commit ebd7aa6

File tree

2 files changed

+344
-64
lines changed

2 files changed

+344
-64
lines changed

Diff for: UTCClass.prw

+185-18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/*/
1414
CLASS UTCClass FROM FwModelEvent
1515
DATA _cProgram as char
16+
DATA _lAuto as logical
1617
DATA cNegField as char
1718
DATA cNegVal as char
1819
DATA Def0 as Array
@@ -43,6 +44,7 @@ CLASS UTCClass FROM FwModelEvent
4344
4445
METHOD New() constructor
4546
METHOD SetProgram()
47+
METHOD SetAuto()
4648
//Padroes do Observer
4749
METHOD DeActivate()
4850
METHOD Activate()
@@ -64,6 +66,7 @@ CLASS UTCClass FROM FwModelEvent
6466
METHOD GenerateKanoah()
6567
METHOD FieldTypeStr()
6668
METHOD GenerateTIR()
69+
METHOD GenerateRotAuto()
6770
METHOD UtcFinalGenerate()
6871
6972
END CLASS
@@ -76,6 +79,7 @@ constructor
7679
/*/
7780
METHOD new() class UTCClASS
7881
::_cProgram := ""
82+
::_lAuto := .F.
7983
8084
//Def0
8185
::Def0 := Array(3)
@@ -153,6 +157,19 @@ Method SetProgram(cProgram) Class UTCClass
153157
154158
Return
155159
160+
/*/{Protheus.doc} setProgram
161+
Set if is automatic from .INI
162+
163+
@author Andrews.Egas
164+
@since 17/07/2018
165+
@version 1.0
166+
/*/
167+
Method SetAuto(lAuto) Class UTCClass
168+
169+
::_lAuto := lAuto
170+
171+
Return
172+
156173
/*/{Protheus.doc} Activate
157174
Model Activate to start variables
158175
@author Andrews.Egas
@@ -450,7 +467,7 @@ If ::DEF_MASTER <> NIL //If it runs before it open the view will be .F.
450467
If oSubModel:GetModel():GetIdField(aKey[n],@oModelOw) > 0
451468
xValue := oModelOw:GetValue(aKey[n],nLine)
452469
Else
453-
xValue := oSubModel:GetValue(aKey[n],nLine)
470+
Loop
454471
EndIf
455472
456473
If ValType(xValue) == "D"
@@ -476,7 +493,9 @@ If ::DEF_MASTER <> NIL //If it runs before it open the view will be .F.
476493
477494
Next
478495
479-
::UpdCheckPoint(ctable,cQuery,aKey,aValues,AllTrim(str(nLine)))
496+
If !Empty(aValues) .And. !Empty(aValues[1])
497+
::UpdCheckPoint(ctable,cQuery,aKey,aValues,AllTrim(str(nLine)))
498+
EndIf
480499
EndIf
481500
conout(" GRID POS ")
482501
@@ -755,10 +774,10 @@ EndIf
755774
cFileName := ::_cProgram
756775
757776
// CSV Creation
758-
If !File(cFileName + "_" + cName + ".CSV") //check if the file already exist, and create next one
759-
nBFile := FCREATE(cFileName + "_" + cName + ".CSV")
777+
If !File("\UTCTOOL\" +cFileName + "_" + cName + ".CSV") //check if the file already exist, and create next one
778+
nBFile := FCREATE("\UTCTOOL\" + cFileName + "_" + cName + ".CSV")
760779
Else
761-
nBFile := FCREATE(cFileName + "_" + cName + "_002"+".CSV")//changehere
780+
nBFile := FCREATE("\UTCTOOL\" + cFileName + "_" + cName + "_002"+".CSV")//changehere
762781
EndIf
763782
764783
If nBFile == -1 //check if was possible to crate the file
@@ -1114,10 +1133,10 @@ lRet := .T.
11141133
cFileName := ::_cProgram
11151134
11161135
// PRW Creation
1117-
If !File(cFileName + "_" + cName + ".PRW") //check if the file already exist, and create next one
1118-
nBFile := FCREATE(cFileName + "_" + cName + ".PRW")
1136+
If !File("\UTCTOOL\" +cFileName + "_" + cName + ".PRW") //check if the file already exist, and create next one
1137+
nBFile := FCREATE("\UTCTOOL\" + cFileName + "_" + cName + ".PRW")
11191138
Else
1120-
nBFile := FCREATE(cFileName + "_" + cName + "_002"+".PRW")//changehere
1139+
nBFile := FCREATE("\UTCTOOL\" + cFileName + "_" + cName + "_002"+".PRW")//changehere
11211140
EndIf
11221141
11231142
If nBFile == -1 //check if was possible to crate the file
@@ -1261,10 +1280,10 @@ cFileName := ::_cProgram
12611280
12621281
12631282
// Kanoah Creation
1264-
If !File(cFileName + "_" + cName + ".TXT") //check if the file already exist, and create next one
1265-
nBFile := FCREATE(cFileName + "_" + cName + ".TXT")
1283+
If !File("\UTCTOOL\" +cFileName + "_" + cName + ".TXT") //check if the file already exist, and create next one
1284+
nBFile := FCREATE("\UTCTOOL\" + cFileName + "_" + cName + ".TXT")
12661285
Else
1267-
nBFile := FCREATE(cFileName + "_" + cName + "_002"+".TXT")//changehere
1286+
nBFile := FCREATE("\UTCTOOL\" + cFileName + "_" + cName + "_002"+".TXT")//changehere
12681287
EndIf
12691288
12701289
If nBFile == -1 //check if was possible to crate the file
@@ -1387,10 +1406,10 @@ lRet := .T.
13871406
cFileName := ::_cProgram
13881407
13891408
// Kanoah Creation
1390-
If !File(cFileName + "_" + cName + ".py") //check if the file already exist, and create next one
1391-
nBFile := FCREATE(cFileName + "_" + cName + ".py")
1409+
If !File("\UTCTOOL\" +cFileName + "_" + cName + ".py") //check if the file already exist, and create next one
1410+
nBFile := FCREATE("\UTCTOOL\" + cFileName + "_" + cName + ".py")
13921411
Else
1393-
nBFile := FCREATE(cFileName + "_" + cName + "_002"+".py")//changehere
1412+
nBFile := FCREATE("\UTCTOOL\" + cFileName + "_" + cName + "_002"+".py")//changehere
13941413
EndIf
13951414
13961415
If nBFile == -1 //check if was possible to crate the file
@@ -1518,6 +1537,127 @@ EndIf
15181537
15191538
Return
15201539
1540+
//-------------------------------------------------------------------
1541+
/*/{Protheus.doc} GenerateRotAuto
1542+
generates the PRW file for automatic routines
1543+
1544+
@author andrews.egas
1545+
@since 18/07/2019
1546+
@version 1.0
1547+
1548+
/*/
1549+
//-------------------------------------------------------------------
1550+
METHOD GenerateRotAuto(oModel, cName) Class UTCClASS
1551+
Local lRet as logical
1552+
Local nBFile as numeric
1553+
Local cFileName as Character
1554+
Local cContFile as Character
1555+
Local n as numeric
1556+
Local nItem as numeric
1557+
Local cConteType as Character
1558+
1559+
lRet := .T.
1560+
1561+
cFileName := ::_cProgram
1562+
1563+
// PRW Creation
1564+
If !File("\UTCTOOL\" +cFileName + "_AUTO_" + cName + ".PRW") //check if the file already exist, and create next one
1565+
nBFile := FCREATE("\UTCTOOL\" + cFileName + "_AUTO_" + cName + ".PRW")
1566+
Else
1567+
nBFile := FCREATE("\UTCTOOL\" + cFileName + "_AUTO_" + cName + "_002"+".PRW")//changehere
1568+
EndIf
1569+
1570+
If nBFile == -1 //check if was possible to crate the file
1571+
MsgStop('Erro ao criar destino. Ferror = '+str(ferror(),4),'Erro')
1572+
lRet := .F.
1573+
Else
1574+
//variables
1575+
cContFile :="" //start writing the file
1576+
1577+
cContFile += "/*/{Protheus.doc} " + cFileName + "Auto" + cFileName + "_01()" + CRLF
1578+
cContFile += "auto creation" + CRLF
1579+
cContFile += "@author UTCTOOL" + CRLF
1580+
cContFile += "@since " + dtoc(dDatabase) + CRLF
1581+
cContFile += "@version 1.0" + CRLF
1582+
cContFile += "/*/" + CRLF
1583+
1584+
cContFile += "User Function " + cFileName + "_01()" + CRLF
1585+
cContFile += "Local dDataBase := cTod('" + dToC(&(::DEF_VARS[3])) +"')" + CRLF
1586+
1587+
cContFile += "Local oModel := FWLoadModel('" + cFileName + "')" + CRLF
1588+
1589+
//DBSEEK
1590+
If !Empty(::SEEK[1]) //check if there is SEEK in this test case (Update or delete)
1591+
cContFile += CRLF
1592+
cContFile += "dbSelectArea('" + ::SEEK[2] + "')" + CRLF
1593+
cContFile += "('" + ::SEEK[2] + "')->(DbSetOrder( " + ::SEEK[3] + " ) )" + CRLF
1594+
cContFile += "('" + ::SEEK[2] + "')->(DbSeek(" + ::SEEK[4] + "))" + CRLF
1595+
cContFile += CRLF
1596+
EndIf
1597+
1598+
//Feed Variables and Activate
1599+
cContFile += "oModel:SetOperation(" + ::OPERATION[2] + ")" + CRLF
1600+
cContFile += "oModel:Activate()" + CRLF + CRLF
1601+
1602+
1603+
//Master
1604+
If !Empty(::DEF_MASTER[1][2]) //If we don't have Master it is DELETE
1605+
For n := 1 to Len(::DEF_MASTER)
1606+
cContFile += CRLF //master Head
1607+
//master
1608+
cContFile += "//Start " + ::DEF_MASTER[n][2] + CRLF
1609+
1610+
For nItem := 3 to Len(::DEF_MASTER[n])
1611+
//return the transformation
1612+
cConteType := ::FieldTypeStr(oModel:GetModel(::DEF_MASTER[n][2]):GetStruct():GetFields(),::DEF_MASTER[n][nItem],::DATA_MASTER[n][nItem])
1613+
If !Empty(cConteType)
1614+
cContFile += "oModel:GetModel('" + ::DEF_MASTER[n][2] + "'):SetValue('" + ::DEF_MASTER[n][nItem] + "', " + cConteType + ")" + CRLF
1615+
EndIf
1616+
Next
1617+
Next
1618+
EndIf
1619+
1620+
//Details
1621+
If !Empty(::DEF_ITEMS[1][2]) //check if we have details in this test
1622+
For n := 1 to Len(::DEF_ITEMS)
1623+
1624+
//validation to check if we need to use addLine (Ex:CNBDETAIL2)
1625+
If n > 1 .And. Val(substr(::DEF_ITEMS[n][2],Len(::DEF_ITEMS[n][2]),1)) > 1
1626+
cContFile += CRLF
1627+
cContFile += "oModel:GetModel('" + ::DATA_ITEMS[n][2] + "'):AddLine()" + CRLF
1628+
EndIf
1629+
1630+
cContFile += CRLF //start Details
1631+
cContFile += "//Start " + ::DATA_ITEMS[n][2] + CRLF
1632+
1633+
For nItem := 3 to Len(::DEF_ITEMS[n])
1634+
cConteType := ::FieldTypeStr(oModel:GetModel(::DATA_ITEMS[n][2]):GetStruct():GetFields(),::DEF_ITEMS[n][nItem],::DATA_ITEMS[n][nItem])
1635+
If !Empty(cConteType)
1636+
cContFile += "oModel:GetModel('" + ::DATA_ITEMS[n][2] + "'):SetValue('" + ::DEF_ITEMS[n][nItem] + "', " + cConteType + ")" + CRLF
1637+
EndIf
1638+
Next
1639+
Next
1640+
EndIf
1641+
1642+
//Commit
1643+
cContFile += CRLF
1644+
cContFile += "oModel:CommitData()" + CRLF
1645+
1646+
cContFile += "Return " + CRLF
1647+
1648+
cContFile += CRLF
1649+
conout("Criado Auto PRW")
1650+
1651+
FWRITE(nBFile,cContFile)
1652+
1653+
FCLOSE(nBFile)
1654+
1655+
MsgInfo(cFileName + "_AUTO_" + cName + ".PRW successfully generated", 'Test Case')
1656+
EndIf
1657+
1658+
Return
1659+
1660+
15211661
//-------------------------------------------------------------------
15221662
/*/{Protheus.doc} FieldTypeStr
15231663
Return the type transformed in string, ex 01/01/2001 returns "CtoD('01/01/2001')"
@@ -1567,12 +1707,32 @@ Return the type transformed in string, ex 01/01/2001 returns "CtoD('01/01/2001')
15671707
/*/
15681708
//-------------------------------------------------------------------
15691709
Method UtcFinalGenerate(oModel) Class UTCClass
1710+
Local bError := ErrorBlock({|e| MyErr(e)})
1711+
Local cName := ""
15701712
1571-
aCheck := UTCCkBox() //1-TestCase.PRW, 2- Group/Suite.PRW 3- Kanoah, 4- TestCase TIR python, 5- Template.CSV
1572-
cName := Alltrim(GetRoutine("Test Name"))
1713+
if !EMPTY(oModel:cSource)
1714+
::SetProgram(oModel:cSource)
1715+
EndIf
1716+
1717+
If !(::_lAuto)
1718+
aCheck := UTCCkBox() //1-TestCase.PRW, 2- Group/Suite.PRW 3- Kanoah, 4- TestCase TIR python, 5- Template.CSV
1719+
cName := Alltrim(GetRoutine("Test Name"))
1720+
Else
1721+
If GetSrvProfString("utcfiles","0") <> "0"
1722+
cfiles := GetSrvProfString("utcfiles","0")
1723+
aCheck := {"1" $ cfiles , "2" $ cfiles , "3" $ cfiles , "4" $ cfiles , "5" $ cfiles , "6" $ cfiles} //create just TestCase e Kanoah
1724+
else
1725+
aCheck := {.T.,.F.,.T.,.F.,.F.,.F.} //create just TestCase e Kanoah
1726+
EndIf
1727+
1728+
cName := "_" + STRTRAN(Time(),":","_")
1729+
EndIf
15731730
15741731
If aCheck[1]
1575-
::GeneratePrw(oModel,cName)
1732+
// BEGIN SEQUENCE
1733+
::GeneratePrw(oModel,cName)
1734+
// END SEQUENCE
1735+
// ErrorBlock(bError)
15761736
EndIf
15771737
If aCheck[2]
15781738
UTCSources()
@@ -1586,5 +1746,12 @@ EndIf
15861746
If aCheck[5]
15871747
::GenerateCsv(cName)
15881748
EndIf
1749+
If aCheck[6]
1750+
::GenerateRotAuto(oModel,cName)
1751+
EndIf
1752+
1753+
Return
15891754
1590-
Return
1755+
Static Function MyErr()
1756+
BREAK
1757+
Return .T.

0 commit comments

Comments
 (0)