home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 21.ddi / VALIDATE.PAK / VALIDATX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  3.8 KB  |  129 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //----------------------------------------------------------------------------
  4. #include <owl\owlpch.h>
  5. #include <owl\applicat.h>
  6. #include <owl\dialog.h>
  7. #include <owl\framewin.h>
  8. #include <owl\edit.h>
  9. #include <owl\checkbox.h>
  10. #include <owl\validate.h>
  11. #include <string.h>  // for strcpy and strcat
  12. #include <stdlib.h>  // for atoi
  13. #include <ctype.h>   // for isdigit and isalpha
  14.  
  15.  
  16. #define CM_EMPINPUT 201
  17.  
  18. #define MAXNAMELEN  35
  19. #define MAXSSLEN    12
  20. #define MAXIDLEN    4
  21. #define MAXDEPTLEN  7
  22. #define MAXSECLEN   3
  23.  
  24. struct TEmployeeStruct {
  25.   char NameEdit[MAXNAMELEN];
  26.   char SSEdit[MAXSSLEN];
  27.   char IDEdit[MAXIDLEN];
  28.   char DeptEdit[MAXDEPTLEN];
  29.   char SecEdit[MAXSECLEN];
  30.   BOOL FullTime;
  31.   BOOL Perm;
  32.   BOOL Exempt;
  33. };
  34.  
  35. //----------------------------------------------------------------------------
  36.  
  37. class TEmployeeDlg : public TDialog {
  38.   public:
  39.     TEmployeeDlg(TWindow* parent, const char* name, TEmployeeStruct& transfer);
  40. };
  41.  
  42. TEmployeeDlg::TEmployeeDlg(TWindow* parent, const char* name, TEmployeeStruct& transfer)
  43.   : TDialog(parent, name),
  44.     TWindow(parent)
  45. {
  46.   TEdit* edit;
  47.   edit = new TEdit(this, 101, sizeof(transfer.NameEdit));
  48.   edit->SetValidator(new TFilterValidator("A-Za-z. "));
  49.   edit = new TEdit(this, 102, sizeof(transfer.SSEdit));
  50.   edit->SetValidator(new TPXPictureValidator("###-##-####"));
  51.   edit = new TEdit(this, 103, sizeof(transfer.IDEdit));
  52.   edit->SetValidator(new TRangeValidator(1, 999));
  53.   edit = new TEdit(this, 104, sizeof(transfer.DeptEdit));
  54.   edit->SetValidator(new TPXPictureValidator("Sales,Dev,Mfg"));
  55.   edit = new TEdit(this, 105, sizeof(transfer.SecEdit));
  56.   edit->SetValidator(new TPXPictureValidator("11,12,13,14,15"));
  57.   new TCheckBox(this, 106, 0);
  58.   new TCheckBox(this, 107, 0);
  59.   new TCheckBox(this, 108, 0);
  60.  
  61.   TransferBuffer = (void far*)&transfer;
  62. }
  63.  
  64. //----------------------------------------------------------------------------
  65.  
  66. class TTestWindow : public TFrameWindow {
  67.   public:
  68.     TTestWindow(TWindow* parent, const char* title);
  69.     void CmEmpInput();
  70.  
  71.   private:
  72.     TEmployeeStruct EmployeeStruct;
  73.  
  74.   DECLARE_RESPONSE_TABLE(TTestWindow);
  75. };
  76.  
  77. DEFINE_RESPONSE_TABLE1(TTestWindow, TFrameWindow)
  78.   EV_COMMAND(CM_EMPINPUT, CmEmpInput),
  79. END_RESPONSE_TABLE;
  80.  
  81.  
  82. TTestWindow::TTestWindow(TWindow* parent, const char* title)
  83.   : TFrameWindow(parent, title),
  84.     TWindow(parent, title)
  85. {
  86.   AssignMenu(200);
  87.   memset(&EmployeeStruct, 0, sizeof EmployeeStruct);
  88. }
  89.  
  90. void
  91. TTestWindow::CmEmpInput()
  92. {
  93.   char empInfo[sizeof(TEmployeeStruct)+5+1];
  94.  
  95.   if (TEmployeeDlg(this,"EMPLOYEEINFO", EmployeeStruct).Execute() == IDOK) {
  96.     strcpy(empInfo, EmployeeStruct.NameEdit);
  97.     strcat(empInfo, "\n");
  98.     strcat(empInfo, EmployeeStruct.SSEdit);
  99.     strcat(empInfo, "\n");
  100.     strcat(empInfo, EmployeeStruct.IDEdit);
  101.     strcat(empInfo, "\n");
  102.     strcat(empInfo, EmployeeStruct.DeptEdit);
  103.     strcat(empInfo, "\n");
  104.     strcat(empInfo, EmployeeStruct.SecEdit);
  105.     strcat(empInfo, "\n");
  106.     strcat(empInfo, EmployeeStruct.FullTime ? "FullTime " : "PartTime ");
  107.     strcat(empInfo, EmployeeStruct.Perm ? "Permanent " : "Temporary ");
  108.     strcat(empInfo, EmployeeStruct.Exempt ? "Exempt " : "NonExempt ");
  109.     MessageBox(empInfo, "Information Stored", MB_OK);
  110.   }
  111. }
  112.  
  113. //----------------------------------------------------------------------------
  114.  
  115. class TValidateApp : public TApplication {
  116.   public:
  117.     TValidateApp() : TApplication("ValidateApp") {}
  118.     void InitMainWindow() {
  119.       EnableCtl3d();
  120.       MainWindow = new TTestWindow(0, "Validate Dialog Input");
  121.     }
  122. };
  123.  
  124. int
  125. OwlMain(int /*argc*/, char* /*argv*/ [])
  126. {
  127.   return TValidateApp().Run();
  128. }
  129.