-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
179 changed files
with
170,265 additions
and
3,224 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file modified
BIN
+9.72 KB
(110%)
Diary.xcworkspace/xcuserdata/wo.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// AdapterProtocol.h | ||
// Common | ||
// | ||
// Created by Owen on 15/7/23. | ||
// Copyright (c) 2015年 Owen. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
@protocol AdapterProtocol <NSObject> | ||
@required | ||
- (id)adapterData:(NSDictionary *)rawData ByManager:(id)manager; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// DataManager.h | ||
// Common | ||
// | ||
// Created by Owen on 15/8/12. | ||
// Copyright (c) 2015年 Owen. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "AdapterProtocol.h" | ||
|
||
@interface DataManager : NSObject | ||
- (NSDictionary *)fetchData:(NSDictionary *)rawData | ||
ByAdapter:(id<AdapterProtocol>)adapter; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// DataManager.m | ||
// Common | ||
// | ||
// Created by Owen on 15/8/12. | ||
// Copyright (c) 2015年 Owen. All rights reserved. | ||
// | ||
|
||
#import "DataManager.h" | ||
|
||
@interface DataManager () | ||
@end | ||
@implementation DataManager | ||
- (NSDictionary *)fetchData:(NSDictionary *)rawData | ||
ByAdapter:(id<AdapterProtocol>)adapter { | ||
if (adapter == nil) { | ||
return rawData; | ||
} else { | ||
return [adapter adapterData:rawData ByManager:self]; | ||
} | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// DataProtocol.h | ||
// Common | ||
// | ||
// Created by Owen on 15/8/20. | ||
// Copyright (c) 2015年 Owen. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "AdapterProtocol.h" | ||
|
||
@protocol DataProtocol <NSObject> | ||
@required | ||
@property(nonatomic, strong, readwrite) id fetchedRawData; | ||
@required | ||
- (id)fetchDataWithAdapter:(id<AdapterProtocol>)adapter; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// DBManager.h | ||
// Common | ||
// | ||
// Created by Owen on 15/8/12. | ||
// Copyright (c) 2015年 Owen. All rights reserved. | ||
// | ||
|
||
#import "DataManager.h" | ||
#import "DataProtocol.h" | ||
@class FMDatabase; | ||
@interface DBManager : NSObject <DataProtocol> { | ||
FMDatabase *db; | ||
} | ||
@property(nonatomic, retain) FMDatabase *db; | ||
|
||
/* | ||
@method getSingle: | ||
@aSql 查询指定表,无参数查询(例如:select * from 表名),返回查询结果 | ||
@result NSDictionary * | ||
*/ | ||
- (NSDictionary *)getSingle:(NSString *)aSql; | ||
|
||
/* | ||
@method getList: | ||
@aSql 查询指定表,无参数查询(例如:select * from 表名),返回查询结果 | ||
@result NSDictionary * | ||
*/ | ||
- (NSMutableArray *)getList:(NSString *)aSql; | ||
|
||
/* | ||
@method insertWithDictionary | ||
@abstract 向指定表插入数据 | ||
@parameter aDic字典里包含一条记录,键是字段名,值是要插入的值 | ||
@result void | ||
*/ | ||
- (void)insertWithTable:(NSString *)tableName Dictionary:(NSDictionary *)aDic; | ||
|
||
/* | ||
@method deleteWithDictionary: Dictionary: | ||
@abstract 删除指定表里的数据 | ||
@parameter aSql删除sql语句,要这样写:delete from tablename where columnname1 | ||
= :columnname1 and(or) ... | ||
aDic字典里是要删除条件,键是字段名;如果aDic为nil,则删除表里所有的数据 | ||
@result BOOL | ||
*/ | ||
- (BOOL)deleteWithSql:(NSString *)aSql andDictionary:(NSDictionary *)aDic; | ||
|
||
/* | ||
@method updateWithSql: Dictionary: | ||
@abstract 更新指定表里的数据 | ||
@parameter aSql更新sql语句,要这样写:update tablename set columnname1=?,... | ||
where columnnamen = ? and(or) ... | ||
aArray数组存储的是和?对应数据 | ||
@result BOOL | ||
*/ | ||
- (BOOL)updateWithSql:(NSString *)aSql andArray:(NSArray *)aArray; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// | ||
// BaseDao.m | ||
// Core | ||
// | ||
// Created by 曹亮 on 14/11/18. | ||
// Copyright (c) 2014年 FamilyTree. All rights reserved. | ||
// | ||
|
||
#import "DBManager.h" | ||
#import "FMDatabase.h" | ||
#import "SharedDaBase.h" | ||
#import "FMDatabaseAdditions.h" | ||
|
||
@implementation DBManager | ||
@synthesize db, fetchedRawData; | ||
|
||
- (id)init { | ||
if (self = [super init]) { | ||
db = [[SharedDaBase sharedDataBase] db]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)createTable:(NSDictionary *)dic{ | ||
//建表 | ||
|
||
NSMutableString *sql = | ||
[[NSMutableString alloc] initWithFormat:@"create table if not exists travel(ID integer primary key autoincrement,"]; | ||
|
||
NSArray *keys = [dic allKeys]; | ||
for (NSString *str in keys) { | ||
[sql appendFormat:@"%@,", str]; | ||
|
||
} | ||
[sql replaceCharactersInRange:NSMakeRange([sql length] - 1, 1) | ||
withString:@")"]; | ||
|
||
if (![db executeUpdate:sql]) { | ||
NSLog(@"建表失败:%@",db.lastErrorMessage); | ||
}else{ | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
- (id)fetchDataWithAdapter:(id<AdapterProtocol>)adapter { | ||
id resultData = nil; | ||
if ([adapter respondsToSelector:@selector(adapterData:ByManager:)]) { | ||
resultData = [adapter adapterData:self.fetchedRawData ByManager:self]; | ||
} else { | ||
resultData = [self.fetchedRawData mutableCopy]; | ||
} | ||
return resultData; | ||
} | ||
|
||
// SELECT | ||
- (NSDictionary *)getSingle:(NSString *)aSql { | ||
FMResultSet *rs = [db executeQuery:aSql]; | ||
[rs next]; | ||
NSDictionary *resultDictionary = rs.resultDictionary; | ||
[rs close]; | ||
return resultDictionary; | ||
} | ||
|
||
// SELECT | ||
- (NSMutableArray *)getList:(NSString *)aSql { | ||
|
||
NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:0]; | ||
FMResultSet *rs = [db executeQuery:aSql]; | ||
while ([rs next]) { | ||
id tr = [rs resultDictionary]; | ||
if (nil == tr) { | ||
[rs close]; | ||
return nil; | ||
} | ||
[result addObject:tr]; | ||
} | ||
[rs close]; | ||
return result; | ||
} | ||
|
||
- (void)insertWithTable:(NSString *)tableName Dictionary:(NSDictionary *)aDic { | ||
if ([aDic count] <= 0) { | ||
return; | ||
} | ||
|
||
[self createTable:aDic]; | ||
|
||
NSMutableString *sql = | ||
[[NSMutableString alloc] initWithFormat:@"INSERT INTO %@(", tableName]; | ||
NSMutableString *para = [[NSMutableString alloc] initWithString:@" VALUES ("]; | ||
NSArray *keys = [aDic allKeys]; | ||
for (NSString *str in keys) { | ||
[sql appendFormat:@"%@,", str]; | ||
[para appendFormat:@":%@,", str]; | ||
} | ||
[sql replaceCharactersInRange:NSMakeRange([sql length] - 1, 1) | ||
withString:@")"]; | ||
[para replaceCharactersInRange:NSMakeRange([para length] - 1, 1) | ||
withString:@")"]; | ||
[sql appendString:para]; | ||
[db executeUpdate:sql withParameterDictionary:aDic]; | ||
if ([db hadError]) { | ||
NSLog(@"Err %d: %@", [db lastErrorCode], [db lastErrorMessage]); | ||
} | ||
} | ||
|
||
- (BOOL)deleteWithSql:(NSString *)aSql andDictionary:(NSDictionary *)aDic { | ||
BOOL success = YES; | ||
if (aDic) { | ||
[db executeUpdate:aSql withParameterDictionary:aDic]; | ||
} else { | ||
[db executeUpdate:aSql]; | ||
} | ||
|
||
if ([db hadError]) { | ||
NSLog(@"Err %d: %@", [db lastErrorCode], [db lastErrorMessage]); | ||
success = NO; | ||
} | ||
return success; | ||
} | ||
- (BOOL)updateWithSql:(NSString *)aSql andArray:(NSArray *)aArray { | ||
BOOL success = YES; | ||
[db executeUpdate:aSql withArgumentsInArray:aArray]; | ||
if ([db hadError]) { | ||
NSLog(@"Err %d: %@", [db lastErrorCode], [db lastErrorMessage]); | ||
success = NO; | ||
} | ||
return success; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// TravelDBManager.h | ||
// Common | ||
// | ||
// Created by Owen on 15/8/12. | ||
// Copyright (c) 2015年 Owen. All rights reserved. | ||
// | ||
|
||
#import "DBManager.h" | ||
|
||
@interface TravelDBManager : DBManager | ||
- (NSArray *)getTravelsByUserID:(NSInteger)userID; | ||
- (void)addTravel:(NSDictionary *)dic; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// TravelDBManager.m | ||
// Common | ||
// | ||
// Created by Owen on 15/8/12. | ||
// Copyright (c) 2015年 Owen. All rights reserved. | ||
// | ||
|
||
#import "TravelDBManager.h" | ||
|
||
@implementation TravelDBManager | ||
- (NSArray *)getTravelsByUserID:(NSInteger)userID { | ||
NSString *strSql = [NSString stringWithFormat:@"SELECT * FROM travel "]; | ||
return [self getList:strSql]; | ||
} | ||
|
||
- (void)addTravel:(NSDictionary *)dic { | ||
[self insertWithTable:@"travel" Dictionary:dic]; | ||
} | ||
@end |
Binary file not shown.
Oops, something went wrong.