PICTURE for DATE() ?

Post Reply
User avatar
Jimmy
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

PICTURE for DATE() ?

Post by Jimmy »

hi,
for my TGrid i have

Code: Select all | Expand

function FW_Record()
return TDataRow()
to use METHOD EDIT() of CLASS TDataRow

now i like to add some PICTURE but which PICTURE for DATE to use depend on language :?:

Code: Select all | Expand

oRec := FW_Record():New( aEdit, cName )

iMax := LEN( aEdit )
FOR ii := 1 TO iMax
   nPosi := ASCAN(::aBroFields, {|x| x[1] = aEdit[ii][1] })
   IF nPosi > 0
      cType  := ::aBroFields[ nPosi ] [ DBS_TYPE ]
      nLen   := ::aBroFields[ nPosi ] [ DBS_LEN ]
      nDec   := ::aBroFields[ nPosi ] [ DBS_DEC ]
      DO CASE
         CASE cType = "C" 
            cNewPic := Replicate("X", nLen)
            oRec:FieldPic( ii, cNewPic )
         CASE cType = "N"
            IF nDec > 0
               cNewPic := Replicate("9", nLen-nDec)+"."+ Replicate("9", nDec)
            ELSE
               cNewPic := Replicate("9", nLen)
            ENDIF
            oRec:FieldPic( ii, cNewPic )
         CASE cType = "D"
            // which PICTURE to use depend on language ?
            cNewPic := "99.99.9999"       // German Date 
            oRec:FieldPic( ii, cNewPic )
         CASE cType = "L"
            cNewPic := "L"
            oRec:FieldPic( ii, cNewPic )
         CASE cType = "M"
            // Memo
      ENDCASE
   ENDIF
NEXT
lEdit := oRec:Edit()
greeting,
Jimmy
User avatar
nageswaragunupudi
Posts: 10691
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: PICTURE for DATE() ?

Post by nageswaragunupudi »

By default, TDataRow's edit method automatically uses DATEFORMAT set for the application.

At the beginning of the application

Code: Select all | Expand

SET DATE GERMAN
SET CENTURY ON
Then all your dates will appear as dd.mm.yyyy in the entire application.
Setting picture everytime we edit a date is waste of time and code space.\

Next, used in the right way, TDataRow and XBrowse do most of these works automatically.
I do not see any point in rewriting everything that is already there in the library.

Code: Select all | Expand

oRec := TDataRow():new( cAlias, "ID,FIRST,AGE,SALARY" )
Is all that is enough and all pictures are correctly applied
Regards

G. N. Rao.
Hyderabad, India
User avatar
Jimmy
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: PICTURE for DATE() ?

Post by Jimmy »

hi,

thx for Answer

your Sample is for DBF so i guess FIELD AGE is Type "D"
i want to use "Record-Set" (not ADO) from TPQServer() which use a Array

when call METHOD Edit() it will "display" right but i can "input" every Type into GET
that´s why i want to use PICTURE " . . " or " / / " or " - - "

---

this is what i have now

Code: Select all | Expand

LOCAL cSetdt  := SET(_SET_DATEFORMAT)

   cSetdt := STRTRAN(cSetdt,"D","9")
   cSetdt := STRTRAN(cSetdt,"M","9")
   cSetdt := STRTRAN(cSetdt,"Y","9")

      CASE cType = "D"
         cNewPic := cSetdt
         oRec:FieldPic( ii, cNewPic )
greeting,
Jimmy
User avatar
nageswaragunupudi
Posts: 10691
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: PICTURE for DATE() ?

Post by nageswaragunupudi »

Code: Select all | Expand

 oRec:FieldPic( ii, cNewPic )
Use

Code: Select all | Expand

 oRec:FieldPic( ii, "@D" )
TDataRow() automatically sets correct dateformt to Dates also

Note:
Picture clauses for Dates in (x)Harbour

PICTURE "@D" // Use dateformat set. (default American, i.e., 'mm/dd/yy' )
PICTURE "@E" // Force European format ( i.e., 'dd/mm/yy' ) even if the format is set to American
Regards

G. N. Rao.
Hyderabad, India
User avatar
driessen
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: PICTURE for DATE() ?

Post by driessen »

Jimmy,

If i put a date in a TGET, I always change the date to a string by using DTOC().
I can give the picture to my date anyway I want and in the VALID clause, I can link a function which checks if the date is correct or not.
Afterwards, I change the string back to a date by using CTOD().

It is quite easy and it gives you the possibilities to add more controls to the valid clause.
Example: if a date you want has to be between two other days, it gives you the posibility to give a message to tell the user what's wrong.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
Jimmy
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: PICTURE for DATE() ?

Post by Jimmy »

hi,
nageswaragunupudi wrote:TDataRow() automatically sets correct dateformt to Dates also
as i say i use a Array which is from "Result-Set" (not ADO) of SQL Query

i don´t "see" DATEFORMAT in CLASS TDataRow
nageswaragunupudi wrote:Note:
Picture clauses for Dates in (x)Harbour
PICTURE "@D" // Use dateformat set. (default American, i.e., 'mm/dd/yy' )
PICTURE "@E" // Force European format ( i.e., 'dd/mm/yy' ) even if the format is set to American
ok, but i don´t know which DATE Setting or which Country User have
greeting,
Jimmy
User avatar
nageswaragunupudi
Posts: 10691
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: PICTURE for DATE() ?

Post by nageswaragunupudi »

i want to use "Record-Set" (not ADO) from TPQServer() which use a Array
Are you not using something like

Code: Select all | Expand

oRs := oServer:Query( "select * from customer order by id" )
 
If so, both XBrowse and TDataRow are fully compatible with PostGre Query and we need not set anything on our own.
We can say

Code: Select all | Expand

TDataRow():New( oRs ):Edit()
// or just
XEdit( oRs )
 
Please try again

Code: Select all | Expand

buildh pgre01
 
in the 32-bit fwh\samples folder
ok, but i don´t know which DATE Setting or which Country User have
Use picture "@D"
Actually we do not need to give any pictue to Get object or XBrowse, they both automatically use the "@D" picture.
In the beginning of Main(), we set the required date format like
SET GERMAN.

Note: In case we propose to distribute the application world wide, we can also set date format according the locale of the PC. But that is a differnt subject.

For now, it is enough to set

Code: Select all | Expand

SET DATE GERMAN
SET CENTURY ON
 
All functions, Gets, Browses, etc automatically use this format.
No need at all to manually provide any picture clause
Regards

G. N. Rao.
Hyderabad, India
User avatar
Jimmy
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: PICTURE for DATE() ?

Post by Jimmy »

hi,
nageswaragunupudi wrote:Please try again

Code: Select all | Expand

buildh pgre01
 
in the 32-bit fwh\samples folder
ok, DATE Format are show right after

Code: Select all | Expand

SET DATE GERMAN
SET CENTURY ON
but i have still Problem with ":edit()"
i can not "save" in that Sample ... something still going wrong
Image

---

Code: Select all | Expand

    TDataRow():New( oRs ):Edit()
    // or just
    XEdit( oRs )    
i have to say that i´m not using XBROWSE / XBROWSER ... i want to use a TGrid()

Code: Select all | Expand

  lEdit := XEdit( aEdit, cName )
aEdit Element have {FIELDname,FIELDvalue} but not "Structure" ...
did i use XEdit() wrong :?:
greeting,
Jimmy
User avatar
nageswaragunupudi
Posts: 10691
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: PICTURE for DATE() ?

Post by nageswaragunupudi »

For editing array of values with known Field Structure, please try something like this:

Code: Select all | Expand

#include "fivewin.ch"

function Main()

local aVals := {1,"Homer","Simpson","32179 Maiden Lane","Springfield","MD",;
                   "20503-8202",SToD("19920918"),.F.,50,6000.00,;
                   "This is a test for record 1"}
local aStruct := ; 
   {{"ID","+",4,0},{"FIRST","C",20,0},{"LAST","C",20,0},{"STREET","C",30,0},;
   {"CITY","C",30,0},{"STATE","C",2,0},{"ZIP","C",10,0},{"HIREDATE","D",8,0},;
   {"MARRIED","L",1,0},{"AGE","N",2,0},{"SALARY","N",9,2},{"NOTES","C",70,0}}

local oArrData

   SET DATE GERMAN
   SET CENTURY ON

   FWNumFormat( "E", .t. )
   SetGetColorFocus()

   oArrData := TArrayData():New( { aVals }, aStruct )
   oArrData:Edit()

return nil
 
All picture clauses are taken care of
Regards

G. N. Rao.
Hyderabad, India
User avatar
Jimmy
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: PICTURE for DATE() ?

Post by Jimmy »

hi,
nageswaragunupudi wrote:For editing array of values with known Field Structure, please try something like this:

All picture clauses are taken care of
ok thx for the Tip
greeting,
Jimmy
User avatar
Jimmy
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: PICTURE for DATE() ?

Post by Jimmy »

hi,

Code: Select all | Expand

   oRec := TArrayData() :New( { aValue }, aFields )
   // now "edit"
   lEdit := oRec:Edit()
YES, that work fine now :D
greeting,
Jimmy
Post Reply