home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bde / inventry.pak / INV_UTIL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  6.9 KB  |  195 lines

  1. // BDE - (C) Copyright 1994 by Borland International
  2.  
  3. #include "inventry.h"
  4.  
  5. //======================================================================
  6. //  Function:
  7. //          WinMsg(Msg, TypeMsg, TypeBtn);
  8. //
  9. //  Input:  pMsg - The message to display.
  10. //          TypeMsg - The type of messagebox to use (i.e. Stop,
  11. //          Information,
  12. //          TypeBtn - The buttons to use (i.e. Yes, No, OK, ...)
  13. //
  14. //  Return: Response from the user.
  15. //
  16. //  Description:
  17. //          Display a message box & return a value representing
  18. //          the button the user pressed. Standard windows input is
  19. //          required for the type of message, and button(s), to use.
  20. //======================================================================
  21. UINT16
  22. WinMsg (pCHAR pMsg, UINT16 TypeMsg, UINT16 TypeBtn)
  23. {
  24.     return(MessageBox(hMainWnd, (LPSTR) pMsg, "Inventory Message",
  25.                       (WORD) TypeBtn | TypeMsg | MB_APPLMODAL));
  26. }
  27.  
  28. //======================================================================
  29. //  Function:
  30. //          ChangeEntryMode();
  31. //
  32. //  Input:  None.
  33. //
  34. //  Return: None.
  35. //
  36. //  Description:
  37. //          Swap the data entry mode. This will either switch from
  38. //          "modify a record" to "add a record," or visa-versa.
  39. //======================================================================
  40. void
  41. ChangeEntryMode (void)
  42. {
  43.     // These variables are used to determine which controls are visible
  44.     UINT16  Show1;          // Controls which are visible at startup
  45.     UINT16  Show2;          // Controls used far adding a record
  46.     UINT16  Show3;          // Menu items to enable
  47.     
  48.     char    szString[150];  // Used to read data from the string resource
  49.  
  50.     if (NewRecMode)
  51.     {
  52.         // Change the mode flag
  53.         NewRecMode = FALSE;
  54.  
  55.         // Show the startup resources
  56.         Show1 = SW_SHOW;
  57.  
  58.         // Hide the OK and Cancel buttons
  59.         Show2 = SW_HIDE;
  60.  
  61.         // Enable the menu options
  62.         Show3 = MF_ENABLED;
  63.     }
  64.     else
  65.     {
  66.         // Change the mode flag
  67.         NewRecMode = TRUE;
  68.  
  69.         // Hide the startup resources
  70.         Show1 = SW_HIDE;
  71.  
  72.         // Show the OK and Cancel buttons
  73.         Show2 = SW_SHOW;
  74.  
  75.         // Disable the menu options
  76.         Show3 = MF_GRAYED;
  77.     }
  78.  
  79.     // These resources are shown when the app starts
  80.     ShowWindow(GetDlgItem(hMainWnd, ID_ADD_REC), Show1);
  81.     ShowWindow(GetDlgItem(hMainWnd, ID_DEL_REC), Show1);
  82.     ShowWindow(GetDlgItem(hMainWnd, ID_FIRST_REC), Show1);
  83.     ShowWindow(GetDlgItem(hMainWnd, ID_PREV_REC), Show1);
  84.     ShowWindow(GetDlgItem(hMainWnd, ID_NEXT_REC), Show1);
  85.     ShowWindow(GetDlgItem(hMainWnd, ID_LAST_REC), Show1);
  86.     ShowWindow(GetDlgItem(hMainWnd, ID_MOD_REC), Show1);
  87.     ShowWindow(GetDlgItem(hMainWnd, ID_UNDO_REC), Show1);
  88.     ShowWindow(GetDlgItem(hMainWnd, ID_ORDER), Show1);
  89.     ShowWindow(GetDlgItem(hMainWnd, ID_SEARCH), Show1);
  90.     ShowWindow(GetDlgItem(hMainWnd, ID_RANGE), Show1);
  91.     ShowWindow(GetDlgItem(hMainWnd, IDS_DATABASE_HDR), Show1);
  92.  
  93.     // These menu options are enabled when the app starts
  94.     EnableMenuItem(GetMenu(hMainWnd), ID_FIRST_REC, Show3);
  95.     EnableMenuItem(GetMenu(hMainWnd), ID_PREV_REC, Show3);
  96.     EnableMenuItem(GetMenu(hMainWnd), ID_NEXT_REC, Show3);
  97.     EnableMenuItem(GetMenu(hMainWnd), ID_LAST_REC, Show3);
  98.     EnableMenuItem(GetMenu(hMainWnd), ID_ADD_REC, Show3);
  99.     EnableMenuItem(GetMenu(hMainWnd), ID_DEL_REC, Show3);
  100.     EnableMenuItem(GetMenu(hMainWnd), ID_MOD_REC, Show3);
  101.     EnableMenuItem(GetMenu(hMainWnd), ID_ORDER, Show3);
  102.     EnableMenuItem(GetMenu(hMainWnd), ID_RANGE, Show3);
  103.     EnableMenuItem(GetMenu(hMainWnd), ID_CLEAR_RANGE, Show3);
  104.     EnableMenuItem(GetMenu(hMainWnd), ID_SEARCH, Show3);
  105.     EnableMenuItem(GetMenu(hMainWnd), ID_UNDO_REC, Show3);   
  106.     
  107.     // These resources need to be disabled while in add record mode
  108.     EnableWindow(GetDlgItem(hMainWnd, ID_ORDER), !NewRecMode);
  109.     EnableWindow(GetDlgItem(hMainWnd, ID_RANGE), !NewRecMode);
  110.     EnableWindow(GetDlgItem(hMainWnd, ID_SEARCH), !NewRecMode);
  111.  
  112.     // These resources are hidden when the application starts
  113.     ShowWindow(GetDlgItem(hMainWnd, IDOK), Show2);
  114.     ShowWindow(GetDlgItem(hMainWnd, IDCANCEL), Show2);
  115.     EnableWindow(GetDlgItem(hMainWnd, IDCANCEL), NewRecMode);
  116.     EnableWindow(GetDlgItem(hMainWnd, IDOK), NewRecMode);
  117.     if(NewRecMode)
  118.     {
  119.         LoadString(hInst, IDS_MAIN, szString, 150);
  120.         SetDlgItemText(hMainWnd, IDS_NEW_REC_DESC, (pCHAR)szString);
  121.     }
  122.     ShowWindow(GetDlgItem(hMainWnd, IDS_NEW_REC_DESC), Show2);
  123.     ShowWindow(GetDlgItem(hMainWnd, IDS_NEW_REC_DESC), Show2);
  124. }
  125.  
  126. //=====================================================================
  127. //  Function:
  128. //          MakeFullPath (pszDirectory, pszRelativeDirectory)
  129. //
  130. //  Input:  pszDirectory            - String to contain the path to the tables
  131. //                                      directory.
  132. //          pszRelativeDirectory    - String which contains the relative offset
  133. //                                      from the current directory.
  134. //
  135. //  Return: int     - If the directory exists
  136. //
  137. //  Description:
  138. //          This function is used to get the fully qualified path to
  139. //          the directory which will contain the tables. This function
  140. //          will only work when pszRelativeDirectory contains either "."
  141. //          an absolute path, or ..\\..\\TABLES.
  142. //=====================================================================
  143. int
  144. MakeFullPath (pCHAR pszDirectory, pCHAR pszRelativeDirectory)
  145. {
  146.     int     iExists;    // Does the directory exist?
  147.     int     iLen;       // Length of the path
  148.     int     iLoop;      // Loop counter
  149.     int     iDepth = 0;
  150.     
  151.     // Assume absolute path if second character is a ':'
  152.     if (pszRelativeDirectory[1] == ':')
  153.     {
  154.         strcpy(pszDirectory, pszRelativeDirectory);
  155.     }
  156.     else if (!strcmp(pszRelativeDirectory, "."))
  157.     {
  158.         // Get the current working directory
  159.         getcwd(pszDirectory, DBIMAXPATHLEN);
  160.     }
  161.     else
  162.     {
  163.         // Get the current working directory
  164.         getcwd(pszDirectory, DBIMAXPATHLEN);
  165.         
  166.         iLen = strlen(pszDirectory);
  167.  
  168.         // Remove relative parts of the path.
  169.         iDepth = 0;
  170.         while (!strncmp(&pszRelativeDirectory[iDepth * 3], "..\\", 3))
  171.         {
  172.             for (iLoop = iLen; iLoop > -1; iLoop = iLoop - 1)
  173.             {
  174.                 if (pszDirectory[iLoop] == '\\')
  175.                 {
  176.                     break;
  177.                 }
  178.             }
  179.             iLen = iLoop - 1;
  180.             iDepth++;
  181.         }
  182.  
  183.         // Copy the 'TABLES' directory to form the full path to the tables.
  184.         //   Need to move szDirectory past the '\\' and szTblDirectory
  185.         //   past the '..\\'.
  186.         strcpy(&pszDirectory[iLoop+1], &pszRelativeDirectory[(3 * iDepth)]);
  187.     }
  188.  
  189.     // Check if the directory exists
  190.     iExists = access(pszDirectory, 00);
  191.  
  192.     return iExists;
  193. }
  194.  
  195.