Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Intrinsic Object reference to rows in GRID?
Message
De
30/10/2001 07:45:19
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
29/10/2001 19:35:28
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00574823
Message ID:
00574935
Vues:
32
>There may be a totally simple and superior way to do this, but I am currently befuddled as to how to achieve the following:
>
>The scenario:
>
>1. Parent/Child form - Invoice/WorkOrder
>2. Grid on form - line-items related to Invoice/WorkOrder #. The RecordSource for the grid is an alias.
>3. Invoice total field = total of calculated qty*price in lineitems grid.
>4. I wish to keep form buffered to allow rollback (don't we all love to be able to change our minds?)
>5. Would like to be able to update invoice total on InteractiveChange event of qty or price controls.
>
>So, to achieve above, I try to store the value in the source table by changing the bound control, and do a requery, as follows;
>
>SELECT sum(qnty*price) as invototal FROM involine WHERE docnum = ;
>ThisForm.Pageframe1.Page1.txtDocnum.value INTO CURSOR _xtotal
>replace invoice.amount with _xtotal.invototal
>ThisForm.Pageframe1.Page1.Basecont1.txtInvoAmt.Value = _xtotal.invototal
>ThisForm.Pageframe1.Page1.Basecont1.txtInvoAmt.Refresh()
>
>
>This yields sporadic and unintelligible results, which is understandable in a buffered situation.
>
>So next, I go looking for properties of the grid that might useful. There, I find ColumnCount, but no RowCount. I think that if I had a RowCount property I could do a quick FOR... NEXT loop or something.
>
>As I type this a glimmer enters my mind about calculating the rowcount by doing a COUNT on the ALIAS against records matching my relational expression, maybe building it into my GRID class.
>
>Is there something already in the language that does most of this, or do I have to keep playing the Mad Inventor?

Andrew,
If you do a scan..endscan on recordsource (alias of child) you could get your buffered data. However you don't need and wouldn't want to move pointer in most cases. SQL operates with data on disk - tableupdated set but that's enough. Scenario goes like this :
-When parent changes data is likely to be tableupdated (or reverted) and thus have SQL selectable data for a particular parentID. SQL sum there and update textbox.value (invoice total replacement should go to tableupdate point, no need to replace per item).

SELECT sum(qnty*price) FROM involine WHERE docnum = ;
ThisForm.Pageframe1.Page1.txtDocnum.value INTO array arrtotal
lnTotal = iif(_Tally=0,0,arrTotal)
ThisForm.Pageframe1.Page1.Basecont1.txtInvoAmt.Value = lnTotal

-Now lnTotal is only affected by changes in qnty and price fields, right ? On gotfocus of both fields you could save the current value to textbox tag :

this.tag = transform(this.value)

-On lostfocus update .txtInvoAmt.Value with new value (subtract old, add new) :
*qnty.lostfocus
with ThisForm.Pageframe1.Page1.Basecont1.txtInvoAmt
 .Value = .Value + (this.value - val(this.tag))*myalias.price
endwith
This way pointer doesn't move and in case of a lot of childs no performance degradations occur (such as a human would do manually - never sum per change only update with difference:).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform