home *** CD-ROM | disk | FTP | other *** search
- #include <sybfront.h>
- #include <sybdb.h>
- #include <sybfrs.h>
-
- #if MSDOS
- # include "aforms.h"
- #endif /* MSDOS */
-
- #define BUFSIZE 100
-
-
- /*
- ** CLCST - Compute the total cost and display it.
- **
- ** Read the quantity, total discount, and price-per-book from the form.
- ** Then, compute the total cost and display the cost on the form.
- ** This routine is called from several procedures.
- */
-
- RETCODE
- clcst(form, qtyfld, discfld, pricefld, costfld)
- FORM *form;
- char *qtyfld;
- char *discfld;
- char *pricefld;
- char *costfld;
- {
- char buf[BUFSIZE];
- int check;
- DBINT qty;
- DBMONEY money;
- DBFLT8 pricef;
- DBFLT8 discount;
- DBFLT8 totcost;
-
- if (fsfreadval(form, qtyfld, -1, NULL, &qty, &check) == NULL ||
- check == -1)
- {
- fsmessage("Please enter the quantity.");
- return(FAIL);
- }
- /* Since the discount is computed, not entered, we trust it. */
- fsfreadval(form, discfld, -1, NULL, &discount, &check);
-
- if (fsfreadval(form, pricefld, -1, NULL, &money, NULL) == NULL ||
- check == -1)
- {
- fsmessage("The price is not in the database.");
- return(FAIL);
- }
- /* We can't use DBMONEY datatype--which is large--in C computations.
- ** So, first convert it to a float.
- */
- dbconvert(NULL, SYBMONEY, &money, -1, SYBFLT8, &pricef, -1);
-
- totcost = (1.00 - (discount/ 100.00) ) * (qty * pricef);
-
- /*
- ** We must convert the value from SYBFLT8 back
- ** to DBMONEY before placing it on the screen.
- */
- dbconvert(NULL, SYBFLT8, &totcost, -1, SYBMONEY, &money, -1);
- fsfwriteval(form, costfld, -1, NULL, -1, SSOFF,
- &money, buf, -1, FALSE);
-
- return (SUCCEED);
- }
-