|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
POWERBUILDER LINKS YOU MUST CLICK ON PowerBuilder Using the PFC Calendar with a Datetime Column
Using the PFC Calendar with a Datetime Column
By: Oleg Podgoretsky
Jun. 1, 2000 12:00 AM
In this article I'll share my experiences of working with the PFC DropDown Calendar and show you how to make this custom user object user-friendly. If you've tried to use this custom visual object, you may have discovered that the PFC Calendar won't populate a calendar if you use a datetime type instead of a date type column. When I first tried to use the PFC DropDown Calendar with PowerBuilder 6.5, instead of the OLE calendar commonly used with PowerBuilder 5.0, I found I couldn't achieve its desired or declared functionality. Each time I accessed the date column with the datetime format column in it, the DropDown Calendar appeared blank instead of showing me a current date. And when I clicked the arrow on the Calendar, the date January 1, 1990, was implemented. This means that the PFC Calendar doesn't recognize the datetime column and therefore assumes it's incorrect and uses the predefined date of January 1, 1990. When the accessed field was blank, the Calendar produced exactly the same result. After my first attempt at using PFC Calendar failed, I started to explore what might cause that kind of behavior and tried to determine the exact place the error occurred. As a result of my investigation, I discovered some pieces of logic missing inside the pfc_main/u_calendar object. I also learned about numerous reports made a few years ago addressing the issue of how to make PFC DropDown Calendar work with Sybase System 11, which uses the column types of datetime and smaldatetime. This problem has been fixed in PFC7, but my fix is so simple that it can be done easily regardless of the level of programming skills. Many people working with PB6.5 who wish to take advantage of PFC fixes just export the services in PB7 and import them into PB6. Many stand-alone services import into PB6 with no problems. This is one of them, although it may also require applying a fix to u_dw or even u_base, where pfc_u_calendar is inherited. The following solution will make your PFC Calendar perform the same way no matter what date format is used.
//gets the current date from the requesting objectThen find the script: ls_date = idw_requestor.GetText()below the comment, and add the following lines of code right after that line: If ls_date = " " or IsNull(ls_date) thenWhat does that code do and why do we need it? The code you just added checks whether string ls_date has any value in it. If it doesn't, the script calls of_SetDate() function, which sets the current date, optionally updating the date in the associated DataWindow column or EditMask control. Idw_requestor is used for DataWindow columns. You should then add exactly the same code for the same reason after the line: ls_date = iem_requestor.Textwhere iem_requestor is used to implement DropDown Calendar on the EditMask control. Now go ahead and locate the comment: //Validate the date. //Keep track if the date was valid or notAdd the following line of code right after the last comment: ls_date = Left(ls_date,10)This code will give you a string ls_date in date format, removing the time value if your format is a datetime. We need that line because the second line of code will convert the string ls_date into a date format and apply that value to the instance variable id_resetdate, used as one of the arguments for of _SetDate function. Each time your string is null or empty, the logic will call and execute of_SetDate() function, which otherwise will be missing. When you use the datetime format in our DataWindow, its script will correct the string that contains datetime-formatted data and transform it into a date format. Finally, save all the changes and exit pfc_main/u_calendar object. Your PFC DropDown Calendar is ready to go. To register columns you want to use with the PFC DropDown Calendar in your u_dw DataWindow control, you should enable the DropDown Calendar calling the u_dw of_SetDropDownCalendar function and then use the of_Register function. In that function you can specify column names you want to register or register all eligible columns using a specified display style. The default display style is NONE or 1. The default style will display the calendar automatically when the column of DropDownListBox style gives focus and doesn't display automatically when the column is of Edit or EditMask style; instead, you display the calendar by coding the call to the u_dw_pfc_DDCalendar event. If you use the DropDownListBox style and the default display style, you can write the following code in your DataWindow constructor event: This.of_SetDropDownCalendar(TRUE)iuo_calendar is the instance name of u_calendar. If your columns are of Edit or EditMask styles, you may use style 2 (DDLB) or 3 (DDLB_WITHARROW). For both of these styles function will convert registered columns to the DropDownListBox edit style. The user displays the calendar by clicking the down arrow, which disappears (style 2) or remains (style 3) after the calendar displays. Your need to display the calendar on registered columns depends on some specific conditions. In this case you should use u_dw function of_SetDropDownCalendar (Boolean). Boolean specifies whether to enable (TRUE) or disable (FALSE) the DropDown Calendar. Figure 1 shows the DropDown Calendar is populated when the registered date column gets focus; in Figure 2 the same DropDown Calendar is populated on the same column but with no date in it. Therefore the current day is shown. Now you can run the application and enjoy your PFC Calendar. PBDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING POWERBUILDER / SYBASE NEWS
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||