strip - nsrivastav/iPhone GitHub Wiki

switch (appdelegate.strip_index) {

case 1:

        
    appdelegate.strip1_detail = [pillboxDb get_strip_detail_slave_table:appdelegate.strip_index];
    NSString *start_date_from_Db = [pillboxDb select_start_date_from_schedule:appdelegate.strip_index];
        
        
     Strip_items *si = [appdelegate.strip1_detail lastObject];
	 	
    int p= [appdelegate.strip1_detail count];
     NSLog(@"the array size is %d",p);
		
  
        
       if ([si.BrandName isEqualToString:@" " ] || [si.BrandName isEqualToString:@"" ]||[si.BrandName isEqualToString:@"(null)"]|| si.BrandName == nil ) {
            myLabel1.text = @"EMPTY";
            
        }
        else {
            myLabel1.text =si.BrandName;
        }
        
        
        NSDate * now_1 = [NSDate date];
		NSDateFormatter *dateFormater_1 = [[NSDateFormatter alloc] init];
		[dateFormater_1 setDateFormat:@"yyyy-MM-dd  HH:mm:ss"];
		NSDate *date_1 = [dateFormater_1 dateFromString:start_date_from_Db];
		[dateFormater_1 release];
		
		
		NSComparisonResult result_0 = [now_1 compare:date_1];
		
		NSLog(@"I am at case 1");
        
        
        switch (result_0)
	{
		case NSOrderedAscending: NSLog(@"%@ is in future from %@", date_1, now_1);
			
			
			NSDateFormatter *dateFormat_0_a = [[NSDateFormatter alloc] init];
			[dateFormat_0_a setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
			NSDate *dateString_0_a = [dateFormat_0_a dateFromString:start_date_from_Db];
			NSString *time_selected_0_a = [dateFormat_0_a stringFromDate:dateString_0_a];
			NSLog(@"The time selected is %@", time_selected_0_a);
			if ([start_date_from_Db length] >= 2 ) {
				hours_strip_1 = [time_selected_0_a substringWithRange: NSMakeRange (10, 6)];
                NSLog(@"The hour strip is %@", hours_strip_1);
				hours_value_1 = [hours_strip_1 substringWithRange:NSMakeRange(0,3)];
                NSLog(@"The hour value is %@", hours_value_1);
				hours_int_1 = [hours_value_1 intValue];
                NSLog(@"The hour int is %d", hours_int_1);
				minute_value_1 = [hours_strip_1 substringWithRange:NSMakeRange(3,3)];
                NSLog(@"The hour minute is %@", minute_value_1);
			}
			
			break;
			
		case NSOrderedDescending:
			
			[pillboxDb insert_start_local_update:appdelegate.strip_index];
			
			
		    NSString *start_date_from_Db = [pillboxDb select_start_date_from_schedule:appdelegate.strip_index];
			// Formatting the time as per the requirement
			
			
			NSDateFormatter *dateFormat_0 = [[NSDateFormatter alloc] init];
			[dateFormat_0 setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
			NSDate *dateString_0 = [dateFormat_0 dateFromString:start_date_from_Db];
			
			NSString *time_selected_0 = [dateFormat_0 stringFromDate:dateString_0];
			
            NSLog(@"The time selected is %@", time_selected_0);
			
			
			if ([start_date_from_Db length] >= 2 ) {
				hours_strip_1 = [time_selected_0 substringWithRange: NSMakeRange (10, 6)];
                NSLog(@"The hour strip is %@", hours_strip_1);
				hours_value_1 = [hours_strip_1 substringWithRange:NSMakeRange(0,3)];
                NSLog(@"The hour value is %@", hours_value_1);
				minute_value_1 = [hours_strip_1 substringWithRange:NSMakeRange(3,3)];
                NSLog(@"The minute value is %@", minute_value_1);
				hours_int_1 = [hours_value_1 intValue];
                NSLog(@"The hour integer is %d", hours_int_1);
				
			}
            break;
            [dateFormat_0 release];
            [dateFormat_0_a release];
    }
            
        
            
            
			if ([si.BrandName isEqualToString:@" " ] || [si.BrandName isEqualToString:@"" ]||[si.BrandName isEqualToString:@"(null)"]|| si.BrandName == nil ) {
				myLabel1.text = @"EMPTY";
				
			}
			else {
				myLabel1.text =si.BrandName;
			}
            
        
        
        NSLog(@"The start_date is %@", si.start_date);
            if ([si.start_date isEqualToString:@" "]|| [si.start_date isEqualToString:@"(null)"]|| [si.start_date isEqualToString:@"" ] || si.start_date == nil) {
				myLabel.text = @"--";
                NSLog(@"The start date is blank");
			}
            
            else{
                
                if (hours_int_1 > 11) {
                    hours_int_1 = hours_int_1-12;
                    NSLog(@"The start date is >11");
                    
                        if (hours_int_1 == 0) {
                            hours_int_1  = 12;
                            }
                        else {
                        
                        }
                    
                    
                    NSString *hour	= [NSString stringWithFormat:@"%d", hours_int_1];
                    
                    NSLog(@"The hour int of start date is %d", hours_int_1);
                    
                    
                    if ([hour isEqualToString:@"10"] || [hour isEqualToString:@"11"] ||[hour isEqualToString:@"12"] ) {
                        myLabel.text = [NSString stringWithFormat:@"NEXT:\u00A0\n%@%@PM",hour,minute_value_1];
                        NSLog(@"The minute int of start date is %@", minute_value_1);
                    }
                    
                    
                    else {
                        myLabel.text = [NSString stringWithFormat:@"NEXT:\n0%@%@PM",hour,minute_value_1];
                        
                        NSLog(@"The minute int of start date in else section is %@", minute_value_1);
                    }
                    myLabel.numberOfLines = 0;
                    [myLabel sizeToFit];
                }
                
                
                
                else if(hours_int_1 >= 0 && hours_int_1 <= 11){
                    
                    myLabel.text = [NSString stringWithFormat:@"NEXT:%@AM",hours_strip_1];
                    
                    NSLog(@"The minute int of start date is %@", hours_strip_1);
                    myLabel.numberOfLines = 0;
                    [myLabel sizeToFit];
                    
                }
                
                
				else {
					myLabel.text = @" "; 
				}
                
			}
	
          			
        break;