//
//  PickerViewController.m
//  Agence
//
//  Created by Olivier Savard on 11-01-22.
//  Copyright 2011 OSInfo Informatique. All rights reserved.
//

#import "PickerViewController.h"
#import "AgenceAppDelegate.h"

@implementation PickerViewController
@synthesize picker;
@synthesize pickerData;




-(IBAction)buttonPressed:(id)sender
{
	NSInteger row = [picker selectedRowInComponent:0];
	NSString *selection = [pickerData objectAtIndex:row];
	AgenceAppDelegate * appDelegate = (AgenceAppDelegate *)[[UIApplication sharedApplication] delegate];
	if (self.title == @"Montant minimum")
		appDelegate.montantMin = [selection stringByReplacingOccurrencesOfString:@"$" withString:@""];
	else if (self.title == @"Montant maximum")
		appDelegate.montantMax = [selection stringByReplacingOccurrencesOfString:@"$" withString:@""];
	[self.navigationController popViewControllerAnimated:YES];
}



- (void)viewDidLoad {
	NSArray *array = [[NSArray alloc] initWithObjects:@"100$",
                      @"200$", @"300$", @"400$",
                      @"500$", @"600$",nil];	
	self.pickerData = array;
	
	
	//CREATION DU BOUTON DE NAVIGATION DE DROITE (OK)
	UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithTitle:@"Ok" style:UIBarButtonItemStylePlain target:self action:@selector(buttonPressed:)];
	self.navigationItem.rightBarButtonItem = button;
	[button release];
	
	
	
	
	 
	if (self.title == @"Montant maximum")
		[picker selectRow:5 inComponent:0 animated:YES];
	[array release];
    [super viewDidLoad];
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
	self.picker = nil;
    self.pickerData = nil;
	[super viewDidUnload];
}


- (void)dealloc {
	[picker release];
	[pickerData release];
    [super dealloc];
}

#pragma mark -
#pragma mark Picker Data Source Methods
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
	return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
	return [pickerData count];
}

#pragma mark Picker Delegate Methods
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
	return [pickerData objectAtIndex:row];
}


@end
