How to Pass Pre-defined field values in EDIT

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
swapan
Posts: 242
Joined: Mon Mar 16, 2009 4:23 am
Location: Kolkata, India
Contact:

How to Pass Pre-defined field values in EDIT

Post by swapan »

Dear All:

I'm just trying to build a very simple transaction enty module (add / modify / delete ) with the help of command EDIT. This command helps to build a working entry module in automated manner

I want to fill a few fields with pre-defined values during each entry/new mode. Like
Licno="XYZ 123456M"
prodcode="T01"
prodname="Txx Tab"

A portion of the source provided below for reference:

Code: Select all

#include "hmg.ch"

function Main()

        // Database driver.
	REQUEST DBFCDX , DBFFPT

        // [x]Harbour modifiers.
	SET CENTURY ON
	SET DELETED ON
        SET DATE ITAL
        // Set default language to English.
        HB_LANGSELECT( "EN" )
        // Define window.
	DEFINE WINDOW Win_1			;
	        AT        0,0 			;
	        WIDTH     640 			;
        	HEIGHT    480 			;
	        TITLE     "DEMO             " 	;
        	MAIN 				;
		ON INIT OpenTable() 		;
		ON RELEASE CloseTable() 	;
		BACKCOLOR GRAY

		DEFINE MAIN MENU OF Win_1
        		POPUP "&File"
                		ITEM "&Batch Entry     "   ACTION BatchEntry()
                                //ITEM "&Batch Label Print" ACTION ExecuteReport('Report1',.t.,.t. )
				SEPARATOR
                                ITEM "About"               ACTION About()
                                SEPARATOR
        	        	ITEM "E&xit"               ACTION Win_1.Release
		        END POPUP
		END MENU

	END WINDOW

        // Open window.
	MAXIMIZE WINDOW Win_1
	ACTIVATE WINDOW Win_1

Return Nil



/*-----------------------------------------------------------------------------*/
Procedure OpenTable()
        CLOSE DATABASES
	//USE TRANS VIA "DBFCDX" INDEX TRANS NEW
	USE TRANS VIA "DBFCDX" NEW

Return Nil



/*-----------------------------------------------------------------------------*/
Procedure CloseTable()

        CLOSE TRANS

Return Nil



/*-----------------------------------------------------------------------------*/
Procedure BatchEntry()

        LOCAL aFields   := { "Product Code","Product Name","Batch No","Mfg. Date","Exp. Date",;
                             "Mfg. Lic.No.","Gross Wt.","Tare Wt.","Net Wt"  }

        LOCAL aReadOnly := { .f., .f., .f., .f., .f., .f., .f., .f., .f. }

        LOCAL bSave     := {|aContent, lEdit| BatchSave( aContent, lEdit ) }

        EDIT WORKAREA    TRANS ;
                TITLE    "Label - Batch Entry" ;
                FIELDS   aFields ;
                READONLY aReadOnly ;
                SAVE     bSave

Return Nil



/*-----------------------------------------------------------------------------*/
Procedure BatchSave( aContent, lEdit )

        LOCAL i
        LOCAL aFields   := { "Prodcode","Prname","Batchno","Mfgdate","Expdate",;
                             "Mfglicno","Grosswt","Tarewt","Netwt"  }
        // Chek content.
        FOR i := 1 TO Len( aContent )
                IF Empty( aContent[i] )
                        MsgInfo( aFields[i] + " - please supply data" )
                        Return .f.
                ENDIF
        NEXT

        // Save record.
        IF .NOT. lEdit
                TRANS->( dbAppend() )
        ENDIF
        FOR i := 1 TO Len( aContent )
                TRANS->( FieldPut( i, aContent[i] ) )
        NEXT

Return .t.

/*-----------------------------------------------------------------------------*/
Procedure SelItem( aItems )

        LOCAL nItem := 0

        DEFINE WINDOW wndSelItem ;
                AT 0, 0 ;
                WIDTH 265 ;
                HEIGHT 160 ;
                TITLE "" ;
                MODAL ;
                NOSIZE ;
                NOSYSMENU

                @ 20, 20 LISTBOX lbxItems ;
                        WIDTH 140 ;
                        HEIGHT 100 ;
                        ITEMS aItems ;
                        VALUE 1 ;
                        FONT "Arial" ;
                        SIZE 9

                @ 20, 170 BUTTON btnSel ;
                        CAPTION "&Select" ;
                        ACTION {|| nItem := wndSelItem.lbxItems.Value, wndSelItem.Release } ;
                        WIDTH 70 ;
                        HEIGHT 30 ;
                        FONT "ms sans serif" ;
                        SIZE 8

        END WINDOW

        wndSelItem.lbxItems.SetFocus

        CENTER WINDOW wndSelItem
        ACTIVATE WINDOW wndSelItem

return ( nItem )
Thanks & Regards,
Swapan Das

http://www.swapandas.com/
User avatar
swapan
Posts: 242
Joined: Mon Mar 16, 2009 4:23 am
Location: Kolkata, India
Contact:

Re: How to Pass Pre-defined field values in EDIT

Post by swapan »

Counting all of you to get solution for this issue..............................
Thanks & Regards,
Swapan Das

http://www.swapandas.com/
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: How to Pass Pre-defined field values in EDIT

Post by sudip »

Dear Swapan,

May be I can't answer your mail, but I am really very happy to see your codes :D
They are very well written :D
Moreover, I also guess, your employer company is using your expertise :D

Best of luck :D

With best regards.

Sudip
With best regards,
Sudip
User avatar
swapan
Posts: 242
Joined: Mon Mar 16, 2009 4:23 am
Location: Kolkata, India
Contact:

Re: How to Pass Pre-defined field values in EDIT

Post by swapan »

sudip wrote:Dear Swapan,

May be I can't answer your mail, but I am really very happy to see your codes :D
They are very well written :D
Moreover, I also guess, your employer company is using your expertise :D

Best of luck :D

With best regards.

Sudip
Dear Sudip: It mainly based on from one sample from hmg!

Dear Roberto Sir:

Is there a way to supply default values to the fields? We are already able to supply the caption for field names, so this feature can make it more useful.
Thanks & Regards,
Swapan Das

http://www.swapandas.com/
User avatar
Czarny_Pijar
Posts: 172
Joined: Thu Mar 18, 2010 11:31 pm
Location: 19.2341 E 50.2267 N

Re: How to Pass Pre-defined field values in EDIT

Post by Czarny_Pijar »

swapan
Probably your code is based on the 'SAMPLES\EDIT.2\demo.prg'.
I've modified this example slightly to accomplish your needs. A pity this is bounded to the 'Advanced Edit Test' exclusively. Compare my code with the original one, and you'd get the clou.
Sorry for the delay, but my knowledge about the HMG-extensions of the clipper is poor, I've just begun.

Code: Select all

Procedure AdvTestSave( aContent, lEdit )

        LOCAL i
        LOCAL aFields  := { "Nombre", "Apellidos", "Dirección", "Población " ,;
                            "Estado", "Codigo ZIP", "F. Nacimiento", "Casado",;
                            "Edad", "Salario", "Notas"    }



//---- Czarny_Pijar addition begin

        if len(alltrim(aContent[1])) = 0         // empty surname ?  ( 1st column) 
          aContent[1]:='Doe'
        endif
        
        if len(alltrim(aContent[2])) = 0         // empty name ?     ( 2nd column)
          aContent[2]:='John'
        endif
        
        if aContent[10] = 0                      //  0 salary ?      ( 10th column)
          aContent[10] :=  123.45        
        endif
        
//---- Czarny_Pijar addition end


//---- Czarny_Pijar substraction begin
        // Chek content
        .
//        FOR i := 1 TO Len( aContent )-4
//                IF Empty( aContent[i] )
//                        MsgInfo( aFields[i] + " no puede estar vacio" )
//                        Return .f.
//                ENDIF
//        NEXT

//---- Czarny_Pijar substraction end

        // Calculate age.
        aContent[9] := 0
        FOR i := ( Year( aContent[7] ) + 1 ) to Year( Date() )
                aContent[9] += 1
        NEXT    

        // Save record.
        IF .NOT. lEdit
                CLIENTES->( dbAppend() )
        ENDIF
        FOR i := 1 TO Len( aContent )
                CLIENTES->( FieldPut( i, aContent[i] ) )
        NEXT

Return .t.
User avatar
Roberto Lopez
HMG Founder
Posts: 4023
Joined: Wed Jul 30, 2008 6:43 pm

Re: How to Pass Pre-defined field values in EDIT

Post by Roberto Lopez »

swapan wrote:
Dear Roberto Sir:

Is there a way to supply default values to the fields? We are already able to supply the caption for field names, so this feature can make it more useful.
EDIT and EDIT EXTENDED commands are fully contributed code (I'm not its author) so, I have not a good knowledge about it (at least not good enough to help you).
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Czarny_Pijar
Posts: 172
Joined: Thu Mar 18, 2010 11:31 pm
Location: 19.2341 E 50.2267 N

Re: How to Pass Pre-defined field values in EDIT

Post by Czarny_Pijar »

After re-thinking my previous snippet I see it isn't perfect - the controls remains blank while adding the new record, the default values are added while Save is performed... To overcome this problem, you can:

1st: append the record with the default values via standard append blank then replace commands;
2nd: invoke the EDIT command, but instead add use edit.

This method also isn't perfect, because :
1) it insist to insert the new record to the database, and you cannot retreat without the touch,
2) also when you have to insert a bunch of records, this method fails.
I think this is all what can be done without resorting to the low-level methods, where the help of the contributor of the EDIT command is needed.
User avatar
swapan
Posts: 242
Joined: Mon Mar 16, 2009 4:23 am
Location: Kolkata, India
Contact:

Re: How to Pass Pre-defined field values in EDIT

Post by swapan »

Czarny_Pijar wrote:After re-thinking my previous snippet I see it isn't perfect - the controls remains blank while adding the new record, the default values are added while Save is performed... To overcome this problem, you can:

1st: append the record with the default values via standard append blank then replace commands;
2nd: invoke the EDIT command, but instead add use edit.

This method also isn't perfect, because :
1) it insist to insert the new record to the database, and you cannot retreat without the touch,
2) also when you have to insert a bunch of records, this method fails.
I think this is all what can be done without resorting to the low-level methods, where the help of the contributor of the EDIT command is needed.
Thanks for your attention & effort..................

Yes, I too was able to pass default/pre-defined values at the time of Save. But I want it to display at the beginning....the user in the entry mode, should be able to see the default values assigned to the respective field(s) and as per condition may be able to alter the default values.
Thanks & Regards,
Swapan Das

http://www.swapandas.com/
User avatar
swapan
Posts: 242
Joined: Mon Mar 16, 2009 4:23 am
Location: Kolkata, India
Contact:

Re: How to Pass Pre-defined field values in EDIT

Post by swapan »

Roberto Lopez wrote:
swapan wrote:
Dear Roberto Sir:

Is there a way to supply default values to the fields? We are already able to supply the caption for field names, so this feature can make it more useful.
EDIT and EDIT EXTENDED commands are fully contributed code (I'm not its author) so, I have not a good knowledge about it (at least not good enough to help you).
Can I request the original contributor(s) of commands EDIT & EDIT EXTENDED through this thread to throw some light on this issue and a way out?!

BTW are Grigory Filiatov & Cristóbal Mollá have developed these beautiful commands? Hope both of you listening to my requests?!
Thanks & Regards,
Swapan Das

http://www.swapandas.com/
User avatar
Czarny_Pijar
Posts: 172
Joined: Thu Mar 18, 2010 11:31 pm
Location: 19.2341 E 50.2267 N

Re: How to Pass Pre-defined field values in EDIT

Post by Czarny_Pijar »

If I can suggest for the contributors the way for solving this problem...

Suppose we've to deal with with my_base.dbf database. In my opinion the easiest way for both programmers/users is:

1) check the existence of defaults/my_base.dbf
2) if exists, read 1st record to get the default values.
Post Reply