************************************************** *-- Class: cdatetextbox (c:\cdbk90\common30\libs\ccustctl.vcx) *-- ParentClass: ctextbox (c:\cdbk90\common30\libs\ccontrls.vcx) *-- BaseClass: textbox *-- Time Stamp: 05/19/07 09:20:04 AM *-- A custom textbox used for entering dates. * #INCLUDE "c:\cdbk90\common30\include\framincl.h" * DEFINE CLASS cdatetextbox AS ctextbox Century = 1 Alignment = 3 Format = "KR" InputMask = "99/99/9999" Width = 72 Name = "cdatetextbox" PROCEDURE LostFocus IF VARTYPE( THIS.VALUE ) <> "D" THIS.SETFOCUS() ENDIF ENDPROC PROCEDURE copyright * Class.............: CDateTextbox * Author............: Y. Alan Griver * Project...........: Codebook 3.0 * Created...........: 07/19/95 14:17:18 * Copyright.........: (c) Flash Creative Management, Inc., 1995 * Major change list.: ENDPROC PROCEDURE KeyPress *-- This method checks the key pressed, allowing the following *-- unique behaviors: *-- +,= next day *-- -,_ previous day *-- T,t, J, j Today's date *-- M,m First day of month *-- H,h, D, d Last day of month *-- Y,y, A, a First day of year *-- R,r Last day of year *-- The NODEFAULT in this case stops the bell from sounding as *-- the date is filled. LPARAMETERS nKeyCode, nShiftAltCtrl LOCAL lcValue, lcMonth, lcYear, ldValue *-- 05/2007 Si ce champs est contenu dans une grille *-- dont la colonne parent est en READONLY = .T. *-- le keypress AGIT et remplit le champs ! *-- Keypress outrepasse le ReadOnly=.T. ! IF TYPE("This.parent") = "O" AND ; THIS.PARENT.BASECLASS = "Column" AND ; THIS.PARENT.READONLY = .T. NODEFAULT RETURN ENDIF DO CASE CASE nKeyCode = ASC("+") OR nKeyCode = ASC("=") THIS.VALUE = THIS.VALUE + 1 NODEFAULT CASE nKeyCode = ASC("-") OR nKeyCode = ASC("_") THIS.VALUE = THIS.VALUE - 1 NODEFAULT *{ Commented at 11:09:42 on September 06, 97 * CASE nKeyCode = ASC("T") or nKeyCode = ASC("t") CASE nKeyCode = ASC("T") OR nKeyCode = ASC("t") OR nKeyCode = ASC("J") OR nKeyCode = ASC("j") *} End Commenting 11:09:42 - September 06, 97 THIS.VALUE = DATE() NODEFAULT CASE nKeyCode = ASC("M") OR nKeyCode = ASC("m") lcMonth = STR(MONTH(THIS.VALUE)) lcYear = STR(YEAR(THIS.VALUE)) *-- CHANGE - JCM - September 06, 1997 - 11:01:08 *-- let's make it the european way * lcValue = lcMonth + "/" + "01" + "/" + lcYear lcValue = "01" + "/" + lcMonth + "/" + lcYear THIS.VALUE = CTOD(lcValue) NODEFAULT *{ Commented at 11:06:25 on September 06, 97 * CASE nKeyCode = ASC("H") or nKeyCode = ASC("h") CASE nKeyCode = ASC("H") OR nKeyCode = ASC("h") OR nKeyCode = ASC("D") OR nKeyCode = ASC("d") *} End Commenting 11:06:25 - September 06, 97 ldValue = GOMONTH(THIS.VALUE,1) lcMonth = STR(MONTH(ldValue)) lcYear = STR(YEAR(ldValue)) *-- CHANGE - JCM - September 06, 1997 - 11:01:08 *-- let's make it the european way * lcValue = lcMonth + "/" + "01" + "/" + lcYear lcValue = "01" + "/" + lcMonth + "/" + lcYear THIS.VALUE = CTOD(lcValue) - 1 NODEFAULT *{ Commented at 11:11:07 on September 06, 97 * CASE nKeyCode = ASC("Y") or nKeyCode = ASC("y") CASE nKeyCode = ASC("Y") OR nKeyCode = ASC("y") OR nKeyCode = ASC("A") OR nKeyCode = ASC("a") *} End Commenting 11:11:07 - September 06, 97 lcValue = "01/01/" + STR(YEAR(THIS.VALUE)) THIS.VALUE = CTOD(lcValue) NODEFAULT CASE nKeyCode = ASC("R") OR nKeyCode = ASC("r") *-- CHANGE - JCM - September 06, 1997 - 11:03:17 * lcValue = "12/31/" + STR(YEAR(this.Value)) lcValue = "31/12/" + STR(YEAR(THIS.VALUE)) THIS.VALUE = CTOD(lcValue) NODEFAULT ENDCASE ENDPROC PROCEDURE Init *-- Make sure that we're using a DATE type of controlsource. IF CTextBox::INIT() *WAIT WIND THIS.CONTROLSOURCE + " " + TYPE( THIS.CONTROLSOURCE ) *-- 02/2003 Car on définit par programmation le controlsource. IF !EMPTY( THIS.CONTROLSOURCE ) *-- 05/2007 Bug dont je comprends rien. *!* IF !INLIST( TYPE( THIS.CONTROLSOURCE ) , "T" , "D" ) IF !INLIST( VARTYPE( THIS.VALUE ) , "T" , "D" ) =MESSAGEBOX(NON_DATE_SOURCE_LOC) RETURN .F. ENDIF ENDIF ENDIF ENDPROC PROCEDURE Error LPARAMETERS tnError, tcMethod, tnLine *-- 23/05/2002 IF tnError = 2034 NODEFAULT =ErrorMsg("Mauvaise Date !") THIS.SETFOCUS() ELSE DODEFAULT(tnError, tcMethod, tnLine) ENDIF ENDPROC ENDDEFINE * *-- EndDefine: cdatetextbox **************************************************>Why do you use numeric textbox class for dates? Do you have sparse property for the column set to .f.?