/**********************************************************************
 * Copyright (C) 2006-2013 by Consultingwerk Ltd. ("CW") -            *
 * www.consultingwerk.de and other contributors as listed             *
 * below.  All Rights Reserved.                                       *
 *                                                                    *
 *  Software is distributed on an "AS IS", WITHOUT WARRANTY OF ANY    *
 *   KIND, either express or implied.                                 *
 *                                                                    *
 *  Contributors:                                                     *
 *                                                                    *
 **********************************************************************/
/*------------------------------------------------------------------------
    File        : CustomerViewerLogic
    Purpose     : Logic class for customer viewer instances
    Syntax      : 
    Description : 
    Author(s)   : Mike Fechner / Consultingwerk Ltd.
    Created     : Sun Sep 08 21:51:30 CEST 2013
    Notes       : 
  ----------------------------------------------------------------------*/

ROUTINE-LEVEL ON ERROR UNDO, THROW.

USING Consultingwerk.SmartComponents.Enum.*                          FROM PROPATH .
USING Consultingwerk.SmartComponents.Base.*                          FROM PROPATH .
USING Consultingwerk.SmartComponentsDemo.CustomerExplorer.Customer.* FROM PROPATH .  
USING Progress.Lang.*                                                FROM PROPATH .

CLASS Consultingwerk.SmartComponentsDemo.CustomerExplorer.Customer.CustomerViewerLogic 
    INHERITS SmartViewerLogic: 

    /*------------------------------------------------------------------------------
        Purpose: Constructor for the CustomerViewerLogic class
        Notes:   
    ------------------------------------------------------------------------------*/
	CONSTRUCTOR PUBLIC CustomerViewerLogic ():
		SUPER ().
		
	END CONSTRUCTOR.

    /*------------------------------------------------------------------------------
        Purpose: Subscribes the events for an attached viewer instance
        Notes:   This method needs to be implemented by the Viewer Logic class and 
                 is supposed to subscribe to control events
    ------------------------------------------------------------------------------*/
	METHOD OVERRIDE PUBLIC VOID SubscribeEvents ():

        {Consultingwerk/subscribeviewerevent.i EmailAddress Validating ValidateEmailHandler}

	END METHOD .

    /*------------------------------------------------------------------------------
        Purpose: Unsubscribes the events for an attached viewer instance
        Notes:   This method needs to be implemented by the Viewer Logic class and 
                 is supposed to unsubscribe from control events
    ------------------------------------------------------------------------------*/
    METHOD OVERRIDE PUBLIC VOID UnsubscribeEvents ():

        {Consultingwerk/unsubscribeviewerevent.i EmailAddress Validating ValidateEmailHandler}

    END METHOD .

    /*------------------------------------------------------------------------------
        Purpose: Event handler for the Validating event of the Email field
        Notes:   
        @param sender The reference to the Control that raised the event
        @param e The CancelEventArgs with the data for this event 
    ------------------------------------------------------------------------------*/
	METHOD PROTECTED VOID ValidateEmailHandler (sender AS System.Object,
	                                            e AS System.ComponentModel.CancelEventArgs):
		
		DEFINE VARIABLE cEmail AS CHARACTER NO-UNDO.
		
		IF THIS-OBJECT:Owner:SmartTableIOState = TableIOStateEnum:FieldsEnabled THEN
		    RETURN . 
		   
		ASSIGN cEmail = CAST (sender, System.Windows.Forms.Control):Text . 
		   
		IF cEmail > "":U THEN 
		    IF INDEX (cEmail, "@":U) = 0 THEN DO:
                Consultingwerk.Util.MessageFormHelper:ShowMessage ("Email address should contain at least @.",
                                                                   Consultingwerk.Windows.Util.Forms.MessageFormImages:ImageError) .
    		  
    		    e:Cancel = TRUE . 
    		END.

	END METHOD .

END CLASS.
