Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 2.09 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //
  2. //  LoginViewController.m
  3. //  VitalSigns
  4. //
  5. //  Created by ehealth on 10-08-10.
  6. //  Copyright 2010 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "LoginViewController.h"
  10. #import "ManagedObjectContextSource.h"
  11. #import "Nurse.h"
  12. #import "Patient.h"
  13. #import "ServerConnectionsController.h"
  14.  
  15. @interface LoginViewController()
  16. - (void)getPatientList;
  17. @end
  18.  
  19.  
  20. @implementation LoginViewController
  21.  
  22. @synthesize userName;
  23. @synthesize userPassword;
  24. @synthesize loginButton;
  25. @synthesize loginIndicator;
  26.  
  27. @synthesize delegate;
  28.  
  29. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  30. - (void)viewDidLoad {
  31.     [super viewDidLoad];
  32.         [[NSNotificationCenter defaultCenter] addObserver:self
  33.                                                                                          selector:@selector(loginDidFail:)
  34.                                                                                                  name:@"badLoginCredentials"
  35.                                                                                            object:nil ];               
  36.         [userName becomeFirstResponder];
  37. }
  38.  
  39.  
  40. - (void)loginDidFail:(NSNotification *)notification {
  41.         NSLog(@"Login did fail");
  42. }
  43.  
  44. - (IBAction)loginButtonPressed: (id) sender {
  45.        
  46.         loginIndicator.hidden = FALSE;
  47.         [loginIndicator startAnimating];
  48.         loginButton.enabled = FALSE;
  49.         [self getPatientList];
  50.         [self.delegate loginViewControllerDidFinish:self];
  51. }
  52.  
  53. - (void)createNurseWithId:(NSString *) nurseID {
  54.         Nurse *nurse = [NSEntityDescription insertNewObjectForEntityForName: @"Nurse"
  55.                                                                                                  inManagedObjectContext: [[ManagedObjectContextSource sharedContextSource] managedObjectContext]];
  56.         nurse.nurseID = userName.text;
  57.        
  58.         // Commit edits
  59.         NSError *error;
  60.         NSAssert1([[[ManagedObjectContextSource sharedContextSource] managedObjectContext] save:&error], @"Error saving nurse ID: %@", error);
  61.        
  62.         //Sanity check
  63.         NSLog(@"nurse ID: %@",nurse.nurseID);  
  64. }
  65.  
  66. //TODO should be else where
  67. - (void)getPatientList {
  68.         //get the patient list from the server
  69.         NSString *username = userName.text;
  70.         NSString *password = userPassword.text;
  71.  
  72.         [[ServerConnectionsController sharedServerConnections] authenticateWithUserID:username andPassword:password];
  73.        
  74.         [[ServerConnectionsController sharedServerConnections] getPatientList];
  75.                
  76. }
  77.  
  78.  
  79.  
  80. @end