@implementation AppGlobal static NSString* strHostName; static NSString* strVersion; static PLSqliteDatabase* dbHelper; static CConfigSetting* configSetting; + (BOOL) Init { strHostName = HTTPURLPREFIX; strVersion = @"1.01"; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *dbPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"TaxOffice.db"]; dbHelper = [[PLSqliteDatabase alloc] initWithPath:dbPath]; NSLog(@"TaxOffice.db path = %@",dbPath); if (![DBInit initDB]) return FALSE; configSetting = [[CConfigSetting alloc] init]; return TRUE; } + (void) DeInit { [dbHelper close]; [dbHelper release]; [configSetting release]; } + (NSString*) DefaultHost { return strHostName; } + (NSString*) Version { return strVersion; } + (PLSqliteDatabase*) DbHelper { return dbHelper; } + (CConfigSetting*) ConfigSetting { return configSetting; } @end
+(BOOL) initDB { PLSqliteDatabase* idb = [AppGlobal DbHelper]; if (![idb open]) { return FALSE; } // 配置信息表 if (![idb tableExists:@"Config"]) { if (![idb executeUpdate: @"CREATE TABLE Config(key integer,value text)"]) return FALSE; } // 客户信息表 if (![idb tableExists:@"Customers"]) { NSString *strSql = @"CREATE TABLE Customers(id integer PRIMARY KEY autoincrement not null," "idno text, name text, tel text, remark text)"; if (![idb executeUpdate: strSql]) { return FALSE; } } // 商品信息表 if (![idb tableExists:@"Products"]) { NSString *strSql = @"CREATE TABLE Products(id integer PRIMARY KEY autoincrement not null," "idno text, name text, type integer, price real," "amount real, units text, remark text)"; if (![idb executeUpdate: strSql]) { return FALSE; } } // return TRUE; }