home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource1 / chint / useful12.hnt < prev    next >
Encoding:
Text File  |  1992-06-09  |  3.8 KB  |  103 lines

  1. How to add records to a transaction file:--
  2.  
  3. 1) Define the "TRAN" transaction database using DataBoss.  You would have
  4.    fields like :--
  5.  
  6.      TRANS_NO     -- 6#          Numeric   [key no. 1, (Unique)]
  7.      TRANS_MODE    -- U          Character
  8.      TRANS_DATE   -- ##/##/####  Character
  9.      TRANS_DESCR  -- 40X         Character
  10.      TRANS_AMOUNT -- 8#.2#       Numeric
  11.  
  12. 2) Generate and compiler the "TRAN"  application.
  13.  
  14. 3) Define the main application from which the transactions will arise.  This
  15.    could be something like and "INV" invoice application.  A very simple
  16.    invoice application could have a single file with fields like :--
  17.  
  18.      INV_NO            -- 10#         Numeric   [key no. 1, (Unique)]
  19.      INV_DATE          -- ##/##/####  Character
  20.      CUSTOMER_ACCT_NO  -- 10U         Character
  21.      CUSTOMER_NAME     -- 20X         Character
  22.      CUSTOMER_ADDRESS1 -- 25X         Character
  23.      CUSTOMER_ADDRESS2 -- 25X         Character
  24.      CUSTOMER_ADDRESS3 -- 25X         Character
  25.      GOODS_DESCR       -- 40X         Character
  26.      COST_OF_GOODS     -- 4#.2#       Numeric
  27.  
  28. 4) Migrate file 1 of the TRAN application to file 2 of the INV application.
  29.    It can be associated with window 1, and does not need to be linked to any
  30.    file.  When TRAN is later generated it will automatically have the code
  31.    to open existing TRAN files and indexes.
  32.  
  33. 5) Write a function to add a record and its indexes to the transaction file.
  34.    Put this code into a function file, (like ADDTRAN.FUN), so that it can be
  35.    included in the main application.
  36.  
  37. void addTransaction(char mode)
  38. {
  39.   int fno, kno;
  40.   long rno, tl;
  41.   keystr tkey;
  42.   bool savok;
  43.  
  44.   savok = ok;       /* Save the current value of ok */
  45.   fno := 2;         /* We want to work with file 2, the TRAN file */
  46.   clear_rec(fno);   /* Initialise the data buffer for file 2 "TRAN1" */
  47.  
  48. /* Calculate the next unique Transaction Number */
  49.   kno = 1;                    /* Key 1 is the unique transaction number */
  50.   clearkey(idxkey[fno][kno]);
  51.   prevkey(idxkey[fno][kno],&rno,tkey);
  52.   if (!ok) tl = 1; else tl = ival(tkey) + 1;
  53.  
  54. /* Initialise fields, be sure to pad or truncate to the correct length for
  55.    character fields, and the correct length & decimal places for numerics */
  56.  
  57.   istr(TRAN1.TRANS_NO,tl,6);
  58.   TRAN1.TRANS_MODE[0] = mode;
  59.   sysdate(TRAN1.TRANS_DATE);
  60.   strconcat(_tts,INV1.INV_NO," ",
  61.                  INV1.CUSTOMER_ACCT_NO," "
  62.                  INV1.GOODS_DESCR,NULL);
  63.   strcopy(TRAN1.TRANS_DESCR,_tts,0,40);
  64.   fstr(TRAN1.TRANS_AMOUNT,valu(INV1.COST_OF_GOODS),11,2);
  65.  
  66. /* Add the record and keys */
  67.   addrec(datf[fno],&rno,&TRAN1);
  68.   for (kno=1; kno <= maxkeyno; kno++) {
  69.     if (keylen[fno][kno] > 0) {
  70.       getakey(tkey,fno,kno);
  71.       addkey(idxkey[fno][kno],&rno,tkey);
  72.       if (!ok)
  73.         dberrm("Attempt To Add Bad Key - Rewrite Procedure Code !!");
  74.     }
  75.   }
  76.  
  77.   ok = savok;  /* Restore value of OK */
  78. }
  79.  
  80. 6) Create a custom skeleton file file that includes ADDTRAN.FUN, and calls
  81.    addTransaction() whenever you want to want another transaction record
  82.    added to the database.
  83.  
  84.    This could be at the end of the "edit_record()", "add_record()" and
  85.    "delete_record()" functions :--
  86.  
  87.    /* Just after the DisplayRec at the end of "edit_record()" */
  88.    if (exitcode != QitKey) addTransaction('E');
  89.  
  90.    /* Just after the DisplayRec at the end of "Add_Record" */
  91.    if (exitcode != QitKey) addTransaction('A');
  92.  
  93.    /* Just before the call to DelARec in "Delete_Record" */
  94.    if (exitCode != QitKey) addTransaction('D');
  95.  
  96. 7) Generate and compile INV, but remember to change the skeleton
  97.    specification on the generate screen from DBC.SKL to INV.SKL
  98.  
  99. 8) Run TRAN.EXE.  This will create the empty TRAN1.DAT and TRAN1.K1 files
  100.  
  101. 9) Run INV.EXE.  Add, Copy, Edit and Delete records.
  102.  
  103. 10) Run TRAN to look at the transactions that have been created.