home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP Advantage / NeXTstep_Advantage.img / YourCallClient / CallClient.m < prev    next >
Text File  |  1993-04-14  |  4KB  |  137 lines

  1. /*    You may freely copy, distribute and reuse the code in this example.
  2.  *    NeXT disclaims any warranty of any kind, expressed or implied, as to
  3.  *    its fitness for any particular use.
  4.  */
  5.  
  6. #import "CallClient.h"
  7.  
  8. @implementation CallClient:Object
  9.  
  10. /* 
  11.  * Purpose: Initializes the CallClient
  12.  *
  13.  * Inherited from Object, overridden by CallClient.
  14.  * Connects the client, through the callProvider proxy, 
  15.  * to the CallServer in the YourCallServer application.  
  16.  */
  17.  
  18. - init
  19. {
  20.     [super init];
  21.     callProvider = [NXConnection connectToName:"CallDataServer"];
  22.     return self;
  23. }
  24.  
  25.  
  26. - awakeFromNib
  27. {
  28.   [customerForm selectText:self];
  29.   [[customerForm window] makeKeyAndOrderFront:self];
  30.   return self;
  31. }
  32.  
  33.  
  34. /*
  35.  * Purpose: Retrieves a call from the database.  
  36.  *
  37.  * Takes the customer name currently displayed in customerFrom. 
  38.  * Requests that the server -- through the proxy -- find a CallData 
  39.  * conformant object for the name.  
  40.  * Displays data from the CallData conformant object in the call form
  41.  * with the name field selected.  
  42.  * If no such record is found, displays an attention panel.  
  43.  * If no name is entered, also displays an attention panel.  
  44.  */
  45.  
  46. - retrieveCall:sender
  47. {
  48.     const char *fetchName;
  49.     id <CallData> fetchRecord = nil;
  50.  
  51.     fetchName = [customerForm stringValueAt:0]; 
  52.     if (fetchName && strlen(fetchName)) {
  53.     fetchRecord = [callProvider lookupCall:fetchName];
  54.     if (fetchRecord) {
  55.         [customerForm setStringValue:[fetchRecord street] at:1]; 
  56.         [customerForm setStringValue:[fetchRecord city] at:2]; 
  57.         [customerForm setStringValue:[fetchRecord state] at:3]; 
  58.         [customerForm setStringValue:[fetchRecord phone] at:4]; 
  59.         [questionText setStringValue:[fetchRecord question]];
  60.         [answerText setStringValue:[fetchRecord answer]];
  61.         [customerForm selectText:self];
  62.     }
  63.     else {
  64.         NXRunAlertPanel("Search Failed", "Customer %s not found", 
  65.         NULL, NULL, NULL, fetchName);
  66.     }
  67.     }
  68.     else {
  69.     NXRunAlertPanel("Search Failed", "Please enter a customer name", 
  70.         NULL, NULL, NULL);
  71.     }
  72.     return self;
  73. }
  74.  
  75.  
  76. /*
  77.  * Purpose: Saves the information in the form to the database
  78.  *
  79.  * Reads the name from the form and tests whether it contains a valid string. 
  80.  * If the name string exists, requests a new CallData conformant object 
  81.  * from the server through the proxy.  
  82.  * Reads data from the Call Information form, puts it in the CallData 
  83.  * conformant object, and requests the server store that object in the 
  84.  * database.
  85.  */
  86.  
  87. - saveCall:sender
  88. {
  89.     const char *formName = NULL;
  90.     id <CallData> newRecord;
  91.  
  92.     formName = [customerForm stringValueAt:0];
  93.     if (formName && strlen(formName)){
  94.     newRecord = [callProvider newRecord];
  95.     [newRecord setName:[customerForm stringValueAt:0]];
  96.     [newRecord setStreet:[customerForm stringValueAt:1]];
  97.     [newRecord setCity:[customerForm stringValueAt:2]];
  98.     [newRecord setState:[customerForm stringValueAt:3]];
  99.     [newRecord setPhone:[customerForm stringValueAt:4]];
  100.     [newRecord setQuestion:[questionText stringValue]];
  101.      [newRecord setAnswer:[answerText stringValue]];
  102.     [callProvider storeCall:newRecord]; 
  103.     }
  104.     return self;
  105. }
  106.  
  107.  
  108. - clearForm:sender;
  109. {
  110.     [questionText setStringValue:NULL];
  111.     [answerText setStringValue:NULL];
  112.     [customerForm setStringValue:NULL at:0];
  113.     [customerForm setStringValue:NULL at:1];
  114.     [customerForm setStringValue:NULL at:2];
  115.     [customerForm setStringValue:NULL at:3];
  116.     [customerForm setStringValue:NULL at:4];
  117.     [customerForm selectText:self];
  118.     return self;
  119. }
  120.  
  121.  
  122. - showInfoPanel:sender
  123. {
  124.     if (!infoPanel)
  125.         [NXApp loadNibSection:"InfoPanel.nib" owner:self];
  126.     [infoPanel makeKeyAndOrderFront:self];
  127.     return self;
  128. }
  129.  
  130.  
  131. - free
  132. {
  133.     return [super free];
  134. }
  135.  
  136. @end
  137.