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