PICTURE for DATE() ?

PICTURE for DATE() ?

Postby Jimmy » Mon Jul 17, 2023 8:46 am

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()
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: PICTURE for DATE() ?

Postby nageswaragunupudi » Mon Jul 17, 2023 9:06 am

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
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: PICTURE for DATE() ?

Postby Jimmy » Mon Jul 17, 2023 11:51 am

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 )
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: PICTURE for DATE() ?

Postby nageswaragunupudi » Mon Jul 17, 2023 12:26 pm

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
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: PICTURE for DATE() ?

Postby driessen » Mon Jul 17, 2023 3:44 pm

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
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: PICTURE for DATE() ?

Postby Jimmy » Tue Jul 18, 2023 9:18 pm

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
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: PICTURE for DATE() ?

Postby nageswaragunupudi » Tue Jul 18, 2023 10:03 pm

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
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: PICTURE for DATE() ?

Postby Jimmy » Wed Jul 19, 2023 5:18 am

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 :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: PICTURE for DATE() ?

Postby nageswaragunupudi » Thu Jul 20, 2023 7:12 am

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
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10625
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: PICTURE for DATE() ?

Postby Jimmy » Thu Jul 20, 2023 8:24 am

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: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: PICTURE for DATE() ?

Postby Jimmy » Sat Jul 22, 2023 9:54 am

hi,

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

YES, that work fine now :D
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 25 guests

cron