You are on page 1of 8

//

// RegisterNewComplaintViewController.m
// ITC_ITC_QMA
//
// Created by corpmisuser on 10/01/17.
// Copyright © 2017 corpmisuser. All rights reserved.
//

#import "RegisterNewComplaintViewController.h"
#import "DBClass.h"
#import "DataObject.h"

@interface RegisterNewComplaintViewController ()

@end

@implementation RegisterNewComplaintViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.scrollView.contentSize=CGSizeMake(320,700);
shiftArray=[[NSMutableArray alloc]init];
defectArray=[[NSMutableArray alloc]init];
// Do any additional setup after loading the view.
}

-(void) viewDidAppear:(BOOL)animated
{
entries=[[NSMutableArray alloc]init];
entries=[[DBClass getSharedInstance] getAllShift];
[self BindAllShift];
defectentries=[[NSMutableArray alloc]init];
defectentries=[[DBClass getSharedInstance]getAllDefect];
[self BindAllDefect];
[self setPickerView ];
}

-(void)BindAllShift
{
shiftCode=@"";
ShiftId=@"";
NSMutableArray *SnameArray=[[NSMutableArray alloc]init];

NSMutableArray *idArray=[[NSMutableArray alloc]init];


for(int i=0; i<[entries count];i++)
{
DataObject *obj=[[DataObject alloc]init];
obj=[entries objectAtIndex:i];

[idArray addObject:obj.srec_id];
[SnameArray addObject:obj.shift_code];

ShiftId = [idArray componentsJoinedByString:@","];


shiftCode = [SnameArray componentsJoinedByString:@","];
// _txtShift.text=shiftCode;

NSLog(@"==========> %@ %@",shiftCode,ShiftId);
}
-(void)BindAllDefect
{
defectDesc=@"";
DefectId=@"";
NSMutableArray *DdescArray=[[NSMutableArray alloc]init];

NSMutableArray *didArray=[[NSMutableArray alloc]init];


for(int i=0; i<[defectentries count];i++)
{
DataObject *obj=[[DataObject alloc]init];
obj=[defectentries objectAtIndex:i];

[didArray addObject:obj.defect_id];
[DdescArray addObject:obj.defect_desc];

DefectId = [didArray componentsJoinedByString:@","];


defectDesc = [DdescArray componentsJoinedByString:@","];
// _txtShift.text=shiftCode;

NSLog(@"==========> %@ %@",defectDesc,DefectId);

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"...........%@",textField.text);

if(textField==_txtShift)
{

tagvalue=1;
_Spickerview.hidden=NO;
}
else if(textField==_txtDefect)
{
tagvalue=2;
_Spickerview.hidden=NO;

}
/*else if(textField==_emailTextField)
{
tagvalue=3;
}*/
[pickerViewShift reloadAllComponents];
}

-(void)setPickerView
{

if(IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)


{
pickerViewShift = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 68,
375.0, 0)];
}
else if(IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
{
pickerViewShift = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 68,
414, 0)];
}
else
{
pickerViewShift = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 388,
320, 180)];
}

// pickerView = [[ALPickerView alloc] initWithFrame:CGRectMake(0, 68, 0,


0)];
pickerViewShift.delegate = self;
_txtShift.inputView = pickerViewShift;
_txtDefect.inputView = pickerView;
//_emailTextField.inputView = pickerView;

UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320,


44)];
toolBar.barStyle = UIBarStyleBlackOpaque;

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]


initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self
action:@selector(doneTouched1:)];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self
action:@selector(cancelTouched:)];
[toolBar setItems:[NSArray arrayWithObjects:cancelButton, [[UIBarButtonItem
alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil
action:nil], doneButton, nil]];
_txtShift.inputAccessoryView = toolBar;
_txtDefect.inputAccessoryView = toolBar;
//.inputAccessoryView = toolBar;
//_emailTextField.inputAccessoryView = toolBar;

selectionStates = [[NSMutableDictionary alloc] init];


DataObject *key=[[DataObject alloc]init];
for (key in entries)
{
[selectionStates setObject:[NSNumber numberWithBool:YES]
forKey:key.shift_code];
}

selectionStatesdefect = [[NSMutableDictionary alloc] init];


DataObject *key1=[[DataObject alloc]init];
for (key1 in defectentries)
{
[selectionStatesdefect setObject:[NSNumber numberWithBool:YES]
forKey:key1.defect_desc];
}

/*
selectionstatesemail = [[NSMutableDictionary alloc] init];
DataObject *key2=[[DataObject alloc]init];
for (key2 in emailentries)
{
[selectionstatesemail setObject:[NSNumber numberWithBool:NO]
forKey:key2.emailaddress];
}*/

// returns the number of 'columns' to display.


- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;

{
return 1;
}

// returns the # of rows in each component..


- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:
(NSInteger)component
{
if(tagvalue==1)
{
return [entries count];
// return [entries Count];
}
else if(tagvalue == 2)
{
return [defectentries count];
}
else
{
return 0;
}
}

- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:


(NSInteger)row forComponent:(NSInteger)component
{
if(tagvalue==1)
{

DataObject *obj=[[DataObject alloc]init];


obj=[entries objectAtIndex:row];

return obj.shift_code;
}
else if(tagvalue == 2)
{
DataObject *obj=[[DataObject alloc]init];
obj=[defectentries objectAtIndex:row];

return obj.defect_desc;
}
else
{
return false;
}
//return [entries objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
if(tagvalue == 1)
{
if (row == -1)
for (id key in [selectionStates allKeys])
[selectionStates setObject:[NSNumber numberWithBool:YES] forKey:key];
else
[selectionStates setObject:[NSNumber numberWithBool:YES] forKey:[[entries
objectAtIndex:row] shift_code]];
}
else
{
if (row == -1)
for (id key in [selectionStatesdefect allKeys])
[selectionStatesdefect setObject:[NSNumber numberWithBool:YES]
forKey:key];
else
[selectionStatesdefect setObject:[NSNumber numberWithBool:YES] forKey:
[[defectentries objectAtIndex:row] defect_desc]];
}

-(void)BindSelectedShifts
{
// brandNames=@"All";
// brandIds=@"";

NSMutableArray *SnameArray=[[NSMutableArray alloc]init];


NSMutableArray *SidArray=[[NSMutableArray alloc]init];
for(int i=0; i<[finalList count];i++)
{
DataObject *obj=[[DataObject alloc]init];
obj=[finalList objectAtIndex:i];

[SnameArray addObject:obj.shift_code];
[SidArray addObject:obj.shiftid];

// if([finalList count]==[entries count])


// {
// brandNames = @"All";
// }
// else
// {
shiftCode = [SnameArray componentsJoinedByString:@","];
// }

ShiftId=[SidArray componentsJoinedByString:@","];
_txtShift.text=shiftCode;
NSLog(@"==========> %@ %@",shiftCode,ShiftId);

shiftArray=[[NSMutableArray alloc]init];
//shiftArray=[[DBClass getSharedInstance] getAllCategory:brandIds media:mediaId
srtdate:startDate enddate:endDate];

// [_collect reloadData];

}
-(void)BindSelectedDefects
{
// brandNames=@"All";
// brandIds=@"";

NSMutableArray *DdescArray=[[NSMutableArray alloc]init];


NSMutableArray *didArray=[[NSMutableArray alloc]init];
for(int i=0; i<[finalList count];i++)
{
DataObject *obj=[[DataObject alloc]init];
obj=[finalList objectAtIndex:i];

[DdescArray addObject:obj.shift_code];
[didArray addObject:obj.shiftid];

// if([finalList count]==[entries count])


// {
// brandNames = @"All";
// }
// else
// {
shiftCode = [DdescArray componentsJoinedByString:@","];
// }

DefectId=[didArray componentsJoinedByString:@","];
_txtDefect.text=defectDesc;

NSLog(@"==========> %@ %@",defectDesc,DefectId);

defectArray=[[NSMutableArray alloc]init];
//shiftArray=[[DBClass getSharedInstance] getAllCategory:brandIds media:mediaId
srtdate:startDate enddate:endDate];

// [_collect reloadData];

}
- (void)doneTouched1:(UIBarButtonItem *)sender
{
_Spickerview.hidden=YES;
finalList=[[NSMutableArray alloc]init];
finalListdefect=[[NSMutableArray alloc]init];
finallistEmail=[[NSMutableArray alloc]init];

if(tagvalue==1)
{
for(int i=0;i<[entries count];i++)
{
NSLog(@"Done....%@",[selectionStates valueForKey:[[entries
objectAtIndex:i] shift_code]]);
if([[NSString stringWithFormat:@"%@",[selectionStates valueForKey:
[[entries objectAtIndex:i] shift_code]]] isEqualToString:@"1"])
{
[finalList addObject:[entries objectAtIndex:i]];
}
}

[self BindSelectedShifts];

// collectiontag=1;

// _lblfilters.text=@"";
// [self changecollectionviewframe];

}
else if(tagvalue==2)
{
for(int i=0;i<[defectentries count];i++)
{
NSLog(@"Done....%@",[selectionStatesdefect valueForKey:[[defectentries
objectAtIndex:i] defect_desc]]);
if([[NSString stringWithFormat:@"%@",[selectionStatesdefect valueForKey:
[[defectentries objectAtIndex:i] defect_desc]]] isEqualToString:@"1"])
{
[finalListdefect addObject:[defectentries objectAtIndex:i]];
}
}

[self BindSelectedDefects];

//collectiontag=1;

// _lblfilters.text=@"";
// [self changecollectionviewframe];

}
/*
else
{
for(int i=0;i<[emailentries count];i++)
{
NSLog(@"Done....%@",[selectionstatesemail valueForKey:[[emailentries
objectAtIndex:i] emailaddress]]);
if([[NSString stringWithFormat:@"%@",[selectionstatesemail valueForKey:
[[emailentries objectAtIndex:i] emailaddress]]] isEqualToString:@"1"])
{
[finallistEmail addObject:[emailentries objectAtIndex:i]];
}
}

[self BindAllEmailAddress];
}*/
else
{
NSLog(@"Done...");
}

[_txtShift resignFirstResponder];
//[_mediaTextField resignFirstResponder];
//[_emailTextField resignFirstResponder];

}
- (void)cancelTouched:(UIBarButtonItem *)sender
{
[_txtShift resignFirstResponder];
// [_mediaTextField resignFirstResponder];
// [_emailTextField resignFirstResponder];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little


preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end

You might also like