Compile function NDW_TW_LOT_CREATE_EVENTS(CtrlEntId, Event, @PARAMS)
#pragma precomp SRP_PreCompiler
#window NDW_TW_LOT_CREATE

Declare function Get_Property, Lot_Services, Error_Services
Declare subroutine Set_Property, Msg    

$Insert LOGICAL

GoToEvent Event for CtrlEntId else
    // Event not implemented
end

Return EventFlow or 1

//-----------------------------------------------------------------------------
// EVENT HANDLERS
//-----------------------------------------------------------------------------

Event WINDOW.CREATE(CreateParam)
    
    EventFlow = 1
    
End Event

Event EDL_PROD_NAME.LOSTFOCUS(Flag, FocusID)
    ProdNameVal = Get_Property(@Window : '.EDL_PROD_NAME', 'TEXT')
    If ProdNameVal[1, 1] EQ 'P' then
        ProdNameVal[1,1] = ''
    end
    Set_Property(@Window : '.EDL_PROD_NAME', 'TEXT', ProdNameVal)
    Set_Property(@Window:'.EDL_WAFER_QTY', 'FOCUS', True$)
end event

Event EDL_WAFER_QTY.LOSTFOCUS(Flag, FocusID)
    QtyVal = Get_Property(@Window : '.EDL_WAFER_QTY', 'TEXT')
    If QtyVal[1, 1] EQ 'Q' then
        QtyVal[1,1] = ''
    end
    If Num(QtyVal) then
        Set_Property(@Window : '.EDL_WAFER_QTY', 'TEXT', QtyVal)
        Set_Property(@Window:'.EDL_VENDOR_LOT_NO', 'FOCUS', True$)
    end else
        Msg(@Window, 'Quantity must be a number.')
        Set_Property(@Window:'.EDL_WAFER_QTY', 'TEXT', '')
        Set_Property(@Window:'.EDL_WAFER_QTY', 'FOCUS', True$)
    end
end event

Event PUB_SUBMIT.CLICK()
    debug
    ThisProdName = Get_Property(@Window : '.EDL_PROD_NAME', 'TEXT')
    ThisQuantity = Get_Property(@Window : '.EDL_WAFER_QTY', 'TEXT')
    If ThisProdName NE '' then
        If ThisQuantity NE '' then
            CreatedLotID = Lot_Services('CreateNewTestWaferLot', 'TW', ThisProdName, ThisQuantity, '', '', '', @USER4)
            If CreatedLotID NE '' then
                Msg(@Window, CreatedLotID : ' successfully created')
                GoSub ResetForm
            end else
                If Error_Services('HasError') then
                    //Known error, get the message
                end else
                    Msg(@Window, 'Unspecified error created new test wafer lot.')
                end
            end
        end else
            //Error: Qty was empty
        end
    end else
        //Error: Prod Name was empty
    end
    
end event


* * * * * * * * * * *
* Internal Go-Subs  *
* * * * * * * * * * *

ResetForm:
    Set_Property(@Window: '.EDL_PROD_NAME', 'TEXT', '')
    Set_Property(@Window: '.EDL_WAFER_QTY', 'TEXT', '')
    Set_Property(@Window: '.EDL_VENDOR_LOT_NO', 'TEXT', '')
    Set_Property(@Window: '.EDL_VENDOR_PROD_ORDER_NO', 'TEXT', '')
    Set_Property(@Window: '.EDL_VENDOR_CODE', 'TEXT', '')
    Set_Property(@Window: '.EDL_PROD_NAME', 'FOCUS', True$)
return


