1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
| Public oForm
oForm = Createobject("myForm")
oForm.Show
Define Class myForm As Form
DataSession = 2
Top = 0
Left = 0
Height = 398
Width = 426
DoCreate = .T.
Caption = "Form1"
Visible = .T.
Name = "Form1"
Add Object txtpid As TextBox With ;
Comment = "", ;
ControlSource = "fatparent.pkid", ;
Height = 23, ;
Left = 108, ;
TabIndex = 4, ;
Top = 12, ;
Width = 81, ;
Name = "txtPid"
Add Object lblpid As Label With ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "Pid", ;
Left = 74, ;
Top = 18, ;
TabIndex = 3, ;
Name = "lblPid"
Add Object txtparentname As TextBox With ;
Comment = "", ;
ControlSource = "fatparent.fatname", ;
Height = 23, ;
Left = 106, ;
TabIndex = 8, ;
Top = 41, ;
Width = 132, ;
Name = "txtParentname"
Add Object lblparentname As Label With ;
AutoSize = .T., ;
BackStyle = 0, ;
Caption = "Parentname", ;
Left = 28, ;
Top = 44, ;
TabIndex = 7, ;
Name = "lblParentname"
Add Object txtmiktar As TextBox With ;
Alignment = 3, ;
Value = 0, ;
Height = 23, ;
Left = 275, ;
Top = 336, ;
Width = 137, ;
Name = "txtMiktar"
Add Object txttoplam As TextBox With ;
Alignment = 3, ;
Value = 0, ;
Height = 23, ;
Left = 275, ;
Top = 366, ;
Width = 137, ;
Name = "txtToplam"
Add Object label1 As Label With ;
Caption = "Toplam", ;
Height = 17, ;
Left = 227, ;
Top = 366, ;
Width = 43, ;
Name = "Label1"
Add Object label2 As Label With ;
Caption = "Miktar", ;
Height = 17, ;
Left = 234, ;
Top = 336, ;
Width = 36, ;
Name = "Label2"
Add Object grid1 As Grid With ;
ColumnCount = 4, ;
AllowAddNew = .f., ;
Height = 253, ;
Left = 24, ;
Top = 72, ;
Width = 389, ;
Name = "Grid1"
Add Object commandgroup1 As CommandGroup With ;
AutoSize = .F., ;
ButtonCount = 4, ;
Value = 1, ;
Height = 37, ;
Left = 264, ;
Top = 24, ;
Width = 144, ;
Name = "Commandgroup1", ;
Command1.AutoSize = .F., ;
Command1.Top = 5, ;
Command1.Left = 5, ;
Command1.Height = 27, ;
Command1.Width = 32, ;
Command1.Caption = "<<", ;
Command1.Name = "Command1", ;
Command2.AutoSize = .F., ;
Command2.Top = 5, ;
Command2.Left = 39, ;
Command2.Height = 27, ;
Command2.Width = 32, ;
Command2.Caption = "<", ;
Command2.Name = "Command2", ;
Command3.AutoSize = .F., ;
Command3.Top = 5, ;
Command3.Left = 73, ;
Command3.Height = 27, ;
Command3.Width = 32, ;
Command3.Caption = ">", ;
Command3.Name = "Command3", ;
Command4.AutoSize = .F., ;
Command4.Top = 5, ;
Command4.Left = 107, ;
Command4.Height = 27, ;
Command4.Width = 32, ;
Command4.Caption = ">>", ;
Command4.Name = "Command4"
Procedure parentchanged
* Parent degistiginde normal olarak tableupdate() olacak veya revert
* Boylece select-sql dogru sonuc verecek
Tableupdate(2,.T.,'FatParent')
Tableupdate(2,.T.,'FatChild')
External Array arrToplam
Select Sum(Fiyat*Miktar), Sum(Miktar) ;
from FatChild ;
where ParId = FatParent.PkId ;
into Array arrToplam
Thisform.txttoplam.Value = Iif(_Tally=0,0,arrToplam[1,1])
Thisform.txtmiktar.Value = Iif(_Tally=0,0,arrToplam[1,2])
Endproc
Procedure Load
Set Exclusive Off
Set Multilocks On
Set Deleted On
Rand(-1)
Create Cursor FatParent (PkId i,FatName c(10))
Create Cursor FatChild (ParId i,Aciklama c(20), Fiyat i, Miktar i)
Index On ParId Tag ParId
For ix = 1 To 20
lcParName = 'Test'+Padl(ix,3,'0')
Insert Into FatParent Values (ix,lcParName)
lnChilds = Int(Rand()*10)+1
For jx = 1 To lnChilds
Insert Into FatChild ;
values ;
(ix,lcParName+' - Item'+Padl(jx,2,'0'),;
(Int(Rand()*10)+1)*1000,Int(Rand()*5)+1)
Endfor
Endfor
CursorSetProp('Buffering',5,'FatParent')
CursorSetProp('Buffering',5,'FatChild')
Select FatParent
Go Top
Set Relation To PkId Into FatChild
Endproc
Procedure Init
With Thisform.grid1
.RecordSource = 'FatChild'
.Columns(1).ControlSource = 'FatChild.Aciklama'
With .Columns(2)
.ControlSource = 'FatChild.Fiyat'
.Header1.Caption = "Price"
.AddObject("myTextbox","myTextBox",;
"thisform.txtToplam, %%delta%% * FatChild.Miktar" )
.CurrentControl="myTextbox"
.myTextBox.Visible = .T.
Endwith
With .Columns(3)
.ControlSource = 'FatChild.Miktar'
.Header1.Caption = "Quantity"
.AddObject("myTextbox","myTextBox",;
"thisform.txtToplam, %%delta%% * FatChild.Fiyat"+;
",thisform.txtMiktar, %%delta%%" )
.CurrentControl="myTextbox"
.myTextBox.Visible = .T.
Endwith
.Columns(3).ControlSource = 'FatChild.Miktar'
.Columns(4).ControlSource = '(FatChild.Fiyat*FatChild.Miktar)'
.Columns(4).Header1.Caption = "ExtendedPrice"
Endwith
Thisform.parentchanged()
Endproc
Procedure grid1.AfterRowColChange
Lparameters nColIndex
If Empty(FatChild.ParId)
Replace ParId With FatParent.PkId In 'FatChild'
Endif
Endproc
Procedure commandgroup1.Valid
Select FatParent
Do Case
Case This.Value = 1
Go Top
Case This.Value = 2
Skip -1
If Bof()
Go Top
Endif
Case This.Value = 3
Skip
If Eof()
Go Bottom
Endif
Case This.Value = 4
Go Bottom
Endcase
Thisform.parentchanged()
Thisform.Refresh
Endproc
Enddefine
Define Class myTextBox As TextBox
Calculation = ""
Procedure Init
Lparameters tcCalculationPairs
This.Calculation = m.tcCalculationPairs
Endproc
Procedure GotFocus
This.Tag = Transform(This.Value)
Endproc
Procedure LostFocus
Local lnDelta,ix
Local Array aCalculation[1]
lnDelta = Evaluate(This.ControlSource) - Val(This.Tag)
For ix=1 To Alines(aCalculation,This.Calculation,.T.,',')-1 Step 2
With Evaluate(aCalculation[m.ix])
.Value = .Value + ;
Evaluate( Stuff(aCalculation[m.ix+1],;
Atc('%%delta%%',aCalculation[m.ix+1]),Len('%%delta%%'),'m.lnDelta') )
Endwith
Endfor
Endproc
Enddefine |