-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddViewController.m
180 lines (143 loc) · 6.15 KB
/
AddViewController.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
/**
* iOpquast
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*/
#import "AppDelegate_iPhone.h"
#import "AddViewController.h"
#import "Sqlite.h"
@implementation AddViewController
@synthesize projectName, projectUrl, projectSelectedId, ecommerce, newsletter, feeds;
- (void) setOptions:(NSString *)projet theme:(NSString *)strtheme {
Sqlite *sqlite = [[Sqlite alloc] init];
[sqlite open:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"opquast.sqlite"]];
NSString *rq = [NSString stringWithFormat:@"SELECT ID FROM pratiques WHERE THEME = '%@';", strtheme];
NSArray *req = [sqlite executeQuery:rq];
for (NSDictionary *row in req) {
NSLog(@"%@", [row valueForKey:@"ID"]);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
[sqlite open:[documentsDirectory stringByAppendingPathComponent:@"data.sqlite"]];
[sqlite executeNonQuery:@"INSERT INTO pratiques VALUES (null, ?, ?, ?);", [row valueForKey:@"ID"], projet, @"3"];
}
[sqlite release];
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
[theTextField resignFirstResponder];
return YES;
}
/*
- (void) noecommerce:(NSString *)projet {
Sqlite *sqlite = [[Sqlite alloc] init];
[sqlite open:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"opquast.sqlite"]];
NSArray *req = [sqlite executeQuery:@"SELECT ID FROM pratiques WHERE THEME = 'E-Commerce';"];
for (NSDictionary *row in req) {
NSLog(@"%@", [row valueForKey:@"ID"]);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
[sqlite open:[documentsDirectory stringByAppendingPathComponent:@"data.sqlite"]];
[sqlite executeNonQuery:@"INSERT INTO pratiques VALUES (null, ?, ?, ?);", [row valueForKey:@"ID"], projet, @"3"];
}
[sqlite release];
}
- (void) nonewsletter:(NSString *)projet {
Sqlite *sqlite = [[Sqlite alloc] init];
[sqlite open:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"opquast.sqlite"]];
NSArray *req = [sqlite executeQuery:@"SELECT ID FROM pratiques WHERE THEME = 'Newsletter';"];
for (NSDictionary *row in req) {
NSLog(@"%@", [row valueForKey:@"ID"]);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
[sqlite open:[documentsDirectory stringByAppendingPathComponent:@"data.sqlite"]];
[sqlite executeNonQuery:@"INSERT INTO pratiques VALUES (null, ?, ?, ?);", [row valueForKey:@"ID"], projet, @"3"];
}
[sqlite release];
}
*/
- (IBAction) save {
if(![projectName.text isEqualToString:@""]) {
Sqlite *sqlite = [[Sqlite alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"data.sqlite"];
if (![sqlite open:writableDBPath]) return;
[sqlite executeNonQuery:@"INSERT INTO project VALUES (null, ?, ?);", projectName.text, projectUrl.text];
NSArray *req = [sqlite executeQuery:@"select key from project order by key desc limit 1;"];
for (NSDictionary *row in req) {
projectSelectedId = [row valueForKey:@"key"];
}
if (ecommerce.selectedSegmentIndex == 1) {
//[self noecommerce:projectSelectedId];
[self setOptions:projectSelectedId theme:@"E-Commerce"];
}
if (newsletter.selectedSegmentIndex == 1) {
//[self nonewsletter:projectSelectedId];
[self setOptions:projectSelectedId theme:@"Newsletter"];
}
if (feeds.selectedSegmentIndex == 1) {
//[self nonewsletter:projectSelectedId];
[self setOptions:projectSelectedId theme:@"Syndication"];
}
[self dismissModalViewControllerAnimated:YES];
/*Opquast_For_iPhoneAppDelegate *appDelegate = (Opquast_For_iPhoneAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.loadedProjectID = projectSelectedId;
appDelegate.loadedProjectName = projectName.text;*/
[self dismissModalViewControllerAnimated:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Error",@"")
message:NSLocalizedString(@"Project field may not be empty",@"")
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (IBAction) cancel {
[self dismissModalViewControllerAnimated:YES];
}
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[self.projectName setDelegate:self];
[self.projectName setReturnKeyType:UIReturnKeyDone];
[self.projectUrl setDelegate:self];
[self.projectUrl setReturnKeyType:UIReturnKeyDone];
}
/*
// 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 {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end