home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a063 / 6.img / SAMPLE / APTFORMS / TITIN.C < prev   
Encoding:
C/C++ Source or Header  |  1990-08-24  |  1.8 KB  |  81 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. **    TITIN - Get the book title information.
  13. **    
  14. **    Retrieve the book information from the SQL Server.
  15. **    If there is no such book, display a message and reposition
  16. **    the cursor on the book field.
  17. **    This procedure is triggered by title field post-processing.
  18. */
  19.  
  20. titin (context, argarray)
  21. FRSCONTEXT         *context;
  22. POINTER            argarray[];
  23. {
  24.  
  25.  
  26.     DBPROCESS        *dbproc;
  27.     FORM             *salesform;
  28.     OBJDSC           objdsc;
  29.     OBJDSC           *titlefld = &objdsc;
  30.     char             buf[BUFSIZE];
  31.     char             *title;
  32.     int              rows;
  33.  
  34.     salesform = fscurform(context);
  35.     dbproc = (DBPROCESS *)argarray[0];
  36.  
  37.     /* Get the book title field */
  38.     fsfgetfld(salesform, "title", -1, NULL, titlefld);
  39.  
  40.     /* Check whether the field has been modified: if not, there's no
  41.     ** need to do anything.  If it has been modified, reset the modified
  42.     ** flag, so that it will reflect only new changes on later events.
  43.     */
  44.     if ( fsfisfldmod(titlefld) == FALSE)
  45.     {
  46.         return;
  47.     }
  48.     else
  49.     {
  50.         fsfclrfldflags(salesform, titlefld, FRS_MODIFIED);
  51.     }
  52.     title = fsfreadval(salesform, "title", -1, NULL, NULL, NULL);
  53.  
  54.     if (title == NULL)
  55.         return;    /* Nothing to process... */
  56.     
  57.     /* Run the query. */
  58.     rows = fssql(dbproc, 
  59.     "select titleid = title_id, price from titles where title = '{title}'");
  60.  
  61.     switch(rows)
  62.     {
  63.       case 0:
  64.          /* If no rows were retrieved, then complain. */
  65.  
  66.         fsmessage("Sorry, no such title.");
  67.         fsfsetfldflags(salesform, titlefld, FRS_MODIFIED);
  68.         fsfsetcurfld(context, titlefld);
  69.         break;
  70.  
  71.       case 1:
  72.         /* All is well. */
  73.         break;
  74.  
  75.       default:
  76.         fsabort("Attempt to read titles failed(fssql)");
  77.         break;
  78.     }
  79.     return;
  80. }
  81.