@netoalmanca/advpl-sensei 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/changelog-generator.md +63 -0
- package/agents/code-generator.md +215 -0
- package/agents/code-reviewer.md +145 -0
- package/agents/debugger.md +83 -0
- package/agents/doc-generator.md +67 -0
- package/agents/docs-reference.md +86 -0
- package/agents/migrator.md +84 -0
- package/agents/process-consultant.md +97 -0
- package/agents/refactorer.md +75 -0
- package/agents/sx-configurator.md +67 -0
- package/commands/changelog.md +66 -0
- package/commands/diagnose.md +67 -0
- package/commands/docs.md +81 -0
- package/commands/document.md +67 -0
- package/commands/explain.md +60 -0
- package/commands/generate.md +111 -0
- package/commands/migrate.md +81 -0
- package/commands/process.md +111 -0
- package/commands/refactor.md +65 -0
- package/commands/review.md +60 -0
- package/commands/sxgen.md +98 -0
- package/commands/test.md +103 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +143 -0
- package/dist/index.js.map +1 -0
- package/package.json +30 -0
- package/skills/advpl-code-generation/SKILL.md +163 -0
- package/skills/advpl-code-generation/patterns-fwformbrowse.md +485 -0
- package/skills/advpl-code-generation/patterns-jobs.md +519 -0
- package/skills/advpl-code-generation/patterns-mvc.md +765 -0
- package/skills/advpl-code-generation/patterns-pontos-entrada.md +708 -0
- package/skills/advpl-code-generation/patterns-rest.md +974 -0
- package/skills/advpl-code-generation/patterns-soap.md +639 -0
- package/skills/advpl-code-generation/patterns-treport.md +481 -0
- package/skills/advpl-code-generation/patterns-workflow.md +779 -0
- package/skills/advpl-code-generation/templates-classes.md +1096 -0
- package/skills/advpl-code-review/SKILL.md +72 -0
- package/skills/advpl-code-review/rules-best-practices.md +444 -0
- package/skills/advpl-code-review/rules-modernization.md +290 -0
- package/skills/advpl-code-review/rules-performance.md +333 -0
- package/skills/advpl-code-review/rules-security.md +302 -0
- package/skills/advpl-debugging/SKILL.md +265 -0
- package/skills/advpl-debugging/common-errors.md +1124 -0
- package/skills/advpl-debugging/performance-tips.md +768 -0
- package/skills/advpl-refactoring/SKILL.md +139 -0
- package/skills/advpl-to-tlpp-migration/SKILL.md +293 -0
- package/skills/advpl-to-tlpp-migration/migration-checklist.md +122 -0
- package/skills/advpl-to-tlpp-migration/migration-rules.md +265 -0
- package/skills/changelog-patterns/SKILL.md +99 -0
- package/skills/code-explanation/SKILL.md +66 -0
- package/skills/documentation-patterns/SKILL.md +172 -0
- package/skills/embedded-sql/SKILL.md +379 -0
- package/skills/probat-testing/SKILL.md +226 -0
- package/skills/probat-testing/patterns-unit-tests.md +614 -0
- package/skills/protheus-business/SKILL.md +92 -0
- package/skills/protheus-business/modulo-compras.md +780 -0
- package/skills/protheus-business/modulo-contabilidade.md +874 -0
- package/skills/protheus-business/modulo-estoque.md +876 -0
- package/skills/protheus-business/modulo-faturamento.md +800 -0
- package/skills/protheus-business/modulo-financeiro.md +1015 -0
- package/skills/protheus-business/modulo-fiscal.md +749 -0
- package/skills/protheus-business/modulo-manutencao.md +848 -0
- package/skills/protheus-business/modulo-pcp.md +743 -0
- package/skills/protheus-reference/SKILL.md +119 -0
- package/skills/protheus-reference/native-functions.md +7029 -0
- package/skills/protheus-reference/rest-api-reference.md +1758 -0
- package/skills/protheus-reference/restricted-functions.md +265 -0
- package/skills/protheus-reference/sx-dictionary.md +854 -0
- package/skills/sx-configuration/SKILL.md +184 -0
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
# Protheus FWFormBrowse Patterns
|
|
2
|
+
|
|
3
|
+
Complete reference for implementing browse and form interfaces using FWFormBrowse, FWExecView, and related classes in TOTVS Protheus.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Overview
|
|
8
|
+
|
|
9
|
+
The FWFormBrowse class provides a grid-type browse object with integrated form capabilities, side buttons, and column details. It is part of the Protheus framework for building CRUD interfaces beyond the standard MVC `FWMBrowse`.
|
|
10
|
+
|
|
11
|
+
Key classes and functions:
|
|
12
|
+
- **FWFormBrowse**: Grid browse with integrated form and side buttons.
|
|
13
|
+
- **FWMBrowse**: Standard MVC browse grid (simpler, dictionary-driven).
|
|
14
|
+
- **FWExecView**: Opens a window displaying an MVC View (FWFormView) of a given source program.
|
|
15
|
+
- **FWFormStruct**: Creates model or view structures from the SX3 data dictionary.
|
|
16
|
+
- **FWBrowse**: Lower-level browse class for custom grid configurations.
|
|
17
|
+
|
|
18
|
+
Required includes:
|
|
19
|
+
```advpl
|
|
20
|
+
#Include "TOTVS.CH"
|
|
21
|
+
#Include "FWMVCDef.ch"
|
|
22
|
+
#Include "FWBROWSE.CH"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 2. FWMBrowse - Standard MVC Browse
|
|
28
|
+
|
|
29
|
+
### 2.1 Basic Usage
|
|
30
|
+
|
|
31
|
+
The simplest way to create a browse grid for an MVC routine:
|
|
32
|
+
|
|
33
|
+
```advpl
|
|
34
|
+
#Include "TOTVS.CH"
|
|
35
|
+
#Include "FWMVCDef.ch"
|
|
36
|
+
|
|
37
|
+
/*/{Protheus.doc} zCadCli
|
|
38
|
+
Cadastro de Clientes com MVC
|
|
39
|
+
@type User Function
|
|
40
|
+
@author Autor
|
|
41
|
+
@since 01/01/2026
|
|
42
|
+
@version 1.0
|
|
43
|
+
/*/
|
|
44
|
+
User Function zCadCli()
|
|
45
|
+
Local oBrowse := Nil
|
|
46
|
+
|
|
47
|
+
oBrowse := FWMBrowse():New()
|
|
48
|
+
oBrowse:SetAlias("SA1")
|
|
49
|
+
oBrowse:SetDescription("Cadastro de Clientes")
|
|
50
|
+
oBrowse:Activate()
|
|
51
|
+
|
|
52
|
+
Return Nil
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 2.2 FWMBrowse Key Methods
|
|
56
|
+
|
|
57
|
+
| Method | Description |
|
|
58
|
+
|--------|-------------|
|
|
59
|
+
| `New()` | Constructor, creates a new browse instance |
|
|
60
|
+
| `SetAlias(cAlias)` | Defines the main table alias |
|
|
61
|
+
| `SetDescription(cDesc)` | Sets the browse title/description |
|
|
62
|
+
| `SetFilterDefault(cFilter)` | Sets a default filter expression |
|
|
63
|
+
| `AddLegend(cExpr, cColor, cDesc)` | Adds a color legend to the browse |
|
|
64
|
+
| `DisableDetails()` | Disables automatic detail display for positioned record |
|
|
65
|
+
| `Activate()` | Activates (displays) the browse |
|
|
66
|
+
|
|
67
|
+
### 2.3 Browse with Legend
|
|
68
|
+
|
|
69
|
+
```advpl
|
|
70
|
+
User Function zCadProd()
|
|
71
|
+
Local oBrowse := Nil
|
|
72
|
+
|
|
73
|
+
oBrowse := FWMBrowse():New()
|
|
74
|
+
oBrowse:SetAlias("SB1")
|
|
75
|
+
oBrowse:SetDescription("Cadastro de Produtos")
|
|
76
|
+
|
|
77
|
+
// Legendas de cor por status
|
|
78
|
+
oBrowse:AddLegend("B1_MSBLQL == '2'", "GREEN", "Ativo")
|
|
79
|
+
oBrowse:AddLegend("B1_MSBLQL == '1'", "RED", "Bloqueado")
|
|
80
|
+
|
|
81
|
+
// Filtro padrao
|
|
82
|
+
oBrowse:SetFilterDefault("B1_TIPO == 'PA'")
|
|
83
|
+
|
|
84
|
+
oBrowse:Activate()
|
|
85
|
+
|
|
86
|
+
Return Nil
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 3. FWFormBrowse - Browse with Integrated Form
|
|
92
|
+
|
|
93
|
+
### 3.1 Constructor and Basic Structure
|
|
94
|
+
|
|
95
|
+
FWFormBrowse provides a more flexible browse that supports custom buttons, form integration, and additional column configurations.
|
|
96
|
+
|
|
97
|
+
```advpl
|
|
98
|
+
#Include "TOTVS.CH"
|
|
99
|
+
#Include "FWBROWSE.CH"
|
|
100
|
+
|
|
101
|
+
User Function zFormBrw()
|
|
102
|
+
Local oBrowse := Nil
|
|
103
|
+
Local oDlg := Nil
|
|
104
|
+
|
|
105
|
+
DbSelectArea("SA1")
|
|
106
|
+
DbSetOrder(1)
|
|
107
|
+
|
|
108
|
+
DEFINE MSDIALOG oDlg FROM 0,0 TO 600,800 PIXEL
|
|
109
|
+
|
|
110
|
+
DEFINE FWFORMBROWSE oBrowse DATA TABLE ALIAS "SA1" OF oDlg
|
|
111
|
+
|
|
112
|
+
oBrowse:Activate()
|
|
113
|
+
|
|
114
|
+
ACTIVATE MSDIALOG oDlg CENTERED
|
|
115
|
+
|
|
116
|
+
Return Nil
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 3.2 FWFormBrowse Key Methods
|
|
120
|
+
|
|
121
|
+
| Method | Description |
|
|
122
|
+
|--------|-------------|
|
|
123
|
+
| `Activate()` | Activates the browse |
|
|
124
|
+
| `AddButton(cTitle, bAction, cToolTip)` | Adds a side button with action |
|
|
125
|
+
| `DisableDetails()` | Disables the detail panel |
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 4. FWExecView - Generic Record View/Edit
|
|
130
|
+
|
|
131
|
+
### 4.1 Syntax
|
|
132
|
+
|
|
133
|
+
```advpl
|
|
134
|
+
FWExecView(cTitle, cProgram, nOperation, oDlg, bCloseOnOK, bOk, nPercReducao, aEnableButtons, bCancel, cOperatId, cToolBar, oModelAct)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
| Parameter | Type | Description |
|
|
138
|
+
|-----------|------|-------------|
|
|
139
|
+
| `cTitle` | Character | Window title |
|
|
140
|
+
| `cProgram` | Character | Name of the MVC program (source with ModelDef/ViewDef) |
|
|
141
|
+
| `nOperation` | Numeric | Operation: 1=View, 3=Insert, 4=Update, 5=Delete |
|
|
142
|
+
| `oDlg` | Object | Discontinued (use Nil) |
|
|
143
|
+
| `bCloseOnOK` | Block | Code block triggered when closing the window |
|
|
144
|
+
| `bOk` | Block | Validation block on Confirm click |
|
|
145
|
+
| `nPercReducao` | Numeric | Window size reduction percentage |
|
|
146
|
+
| `aEnableButtons` | Array | Array of 14 positions controlling button visibility |
|
|
147
|
+
| `bCancel` | Block | Code block triggered on Cancel |
|
|
148
|
+
|
|
149
|
+
### 4.2 aEnableButtons Array Positions
|
|
150
|
+
|
|
151
|
+
| Position | Button | Default |
|
|
152
|
+
|----------|--------|---------|
|
|
153
|
+
| 1 | Copy | `.T.` |
|
|
154
|
+
| 2 | Cut | `.T.` |
|
|
155
|
+
| 3 | Paste | `.T.` |
|
|
156
|
+
| 4 | Calculator | `.T.` |
|
|
157
|
+
| 5 | Spool | `.T.` |
|
|
158
|
+
| 6 | Print | `.T.` |
|
|
159
|
+
| 7 | Confirm | `.T.` |
|
|
160
|
+
| 8 | Cancel | `.T.` |
|
|
161
|
+
| 9 | WalkThrough | `.T.` |
|
|
162
|
+
| 10 | Environment | `.T.` |
|
|
163
|
+
| 11 | Mashup | `.T.` |
|
|
164
|
+
| 12 | Help | `.T.` |
|
|
165
|
+
| 13 | HTML Form | `.T.` |
|
|
166
|
+
| 14 | ECM | `.T.` |
|
|
167
|
+
|
|
168
|
+
Each position is an array of `{lEnabled, cCustomTitle}`.
|
|
169
|
+
|
|
170
|
+
### 4.3 View Record
|
|
171
|
+
|
|
172
|
+
```advpl
|
|
173
|
+
User Function zViewCli()
|
|
174
|
+
Local aArea := GetArea()
|
|
175
|
+
Local cFunBkp := FunName()
|
|
176
|
+
|
|
177
|
+
DbSelectArea("SA1")
|
|
178
|
+
DbSetOrder(1)
|
|
179
|
+
|
|
180
|
+
If DbSeek(xFilial("SA1") + "000001" + "01")
|
|
181
|
+
SetFunName("zCadCli")
|
|
182
|
+
FWExecView("Visualizar Cliente", "zCadCli", MODEL_OPERATION_VIEW)
|
|
183
|
+
SetFunName(cFunBkp)
|
|
184
|
+
Else
|
|
185
|
+
MsgAlert("Cliente nao encontrado.")
|
|
186
|
+
EndIf
|
|
187
|
+
|
|
188
|
+
RestArea(aArea)
|
|
189
|
+
|
|
190
|
+
Return Nil
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### 4.4 Insert with Custom Buttons
|
|
194
|
+
|
|
195
|
+
```advpl
|
|
196
|
+
User Function zIncCli()
|
|
197
|
+
Local aButtons := {}
|
|
198
|
+
Local nI := 0
|
|
199
|
+
|
|
200
|
+
// Configura botoes: desabilita Copy/Cut/Paste, customiza Confirm/Cancel
|
|
201
|
+
For nI := 1 To 14
|
|
202
|
+
aAdd(aButtons, {.T., Nil})
|
|
203
|
+
Next nI
|
|
204
|
+
|
|
205
|
+
// Desabilita Copy, Cut, Paste
|
|
206
|
+
aButtons[1] := {.F., Nil}
|
|
207
|
+
aButtons[2] := {.F., Nil}
|
|
208
|
+
aButtons[3] := {.F., Nil}
|
|
209
|
+
|
|
210
|
+
// Customiza titulo do Confirm e Cancel
|
|
211
|
+
aButtons[7] := {.T., "Salvar"}
|
|
212
|
+
aButtons[8] := {.T., "Cancelar"}
|
|
213
|
+
|
|
214
|
+
FWExecView("Incluir Cliente", "zCadCli", MODEL_OPERATION_INSERT, ;
|
|
215
|
+
Nil, {|| .T.}, Nil, Nil, aButtons)
|
|
216
|
+
|
|
217
|
+
Return Nil
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### 4.5 Edit Positioned Record
|
|
221
|
+
|
|
222
|
+
```advpl
|
|
223
|
+
User Function zEditCli()
|
|
224
|
+
Local aArea := GetArea()
|
|
225
|
+
Local cFunBkp := FunName()
|
|
226
|
+
|
|
227
|
+
DbSelectArea("SA1")
|
|
228
|
+
DbSetOrder(1)
|
|
229
|
+
|
|
230
|
+
If DbSeek(xFilial("SA1") + "000001" + "01")
|
|
231
|
+
SetFunName("zCadCli")
|
|
232
|
+
FWExecView("Alterar Cliente", "zCadCli", MODEL_OPERATION_UPDATE)
|
|
233
|
+
SetFunName(cFunBkp)
|
|
234
|
+
EndIf
|
|
235
|
+
|
|
236
|
+
RestArea(aArea)
|
|
237
|
+
|
|
238
|
+
Return Nil
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## 5. FWFormStruct - SX3 Metadata Structure
|
|
244
|
+
|
|
245
|
+
### 5.1 Constructor
|
|
246
|
+
|
|
247
|
+
```advpl
|
|
248
|
+
oStruct := FWFormStruct(nType, cAlias)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
| Parameter | Type | Description |
|
|
252
|
+
|-----------|------|-------------|
|
|
253
|
+
| `nType` | Numeric | `1` = Model structure, `2` = View structure |
|
|
254
|
+
| `cAlias` | Character | Table alias (SX3 registered) |
|
|
255
|
+
|
|
256
|
+
### 5.2 Key Methods
|
|
257
|
+
|
|
258
|
+
| Method | Description |
|
|
259
|
+
|--------|-------------|
|
|
260
|
+
| `RemoveField(cFieldName)` | Removes a field from the structure |
|
|
261
|
+
| `SetProperty(cFieldName, nProperty, xValue)` | Changes a field property |
|
|
262
|
+
| `AddField(cFieldName, ...)` | Adds a new field to the structure |
|
|
263
|
+
| `AddTrigger(cOrigin, cDest, bWhen, bExec)` | Adds a field trigger |
|
|
264
|
+
|
|
265
|
+
### 5.3 SetProperty Constants (from FWMVCDef.ch)
|
|
266
|
+
|
|
267
|
+
| Constant | Description |
|
|
268
|
+
|----------|-------------|
|
|
269
|
+
| `MODEL_FIELD_WHEN` | Editing condition (code block) |
|
|
270
|
+
| `MODEL_FIELD_INIT` | Initial value (code block) |
|
|
271
|
+
| `MODEL_FIELD_VALID` | Validation (code block) |
|
|
272
|
+
| `MODEL_FIELD_OBRIGAT` | Required field (logical) |
|
|
273
|
+
|
|
274
|
+
### 5.4 Manipulating Structure
|
|
275
|
+
|
|
276
|
+
```advpl
|
|
277
|
+
Static Function ModelDef()
|
|
278
|
+
Local oStSA1 := FWFormStruct(1, "SA1")
|
|
279
|
+
|
|
280
|
+
// Remover campo que nao sera usado
|
|
281
|
+
oStSA1:RemoveField("A1_ZORDER")
|
|
282
|
+
|
|
283
|
+
// Tornar campo obrigatorio
|
|
284
|
+
oStSA1:SetProperty("A1_NOME", MODEL_FIELD_OBRIGAT, .T.)
|
|
285
|
+
|
|
286
|
+
// Definir valor inicial
|
|
287
|
+
oStSA1:SetProperty("A1_LOJA", MODEL_FIELD_INIT, {|| "01"})
|
|
288
|
+
|
|
289
|
+
// Condicao de edicao (somente na inclusao)
|
|
290
|
+
oStSA1:SetProperty("A1_COD", MODEL_FIELD_WHEN, ;
|
|
291
|
+
{|| FWModeInsert()})
|
|
292
|
+
|
|
293
|
+
// Adicionar trigger
|
|
294
|
+
oStSA1:AddTrigger( ;
|
|
295
|
+
"A1_CEP", ; // Campo origem
|
|
296
|
+
"A1_MUN", ; // Campo destino
|
|
297
|
+
{|| .T.}, ; // Condicao
|
|
298
|
+
{|| Posicione("SYR", 1, xFilial("SYR") + M->A1_CEP, "YR_MUN")} ;
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
// ... continua com criacao do modelo
|
|
302
|
+
Return oModel
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## 6. Complete Example - Custom CRUD with FWFormBrowse
|
|
308
|
+
|
|
309
|
+
Full working example of a custom CRUD for a product catalog using FWMBrowse with MVC.
|
|
310
|
+
|
|
311
|
+
```advpl
|
|
312
|
+
#Include "TOTVS.CH"
|
|
313
|
+
#Include "FWMVCDef.ch"
|
|
314
|
+
|
|
315
|
+
/*/{Protheus.doc} zProdMVC
|
|
316
|
+
Cadastro de Produtos customizado com MVC
|
|
317
|
+
@type User Function
|
|
318
|
+
@author Autor
|
|
319
|
+
@since 01/01/2026
|
|
320
|
+
@version 1.0
|
|
321
|
+
/*/
|
|
322
|
+
User Function zProdMVC()
|
|
323
|
+
Local oBrowse := Nil
|
|
324
|
+
|
|
325
|
+
oBrowse := FWMBrowse():New()
|
|
326
|
+
oBrowse:SetAlias("SB1")
|
|
327
|
+
oBrowse:SetDescription("Cadastro de Produtos")
|
|
328
|
+
|
|
329
|
+
// Legendas
|
|
330
|
+
oBrowse:AddLegend("B1_MSBLQL == '2'", "GREEN", "Ativo")
|
|
331
|
+
oBrowse:AddLegend("B1_MSBLQL == '1'", "RED", "Bloqueado")
|
|
332
|
+
|
|
333
|
+
oBrowse:Activate()
|
|
334
|
+
|
|
335
|
+
Return Nil
|
|
336
|
+
|
|
337
|
+
// =============================================================
|
|
338
|
+
// MenuDef
|
|
339
|
+
// =============================================================
|
|
340
|
+
Static Function MenuDef()
|
|
341
|
+
Local aRotina := {}
|
|
342
|
+
|
|
343
|
+
ADD OPTION aRotina TITLE "Visualizar" ACTION "VIEWDEF.ZPRODMVC" OPERATION MODEL_OPERATION_VIEW ACCESS 0
|
|
344
|
+
ADD OPTION aRotina TITLE "Incluir" ACTION "VIEWDEF.ZPRODMVC" OPERATION MODEL_OPERATION_INSERT ACCESS 0
|
|
345
|
+
ADD OPTION aRotina TITLE "Alterar" ACTION "VIEWDEF.ZPRODMVC" OPERATION MODEL_OPERATION_UPDATE ACCESS 0
|
|
346
|
+
ADD OPTION aRotina TITLE "Excluir" ACTION "VIEWDEF.ZPRODMVC" OPERATION MODEL_OPERATION_DELETE ACCESS 0
|
|
347
|
+
ADD OPTION aRotina TITLE "Copiar" ACTION "VIEWDEF.ZPRODMVC" OPERATION MODEL_OPERATION_COPY ACCESS 0
|
|
348
|
+
|
|
349
|
+
Return aRotina
|
|
350
|
+
|
|
351
|
+
// =============================================================
|
|
352
|
+
// ModelDef
|
|
353
|
+
// =============================================================
|
|
354
|
+
Static Function ModelDef()
|
|
355
|
+
Local oModel := Nil
|
|
356
|
+
Local oStSB1 := FWFormStruct(1, "SB1")
|
|
357
|
+
|
|
358
|
+
// Remover campos desnecessarios
|
|
359
|
+
oStSB1:RemoveField("B1_ZORDER")
|
|
360
|
+
|
|
361
|
+
// Tornar campos obrigatorios
|
|
362
|
+
oStSB1:SetProperty("B1_DESC", MODEL_FIELD_OBRIGAT, .T.)
|
|
363
|
+
oStSB1:SetProperty("B1_UM", MODEL_FIELD_OBRIGAT, .T.)
|
|
364
|
+
oStSB1:SetProperty("B1_TIPO", MODEL_FIELD_OBRIGAT, .T.)
|
|
365
|
+
|
|
366
|
+
// Valor inicial para tipo
|
|
367
|
+
oStSB1:SetProperty("B1_TIPO", MODEL_FIELD_INIT, {|| "PA"})
|
|
368
|
+
|
|
369
|
+
// Valor inicial para unidade de medida
|
|
370
|
+
oStSB1:SetProperty("B1_UM", MODEL_FIELD_INIT, {|| "UN"})
|
|
371
|
+
|
|
372
|
+
// Cria modelo
|
|
373
|
+
oModel := MPFormModel():New("ZPRODMVC", ;
|
|
374
|
+
{|oMdl| PreValidProd(oMdl)}, ;
|
|
375
|
+
{|oMdl| PosValidProd(oMdl)}, ;
|
|
376
|
+
{|oMdl| CommitProd(oMdl)}, ;
|
|
377
|
+
{|oMdl| CancelProd(oMdl)} ;
|
|
378
|
+
)
|
|
379
|
+
oModel:SetDescription("Cadastro de Produtos")
|
|
380
|
+
|
|
381
|
+
// Master - Dados do produto
|
|
382
|
+
oModel:AddFields("SB1MASTER", /*cOwner*/, oStSB1)
|
|
383
|
+
oModel:SetPrimaryKey({"B1_FILIAL", "B1_COD"})
|
|
384
|
+
|
|
385
|
+
Return oModel
|
|
386
|
+
|
|
387
|
+
// Pre-validacao
|
|
388
|
+
Static Function PreValidProd(oModel)
|
|
389
|
+
Local lRet := .T.
|
|
390
|
+
Local oMaster := oModel:GetModel("SB1MASTER")
|
|
391
|
+
Local cDesc := oMaster:GetValue("B1_DESC")
|
|
392
|
+
|
|
393
|
+
If Empty(cDesc)
|
|
394
|
+
Help(Nil, Nil, "PRODVAL", Nil, "Descricao do produto e obrigatoria.", 1, 0)
|
|
395
|
+
lRet := .F.
|
|
396
|
+
EndIf
|
|
397
|
+
|
|
398
|
+
Return lRet
|
|
399
|
+
|
|
400
|
+
// Pos-validacao
|
|
401
|
+
Static Function PosValidProd(oModel)
|
|
402
|
+
Return .T.
|
|
403
|
+
|
|
404
|
+
// Commit
|
|
405
|
+
Static Function CommitProd(oModel)
|
|
406
|
+
FWFormCommit(oModel)
|
|
407
|
+
Return Nil
|
|
408
|
+
|
|
409
|
+
// Cancel
|
|
410
|
+
Static Function CancelProd(oModel)
|
|
411
|
+
FWFormCancel(oModel)
|
|
412
|
+
Return Nil
|
|
413
|
+
|
|
414
|
+
// =============================================================
|
|
415
|
+
// ViewDef
|
|
416
|
+
// =============================================================
|
|
417
|
+
Static Function ViewDef()
|
|
418
|
+
Local oView := Nil
|
|
419
|
+
Local oModel := FWLoadModel("ZPRODMVC")
|
|
420
|
+
Local oStSB1 := FWFormStruct(2, "SB1")
|
|
421
|
+
|
|
422
|
+
oView := FWFormView():New()
|
|
423
|
+
oView:SetModel(oModel)
|
|
424
|
+
|
|
425
|
+
oView:AddField("VIEW_SB1", oStSB1, "SB1MASTER")
|
|
426
|
+
|
|
427
|
+
oView:CreateHorizontalBox("BOXPROD", 100)
|
|
428
|
+
oView:SetOwnerView("VIEW_SB1", "BOXPROD")
|
|
429
|
+
|
|
430
|
+
oView:EnableTitleView("VIEW_SB1", "Dados do Produto")
|
|
431
|
+
|
|
432
|
+
Return oView
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
## 7. FWExecView with Reduced Window
|
|
438
|
+
|
|
439
|
+
Use `nPercReducao` to show the MVC form in a smaller popup window:
|
|
440
|
+
|
|
441
|
+
```advpl
|
|
442
|
+
// Abre a view com 30% de reducao de tamanho
|
|
443
|
+
FWExecView("Detalhes do Produto", "ZPRODMVC", MODEL_OPERATION_VIEW, ;
|
|
444
|
+
Nil, {|| .T.}, Nil, 30)
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
---
|
|
448
|
+
|
|
449
|
+
## 8. Programmatic Access via FWLoadModel
|
|
450
|
+
|
|
451
|
+
You can load and manipulate a model programmatically without any UI:
|
|
452
|
+
|
|
453
|
+
```advpl
|
|
454
|
+
User Function zLoadProd()
|
|
455
|
+
Local oModel := Nil
|
|
456
|
+
Local oMaster := Nil
|
|
457
|
+
Local lRet := .F.
|
|
458
|
+
|
|
459
|
+
// Carrega o modelo
|
|
460
|
+
oModel := FWLoadModel("ZPRODMVC")
|
|
461
|
+
oModel:SetOperation(MODEL_OPERATION_INSERT)
|
|
462
|
+
oModel:Activate()
|
|
463
|
+
|
|
464
|
+
// Acessa o submodelo master
|
|
465
|
+
oMaster := oModel:GetModel("SB1MASTER")
|
|
466
|
+
|
|
467
|
+
// Define valores
|
|
468
|
+
oMaster:SetValue("B1_COD", "TST001")
|
|
469
|
+
oMaster:SetValue("B1_DESC", "Produto Teste Programatico")
|
|
470
|
+
oMaster:SetValue("B1_TIPO", "PA")
|
|
471
|
+
oMaster:SetValue("B1_UM", "UN")
|
|
472
|
+
|
|
473
|
+
// Valida e grava
|
|
474
|
+
If oModel:VldData()
|
|
475
|
+
oModel:CommitData()
|
|
476
|
+
lRet := .T.
|
|
477
|
+
Conout("Produto incluido com sucesso!")
|
|
478
|
+
Else
|
|
479
|
+
Conout("Erro na validacao do produto.")
|
|
480
|
+
EndIf
|
|
481
|
+
|
|
482
|
+
oModel:DeActivate()
|
|
483
|
+
|
|
484
|
+
Return lRet
|
|
485
|
+
```
|