Data Control Form

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
sudip
Posts: 1446
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India
Has thanked: 5 times
Been thanked: 2 times

Data Control Form

Post by sudip »

Hi,

I am using a data control form. How can I cancel a new data, which was added by "APPEND BLANK"?

Regards.

Sudip
With best regards,
Sudip

User avatar
esgici
Posts: 4538
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 410 times
Been thanked: 118 times
Contact:

Post by esgici »

sudip wrote: How can I cancel a new data, which was added by "APPEND BLANK"?
Sudip
Hi Sudip

As far as know there isn't an "express" way for this. You have write code for DELETE the newly added record.

Regards

--

Esgici
Viva INTERNATIONAL HMG :D

User avatar
sudip
Posts: 1446
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India
Has thanked: 5 times
Been thanked: 2 times

Post by sudip »

Hello Esgici,

I think using memory variable for each field and array for one to many will be a better choice.

Using this I can easily check for uniqueness of primary key and secondary keys.

This needs more coding from programmer's side, but this will work (I hope) :)

With best regards.

Sudip
With best regards,
Sudip

User avatar
sudip
Posts: 1446
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India
Has thanked: 5 times
Been thanked: 2 times

Post by sudip »

Hi,

I wrote a prototype of data entry cum selection form.
I am confused where to post the code. But as it is related to the topic "Data Control Form", I put it here.
Please tell me where to put it if I made a mistake.

Please send your suggestion :)

Code: Select all

/*
  Here accunting year can be added, edited, modified and selected.
   _accyrid, _accfrom, _accto are global variables
*/


#include "minigui.ch"

// Addmode, Editmode are static variables required
// for behavior  and action of form controls
Static Addmode, Editmode

Function wAccyr()
   Addmode := .f.
   Editmode := .f.

   // netselect(cTable)
   // check if table is used or not
   // if not used, use it in shared mode with all indexes
   // select the workarea
   netselect("accyr")
   go top

   DEFINE WINDOW frmAccyr ;
   AT 140 , 235 WIDTH 418 HEIGHT 199 ;
   TITLE "Accounting Year" ;
   MODAL NOSYSMENU ;
   on init RefreshForm()

  @ 10, 10 LABEL Label_1 ;
            WIDTH  54  ;
            HEIGHT 22  ;
            VALUE "A/c Yr ID:"

  @ 10, 110 TEXTBOX txtAccyrid ;
            WIDTH  120         ;
            HEIGHT 24          ;
            READONLY

  @ 40, 10 LABEL Label_2 ;
            WIDTH  51    ;
            HEIGHT 17     ;
            VALUE "From:"

  @ 40, 110 TEXTBOX txtAccfrom ;
            WIDTH  120         ;
            HEIGHT 24          ;
            DATE               ;
            on enter frmAccyr.txtAccto.setfocus ;
            on lostfocus createaccyrid()

  DEFINE LABEL Label_3
            ROW    70
            COL    10
            WIDTH  33
            HEIGHT 30
            VALUE "To:"
     END LABEL

  @ 70, 110 TEXTBOX txtAccto ;
            WIDTH  120       ;
            HEIGHT 24        ;
            DATE             ;
            on enter frmAccyr.btnSelect.setfocus ;
            on lostfocus createaccyrid()

    DEFINE BUTTON btnPrev
           ROW    130
           COL    110
           WIDTH  50
           HEIGHT 28
           CAPTION "<"
           action PrevRecord()
     END BUTTON

    DEFINE BUTTON btnNext
           ROW    130
           COL    180
           WIDTH  50
           HEIGHT 28
           CAPTION ">"
           action NextRecord()
     END BUTTON

    DEFINE BUTTON btnAdd
           ROW    10
           COL    290
           WIDTH  100
           HEIGHT 28
           CAPTION "&Add"
           action AddData()
     END BUTTON

    DEFINE BUTTON btnModify
           ROW    40
           COL    290
           WIDTH  100
           HEIGHT 28
           CAPTION "&Modify"
           action ModiData()
     END BUTTON

    DEFINE BUTTON btnDelete
           ROW    70
           COL    290
           WIDTH  100
           HEIGHT 28
           CAPTION "&Delete"
           action DelData()
     END BUTTON

    DEFINE BUTTON btnSelect
           ROW    100
           COL    290
           WIDTH  100
           HEIGHT 28
           CAPTION "&Select"
           ACTION SaveData()
     END BUTTON

    DEFINE BUTTON btnCancel
           ROW    130
           COL    290
           WIDTH  100
           HEIGHT 28
           CAPTION "&Cancel"
           ACTION CancelData()
     END BUTTON

   END WINDOW

   frmAccyr.txtAccfrom.setfocus
   CENTER WINDOW frmAccyr

   ACTIVATE WINDOW frmAccyr
   RETURN NIL



Static function TopRecord()
   netselect("accyr")
   go top
   RefreshForm()


Static function PrevRecord()
   netselect("accyr")
   if !bof()
      skip -1
   endif
   if bof()
      go top
   endif
   RefreshForm()


Static function NextRecord()
   netselect("accyr")
   if !eof()
      skip
   endif
   if eof()
      go bottom
   endif
   RefreshForm()


Static function LastRecord()
   netselect("accyr")
   go bottom
   RefreshForm()

Static function AddData()
   memvar->accyrid = space(10)
   MEMVAR->ACCFROM :=  MEMVAR->ACCTO := CTOD("")
   Addmode := .t.
   RefreshForm()
   frmAccyr.txtAccfrom.setfocus
   RETURN NIL


STATIC FUNCTION ModiData()
   netselect("accyr")
   if eof() .or. bof()
      return nil
   endif
   editmode = .t.
   refreshform()
   frmAccyr.txtAccfrom.setfocus
   return nil


static function DelData()
   netselect("accyr")
   if eof() .or. bof()
      return nil
   endif
   if msgyesno("Want to delete?")
      // here we can check for intigrity
      delete
      if !eof()
         skip
      endif
      if eof()
         go bottom
      endif
      RefreshForm()
   endif


static function SaveData()
   local mRecno
   netselect("accyr")
   if !(addmode .or. editmode)
      // user pressed select button
      if eof() .or. bof()
         msginfo("Record Blank. Cannot select")
         return nil
      endif
      // _accyrid, _accfrom, _accto are global variables
      _accyrid = accyr->accyrid
      _accfrom = accyr->accfrom
      _accto = accto
      netselect("accyr")
      use
      // folloing part is for my program specific
      // I store data for each accounting year 
      // separately in different accounting year folder
      dirmake(_accyrid)
      dirchange(_accyrid)
      Setup_tables()
      frmAccyr.release
   else
      CreateAccyrID()
      // validation check
      if empty(frmAccyr.txtAccfrom.value) .or. empty(frmAccyr.txtAccto.value) .or. ;
            frmAccyr.txtAccfrom.value > frmAccyr.txtAccto.value
         msginfo("Invalid Accounting Year Range!")
         return nil
      endif
      netselect("accyr")
      mRecno = iif(eof(), 0, recno())
      set order to tag accyrid
      seek frmAccyr.txtAccyrid.value
      if found() .and. (addmode .or. recno() <> mRecno)
         if mRecno <>0
            go (mRecno)
         endif
         msginfo("Duplicate Accounting Year ID!")
         return nil
      endif
      
      // proceed if everything is ok
      if addmode
         append blank
      else
         rlock()
      endif
      accyr->accyrid := frmAccyr.txtAccyrid.value
      accyr->accfrom := frmAccyr.txtAccfrom.value
      accyr->accto := frmAccyr.txtAccto.value
      commit
      unlock
      addmode = .f.
      editmode = .f.
      Refreshform()
   endif
   return nil


static function CancelData()
   if addmode .or. editmode
      AddMode = .f.
      EditMode = .f.
      refreshform()
   else
      exit_prog()
   endif
   return nil


static function RefreshForm()
   frmAccyr.txtAccyrid.value := iif(addmode, "", accyr->accyrid)
   frmAccyr.txtAccfrom.value := iif(addmode, ctod(""), accyr->accfrom)
   frmAccyr.txtAccto.value := iif(addmode, ctod(""), accyr->accto)
   frmAccyr.txtAccyrid.enabled := .f.
   frmAccyr.txtAccfrom.enabled := (addmode .or. editmode)
   frmAccyr.txtAccto.enabled := (addmode .or. editmode)
   if addmode .or. editmode
      frmAccyr.btnSelect.caption := "&Save"
   else
      frmAccyr.btnSelect.caption := "&Select"
      frmAccyr.btnSelect.setfocus
   endif

   return nil


// Automatically create an id for accounting year
Static function CreateAccyrid()
   frmAccyr.txtAccyrid.value := ltrim(str(year(frmAccyr.txtAccfrom.value)))+ltrim(str(year(frmAccyr.txtAccto.value)))
   return nil

With best regards.

Sudip
With best regards,
Sudip

User avatar
mol
Posts: 3409
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 268 times
Been thanked: 173 times
Contact:

Post by mol »

I tried to compile your project, but I have got:
Harbour 1.0.1 Intl. (Rev. 9429)
Copyright (c) 1999-2008, http://www.harbour-project.org/
Compiling 'sudip.prg'...
Lines 11518, Functions/Procedures 12
Generating C source output to 'sudip.c'... Done.
sudip.o:sudip.c:(.data+0x18): undefined reference to `HB_FUN_NETSELECT'
sudip.o:sudip.c:(.data+0x2b8): undefined reference to `HB_FUN_SETUP_TABLES'
sudip.o:sudip.c:(.data+0x378): undefined reference to `HB_FUN_EXIT_PROG'

User avatar
sudip
Posts: 1446
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India
Has thanked: 5 times
Been thanked: 2 times

Post by sudip »

Hello MOL,

Thank you very much.

I didn't send those functions, because I thought the message would become very lengthy. I am sending them now ...

Code: Select all

Function Set_prog()
   set talk off
   set dele on
   set date brit
   set cent on
   set epoch to 1950
   SET BROWSESYNC ON
   SET NAVIGATION EXTENDED
   SET INTERACTIVECLOSE QUERY MAIN
   set font to "Arial", 09
   REQUEST DBFCDX , DBFFPT
   RDDSETDEFAULT( "DBFCDX" )
   s_user()
   s_accyr()
   return nil



Function Setup_tables()
   s_acct()
   return nil


Function Start_prog()
   Login()
   wAccyr()
   winMain.title := "Control ("+dtoc(_accfrom)+" - "+dtoc(_accto)+")"
   return nil

Function Exit_prog()
   release window winmain
   close all
   return nil


Function s_user()
   local adbf := {}
   aadd(adbf,  {"userid",   "c",  14,   0})
   aadd(adbf,  {"password", "c",  14,   0})
   if dbcreachk("user", adbf) .or. !file("user.cdx")
      if select("user") = 0
         use user exclusive
      endif
      select user
      index on userid tag userid
      use
   endif
   if select("user") = 0
      use user shared new
   endif
   select user
   if reccount()= 0
      append blank
      replace userid with "user"
      replace password with pass_in("user")
      unlock
   endif
   use
   retur nil

Function s_accyr()
   local adbf := {}
   aadd(adbf,   {"accyrid",   "c",   10,   0})
   aadd(adbf,   {"accfrom",   "d",   8,   0})
   aadd(adbf,   {"accto",   "d",   8,   0})
   if dbCreaChk("accyr", adbf) .or. !file("accyr.cdx")
      if select("accyr") = 0
         use accyr exclusive
      endif
      select accyr
      index on accyrid tag accyrid
      use
   endif
   return nil



//----------------------------------------- acct.dbf
function s_acct()
   local adbf := {}
   aadd(adbf,   {"acctcd",      "c",   10,   0})
   aadd(adbf,   {"acctnm",      "c",   40,   0})
   aadd(adbf,   {"actype",      "c",    1,   0})
   aadd(adbf,   {"istrad",      "l",    1,   0})
   aadd(adbf,   {"contra",      "l",    1,   0})
   aadd(adbf,   {"istax",       "l",    1,   0})
   aadd(adbf,   {"subled",      "l",    1,   0})
   aadd(adbf,   {"splac",       "l",    1,   0})
   aadd(adbf,   {"opgbal",      "n",   12,   2})
   aadd(adbf,   {"clobal",      "n",   12,   2})
   if dbCreaChk("acct", adbf) .or. !file("acct.cdx")
      if select("acct") = 0
         use acct exclusive
      endif
      index on acctcd tag acctcd
      index on upper(acctnm) tag acctnm
      use
   endif
   if select("acct") = 0
      use acct
   endif
   AcctInit()
   select acct
   use
   return nil


function AcctInit()
   local aRec := {}, Ctracctcd := 1, Ctracctnm := 2, CtrAcType := 3, ;
           CtrIsTrad := 4, CtrContra := 5, CtrIsTax := 6, CtrSubLed := 7, ;
           CtrSplAc := 8, i
   aadd(aRec, {"CASH",   "Cash",             "A", .F., .T., .F., .F., .t.})
   aadd(aRec, {"BANK",   "Bank",             "A", .F., .T., .F., .F., .t.})
   aadd(aRec, {"CHQIH",  "Cheque in Hand",   "A", .F., .T., .F., .F., .t.})
   aadd(aRec, {"SALE",   "Sales",            "I", .T., .F., .F., .T., .t.})
   aadd(aRec, {"PUR",    "Purchase",         "E", .T., .F., .F., .T., .t.})
   aadd(aRec, {"DBTR",   "Sundry Debtors",   "A", .F., .F., .F., .T., .t.})
   aadd(aRec, {"CRDTR",  "Sundry Creditors", "L", .F., .F., .F., .T., .t.})

   select acct
   set order to tag acctcd
   for i = 1 to len(aRec)
      seek aRec[i, Ctracctcd]
      if !found()
         append blank
         replace acctcd with aRec[i, Ctracctcd]
         replace acctnm with aRec[i, Ctracctnm]
         replace AcType with aRec[i, CtrAcType]
         replace Contra with aRec[i, CtrContra]
         replace isTax with  aRec[i, CtrIsTax]
         replace SubLed with aRec[i, CtrSubled]
         replace SplAc with  aRec[i, CtrSplAc]
      endif
   next
   return nil




FUNCTION dbCreaChk(fname, adbf)
   local aStruct, option, lChange := .f., lNew := .f., i, newrec, oldrec
   fname := upper(fname)
   if !file(fname+".dbf")
      set exclusive on
      dbcreate(fname, adbf)
      set exclusive off
      return .t.
   endif
   use (fname)
   aStruct = dbstruct()
   use

   if len(aStruct) != len(adbf)
      lChange = .t.
   else
      i = 1
      do while i <= len(aStruct) .and. !lNew .and. !lChange
         if len(aStruct[i, DBS_NAME]) != len(adbf[i, DBS_NAME]) ;
            .or. upper(aStruct[i, DBS_NAME]) != upper(adbf[i, DBS_NAME]) ;
            .or. upper(aStruct[i, DBS_TYPE]) != upper(adbf[i, DBS_TYPE]) ;
            .or. aStruct[i, DBS_LEN] != adbf[i, DBS_LEN] ;
            .or. aStruct[i, DBS_DEC] != adbf[i, DBS_DEC]
            lChange = .t.
         endif
         i++
      enddo
   endif

   if lChange
      if msgyesno(fname+" structure has been changed. Change";
                                   +" the structure ?")
         set exclusive on
         use (fname)
         pack
         oldrec = reccount()
         use
         deletefile("settemp.dbf")
         if renamefile(fname+".dbf", "settemp.dbf") != 0
            msginfo("Cannot change file structure!",)
            QUIT
         ENDIF
         dbcreate(fname, adbf)
         use (fname)
         append from settemp
         newrec = reccount()
         use
         if newrec != oldrec
            msginfo("Problem in creating file :"+fname+;
                   ". You can get all records in the file SETTEMP.DBF")
            quit
         endif
         deletefile("settemp.dbf")
         set exclusive off
         return .t.
      else
         msginfo(fname+" structure mismatch")
         quit
      endif
   endif
   return .f.



function NetSelect(cTable)
   if select(cTable) = 0
      use &cTable shared new
   endif
   return nil

With best regards.

Sudip
With best regards,
Sudip

User avatar
Rathinagiri
Posts: 5324
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 200 times
Been thanked: 210 times
Contact:

Post by Rathinagiri »

Thank you Sudip.

You can post the code inside [ code] [/code] bbcode tag, so that the space in every line is maintained.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
sudip
Posts: 1446
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India
Has thanked: 5 times
Been thanked: 2 times

Post by sudip »

Thank you Rathi. :)

I shall do that.

Regards.

Sudip
With best regards,
Sudip

Post Reply