home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / OPENSTEP / Utilities / CreditCardChecker-2.0-MIS / CCCCObject.m < prev    next >
Encoding:
Text File  |  1997-06-29  |  3.3 KB  |  128 lines

  1. #import "CCCCObject.h"
  2.  
  3. @implementation CCCCObject
  4.  
  5.  
  6. - (void)applicationDidFinishLaunching:(NSNotification *)notification
  7. // In order for your object to receive this notification make sure that
  8. // your object is a delegate or "File's Owner" in IB.
  9. // Connected from "File's Owner" to MenuObject in this case.
  10. {
  11.  
  12.     [TheWindow makeKeyAndOrderFront:NULL];
  13.     [CCnumber selectText:self];
  14. }
  15.  
  16.  
  17. - (void)CheckIt:(id)sender
  18. {
  19.     // This program is based on cc_cksum. Credit Card check sum program
  20.     // from 2600 magazine.
  21.     //
  22.     // Adapted for OpenStep by Eric Tremblay June 29, 1997
  23.  
  24.     // Local Variables
  25.     const char *cc;
  26.     int check, len, prod, j;
  27.  
  28.         // Assign the value in the panel to the cc variable.
  29.         cc = [[CCnumber stringValue] cString];
  30.     
  31.         if (cc[0] != '3' && cc[0] != '4' && cc[0] != '5' && cc[0] != '6') {
  32.             [Status setStringValue:@"Card number must start with 3, 4, 5, or 6."];
  33.             [Status setTextColor:[NSColor purpleColor]];
  34.             [CCnumber selectText:self]; 
  35.             return;
  36.         }
  37.  
  38.         // Counts the string length of the cc variable.
  39.         len = strlen(cc);
  40.  
  41.         
  42.         if (cc[0] == '5' && len != 16) {
  43.             [Status setStringValue:@"Mastercard must be 16 digits."];
  44.             [Status setTextColor:[NSColor orangeColor]];
  45.             [CCnumber selectText:self]; 
  46.             return;
  47.         }
  48.  
  49.         
  50.         if (cc[0] == '4' && (len != 13 && len != 16)) {
  51.             [Status setStringValue:@"Visa numbers must be 13 or 16 digits."];
  52.             [Status setTextColor:[NSColor orangeColor]];
  53.             [CCnumber selectText:self]; 
  54.             return;
  55.         }
  56.  
  57.         
  58.         if (cc[0] == '3' && len != 15) {
  59.             [Status setStringValue:@"American Express numbers must be 15 digits."];
  60.             [Status setTextColor:[NSColor orangeColor]];
  61.             [CCnumber selectText:self]; 
  62.             return;
  63.         }
  64.  
  65.         
  66.         if (cc[0] == '6' && len != 16) {
  67.             [Status setStringValue:@"Discover numbers must be 16 digits."];
  68.             [Status setTextColor:[NSColor orangeColor]];
  69.             [CCnumber selectText:self]; 
  70.             return;
  71.         }
  72.  
  73.         
  74.         //  Perform checksum - Weighing list 212121212121...
  75.         check = 0;
  76.         for (j = 0; j < len; ++j) {
  77.             prod = cc[j] - '0';
  78.             if (((len - (j + 1)) %2)) {
  79.                 prod *= 2;
  80.             }
  81.             if (prod >= 10) {
  82.                 prod = prod - 9;
  83.             }
  84.             check += prod;
  85.         }
  86.         
  87.         if ((check % 10) == 0) {
  88.             [Status setStringValue:@"Card has good checksum"];
  89.             [Status setTextColor:[NSColor greenColor]];
  90.             [CCnumber selectText:self]; 
  91.         } else {
  92.             [Status setStringValue:@"Card has BAD checksum"];
  93.             [Status setTextColor:[NSColor redColor]];
  94.             [CCnumber selectText:self]; 
  95.         }
  96.         
  97. }
  98.  
  99. - (void)InfoPanel:(id)sender
  100. {
  101.  
  102.     [NSBundle loadNibNamed:@"InfoPanel.nib" owner:self]; // load nib
  103.     
  104. }
  105.  
  106. - (void)IntroAndHelp:(id)sender
  107. {
  108.  
  109.     [NSBundle loadNibNamed:@"HelpIntro.nib" owner:self]; // load nib
  110.     
  111. }
  112.  
  113. - (void)MoreInfo:(id)sender
  114. {
  115.  
  116.     [NSBundle loadNibNamed:@"MoreInfo.nib" owner:self]; // load nib
  117.     
  118. }
  119.  
  120. - (void)ClearStatus:(id)sender
  121. {
  122.  
  123.     [Status setStringValue:@"Hello World!!!"];
  124.  
  125. }
  126.  
  127. @end
  128.