-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFieldVisitsController.m
executable file
·189 lines (151 loc) · 5.81 KB
/
FieldVisitsController.m
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#import "FieldVisitsController.h"
@implementation FieldVisitsController
@synthesize fieldArray;
@synthesize fieldView;
@synthesize orderBy;
@synthesize fieldDao;
@synthesize sortIndex;
@synthesize dateFormatter;
-(IBAction)addFieldClicked:(id)sender{
/*
AddNewCompany *newCom=[[AddNewCompany alloc]
initWithNibName:@"AddNewCompany"
bundle:nil];
*/
EditField *newfield=[[EditField alloc] initWithNibName:@"EditField" bundle:nil];
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title = @"Field Visits";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
newfield.title=@"New Field";
newfield.edit = FALSE;
newfield.status = 0;
[[self navigationController] pushViewController:newfield animated:YES];
}
- (void) viewWillAppear:(BOOL) animated {
[super viewWillAppear:animated];
[self refreshFieldView];
}
-(void)refreshFieldView{
self.fieldArray = [NSMutableArray array];
fieldDao = [[FieldDao alloc] init];
self.fieldArray = [fieldDao select:self.sortIndex];
[fieldView reloadData];
}
- (void)viewDidLoad {
self.sortIndex=0;
[super viewDidLoad];
self.fieldView.backgroundColor=[Constants backgroundColor];
self.fieldView.separatorColor = [Constants tableLineColor];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.fieldArray count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"";
}
#pragma mark Section header delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 58.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *aCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (aCell == nil)
{
aCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
aCell.tag = 5;
}else {
UIView *viewToRemove1 = nil;
viewToRemove1 = [aCell.contentView viewWithTag:100+(aCell.tag)*10+indexPath.row];
if (viewToRemove1)
[viewToRemove1 removeFromSuperview];
UIView *viewToRemove2 = nil;
viewToRemove2 = [aCell.contentView viewWithTag:200+(aCell.tag)*10+indexPath.row];
if (viewToRemove2)
[viewToRemove2 removeFromSuperview];
UIView *viewToRemove3 = nil;
viewToRemove3 = [aCell.contentView viewWithTag:300+(aCell.tag)*10+indexPath.row];
if (viewToRemove3)
[viewToRemove3 removeFromSuperview];
}
aCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Field *c = [fieldArray objectAtIndex:indexPath.section];
CGRect nameFrame = CGRectMake(20.0, 2.0, 260.0, 30.0);
UILabel *nameLabel = [[[UILabel alloc] initWithFrame:nameFrame] autorelease];
nameLabel.backgroundColor = [Constants backgroundColor];
nameLabel.textColor = [UIColor blackColor];
nameLabel.textAlignment = UITextAlignmentLeft;
nameLabel.font = [UIFont boldSystemFontOfSize:14.0];
nameLabel.tag = 100+(aCell.tag)*10+indexPath.row;
nameLabel.text = c.name;
[aCell.contentView addSubview:nameLabel];
CGRect numFrame = CGRectMake(20.0, 30.0, 120.0, 20.0);
UILabel *numLabel = [[[UILabel alloc] initWithFrame:numFrame] autorelease];
numLabel.backgroundColor = [Constants backgroundColor];
numLabel.textColor = [Constants labelTextColor];
numLabel.textAlignment = UITextAlignmentLeft;
numLabel.font = [UIFont systemFontOfSize:12.0];
numLabel.tag = 200+(aCell.tag)*10+indexPath.row;
numLabel.text = [NSString stringWithFormat:@"%@%d",@"Importance:",[c getImportance]];
[aCell.contentView addSubview:numLabel];
CGRect impFrame = CGRectMake(140.0, 30.0, 140.0, 20.0);
UILabel *impLabel = [[[UILabel alloc] initWithFrame:impFrame] autorelease];
impLabel.backgroundColor = [Constants backgroundColor];
impLabel.textColor = [Constants labelTextColor];
impLabel.textAlignment = UITextAlignmentRight;
impLabel.font = [UIFont systemFontOfSize:12.0];
impLabel.tag = 300+(aCell.tag)*10+indexPath.row;
impLabel.text = [self converStrToShowTimeFomart:c.time];
// NSDateFormatter *dbDateFormatter=[[NSDateFormatter alloc] init];
// [dbDateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:SS"];
// NSDateFormatter *showDateFormatter=[[NSDateFormatter alloc] init];
// [showDateFormatter setDateFormat:@"MMM dd yyyy"];
// if ([c.time length]>0) {
// NSDate *time = [dbDateFormatter dateFromString:c.time];
// impLabel.text = [NSString stringWithFormat:@"%@", [showDateFormatter stringFromDate:time]];
//// [time release];
// }else {
// impLabel.text = @"";
// }
[aCell.contentView addSubview:impLabel];
// [dbDateFormatter release];
// [showDateFormatter release];
//aCell.text = [[companiesArray objectAtIndex:indexPath.section] valueForKey:kCPnameKey];
return aCell;
}
//selectRowAtIndexPath didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
Field *c = [fieldArray objectAtIndex:indexPath.section];
EditField *detailViewController = [[EditField alloc] initWithNibName:@"EditField" bundle:nil];
detailViewController.edit=TRUE;
detailViewController.status = 1;
[detailViewController setIndex:[c getIndex]];
[self.navigationController pushViewController:detailViewController animated:YES];
}
- (IBAction)fieldOnSort:(id)sender{
UISegmentedControl *sg = sender;
self.sortIndex = sg.selectedSegmentIndex;
[self refreshFieldView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
fieldArray = nil;
[fieldView release];
}
- (void)dealloc {
[super dealloc];
}
@end