home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a063 / 6.img / SAMPLE / APTFORMS / CLCST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-24  |  1.7 KB  |  68 lines

  1. #include <sybfront.h>
  2. #include <sybdb.h>
  3. #include <sybfrs.h>
  4.  
  5. #if MSDOS
  6. #    include    "aforms.h"
  7. #endif /* MSDOS */
  8.  
  9. #define BUFSIZE 100
  10.  
  11.  
  12. /*
  13. **    CLCST - Compute the total cost and display it.
  14. **
  15. **    Read the quantity, total discount, and price-per-book from the form.
  16. **    Then, compute the total cost and display the cost on the form.
  17. **    This routine is called from several procedures.
  18. */
  19.  
  20. RETCODE
  21. clcst(form, qtyfld, discfld, pricefld, costfld)
  22. FORM            *form;
  23. char            *qtyfld;
  24. char            *discfld;
  25. char            *pricefld;
  26. char            *costfld;
  27. {
  28.     char          buf[BUFSIZE];
  29.     int           check;
  30.     DBINT         qty;
  31.     DBMONEY       money;
  32.     DBFLT8        pricef;
  33.     DBFLT8        discount;
  34.     DBFLT8        totcost;
  35.  
  36.     if (fsfreadval(form, qtyfld, -1, NULL, &qty, &check) == NULL ||
  37.          check == -1)
  38.     {
  39.         fsmessage("Please enter the quantity.");
  40.         return(FAIL);
  41.     }
  42.     /* Since the discount is computed, not entered, we trust it. */
  43.     fsfreadval(form, discfld, -1, NULL, &discount, &check);
  44.  
  45.     if (fsfreadval(form, pricefld, -1, NULL, &money, NULL) == NULL ||
  46.          check == -1)
  47.     {
  48.         fsmessage("The price is not in the database.");
  49.         return(FAIL);
  50.     }
  51.     /* We can't use DBMONEY datatype--which is large--in C computations.
  52.     ** So, first convert it to a float.
  53.     */
  54.     dbconvert(NULL, SYBMONEY, &money, -1, SYBFLT8, &pricef, -1);
  55.     
  56.     totcost = (1.00 - (discount/ 100.00) ) * (qty * pricef);
  57.  
  58.     /*
  59.     **  We must convert the value from SYBFLT8 back
  60.     **  to DBMONEY before placing it on the screen.
  61.     */
  62.     dbconvert(NULL, SYBFLT8, &totcost, -1, SYBMONEY, &money, -1);
  63.     fsfwriteval(form, costfld, -1, NULL, -1, SSOFF,
  64.             &money, buf, -1, FALSE);
  65.  
  66.     return (SUCCEED);
  67. }
  68.