pragma mark data validation MKAddNPAddressViewCo ntrollerFormFields em

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma mark - data validation
-(MKAddNPAddressViewControllerFormFields)emptyFields
{
//checking for empty data fields
MKAddNPAddressViewControllerFormFields emptyFields=MKAddNPAddressViewControllerFormFieldNone;
if ((self.departmentAddress.name==nil) || ([self.departmentAddress.name isEqualToString:@""]))
{
emptyFields=emptyFields | (MKAddNPAddressViewControllerFormFieldName);
};
if ((self.departmentAddress.surname==nil) || ([self.departmentAddress.surname isEqualToString:@""]))
{
emptyFields=emptyFields | (MKAddNPAddressViewControllerFormFieldSurname);
};
if ((self.departmentAddress.phoneNumber==nil) || ([self.departmentAddress.phoneNumber isEqualToString:@""]))
{
emptyFields=emptyFields | (MKAddNPAddressViewControllerFormFieldPhone);
};
if ((self.departmentAddress.regionID==nil) || (self.departmentAddress.regionName==nil) || ([self.departmentAddress.regionName isEqualToString:@""]))
{
emptyFields=emptyFields | (MKAddNPAddressViewControllerFormFieldRegion);
};
if ((self.departmentAddress.cityID==nil) || (self.departmentAddress.cityName==nil) || ([self.departmentAddress.cityName isEqualToString:@""]))
{
emptyFields=emptyFields | (MKAddNPAddressViewControllerFormFieldCity);
};
if ((self.departmentAddress.departmentID==nil) || (self.departmentAddress.departmentName==nil) || ([self.departmentAddress.departmentName isEqualToString:@""]))
{
emptyFields=emptyFields | (MKAddNPAddressViewControllerFormFieldDepartment);
};
return emptyFields;
}
#pragma mark - Actions
-(IBAction)doneButtonDidPress:(id)sender
{
MK_Log;
MKAddNPAddressViewControllerFormFields emptyFields=[self emptyFields];
if (emptyFields!=MKAddNPAddressViewControllerFormFieldNone)
{
NSLog(@"%@: %@ called. emptyFields: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), [NSString stringWithBitMask:(emptyFields)]);
NSString *messageStr=@"Необходимо заполнить ";
if (emptyFields & MKAddNPAddressViewControllerFormFieldName)
{
messageStr=[messageStr stringByAppendingString:@"имя, "];
};
if (emptyFields & MKAddNPAddressViewControllerFormFieldSurname)
{
messageStr=[messageStr stringByAppendingString:@"фамилию, "];
};
if (emptyFields & MKAddNPAddressViewControllerFormFieldPhone)
{
messageStr=[messageStr stringByAppendingString:@"телефон, "];
};
if (emptyFields & MKAddNPAddressViewControllerFormFieldRegion)
{
messageStr=[messageStr stringByAppendingString:@"регион, "];
};
if (emptyFields & MKAddNPAddressViewControllerFormFieldCity)
{
messageStr=[messageStr stringByAppendingString:@"город, "];
};
if (emptyFields & MKAddNPAddressViewControllerFormFieldDepartment)
{
messageStr=[messageStr stringByAppendingString:@"отделение, "];
};
messageStr=[messageStr stringByPaddingToLength:(messageStr.length-2) withString:@"" startingAtIndex:0];
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Внимание" message:messageStr delegate:nil cancelButtonTitle:@"Ок" otherButtonTitles: nil];
[alert show];
}
else
{
[self saveData];
};
}