home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a063 / 6.img / SAMPLE / APTFORMS / SE_MAIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-24  |  3.5 KB  |  132 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. /*    MAIN body of the Sales Entry System.
  10. **
  11. **    Open a connection to the SQL Server and set the database context
  12. **    to the database that is to receive the new sales data.  If that 
  13. **    succeeds, install the procedures called by the form, and turn
  14. **    control over to the forms run-time system.
  15. */
  16.  
  17. extern  int  gthdr();
  18. extern  int  strin();
  19. extern  int  titin();
  20. extern  int  dscin();
  21. extern  int  rgdsc();
  22. extern  int  adisc();
  23. extern  int  clrfd();
  24. extern  int  inval();
  25. extern  int  printform();
  26. extern  int  msg_handler();
  27. extern  int  err_handler();
  28.  
  29. static FSPROCEDURE procarray[] =     {
  30.     {"gthdr",       gthdr,          NULL,   SYB_C},
  31.     {"strin",       strin,          NULL,   SYB_C},
  32.     {"titin",       titin,          NULL,   SYB_C},
  33.     {"dscin",       dscin,          NULL,   SYB_C},
  34.     {"rgdsc",       rgdsc,          NULL,   SYB_C},
  35.     {"adisc",       adisc,          NULL,   SYB_C},
  36.     {"clrfd",       clrfd,          NULL,   SYB_C},
  37.     {"inval",       inval,          NULL,   SYB_C},
  38.     {"printform",   printform,      NULL,   SYB_C},
  39.     {NULL, NULL, NULL, SYB_C},      };
  40.  
  41. main(argc, argv)
  42. int       argc;
  43. char      *argv[ ];
  44. {
  45.     LOGINREC        *loginrec;
  46.     DBPROCESS       *dbproc;
  47.     FORM            *salesform;
  48.     POINTER         argarray[1];
  49.     FSPROCEDURE     *oldprocarray;
  50.  
  51.     /* Initialize the terminal environment.  Fsopenscreen uses
  52.     ** non-NULL parameters if it is running on a bitmap terminal.
  53.     ** In other environments, non-NULL parameters are simply ignored.
  54.     */
  55.     if (fsopenscreen(&argc, argv, "Sales Application") == FAIL)
  56.     {
  57.         printf("Couldn't initialize the screen.\n");
  58.         exit(STDEXIT);
  59.     }
  60.  
  61. #if BDS42 || VMS
  62.     /* Initialize DB-Library. */
  63.     if (dbinit() == FAIL)
  64.         exit(ERREXIT);
  65. #endif /* BSD42 || VMS */    
  66.  
  67.     /* Call login routine, which opens a DBPROCESS and allocates
  68.     ** a LOGINREC structure.   loginrec must be a pointer to
  69.     ** a pointer.
  70.     */
  71.     if ((dbproc = fsdblogin(&loginrec, "Sales Entry Login") ) == NULL)
  72.     {
  73.         /* User backed out of login screen. */
  74.         fsclosescreen();
  75.         dbexit();
  76.         exit(STDEXIT);
  77.     }
  78.  
  79.     /* Install message and error handlers. */
  80.     dbmsghandle(msg_handler);
  81.     dberrhandle(err_handler);
  82.  
  83.  
  84.     /* The forms run-time system needs a DBPROCESS for the Values Key.  This 
  85.     ** application can share the DBPROCESS, since the application queries are
  86.     ** fully finished at all times that the user has control of the screen.
  87.     */
  88.     fsdbproc(dbproc);
  89.  
  90.     /* Change to the PUBS database.  */
  91.     dbuse(dbproc, "pubs");
  92.  
  93.     /* Load the form. */
  94.     if (( salesform = fsgetform("sntr", "3") ) == NULL)
  95.     {
  96.         fsabort("Unable to open form sntr 3.\n");
  97.     }
  98.  
  99.     /* Install the array of external procedures which will be called by
  100.     ** the form.  Save the previous array of procedures so that it can
  101.     ** be restored when this module ends.
  102.     */
  103.     oldprocarray = fsinstallproc(procarray);
  104.  
  105.     /* Set the parameter(s) for the external procedures. */
  106.  
  107.     argarray[0]  = (POINTER) dbproc;
  108.     fsprocargs("inval", argarray);
  109.     fsprocargs("gthdr", argarray);
  110.     fsprocargs("strin", argarray);
  111.     fsprocargs("titin", argarray);
  112.     fsprocargs("dscin", argarray);
  113.  
  114.  
  115.     /* Turn control over to the forms run-time system. */
  116.     fscallform(salesform);
  117.  
  118.     /* Clean up! */
  119.  
  120.     dbclose(dbproc);
  121.     dbexit();
  122.     fsclosescreen();
  123.  
  124.     /*  Restore the old procedure array--pointless since this is
  125.     **  the main routine, but normally a good idea.
  126.     */
  127.     fsinstallproc(oldprocarray);
  128.  
  129.     exit(STDEXIT);
  130.  
  131. } /* End of program. */
  132.