File: n_svc_requirededit.sru
Size: 7162
Date: Mon, 07 Apr 2008 21:31:25 +0200
$PBExportHeader$n_svc_requirededit.sru
$PBExportComments$Required Edit
forward
global type n_svc_requirededit from n_svc_base
end type
end forward

global type n_svc_requirededit from n_svc_base
end type
global n_svc_requirededit n_svc_requirededit

type variables
Protected:

CONSTANT LONG REQUIRED_COLOR = CColor.REQUIRED_BACKGROUND_COLOR
CONSTANT long REQUIRED_LABEL_COLOR = CColor.LINK
CONSTANT long REQUIRED_FAILED_LABEL_COLOR = CColor.RED
end variables

forward prototypes
protected function statictext of_findbuddy (ref n_svc_mgr anv_svc, readonly powerobject apo, readonly string as_classname)
public function boolean of_validaterequiredfields (ref n_svc_mgr anv_svc, readonly w_main aw)
public function boolean of_validaterequiredfields (ref n_svc_mgr anv_svc, readonly u_base_container auo)
protected function boolean of_validatefields (ref n_svc_mgr anv_svc, readonly powerobject apo)
protected subroutine of_showmessage (readonly string as_msg)
protected subroutine of_activatebuddy (readonly statictext ast, readonly boolean ab_failed)
protected function string of_formatlabeltext (readonly string as_labeltext)
public subroutine of_setrequired (ref n_svc_mgr anv_svc, readonly u_mle amle, readonly boolean ab_required, ref statictext ast_buddylabel)
public subroutine of_setrequired (ref n_svc_mgr anv_svc, readonly u_sle asle, readonly boolean ab_required, ref statictext ast_buddylabel)
public function boolean of_validateobject (ref n_svc_mgr anv_svc, readonly dragobject ado, readonly string as_text, readonly statictext ast_buddy, ref string as_msg)
end prototypes

protected function statictext of_findbuddy (ref n_svc_mgr anv_svc, readonly powerobject apo, readonly string as_classname);statictext lst
n_svc_powerbuilder lnv_pb
powerobject lpo_parent
windowobject lwo[]
string ls_classname
long ll_count, n

anv_svc.of_LoadSvc(lnv_pb, CSvc.POWERBUILDER)

lpo_parent = apo.GetParent()
ll_count = lnv_pb.of_GetWindowObjects(lpo_parent, lwo)

FOR n = 1 to ll_count
   IF lwo[n].TypeOf() = statictext! THEN
      ls_classname = lwo[n].Classname()
      IF as_classname = ls_classname THEN
         //cast and return
         lst = lwo[n]
         EXIT
      END IF
   END IF
NEXT

RETURN lst
end function

public function boolean of_validaterequiredfields (ref n_svc_mgr anv_svc, readonly w_main aw);RETURN of_ValidateFields(anv_svc, aw)
end function

public function boolean of_validaterequiredfields (ref n_svc_mgr anv_svc, readonly u_base_container auo);RETURN of_ValidateFields(anv_svc, auo)
end function

protected function boolean of_validatefields (ref n_svc_mgr anv_svc, readonly powerobject apo);n_svc_powerbuilder lnv_pb
n_svc_isempty lnv_check
windowobject lwo[]
long ll_count, n, c
statictext lst_buddy
boolean lb_ret
string ls_msg, ls_msgs[]
dragobject lwo_errors[]

anv_svc.of_LoadSvc(lnv_pb, CSvc.POWERBUILDER)
anv_svc.of_LoadSvc(lnv_check, CSvc.ISEMPTY)

ll_count = lnv_pb.of_GetWindowObjects(apo, lwo)
FOR n = 1 to ll_count
   
   lb_ret = TRUE
   
   CHOOSE CASE lwo[n].TypeOf()
      CASE SingleLineEdit!
         IF lnv_pb.of_isdescendant(CFBase.SingleLineEdit, lwo[n].ClassDefinition) THEN
            u_sle lsle
            //cast
            lsle = lwo[n]
            lst_buddy = lsle.of_GetBuddyLabel()
            
            IF lsle.#Required THEN
               lb_ret = of_ValidateObject(anv_svc, lsle, lsle.Text, lst_buddy, ls_msg)
            END IF
         END IF
      CASE MultiLineEdit!
         IF lnv_pb.of_isdescendant(CFBase.MultiLineEdit, lwo[n].ClassDefinition) THEN
            u_mle lmle
            //cast
            lmle = lwo[n]
            lst_buddy = lmle.of_GetBuddyLabel()
            
            IF lmle.#Required THEN
               lb_ret = of_ValidateObject(anv_svc, lmle, lmle.Text, lst_buddy, ls_msg)
            END IF
         END IF
      CASE Datawindow!
         IF lnv_pb.of_isdescendant(CFBase.DatawindowForm, lwo[n].ClassDefinition) THEN
            u_dw_form ldw
            //cast
            ldw = lwo[n]
            
            IF ldw.#ValidateRequiredFields THEN
               lb_ret = ldw.of_Validatefields() = 0
               SetNull(ls_msg)// = "value required"
               //lb_ret = of_ValidateObject(anv_svc, lmle, lmle.Text, lst_buddy, ls_msg)
            END IF
         END IF      
      CASE UserObject!
         //recurse
         IF lnv_pb.of_isdescendant(CFBase.UOContainer, lwo[n].ClassDefinition) THEN
            lb_ret = of_ValidateRequiredFields(anv_svc, lwo[n])
         END IF
   END CHOOSE
   
   IF NOT lb_ret THEN
      c ++
      ls_msgs[c] = ls_msg
      lwo_errors[c] = lwo[n]
   END IF
NEXT

IF UPPERBOUND(ls_msgs) > 0 THEN
   of_showmessage(ls_msgs[1])
   lwo_errors[1].SetFocus()
   RETURN FALSE
END IF

RETURN TRUE
end function

protected subroutine of_showmessage (readonly string as_msg);MessageBox("Required Value Missing", as_msg, Exclamation!)
end subroutine

protected subroutine of_activatebuddy (readonly statictext ast, readonly boolean ab_failed);IF NOT ISVALID(ast) THEN RETURN

IF ab_failed THEN
   ast.TextColor = REQUIRED_FAILED_LABEL_COLOR
// ast.Weight = 700
ELSE
   ast.TextColor = REQUIRED_LABEL_COLOR
// ast.Weight = 400
END IF
end subroutine

protected function string of_formatlabeltext (readonly string as_labeltext);string ls_ret

ls_ret = TRIM(as_labeltext)

IF RIGHT(ls_ret, 1) = ":" THEN
   ls_ret = MID(ls_ret, 1, LEN(ls_ret) - 1)
END IF

RETURN ls_ret
end function

public subroutine of_setrequired (ref n_svc_mgr anv_svc, readonly u_mle amle, readonly boolean ab_required, ref statictext ast_buddylabel);//buddy label
IF NOT ISVALID(ast_buddylabel) THEN &
   ast_buddylabel = of_FindBuddy(anv_svc, amle, amle.#BuddyLabel)

IF ab_required THEN
   amle.BackColor = REQUIRED_COLOR
   IF ISVALID(ast_buddylabel) THEN &
      ast_buddyLabel.TextColor = REQUIRED_LABEL_COLOR
ELSE
   amle.BackColor = CColor.WINDOW_BACKGROUND
   IF ISVALID(ast_buddylabel) THEN &
      ast_buddyLabel.TextColor = CColor.BUTTON_TEXT
END IF
end subroutine

public subroutine of_setrequired (ref n_svc_mgr anv_svc, readonly u_sle asle, readonly boolean ab_required, ref statictext ast_buddylabel);//buddy label
IF NOT ISVALID(ast_buddylabel) THEN &
   ast_buddylabel = of_FindBuddy(anv_svc, asle, asle.#BuddyLabel)

IF ab_required THEN
   asle.BackColor = REQUIRED_COLOR
   IF ISVALID(ast_buddylabel) THEN &
      ast_buddyLabel.TextColor = REQUIRED_LABEL_COLOR
ELSE
   asle.BackColor = CColor.WINDOW_BACKGROUND
   IF ISVALID(ast_buddylabel) THEN &
      ast_buddyLabel.TextColor = CColor.BUTTON_TEXT
END IF
end subroutine

public function boolean of_validateobject (ref n_svc_mgr anv_svc, readonly dragobject ado, readonly string as_text, readonly statictext ast_buddy, ref string as_msg);n_svc_isempty lnv_check
string ls_msg

ls_msg = "Please supply a value for "
anv_svc.of_LoadSvc(lnv_check, CSvc.ISEMPTY)

IF lnv_check.of_IsEmpty(as_text) THEN
   //check if buddy available
   IF ISVALID(ast_buddy) THEN
      of_ActivateBuddy(ast_buddy, TRUE)
      ls_msg += of_FormatLabelText(ast_buddy.Text) + "."
   ELSE
      ls_msg += "required field."
   END IF
   
   //of_ShowMessage(ls_msg)
   //ado.SetFocus()
   as_msg = ls_msg
   
   RETURN FALSE
ELSE
   of_ActivateBuddy(ast_buddy, FALSE)
END IF

RETURN TRUE
end function

on n_svc_requirededit.create
call super::create
end on

on n_svc_requirededit.destroy
call super::destroy
end on