Page 1 of 1

PICTURE for DATE() ?

PostPosted: Mon Jul 17, 2023 8:46 am
by Jimmy
hi,
for my TGrid i have
Code: Select all  Expand view
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 view
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()

Re: PICTURE for DATE() ?

PostPosted: Mon Jul 17, 2023 9:06 am
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 view
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 view
oRec := TDataRow():new( cAlias, "ID,FIRST,AGE,SALARY" )

Is all that is enough and all pictures are correctly applied

Re: PICTURE for DATE() ?

PostPosted: Mon Jul 17, 2023 11:51 am
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 view
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 )

Re: PICTURE for DATE() ?

PostPosted: Mon Jul 17, 2023 12:26 pm
by nageswaragunupudi
Code: Select all  Expand view
oRec:FieldPic( ii, cNewPic )

Use
Code: Select all  Expand view
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

Re: PICTURE for DATE() ?

PostPosted: Mon Jul 17, 2023 3:44 pm
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.

Re: PICTURE for DATE() ?

PostPosted: Tue Jul 18, 2023 9:18 pm
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

Re: PICTURE for DATE() ?

PostPosted: Tue Jul 18, 2023 10:03 pm
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 view

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 view

TDataRow():New( oRs ):Edit()
// or just
XEdit( oRs )
 

Please try again
Code: Select all  Expand view

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 view

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

Re: PICTURE for DATE() ?

PostPosted: Wed Jul 19, 2023 5:18 am
by Jimmy
hi,
nageswaragunupudi wrote:Please try again
Code: Select all  Expand view

buildh pgre01
 

in the 32-bit fwh\samples folder

ok, DATE Format are show right after
Code: Select all  Expand view
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 view
    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 view
 lEdit := XEdit( aEdit, cName )

aEdit Element have {FIELDname,FIELDvalue} but not "Structure" ...
did i use XEdit() wrong :?:

Re: PICTURE for DATE() ?

PostPosted: Thu Jul 20, 2023 7:12 am
by nageswaragunupudi
For editing array of values with known Field Structure, please try something like this:
Code: Select all  Expand view
#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

Re: PICTURE for DATE() ?

PostPosted: Thu Jul 20, 2023 8:24 am
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

Re: PICTURE for DATE() ?

PostPosted: Sat Jul 22, 2023 9:54 am
by Jimmy
hi,

Code: Select all  Expand view
  oRec := TArrayData() :New( { aValue }, aFields )
   // now "edit"
   lEdit := oRec:Edit()

YES, that work fine now :D