Click Method
Object:frmordhistory.cmdAddToCurrentOrder
Expand/Collapse source code of procedure cmdAddToCurrentOrder.Click Source Code
LOCAL lcAlias, ;
      loGrid, ;
      lnOldArea, ;
      lnNumItemsAdded

lnNumItemsAdded = 0
LOCAL lnThisSessionID, ;
      lnTargetSessionID

*-- Here we save the current form's data session ID and
*-- the data session ID of the order entry form to which
*-- this form is "linked". It is used to switch sessions
*-- when adding items to the order entry form's grid.
lnThisSessionID = thisform.DataSessionID
lnTargetSessionID = thisform.oOrdEntryForm.DataSessionID

lnOldArea = SELECT()

*-- Prevent painting of both forms until we're done adding
*-- records
thisform.LockScreen = .T.
thisform.oOrdEntryForm.LockScreen = .T.
loGrid = thisform.grdLineItems
lcAlias = loGrid.RecordSource

SELECT (lcAlias)
WAIT WINDOW UPDATEORDER_LOC NOWAIT
SCAN
  *-- Check if tag is checked
  IF citems.exp_1
    lcProductID = citems.product_id
    lnUnitPrice = citems.unit_price
    lnQuantity = citems.quantity
    *-- Select the apppropriate data session
    SET DATASESSION TO (lnTargetSessionID)
    INSERT INTO order_line_items ;
      (order_id, product_id, unit_price, quantity) ;
      VALUES ;
      (orders.order_id, lcProductID, lnUnitPrice, lnQuantity)
    SET DATASESSION TO (lnThisSessionID)
    lnNumItemsAdded = lnNumItemsAdded + 1
  ENDIF
ENDSCAN

=TABLEREVERT(.T., "cItems")

*-- Delete any blank records in the Order Entry form
IF lnNumItemsAdded > 0
  SET DATASESSION TO (lnTargetSessionID)
  SELECT order_line_items
  DELETE FOR EMPTY(product_id) 
  GO BOTTOM
  SET DATASESSION TO (lnThisSessionID)
ENDIF  

SELECT (lnOldArea)

thisform.oOrdEntryForm.ClearLink()
thisform.Hide()
thisform.oOrdEntryForm.RefreshForm()
thisform.oOrdEntryForm.LockScreen = .F.
WAIT CLEAR
RELEASE thisform