1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873 |
- #import "DB_Que_Helper.h"
- #import "Question.h"
- #import "markGroup.h"
- #import "markInfo.h"
- #import "Grade.h"
- #import <sqlite3.h>
- @interface DB_Que_Helper ()
- @property (copy, readwrite, nonatomic) NSDictionary *updateDataDic;
- @property (copy, readwrite, nonatomic) NSArray *updateIdArr;
- @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_A_Arr;
- @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_B_Arr;
- @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_A_Zero_Arr;
- @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_A_One_Arr;
- @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_A_Two_Arr;
- @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_B_Zero_Arr;
- @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_B_One_Arr;
- @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_B_Two_Arr;
- @end
- static FMDatabase *shareDataBase = nil;
- @implementation DB_Que_Helper
- /**
- 创建数据库类的单例对象
- **/
- + (FMDatabase *)createDataBase {
- if (![[NSFileManager defaultManager] fileExistsAtPath:dataBasePath2]) {
- //NSLog(@"拷贝数据库");
- [DB_Que_Helper copyFileDatabase];
- }
-
-
- /**线程安全的。
- 其实就是一个单例的方法
- 好处:
- 1 线程安全
- 2 很好满足静态分析器要求
- 3 和自动引用计数(ARC)兼容
- 4 仅需要少量代码
- 缺点:
- 仍可以创建非共享的实例
- */
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- shareDataBase = [FMDatabase databaseWithPath:dataBasePath2];
-
- /// 升级函数
- FMDBMigrationManager * manager = [FMDBMigrationManager managerWithDatabaseAtPath:dataBasePath2 migrationsBundle:[NSBundle mainBundle]];
- BOOL resultState=NO;
- NSError * error=nil;
- if (!manager.hasMigrationsTable) {
- resultState=[manager createMigrationsTable:&error];
- }
- resultState = [manager migrateDatabaseToVersion:UINT64_MAX progress:nil error:&error];
-
- //添加成绩表
- [DB_Que_Helper createNewTable];
- //添加错题、收藏、排错、已做题表
- [DB_Que_Helper createNewQuestionTable];
- //添加大货车错题、收藏、排错、已做题表
- // [DB_Que_Helper createGZPY_EXAM_CYRYNewQuestionTable];
-
- //添加已做过字段 这个很早的版本都添加过了 不用再添加了 可以删除
- //[DB_Que_Helper addDone];
- });
-
-
- int version = [self getDataBaseVersion];//打开数据库(网上有说打开关闭数据库比较耗cpu,不建议关闭)
- switch (version) {
- case 1: {
- //更新题库
- BOOL isSuccess = [shareDataBase executeUpdate:@"update question set answer = 32 ,explain = '在暂住地初次申领机动车驾驶证的,是可以直接申领大型货车驾驶证的。\n根据2016年4月1日起开始实行的驾驶证新规,取消了异地考驾照对A/B证的限制,A/B也可以在暂住地申领了,但是需要有当地的居住证或者暂住证。' where _id=501"];
- NSLog(@"%d",isSuccess);
- //更新版本
- [shareDataBase executeUpdate:[NSString stringWithFormat:@"update db_versions set version = %d where id=1",version+1]];
- }
- break;
- default:
- break;
- }
-
- if ([shareDataBase open]) {
- int num = -1;
- FMResultSet *s = [shareDataBase executeQuery:@"SELECT * FROM db_versions WHERE id=1"];
- if ([s next]) {
- num=[[s stringForColumn:@"version"] intValue];
- if (num == 0) {
- for (NSString *idStr in self.updateIdArr) {
- [self updateQuestionWithId:idStr];
- }
- NSString *sqlStr = [NSString stringWithFormat:@"UPDATE db_versions SET version = 1 WHERE id=1"];
- BOOL isSuccess = [shareDataBase executeUpdate:sqlStr];
- NSLog(@"%@",isSuccess? @"Success!" : @"Failed!");
- }
- }
-
- [shareDataBase close];
- }
-
- return shareDataBase;
- }
- /**创建grade表。保存我的成绩
- */
- +(void)createNewTable
- {
- if ([shareDataBase open])
- {
- //创建表 如果表不存在
- [shareDataBase executeUpdate:@"CREATE TABLE IF NOT EXISTS grade (id integer PRIMARY KEY AUTOINCREMENT, date text, score text, time text , honor text,subject text ,car_type text ,sfzhm text);"];
-
- //判断字段是否存在 老学员的表中没有这个字段 这里判断添加 并赋初始值
- NSString *sfzhm = @"sfzhm";
- if (![shareDataBase columnExists:sfzhm inTableWithName:@"grade"])
- {
- NSString *sql;
- sql = [NSString stringWithFormat:@"ALTER TABLE grade ADD sfzhm text"];
- [shareDataBase executeUpdate:sql];
- [DB_Que_Helper setGradeDefaultValue];
- }else{
- //NSLog(@"sfzhm已存在");
- }
-
- [shareDataBase close];
- }
- }
- +(void)createNewQuestionTable
- {
- if ([shareDataBase open])
- {
- //创建错题类表 type:1、错题 2、收藏 3、排错 4、已做未做 isUpdata:是否上传
- [shareDataBase executeUpdate:@"CREATE TABLE IF NOT EXISTS markQuestion (id integer PRIMARY KEY AUTOINCREMENT, _id integer, type text, isUpdata text, subject text ,car_type text ,sfzhm text);"];
-
- [shareDataBase close];
- }
- }
- +(void)insertGrade:(Grade*)gra
- {
- if ([shareDataBase open])
- {
- //将考试成绩存到数据库
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
- [shareDataBase executeUpdate:@"INSERT INTO grade (date,score,time,honor,subject,car_type,sfzhm) VALUES (?,?,?,?,?,?,?);", gra.graDate,gra.graScore,gra.graTime,gra.graHonor,myDelegate.subject,defUser.car_type,sfzhm];
- [shareDataBase close];
- }
- }
- /**注意:表也是有题库名和科目的 按照题库和科目 找到对应的成绩
- */
- +(NSArray *)queryAllGrades
- {
- NSMutableArray *arr=[[NSMutableArray alloc]init];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
- FMResultSet *s=[shareDataBase executeQuery:[NSString stringWithFormat:@"select * from grade where car_type = '%@' and subject = '%@' and sfzhm = '%@'",defUser.car_type,myDelegate.subject,sfzhm]];
- while ([s next]) {
-
- Grade *gra=[[Grade alloc]init];
- gra.graDate=[s stringForColumn:@"date"];
- gra.graHonor=[s stringForColumn:@"honor"];
- gra.graScore=[s stringForColumn:@"score"];
- gra.graTime=[s stringForColumn:@"time"];
-
- [arr addObject:gra];
- //NSLog(@"邪门---><>%@--->%@----.%@----->%@",gra.graDate,gra.graHonor,gra.graScore,gra.graTime);
- }
- }else{
- // NSLog(@"成绩数据库未打开----db unOpen");
- [LoadingView showMsg:@"读取成绩失败!"];
- }
- return arr;
- }
- /**添加done和favorite字段
- 现在用的 iscollect 和 isdone 字段 这个方法不用了吧 不过如果需要添加字段 可以使用这个方法
- 可以删除 --danson
- */
- +(void)addDone{
- //判断字段是否存在
- NSString* done = @"done";
- [shareDataBase open];
- if (![shareDataBase columnExists:done inTableWithName:@"question"])
- {
- NSString *sql;
- sql = [NSString stringWithFormat:@"ALTER TABLE question ADD done text"];
- [shareDataBase executeUpdate:sql];
- [DB_Que_Helper setDefaultValue];
- }else{
- //NSLog(@"done已存在");
- }
-
- [shareDataBase close];
- }
- +(void)addDoneAndFavorite{
- //判断字段是否存在
- NSString* done = @"done";
- [shareDataBase open];
- if (![shareDataBase columnExists:done inTableWithName:@"question"])
- {
- NSString *sql;
- sql = [NSString stringWithFormat:@"ALTER TABLE question ADD done text"];
- [shareDataBase executeUpdate:sql];
- sql = [NSString stringWithFormat:@"ALTER TABLE question ADD favorite text"];
- [shareDataBase executeUpdate:sql];
-
- [DB_Que_Helper setDefaultValue];
- }else{
- // NSLog(@"done&fav exist");
- }
-
- [shareDataBase close];
- }
- +(BOOL)setStateWithArray:(NSArray *)questions
- {
- BOOL isOk = NO;
- BOOL allIsOK = YES;
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- for (NSDictionary* obj in questions) {
- NSInteger qId = [obj[@"QID"] integerValue];
- NSString *kType = obj[@"TYPE"];
-
- NSString *sql;
- if ([kType isEqualToString:@"1"])
- {
- //收藏
- sql = [NSString stringWithFormat:@"update question set iscollect = %@ where _id=%ld",@"1",(long)qId];
- }
- else if ([kType isEqualToString:@"2"])
- {
- //错题
- sql = [NSString stringWithFormat:@"update question set state = %@ where _id=%ld",@"1",(long)qId];
- }
- else
- {
- //排除
- sql = [NSString stringWithFormat:@"update question set isdone = %@ where _id=%ld",@"1",(long)qId];
- }
-
- isOk=[shareDataBase executeUpdate:sql];
- if (isOk == NO) {
-
- allIsOK = NO;
- }
- }
-
- //同步数据后 查询错题数量
- NSString *sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = '1' and subject = '1'",defUser.car_type];
- int cnt1 = [shareDataBase intForQuery:sql];
-
- sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = '1' and subject = '4'",defUser.car_type];
- int cnt2 = [shareDataBase intForQuery:sql];
-
- sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = '1'",defUser.car_type];
- int cnt3 = [shareDataBase intForQuery:sql];
-
- myDelegate.faultArray = [NSMutableArray arrayWithObjects:[NSString stringWithFormat:@"%d",cnt1],[NSString stringWithFormat:@"%d",cnt2],[NSString stringWithFormat:@"%d",cnt3], nil];
- [shareDataBase close];
- }
- //NSLog(@"数据库数据更新%@",allIsOK == 1 ? @"成功" : @"失败");
- //NSLog(@"错题书------>%@",myDelegate.faultArray);
-
- return allIsOK;
- }
- //如果同步失败 或无数据做的操作
- +(void)getFaultIfNotNet
- {
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = 1 and subject = 1",defUser.car_type];
- int cnt1 = [shareDataBase intForQuery:sql];
-
- sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = 1 and subject = 4",defUser.car_type];
- int cnt2 = [shareDataBase intForQuery:sql];
-
- sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = 1",defUser.car_type];
- int cnt3 = [shareDataBase intForQuery:sql];
-
- myDelegate.faultArray = [NSMutableArray arrayWithObjects:[NSString stringWithFormat:@"%d",cnt1],[NSString stringWithFormat:@"%d",cnt2],[NSString stringWithFormat:@"%d",cnt3], nil];
- [shareDataBase close];
- }
- }
- +(BOOL)setState:(NSString*)state withId:(NSInteger)qid withType:(NSString *)type
- {
- NSString *sql;
- if ([type isEqualToString:@"1"])
- {
- //收藏
- sql = [NSString stringWithFormat:@"update question set iscollect = %@ where _id=%ld",state,(long)qid];
- }
- else if ([type isEqualToString:@"2"])
- {
- //错题
- sql = [NSString stringWithFormat:@"update question set state = %@ where _id=%ld",state,(long)qid];
- }
- else
- {
- //排除
- // NSLog(@"数据库更改排错状态");
- sql = [NSString stringWithFormat:@"update question set isdone = %@ where _id=%ld",state,(long)qid];
- }
- BOOL isOk = NO;
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
- isOk=[shareDataBase executeUpdate:sql];
- [shareDataBase close];
- }
- //NSLog(@"数据库数据更新%@",isOk == 1 ? @"成功" : @"失败");
- return isOk;
- }
- //如果新加了字段 要有这个操作置零 --danson
- +(void)setDefaultValue
- {
- /**fmdb一定要重新开。因为刚才没有2个字段。现在有了2个字段。
- */
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- shareDataBase = [FMDatabase databaseWithPath:dataBasePath2];
- });
-
- if ([shareDataBase open]) {
- [shareDataBase executeUpdate:[NSString stringWithFormat:@"update question set done = 0"]];
- }
- [shareDataBase close];
- }
- +(void)setGradeDefaultValue
- {
- /**fmdb一定要重新开。因为刚才没有2个字段。现在有了2个字段。
- */
- //这样会进死循环
- //shareDataBase=[DB_Que_Helper createDataBase];
- //这个会导致打开多个数据库
- //shareDataBase = [FMDatabase databaseWithPath:dataBasePath2];
- //dansonmark
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- shareDataBase = [FMDatabase databaseWithPath:dataBasePath2];
- });
-
- if ([shareDataBase open]) {
- //ALTER TABLE grade ADD sfzhm text
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
- [shareDataBase executeUpdate:[NSString stringWithFormat:@"update grade set sfzhm = '%@'",sfzhm]];
- //NSLog(@"写入----><>%d",isok);
- }
- [shareDataBase close];
- }
- /**不要判断是否存在,直接写入覆盖。
- */
- +(void)removeDB
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,NSUserDomainMask, YES);
-
- //NSLog(@"documentsDirectory数组路径----><>%@",paths);
-
- NSString *documentsDirectory = [paths firstObject];
-
- NSString *documentLibraryFolderPath = [documentsDirectory stringByAppendingPathComponent:dataBaseName2];
-
- [[NSFileManager defaultManager] removeItemAtPath:documentLibraryFolderPath error:nil];
- }
- /**
- **关闭数据库
- **/
- + (void)closeDataBase {
- if(![shareDataBase close]) {
- NSLog(@"数据库关闭异常,请检查");
- return;
- }
- }
- //拷贝数据库
- +(void)copyFileDatabase {
- NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
-
- NSString *documentLibraryFolderPath = [documentsDirectory stringByAppendingPathComponent:dataBaseName2];
- if ([[NSFileManager defaultManager] fileExistsAtPath:documentLibraryFolderPath]) {
- // NSLog(@"文件已经存在了");
- }else {
- NSString *resourceSampleImagesFolderPath =[[NSBundle mainBundle]pathForResource:@"miaxis" ofType:@"db"];
- //NSLog(@"%@",resourceSampleImagesFolderPath);
- NSData *mainBundleFile = [NSData dataWithContentsOfFile:resourceSampleImagesFolderPath];
- [[NSFileManager defaultManager] createFileAtPath:documentLibraryFolderPath
- contents:mainBundleFile
- attributes:nil];
- }
- }
- +(NSArray *)queryAllQuestion
- {
- NSMutableArray *questions=[[NSMutableArray alloc]init];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
- FMResultSet *s=[shareDataBase executeQuery:[NSString stringWithFormat:@"select * from question where car_type = '%@' ",defUser.car_type]];
- while ([s next]) {
- Question *question=[[Question alloc]init];
- question._id=[s stringForColumn:@"_id"];
- question.option_type=[s stringForColumn:@"option_type"];
- question.media_type=[s stringForColumn:@"media_type"];
- question.chapter=[s stringForColumn:@"chapter"];
- question.questionLabel=[s stringForColumn:@"question_label"];
- question.question=[s stringForColumn:@"question"];
- question.media=[s stringForColumn:@"media"];
- question.answer=[s stringForColumn:@"answer"];
- question.optionA=[s stringForColumn:@"option_a"];
- question.optionB=[s stringForColumn:@"option_b"];
- question.optionC=[s stringForColumn:@"option_c"];
- question.optionD=[s stringForColumn:@"option_d"];
- question.explain=[s stringForColumn:@"explain"];
- question.state=[s stringForColumn:@"state"];
- question.subject=[s stringForColumn:@"subject"];
- [questions addObject:question];
- }
- }else{
- NSLog(@"题库获取失败,数据库未打开");
- }
- return questions;
- }
- +(NSArray*)queryArea
- {
- /**从数据库找地址信息
- */
- NSMutableArray *questions=[[NSMutableArray alloc] init];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
- FMResultSet *s=[shareDataBase executeQuery:[NSString stringWithFormat:@"select * from area"]];
- while ([s next]) {
- NSMutableDictionary* question = [NSMutableDictionary dictionary];
- question[@"name"] = [s stringForColumn:@"name"];
- question[@"code"] = [s stringForColumn:@"code"];
- question[@"parent_code"] = [s stringForColumn:@"parent_code"];
- [questions addObject:question];
- }
- }else{
- NSLog(@"ERROR: db unOpen");
- }
- return questions;
- }
- +(NSArray *)queryQuestion:(NSString *)where
- {
- NSMutableArray *questions=[[NSMutableArray alloc]init];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sql = @"";
- //章节考试用到
- if ([where rangeOfString:@"subject = '1'"].location != NSNotFound)
- {
- sql=[NSString stringWithFormat:@"select * from question where car_type = '%@' and %@",defUser.car_type,where];
- }
- if ([where rangeOfString:@"subject = '4'"].location != NSNotFound)
- {
- sql=[NSString stringWithFormat:@"select * from question where car_type = 'C1' and %@",where ];
- if ([defUser.car_type isEqualToString:@"D"]) {
- sql=[NSString stringWithFormat:@"select * from question where car_type = 'D' and %@",where ];
- }
- }
-
- //资格证 非强化 非全部题
- if ([defUser.car_type isEqualToString:@"1"] || [defUser.car_type isEqualToString:@"2"] || [defUser.car_type isEqualToString:@"3"] || [defUser.car_type isEqualToString:@"4"] || [defUser.car_type isEqualToString:@"5"] || [defUser.car_type isEqualToString:@"6"])
- {
- if (![where isEqualToString:@"strong"])
- {
- if (where.length > 12) {
- where = [where substringFromIndex:13];
- }
- sql=[NSString stringWithFormat:@"select * from question where car_type = '%@'%@",defUser.car_type,where];
- }
- }
- if ([where isEqualToString:@"strong"])//代表强化练习
- {
- sql=[NSString stringWithFormat:@"select * from question where %@",myDelegate.where];
- }
-
- FMResultSet *s=[shareDataBase executeQuery:sql];
- questions = [Question questionsWithFMResultSet:s];
-
- //NSLog(@"这里找出要显示的题目sql-->%@-------where-->%@------count-->%d",sql,where,(int)questions.count);
-
- [shareDataBase close];
- }
- return questions;
- }
- //查找章节列表
- +(NSArray *)queryList:(NSString *)where
- {
- NSMutableArray *lists=[[NSMutableArray alloc]init];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
- FMResultSet *s=[shareDataBase executeQuery:where];
-
- while ([s next])
- {
- NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[s stringForColumn:@"title"],@"title",[s stringForColumn:@"ID"],@"chapter", nil];
- [lists addObject:dic];
- }
- [shareDataBase close];
- }
- return lists;
- }
- //查找标识
- +(NSArray *)queryMark:(NSString *)where
- {
- NSMutableArray *markArray = [NSMutableArray array];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
- FMResultSet *s=[shareDataBase executeQuery:[NSString stringWithFormat:@"select * from APP_MARK_GROUP where MG_PARENT = '%@'",where]];
-
- markArray = [markGroup markGroupWithFMResultSet:s];
- [shareDataBase close];
- }
-
- return markArray;
- }
- +(NSArray *)queryDetailMark:(NSString *)where
- {
- NSMutableArray *markArray = [NSMutableArray array];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- FMResultSet *s=[shareDataBase executeQuery:[NSString stringWithFormat:@"select * from APP_MARK_INFO where %@",where]];
-
- markArray = [markInfo markInfoWithFMResultSet:s];
- [shareDataBase close];
- }
- return markArray;
- }
- +(BOOL)updateDB:(NSString *)sql
- {
- shareDataBase=[DB_Que_Helper createDataBase];
- BOOL isOk = NO;
- if ([shareDataBase open])
- {
- isOk=[shareDataBase executeUpdate:sql];
- [shareDataBase close];
- }
- return isOk;
- }
- //添加已做的题
- +(void)addToDoneQue:(NSInteger)ID
- {
-
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
- [shareDataBase executeUpdate:[NSString stringWithFormat:@"update question set done = 1 where _id=%d",(int)ID]];
- [shareDataBase close];
- }
-
- }
- //这里也错了 和数据库字段不符 delete --数据库问题--danson
- +(BOOL)addToStrengthenQue:(NSInteger)ID
- {
- BOOL isOk = NO;
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
- isOk=[shareDataBase executeUpdate:[NSString stringWithFormat:@"update question set state = 1 where _id=%d",(int)ID]];
- [shareDataBase close];
- }
-
- return isOk;
- }
- +(BOOL)removeToStrengthenQue:(NSInteger)ID
- {
- BOOL isOk = NO;
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
- isOk=[shareDataBase executeUpdate:[NSString stringWithFormat:@"update question set state = 0 where _id=%d",(int)ID]];
- [shareDataBase close];
- }
-
- return isOk;
- }
- /**
- 抽考试题
- */
- +(NSArray *)queryExamQuestion
- {
- NSMutableArray *questions=[[NSMutableArray alloc]init];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
- //模拟考试中....
- //从数据库中随机抽取相应数目的题目 应该不用考虑题目存放数组位置问题吧 因为不是耗时操作 按代码先后顺序来排序
-
- /*
- 车型 科目 题目数量 总分数 合格分数 考试时间 错误题自动交卷 单选题数 每题分数 多选题数 多选题分数 判断题数量 判断题分数
- C1 1 100 100 90 45 10 60 1 0 0 40 1
- C1 4 50 100 90 30 5 20 2 5 2 25 2
-
- A1 1 100 100 90 45 10 60 1 0 0 40 1
- A1 4 50 100 90 30 5 20 2 5 2 25 2
-
-
- A2 1 100 100 90 45 10 60 1 0 0 40 1
- A2 4 50 100 90 30 5 20 2 5 2 25 2
-
-
- D 1 50 100 90 30 5 30 2 0 0 20 2
- D 4 50 100 90 30 5 30 2 0 0 20 2
-
-
- 1 1 90 100 80 60 9 40 1 10 2 40 1
- 2 1 90 100 80 90 9 40 1 10 2 40 1
- 3 1 100 100 90 90 10 57 1 0 0 43 1
- 4 1 100 100 80 60 10 19 1 36 1 45 1
- 5 1 90 100 80 45 9 50 1 10 2 30 1
- */
-
- int chooseNum = 0;
- int chooseMoreNum = 0;
- int judgeNum = 0;
-
- //@"C1",@"A2",@"A1",@"D",@"4",@"1",@"2",@"3",@"5"
- if ([defUser.car_type isEqualToString:@"C1"]) {
- if ([myDelegate.subject isEqualToString:@"1"]) {
- chooseNum = 60;
- chooseMoreNum = 0;
- judgeNum = 40;
- }else {
- chooseNum = 20;
- chooseMoreNum = 10;
- judgeNum = 20;
- }
- }else if ([defUser.car_type isEqualToString:@"A2"]) {
- if ([myDelegate.subject isEqualToString:@"1"]) {
- chooseNum = 60;
- chooseMoreNum = 0;
- judgeNum = 40;
- }else {
- chooseNum = 20;
- chooseMoreNum = 5;
- judgeNum = 25;
- }
- }else if ([defUser.car_type isEqualToString:@"A1"]) {
- if ([myDelegate.subject isEqualToString:@"1"]) {
- chooseNum = 60;
- chooseMoreNum = 0;
- judgeNum = 40;
- }else {
- chooseNum = 20;
- chooseMoreNum = 5;
- judgeNum = 25;
- }
- }else if ([defUser.car_type isEqualToString:@"D"]) {
- if ([myDelegate.subject isEqualToString:@"1"]) {
- chooseNum = 30;
- chooseMoreNum = 0;
- judgeNum = 20;
- }else {
- chooseNum = 30;
- chooseMoreNum = 0;
- judgeNum = 20;
- }
- }else if ([defUser.car_type isEqualToString:@"1"]) {
- chooseNum = 40;
- chooseMoreNum = 10;
- judgeNum = 40;
- }else if ([defUser.car_type isEqualToString:@"2"]) {
- chooseNum = 40;
- chooseMoreNum = 10;
- judgeNum = 40;
- }else if ([defUser.car_type isEqualToString:@"3"]) {
- chooseNum = 57;
- chooseMoreNum = 0;
- judgeNum = 43;
- }else if ([defUser.car_type isEqualToString:@"4"]) {
- chooseNum = 19;
- chooseMoreNum = 36;
- judgeNum = 45;
- }else if ([defUser.car_type isEqualToString:@"5"]) {
- chooseNum = 50;
- chooseMoreNum = 10;
- judgeNum = 30;
- }else if ([defUser.car_type isEqualToString:@"6"]) {
- chooseNum = 50;
- chooseMoreNum = 10;
- judgeNum = 30;
- }
-
- /*
- for (int i = 0; i < 3; i ++) {
- //i=0判断 i=1单选 i=2多选
- NSString *sql = [NSString stringWithFormat:@"select * from question where car_type = '%@' and subject = %@ and option_type = %d order by random() limit %d",defUser.car_type,myDelegate.subject,i,chooseNum];
- //除了摩托车 其他的公用C1科四题库
- if ([myDelegate.subject isEqualToString:@"4"] && ![defUser.car_type isEqualToString:@"D"]) {
- sql = [NSString stringWithFormat:@"select * from question where car_type = 'C1' and subject = %@ and option_type = %d order by random() limit %d",myDelegate.subject,i,chooseNum];
- }
- if ([defUser.car_type isEqualToString:@"1"] || [defUser.car_type isEqualToString:@"2"] || [defUser.car_type isEqualToString:@"3"] || [defUser.car_type isEqualToString:@"4"] || [defUser.car_type isEqualToString:@"5"])
- {
- sql = [NSString stringWithFormat:@"select * from question where car_type = '%@' and option_type = %d order by random() limit %d",defUser.car_type,i,chooseNum];
- }
- FMResultSet *s=[shareDataBase executeQuery:sql];
- [questions addObjectsFromArray:[Question questionsWithFMResultSet:s]];
- }
- */
-
- //判断0
- if (judgeNum > 0) {
- NSString *sql = [NSString stringWithFormat:@"select * from question where car_type = '%@' and subject = %@ and option_type = 0 order by random() limit %d",defUser.car_type,myDelegate.subject,judgeNum];
- //除了摩托车 其他的公用C1科四题库
- if ([myDelegate.subject isEqualToString:@"4"] && ![defUser.car_type isEqualToString:@"D"]) {
- sql = [NSString stringWithFormat:@"select * from question where car_type = 'C1' and subject = %@ and option_type = 0 order by random() limit %d",myDelegate.subject,judgeNum];
- }
- if ([defUser.car_type isEqualToString:@"1"] || [defUser.car_type isEqualToString:@"2"] || [defUser.car_type isEqualToString:@"3"] || [defUser.car_type isEqualToString:@"4"] || [defUser.car_type isEqualToString:@"5"] || [defUser.car_type isEqualToString:@"6"])
- {
- sql = [NSString stringWithFormat:@"select * from question where car_type = '%@' and option_type = 0 order by random() limit %d",defUser.car_type,judgeNum];
- }
- FMResultSet *s=[shareDataBase executeQuery:sql];
- [questions addObjectsFromArray:[Question questionsWithFMResultSet:s]];
- }
-
- //单选1
- if (chooseNum > 0) {
- NSString *sql = [NSString stringWithFormat:@"select * from question where car_type = '%@' and subject = %@ and option_type = 1 order by random() limit %d",defUser.car_type,myDelegate.subject,chooseNum];
- //除了摩托车 其他的公用C1科四题库
- if ([myDelegate.subject isEqualToString:@"4"] && ![defUser.car_type isEqualToString:@"D"]) {
- sql = [NSString stringWithFormat:@"select * from question where car_type = 'C1' and subject = %@ and option_type = 1 order by random() limit %d",myDelegate.subject,chooseNum];
- }
- if ([defUser.car_type isEqualToString:@"1"] || [defUser.car_type isEqualToString:@"2"] || [defUser.car_type isEqualToString:@"3"] || [defUser.car_type isEqualToString:@"4"] || [defUser.car_type isEqualToString:@"5"] || [defUser.car_type isEqualToString:@"6"])
- {
- sql = [NSString stringWithFormat:@"select * from question where car_type = '%@' and option_type = 1 order by random() limit %d",defUser.car_type,chooseNum];
- }
- FMResultSet *s2=[shareDataBase executeQuery:sql];
- [questions addObjectsFromArray:[Question questionsWithFMResultSet:s2]];
- }
-
- //多选2
- if (chooseMoreNum > 0) {
- NSString *sql = [NSString stringWithFormat:@"select * from question where car_type = '%@' and subject = %@ and option_type = 2 order by random() limit %d",defUser.car_type,myDelegate.subject,chooseMoreNum];
- //除了摩托车 其他的公用C1科四题库
- if ([myDelegate.subject isEqualToString:@"4"] && ![defUser.car_type isEqualToString:@"D"]) {
- sql = [NSString stringWithFormat:@"select * from question where car_type = 'C1' and subject = %@ and option_type = 2 order by random() limit %d",myDelegate.subject,chooseMoreNum];
- }
- if ([defUser.car_type isEqualToString:@"1"] || [defUser.car_type isEqualToString:@"2"] || [defUser.car_type isEqualToString:@"3"] || [defUser.car_type isEqualToString:@"4"] || [defUser.car_type isEqualToString:@"5"] || [defUser.car_type isEqualToString:@"6"])
- {
- sql = [NSString stringWithFormat:@"select * from question where car_type = '%@' and option_type = 2 order by random() limit %d",defUser.car_type,chooseMoreNum];
- }
- FMResultSet *s3=[shareDataBase executeQuery:sql];
- [questions addObjectsFromArray:[Question questionsWithFMResultSet:s3]];
- }
-
- [shareDataBase close];
- }
- return questions;
- }
- //清空错题、收藏、排错
- +(void)clearFavInfo
- {
- //每次进程序都要有这样的操作
- shareDataBase=[DB_Que_Helper createDataBase];
- if([shareDataBase open])
- {
- [shareDataBase executeUpdate:@"update question set state = 0 where state = 1"];
- [shareDataBase executeUpdate:@"update question set state = 0 where iscollect = 1"];
- [shareDataBase executeUpdate:@"update question set state = 0 where isdone = 1"];
- [shareDataBase close];
- return;
- }else{
- NSLog(@"db error");
- return;
- }
- }
- /**
- 从选择页面过来查询多少题目
- */
- +(NSInteger)countForQuery:(NSString *)where
- {
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sql;
- if ([where isEqualToString:@"subject = 1"])
- {
- sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and %@",defUser.car_type,where];
- }
- else if ([where isEqualToString:@"subject = 4"])
- {
- //NSLog(@"摩托车科是--%@",defUser.car_type);
- if ([defUser.car_type isEqualToString:@"D"]) {
- sql=[NSString stringWithFormat:@"select count(*) from question where car_type = 'D' and %@",where];
- }else{
- sql=[NSString stringWithFormat:@"select count(*) from question where car_type = 'C1' and %@",where];
- }
- }
- else if ([where isEqualToString:@"nil"])
- {
- sql= RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [NSString stringWithFormat:@"select count(*) from question where car_type = '%@'",defUser.car_type] : ([defUser.car_type isEqualToString:@"2"]? [NSString stringWithFormat:@"select count(*) from GZPT_EXAM_CYRY"] : [NSString stringWithFormat:@"select count(*) from question where car_type = '%@'",defUser.car_type]);
- }
- else if ([where isEqualToString:@"state = 1 and subject = 1"])
- {
- sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and %@",defUser.car_type,where];
- }
- else if ([where isEqualToString:@"state = 1 and subject = 4"])
- {
- sql=[NSString stringWithFormat:@"select count(*) from question where car_type = 'C1' and %@",where ];
- }
- else
- {
- sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = 1",defUser.car_type];
- }
- if ([where rangeOfString:@"strong"].location != NSNotFound)
- {
- sql=[NSString stringWithFormat:@"select count(*) from question where %@",myDelegate.where];
- }
-
- // if ([where isEqualToString:@"done"])
- // {
- // sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and done = 1 and %@",defUser.car_type,myDelegate.where];
- // if ([myDelegate.where isEqualToString:@"done"])
- // {
- // sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and done = 1",defUser.car_type];
- // }
- // }
-
- NSInteger cnt = [shareDataBase intForQuery:sql];
- [shareDataBase close];
- //NSLog(@"这里查题目数量--sql-->%@-------where-->%@------count-->%d",sql,where,(int)cnt);
- return cnt;
- }
- return 0;
- }
- +(NSArray *)queryColumnNameWithTable:(NSString *)tableName
- {
- sqlite3 *database;
- sqlite3_open([dataBasePath2 UTF8String], &database);
-
- sqlite3_stmt *statement;
-
- //获取数据库的表的名字
- // const char *getTableInfo = "select * from sqlite_master where type='table' order by name";
- // sqlite3_prepare_v2(database, getTableInfo, -1, &statement, nil);
- // while (sqlite3_step(statement) == SQLITE_ROW) {
- // char *nameData = (char *)sqlite3_column_text(statement, 1);
- // NSString *tableName = [[NSString alloc] initWithUTF8String:nameData];
- // NSLog(@"name:%@",tableName);
- // }
-
- NSMutableArray *array = [NSMutableArray array];
- NSString *columnName = @"";
- //获取某表中字段的名字
- const char *getColumn = "PRAGMA table_info(question)";
- sqlite3_prepare_v2(database, getColumn, -1, &statement, nil);
- while (sqlite3_step(statement) == SQLITE_ROW) {
- char *nameData = (char *)sqlite3_column_text(statement, 1);
- columnName = [[NSString alloc] initWithUTF8String:nameData];
- //NSLog(@"columnName:%@",columnName);
- [array addObject:columnName];
- }
-
- sqlite3_finalize(statement);
-
- return array;
- }
- #pragma mark markQuestion
- //(_id integer PRIMARY KEY, type text, isUpdata text, subject text ,car_type text ,sfzhm text)
- +(BOOL)setMarkQuestionWithQuestion:(NSInteger)qId Type:(NSString *)markType State:(NSInteger)state
- {
- BOOL isOk = NO;
- shareDataBase=[DB_Que_Helper createDataBase];
- state = [markType isEqualToString:@"4"]? 0 : [self queryIsHaveWithQuestion:qId Type:markType];
- if ([shareDataBase open]) {
-
- if (state == 0) {
- //添加
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
- //在调这个方法前已经判断过 是否已经存在
- isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"insert into markQuestion (_id,type,isUpdata,subject,car_type,sfzhm)values(%ld,'%@','0','%@','%@','%@')",(long)qId,markType,myDelegate.subject,defUser.car_type,sfzhm]];
- }
- if (state == 1) {
- //删除
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
- isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"delete from markQuestion where _id=%ld and type='%@' and sfzhm='%@'",(long)qId,markType,sfzhm]];
- }
- [shareDataBase close];
- }
- return isOk;
- }
- +(BOOL)queryIsHaveWithQuestion:(NSInteger)qId Type:(NSString *)markType
- {
- BOOL isOk = NO;
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- NSInteger cnt = [shareDataBase intForQuery:[NSString stringWithFormat:@"select count(*) from markQuestion where _id=%ld and type='%@' and subject = '%@' and car_type = '%@' and sfzhm = '%@'",(long)qId,markType,myDelegate.subject,defUser.car_type,sfzhm]];
- if (cnt > 0) {
- isOk = YES;
- }
- [shareDataBase close];
- }
-
- return isOk;
- }
- +(NSArray *)queryMarkQuestionWithType:(NSString *)markType
- {
- NSMutableArray *questions = [[NSMutableArray alloc]init];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
-
- NSString *sql;//1、错题 2、收藏 3、排错 4、已做未做 5、除去排除的题
-
- if ([markType isEqualToString:@"4"]){
- sql=[NSString stringWithFormat:@"select * from question where subject = '%@' and car_type = '%@' and _id not in (select _id from markQuestion where type = '4' and subject = '%@' and car_type = '%@' and sfzhm = '%@')",myDelegate.subject,defUser.car_type,myDelegate.subject,defUser.car_type,sfzhm];
- }else if ([markType isEqualToString:@"5"]){
- //除去排错剩下的所有题
- sql=[NSString stringWithFormat:@"select * from question where subject = '%@' and car_type = '%@' and _id not in (select _id from markQuestion where type = '3' and subject = '%@' and car_type = '%@' and sfzhm = '%@')",myDelegate.subject,defUser.car_type,myDelegate.subject,defUser.car_type,sfzhm];
-
- if ([myDelegate.subject isEqualToString:@"4"])
- {
- sql=[NSString stringWithFormat:@"select * from question where subject = '%@' and car_type = 'C1' and _id not in (select _id from markQuestion where type = '3' and subject = '%@' and car_type = '%@' and sfzhm = '%@')",myDelegate.subject,myDelegate.subject,defUser.car_type,sfzhm];
- if ([defUser.car_type isEqualToString:@"D"]) {
- sql=[NSString stringWithFormat:@"select * from question where subject = '%@' and car_type = 'D' and _id not in (select _id from markQuestion where type = '3' and subject = '%@' and car_type = '%@' and sfzhm = '%@')",myDelegate.subject,myDelegate.subject,defUser.car_type,sfzhm];
- }
- }
-
- }else{
- sql=[NSString stringWithFormat:@"select * from question where _id in (select _id from markQuestion where type = '%@' and subject = '%@' and car_type = '%@' and sfzhm = '%@')",markType,myDelegate.subject,defUser.car_type,sfzhm];
- }
-
- //如果是资格证 就将科目的判断去掉
- if ([defUser.car_type isEqualToString:@"1"] || [defUser.car_type isEqualToString:@"2"] || [defUser.car_type isEqualToString:@"3"] || [defUser.car_type isEqualToString:@"4"] || [defUser.car_type isEqualToString:@"5"] || [defUser.car_type isEqualToString:@"6"])
- {
- if ([sql containsString:[NSString stringWithFormat:@"subject = '%@' and",myDelegate.subject]]) {
-
- sql = [sql stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"subject = '%@' and",myDelegate.subject] withString:@""];
- }
- }
-
-
- FMResultSet *s=[shareDataBase executeQuery:sql];
- questions = [Question questionsWithFMResultSet:s];
-
- //NSLog(@"这里找出要显示的题目sql-->%@------------count-->%d",sql,(int)questions.count);
-
- [shareDataBase close];
- }
- return questions;
- }
- +(NSArray *)queryMarkQuestionWithUpData:(NSInteger)isUpdata MarkType:(NSString *)markType Subject:(NSString *)sub
- {
- NSMutableArray<NSString *> *array = [NSMutableArray array];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
- NSString *sql;
-
- sql=[NSString stringWithFormat:@"select * from markQuestion where subject = '%@' and car_type = '%@' and type = '%@' and isUpdata = '0' and sfzhm = '%@'",sub,defUser.car_type,markType,sfzhm];
-
-
- if (isUpdata == 1) {
- sql = [sql stringByReplacingOccurrencesOfString:@" and isUpdata = '0'" withString:@""];
- }
-
- FMResultSet *s=[shareDataBase executeQuery:sql];
-
- while ([s next]) {
-
- NSString *questId = [s stringForColumn:@"_id"];
-
- [array addObject:questId];
- }
-
- [shareDataBase close];
- }
- //NSLog(@"题目---><>%@",array);
- return array;
- }
- +(NSInteger)queryMarkQuestionWithMarkType:(NSString *)markType
- {
- NSInteger cnt = 0;
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- cnt = [shareDataBase intForQuery:[NSString stringWithFormat:@"select count(*) from markQuestion where subject = '%@' and car_type = '%@' and sfzhm = '%@' and type = '%@'",myDelegate.subject,defUser.car_type,sfzhm,markType]];
-
- [shareDataBase close];
- }
- return cnt;
- }
- +(BOOL)setIsUpdateWithType:(NSString *)markType
- {
- BOOL isOk = NO;
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- NSString *sql;
- if ([markType isEqualToString:@"0"]) {
-
- sql = [NSString stringWithFormat:@"update markQuestion set isUpdata = '1' where subject = '%@' and car_type = '%@' and sfzhm = '%@'",myDelegate.subject,defUser.car_type,sfzhm];
- }else{
- sql = [NSString stringWithFormat:@"update markQuestion set isUpdata = '1' where type = '%@' and subject = '%@' and car_type = '%@' and sfzhm = '%@'",markType,myDelegate.subject,defUser.car_type,sfzhm];
- }
-
- isOk = [shareDataBase executeUpdate:sql];
-
- [shareDataBase close];
- }
-
- return isOk;
- }
- +(BOOL)setIsUpdateWithArray:(NSArray<NSString *> *)array
- {
- BOOL isOk = NO;
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- NSString *sql;
-
- NSString *sub1 = @"";
- NSString *sub4 = @"";
- for (NSString *tagStr in array) {
- NSInteger tag = [tagStr integerValue];
- NSString *typeStr = @"1";
- if (tag == 3 || tag == 6) {
- typeStr = @"2";
- }
- if (tag == 4 || tag == 7) {
- typeStr = @"3";
- }
- if (tag < 5) {//科一
- sub1 = [sub1 stringByAppendingString:[NSString stringWithFormat:@"%@,",typeStr]];
- }else{//科四
- sub4 = [sub4 stringByAppendingString:[NSString stringWithFormat:@"%@,",typeStr]];
- }
- }
-
- if (sub1.length > 0) {
- sub1 = [sub1 substringToIndex:sub1.length - 1];
- sql = [NSString stringWithFormat:@"update markQuestion set isUpdata = '1' where subject = '1' and car_type = '%@' and sfzhm = '%@' and type in (%@)",defUser.car_type,sfzhm,sub1];
- isOk = [shareDataBase executeUpdate:sql];
- }
-
- if (sub4.length > 0) {
- sub4 = [sub4 substringToIndex:sub4.length - 1];
- sql = [NSString stringWithFormat:@"update markQuestion set isUpdata = '1' where subject = '4' and car_type = '%@' and sfzhm = '%@' and type in (%@)",defUser.car_type,sfzhm,sub4];
- isOk = [shareDataBase executeUpdate:sql];
- }
-
- [shareDataBase close];
- }
- return isOk;
- }
- +(BOOL)setMarkQuestionWithArray:(NSArray *)questions
- {
- BOOL isOk = NO;
- BOOL allIsOK = YES;
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- //NSLog(@"-----><>%@",questions);
-
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- for (NSDictionary *obj in questions) {
- NSInteger qId = [obj[@"QID"] integerValue];
-
- NSString *kType = obj[@"TYPE"];
- NSString *markType;
- if ([kType isEqualToString:@"1"]){
- //收藏
- markType = @"2";
- }else if ([kType isEqualToString:@"2"]){
- //错题
- markType = @"1";
- }else{
- //排除
- markType = @"3";
- }
-
- NSString *cartype = defUser.car_type;
- if ([obj[@"CARTYPE"] length] > 0) {
- cartype = obj[@"CARTYPE"];
- }
-
- NSString *sub = myDelegate.subject;
- if ([obj[@"SUBJECT"] length] > 0) {
- sub = obj[@"SUBJECT"];
- }
-
-
- if ([markType isEqualToString:@"1"]) {
-
- NSInteger cnt = [shareDataBase intForQuery:[NSString stringWithFormat:@"select count(*) from markQuestion where _id=%ld and type='4' and subject = '%@' and car_type = '%@' and sfzhm = '%@'",(long)qId,sub,cartype,sfzhm]];
- if (cnt == 0) {
- [shareDataBase executeUpdate:[NSString stringWithFormat:@"insert into markQuestion (_id,type,isUpdata,subject,car_type,sfzhm)values(%ld,'4','1','%@','%@','%@')",(long)qId,sub,cartype,sfzhm]];
- }
- }
-
- //dansonmark这里的科目 车型应该来自服务器 如果服务器不返回 就要从本地题目库查
- isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"insert into markQuestion (_id,type,isUpdata,subject,car_type,sfzhm)values(%ld,'%@','1','%@','%@','%@')",(long)qId,markType,sub,cartype,sfzhm]];
-
- if (isOk == NO) {
- allIsOK = NO;
- }
- }
- [shareDataBase close];
- }
- return allIsOK;
- }
- +(BOOL)deleteAllMarkQuestion
- {
- BOOL isOk = NO;
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"delete from markQuestion where type != '4' and sfzhm='%@'",sfzhm]];
- [shareDataBase close];
- }
- return isOk;
- }
- +(void)moveIsDoneToMarkQuestion
- {
- //等以后就版本没有了 就不用管这个了
- NSArray *columnArray = [DB_Que_Helper queryColumnNameWithTable:@"question"];
-
- if (![columnArray containsObject:@"done"]) {
- //说明是新版 没有了done字段。不需要转移已做题
- return;
- }
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- FMResultSet *s=[shareDataBase executeQuery:@"select * from question where done = 1"];
- NSMutableArray *questions = [Question questionsWithFMResultSet:s];
-
- for (Question *question in questions) {
- //NSLog(@"插入已做题");
- [shareDataBase executeUpdate:[NSString stringWithFormat:@"insert into markQuestion (_id,type,isUpdata,subject,car_type,sfzhm)values(%d,'4','0','%@','%@','%@')",[question._id intValue],myDelegate.subject,defUser.car_type,sfzhm]];
- }
-
- [shareDataBase close];
- }
- }
- #pragma mark - miaxis.db数据库升级
- + (int)getDataBaseVersion {
- //避免多线程操作带来的弊端 (互斥锁)
- @synchronized([DB_Que_Helper class]) {
- int num=0;
- if ([shareDataBase open]) {
- FMResultSet *s = [shareDataBase executeQuery:@"SELECT * FROM db_versions WHERE id=1"];
- if ([s next]) {
- num = [[s stringForColumn:@"version"] intValue];
- }
- }
- return num;
- }
- }
- + (void)updateQuestionWithId:(NSString *)idStr {
- NSString *sqlStr0 = [NSString stringWithFormat:@"UPDATE question SET question = '%@' WHERE _id = %ld",self.updateDataDic[idStr][@"question"],(long)idStr.integerValue];
- NSString *sqlStr1 = [NSString stringWithFormat:@"UPDATE question SET explain = '%@' WHERE _id = %ld",self.updateDataDic[idStr][@"explain"],(long)idStr.integerValue];
- BOOL isSuccess0 = [shareDataBase executeUpdate:sqlStr0];
- BOOL isSuccess1 = [shareDataBase executeUpdate:sqlStr1];
- NSLog(@"%@ %@",isSuccess0? @"Success!" : @"Failed!",isSuccess1? @"Success!" : @"Failed!");
- }
- + (NSDictionary *)updateDataDic {
- return @{
- @"332" : @{
- @"question" : @"年龄在70周岁以上的驾驶人多长时间提交一次身体条件证明?",
- @"explain" : @"新修改的《机动车驾驶证申领和使用规定》还放宽了未体检注销驾驶证后恢复驾驶资格的年龄,规定:年龄在70周岁以上的驾驶人,在一个记分周期结束后一年内未提交身体条件证明的,车辆管理所将注销其机动车驾驶证。",
- },
- @"466" : @{
- @"question" : @"年龄在70周岁以上,在一个记分周期结束后一年内未提交身体条件证明的,其机动车驾驶证将会被车辆管理所注销。",
- @"explain" : @"新修改的《机动车驾驶证申领和使用规定》还放宽了未体检注销驾驶证后恢复驾驶资格的年龄,规定:年龄在70周岁以上的驾驶人,在一个记分周期结束后一年内未提交身体条件证明的,车辆管理所将注销其机动车驾驶证。",
- },
- @"521" : @{
- @"question" : @"年龄在70周岁以上的机动车驾驶人,应当每年进行一次身体检查的目的是什么?",
- @"explain" : @"新修改的《机动车驾驶证申领和使用规定》还放宽了未体检注销驾驶证后恢复驾驶资格的年龄,规定:年龄在70周岁以上的驾驶人,在一个记分周期结束后一年内未提交身体条件证明的,车辆管理所将注销其机动车驾驶证。",
- },
- @"3960" : @{
- @"question" : @"申请小型汽车准驾车型驾驶证的人年龄条件是多少?",
- @"explain" : @"《公安部令第123号》第十一条:申请小型汽车、小型自动挡汽车、残疾人专用小型自动挡载客汽车、轻便摩托车准驾车型的,在18周岁以上、70周岁以下。",
- },
- @"3962" : @{
- @"question" : @"申请小型汽车汽车驾驶证的,年龄应在18周岁以上70周岁以下。",
- @"explain" : @"《公安部令第123号》第十一条:申请小型汽车、小型自动挡汽车、残疾人专用小型自动挡载客汽车、轻便摩托车准驾车型的,在18周岁以上、70周岁以下。",
- },
- @"3976" : @{
- @"question" : @"年龄在70周岁以上的驾驶人多长时间提交一次身体条件证明?",
- @"explain" : @"新修改的《机动车驾驶证申领和使用规定》还放宽了未体检注销驾驶证后恢复驾驶资格的年龄,规定:年龄在70周岁以上的驾驶人,在一个记分周期结束后一年内未提交身体条件证明的,车辆管理所将注销其机动车驾驶证。",
- },
- @"2738" : @{
- @"question" : @"申请小型汽车准驾车型驾驶证的人年龄条件是多少?",
- @"explain" : @"《公安部令第123号》第十一条:申请小型汽车、小型自动挡汽车、残疾人专用小型自动挡载客汽车、轻便摩托车准驾车型的,在18周岁以上、70周岁以下。",
- },
- @"2740" : @{
- @"question" : @"申请小型汽车汽车驾驶证的,年龄应在18周岁以上70周岁以下。",
- @"explain" : @"《公安部令第123号》第十一条:申请小型汽车、小型自动挡汽车、残疾人专用小型自动挡载客汽车、轻便摩托车准驾车型的,在18周岁以上、70周岁以下。",
- },
- @"2754" : @{
- @"question" : @"年龄在70周岁以上的驾驶人多长时间提交一次身体条件证明?",
- @"explain" : @"新修改的《机动车驾驶证申领和使用规定》还放宽了未体检注销驾驶证后恢复驾驶资格的年龄,规定:年龄在70周岁以上的驾驶人,在一个记分周期结束后一年内未提交身体条件证明的,车辆管理所将注销其机动车驾驶证。",
- },
- @"3627" : @{
- @"question" : @"年龄在70周岁以上,在1个记分周期结束后,( )内未提交身体检查结果的,车辆管理所注销其驾驶证。",
- @"explain" : @"新修改的《机动车驾驶证申领和使用规定》还放宽了未体检注销驾驶证后恢复驾驶资格的年龄,规定:年龄在70周岁以上的驾驶人,在一个记分周期结束后一年内未提交身体条件证明的,车辆管理所将注销其机动车驾驶证。",
- },
- @"3631" : @{
- @"question" : @"年龄在60岁以上,超过机动车驾驶证有效期一年以上未换证的,车辆管理所将注销其驾驶证。",
- @"explain" : @"《公安部令第123号》第六十七条:机动车驾驶人具有下列情形之一的,车辆管理所应当注销其机动车驾驶证:(七)超过机动车驾驶证有效期一年以上未换证的。",
- },
- @"3595" : @{
- @"question" : @"年龄在60岁以上持有准驾车型为大型客车的驾驶人,应当到驾驶证核发地车辆管理所换领准驾车型为小型汽车或小型自动挡汽车的驾驶证。",
- @"explain" : @"《公安部令第123号》第五十条:年龄在60周岁以上的,不得驾驶大型客车、牵引车、城市公交车、中型客车、大型货车、无轨电车和有轨电车;持有大型客车、牵引车、城市公交车、中型客车、大型货车驾驶证的,应当到机动车驾驶证核发地车辆管理所换领准驾车型为小型汽车或者小型自动挡汽车的机动车驾驶证。",
- },
- };
- }
- + (NSArray *)updateIdArr {
- return @[@"332", @"466", @"521", @"3960", @"3962", @"3976", @"2738", @"2740", @"2754", @"3627", @"3631", @"3595"];
- }
- #pragma mark - 2021年2月18新增功能大车考试
- +(void)createGZPY_EXAM_CYRYNewQuestionTable
- {
- if ([shareDataBase open])
- {
- //创建错题类表 type:1、错题 2、收藏 3、排错 4、已做未做 isUpdata:是否上传
- [shareDataBase executeUpdate:@"CREATE TABLE IF NOT EXISTS GZPT_EXAM_CYRY_MARK_QUESTION (id integer PRIMARY KEY AUTOINCREMENT, eq_id integer, type text, isUpdata text ,sfzhm text);"];
-
- [shareDataBase close];
- }
- }
- //得到考题
- + (NSArray *)queryGZPZ_EXAM_CYRYExamQuestion {
- NSMutableArray *questions = [[NSMutableArray alloc]init];
- shareDataBase = [DB_Que_Helper createDataBase];
-
- // if ([defUser.userDict[@"city"] isEqualToString:@"2101"]) {
- /// cykhModal: 1启用AB试卷, 0普通模式
- if ([defUser.userDict[@"cykhModal"] isEqualToString:@"1"]) {
- int x = arc4random() % 2;
- NSArray *chooseArr = (x == 0)? self.JinZhou_GZPZ_EXAM_CYRY_A_Arr : self.JinZhou_GZPZ_EXAM_CYRY_B_Arr;
- NSMutableArray *strArr = [NSMutableArray array];
- [chooseArr.rac_sequence.signal subscribeNext:^(NSString *idStr) {
- NSString *sql = [NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY where eq_id = %@",idStr];
- [strArr addObject:sql];
- } completed:^{
- if ([shareDataBase open]) {
- [shareDataBase executeStatements:[strArr componentsJoinedByString:@";"] withResultBlock:^int(NSDictionary * _Nonnull resultsDictionary) {
- Question *question = [[Question alloc]init];
- question._id = !([resultsDictionary[@"eq_id"] isKindOfClass:[NSNull class]])? resultsDictionary[@"eq_id"] : @"";
- question.option_type = !([resultsDictionary[@"option_type"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_type"] : @"";
- question.media_type = !([resultsDictionary[@"media_type"] isKindOfClass:[NSNull class]])? resultsDictionary[@"media_type"] : @"";
- question.chapter = !([resultsDictionary[@"chapter"] isKindOfClass:[NSNull class]])? resultsDictionary[@"chapter"] : @"";
- question.questionLabel = !([resultsDictionary[@"question_label"] isKindOfClass:[NSNull class]])? resultsDictionary[@"question_label"] : @"";
- question.question = !([resultsDictionary[@"question"] isKindOfClass:[NSNull class]])? resultsDictionary[@"question"] : @"";
- question.media = !([resultsDictionary[@"media"] isKindOfClass:[NSNull class]])? resultsDictionary[@"media"] : @"";
- question.answer = !([resultsDictionary[@"answer"] isKindOfClass:[NSNull class]])? resultsDictionary[@"answer"] : @"";
- question.optionA = !([resultsDictionary[@"option_a"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_a"] : @"";
- question.optionB = !([resultsDictionary[@"option_b"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_b"] : @"";
- question.optionC = !([resultsDictionary[@"option_c"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_c"] : @"";
- question.optionD = !([resultsDictionary[@"option_d"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_d"] : @"";
- question.state = !([resultsDictionary[@"state"] isKindOfClass:[NSNull class]])? resultsDictionary[@"state"] : @"";
- question.move = !([resultsDictionary[@"isdone"] isKindOfClass:[NSNull class]])? resultsDictionary[@"isdone"] : @"";
- question.favorite = !([resultsDictionary[@"iscollect"] isKindOfClass:[NSNull class]])? resultsDictionary[@"iscollect"] : @"";
-
- [questions addObject:question];
- return 0;
- }];
- [shareDataBase close];
- }
- }];
- } else {
- /// 考试项目(chapter) 题量(num)
- /// (option_type) 判断(0) 单选(1) 多选(2)
- /// 1.驾驶员的职业道德、职业心理与职业健康 1 1 2
- /// 2.道路货物运输从业相关法律法规 2 3 5
- /// 3.道路货物运输相关标准 1 2 1
- /// 4.道路货物运输专业知识 4 4 4
- /// 5.汽车使用技术 3 2 3
- /// 6.道路货物运输安全、应急处置(理论知识) 3 4 5
- ///
- ///合计 14 16 20
- NSArray *chooseQuestionArr = @[
- @{@"chapter" : @(1), @"option_type" : @(0), @"num" : @(1)},
- @{@"chapter" : @(2), @"option_type" : @(0), @"num" : @(2)},
- @{@"chapter" : @(3), @"option_type" : @(0), @"num" : @(1)},
- @{@"chapter" : @(4), @"option_type" : @(0), @"num" : @(4)},
- @{@"chapter" : @(5), @"option_type" : @(0), @"num" : @(3)},
- @{@"chapter" : @(6), @"option_type" : @(0), @"num" : @(3)},
-
- @{@"chapter" : @(1), @"option_type" : @(1), @"num" : @(1)},
- @{@"chapter" : @(2), @"option_type" : @(1), @"num" : @(3)},
- @{@"chapter" : @(3), @"option_type" : @(1), @"num" : @(2)},
- @{@"chapter" : @(4), @"option_type" : @(1), @"num" : @(4)},
- @{@"chapter" : @(5), @"option_type" : @(1), @"num" : @(2)},
- @{@"chapter" : @(6), @"option_type" : @(1), @"num" : @(4)},
-
- @{@"chapter" : @(1), @"option_type" : @(2), @"num" : @(2)},
- @{@"chapter" : @(2), @"option_type" : @(2), @"num" : @(5)},
- @{@"chapter" : @(3), @"option_type" : @(2), @"num" : @(1)},
- @{@"chapter" : @(4), @"option_type" : @(2), @"num" : @(4)},
- @{@"chapter" : @(5), @"option_type" : @(2), @"num" : @(3)},
- @{@"chapter" : @(6), @"option_type" : @(2), @"num" : @(5)},
- ];
- NSMutableArray *strArr = [NSMutableArray array];
- [chooseQuestionArr.rac_sequence.signal subscribeNext:^(NSDictionary *chooseQuestionDic) {
- NSString *sql = [NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY where chapter = %@ and option_type = %@ order by random() limit %@",chooseQuestionDic[@"chapter"], chooseQuestionDic[@"option_type"], chooseQuestionDic[@"num"]];
- [strArr addObject:sql];
- } completed:^{
- if ([shareDataBase open]) {
- [shareDataBase executeStatements:[strArr componentsJoinedByString:@";"] withResultBlock:^int(NSDictionary * _Nonnull resultsDictionary) {
- Question *question = [[Question alloc]init];
- question._id = !([resultsDictionary[@"eq_id"] isKindOfClass:[NSNull class]])? resultsDictionary[@"eq_id"] : @"";
- question.option_type = !([resultsDictionary[@"option_type"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_type"] : @"";
- question.media_type = !([resultsDictionary[@"media_type"] isKindOfClass:[NSNull class]])? resultsDictionary[@"media_type"] : @"";
- question.chapter = !([resultsDictionary[@"chapter"] isKindOfClass:[NSNull class]])? resultsDictionary[@"chapter"] : @"";
- question.questionLabel = !([resultsDictionary[@"question_label"] isKindOfClass:[NSNull class]])? resultsDictionary[@"question_label"] : @"";
- question.question = !([resultsDictionary[@"question"] isKindOfClass:[NSNull class]])? resultsDictionary[@"question"] : @"";
- question.media = !([resultsDictionary[@"media"] isKindOfClass:[NSNull class]])? resultsDictionary[@"media"] : @"";
- question.answer = !([resultsDictionary[@"answer"] isKindOfClass:[NSNull class]])? resultsDictionary[@"answer"] : @"";
- question.optionA = !([resultsDictionary[@"option_a"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_a"] : @"";
- question.optionB = !([resultsDictionary[@"option_b"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_b"] : @"";
- question.optionC = !([resultsDictionary[@"option_c"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_c"] : @"";
- question.optionD = !([resultsDictionary[@"option_d"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_d"] : @"";
- question.state = !([resultsDictionary[@"state"] isKindOfClass:[NSNull class]])? resultsDictionary[@"state"] : @"";
- question.move = !([resultsDictionary[@"isdone"] isKindOfClass:[NSNull class]])? resultsDictionary[@"isdone"] : @"";
- question.favorite = !([resultsDictionary[@"iscollect"] isKindOfClass:[NSNull class]])? resultsDictionary[@"iscollect"] : @"";
-
- [questions addObject:question];
- return 0;
- }];
- [shareDataBase close];
- }
- }];
- }
-
- return questions;
- }
- + (NSArray *)queryGZPZ_EXAM_CYRYAllQuestion {
- NSMutableArray *questions=[[NSMutableArray alloc]init];
- shareDataBase = [DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
- FMResultSet *s=[shareDataBase executeQuery:[NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY"]];
- while ([s next]) {
- Question *question=[[Question alloc]init];
- question._id=[s stringForColumn:@"eq_id"];
- question.option_type=[s stringForColumn:@"option_type"];
- question.media_type=[s stringForColumn:@"media_type"];
- question.chapter=[s stringForColumn:@"chapter"];
- question.questionLabel=[s stringForColumn:@"question_label"];
- question.question=[s stringForColumn:@"question"];
- question.media=[s stringForColumn:@"media"];
- question.answer=[s stringForColumn:@"answer"];
- question.optionA=[s stringForColumn:@"option_a"];
- question.optionB=[s stringForColumn:@"option_b"];
- question.optionC=[s stringForColumn:@"option_c"];
- question.optionD=[s stringForColumn:@"option_d"];
- question.favorite=[s stringForColumn:@"favorite"];
- question.done=[s stringForColumn:@"done"];
- [questions addObject:question];
- }
- }else{
- NSLog(@"题库获取失败,数据库未打开");
- }
- return questions;
- }
- //查找章节列表
- + (NSArray *)queryGZPZ_EXAM_CYRYList:(NSString *)where {
- NSMutableArray *lists=[[NSMutableArray alloc]init];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
- FMResultSet *s=[shareDataBase executeQuery:where];
-
- while ([s next])
- {
- NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[s stringForColumn:@"name"],@"title",[s stringForColumn:@"id"],@"chapter", nil];
- [lists addObject:dic];
- }
- [shareDataBase close];
- }
- return lists;
- }
- + (NSArray *)queryGZPZ_EXAM_CYRYQuestion:(NSString *)where {
- NSMutableArray *questions=[[NSMutableArray alloc]init];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sql=[NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY where %@",where];
-
- FMResultSet *s=[shareDataBase executeQuery:sql];
- questions = [Question questionsForGZPZWithFMResultSet:s];
-
- [shareDataBase close];
- }
- return questions;
- }
- + (NSArray *)queryGZPZ_EXAM_CYRYMarkQuestionWithType:(NSString *)markType {
- NSMutableArray *questions = [[NSMutableArray alloc]init];
- shareDataBase = [DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
-
- NSString *sql;//1、错题 2、收藏 3、排错 4、已做未做 5、除去排除的题
-
- if ([markType isEqualToString:@"4"]){
- sql=[NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY where eq_id not in (select eq_id from GZPT_EXAM_CYRY_MARK_QUESTION where type = '4' and sfzhm = '%@')",sfzhm];
- }else if ([markType isEqualToString:@"5"]){
- //除去排错剩下的所有题
- sql=[NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY where eq_id not in (select eq_id from GZPT_EXAM_CYRY_MARK_QUESTION where type = '3' and sfzhm = '%@')",sfzhm];
- }else{
- sql=[NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY where eq_id in (select eq_id from GZPT_EXAM_CYRY_MARK_QUESTION where type = '%@' and sfzhm = '%@')",markType,sfzhm];
- }
-
- FMResultSet *s = [shareDataBase executeQuery:sql];
- questions = [Question questionsForGZPZWithFMResultSet:s];
-
- //NSLog(@"这里找出要显示的题目sql-->%@------------count-->%d",sql,(int)questions.count);
-
- [shareDataBase close];
- }
- return questions;
- }
- + (BOOL)setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:(NSInteger)qId Type:(NSString *)markType State:(NSInteger)state {
- BOOL isOk = NO;
- shareDataBase=[DB_Que_Helper createDataBase];
- state = [markType isEqualToString:@"4"]? 0 : [self queryGZPZ_EXAM_CYRYIsHaveWithQuestion:qId Type:markType];
- if ([shareDataBase open]) {
-
-
- if (state == 0) {
- //添加
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
- //在调这个方法前已经判断过 是否已经存在
- isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"insert into GZPT_EXAM_CYRY_MARK_QUESTION (eq_id,type,isUpdata,sfzhm)values(%ld,'%@','0','%@')",(long)qId,markType,sfzhm]];
- }
- if (state == 1) {
- //删除
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
- isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"delete from GZPT_EXAM_CYRY_MARK_QUESTION where eq_id=%ld and type='%@' and sfzhm='%@'",(long)qId,markType,sfzhm]];
- }
- [shareDataBase close];
- }
- return isOk;
- }
- + (BOOL)queryGZPZ_EXAM_CYRYIsHaveWithQuestion:(NSInteger)qId Type:(NSString *)markType {
- BOOL isOk = NO;
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- NSInteger cnt = [shareDataBase intForQuery:[NSString stringWithFormat:@"select count(*) from GZPT_EXAM_CYRY_MARK_QUESTION where eq_id=%ld and type='%@' and sfzhm = '%@'",(long)qId,markType,sfzhm]];
- if (cnt > 0) {
- isOk = YES;
- }
- [shareDataBase close];
- }
-
- return isOk;
- }
- + (NSArray *)queryGZPZ_EXAM_CYRYMarkQuestionWithUpData:(NSInteger)isUpdata MarkType:(NSString *)markType Subject:(NSString *)sub {
- NSMutableArray<NSString *> *array = [NSMutableArray array];
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
- NSString *sql;
-
- sql=[NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY_MARK_QUESTION where type = '%@' and isUpdata = '0' and sfzhm = '%@'",markType,sfzhm];
-
-
- if (isUpdata == 1) {
- sql = [sql stringByReplacingOccurrencesOfString:@" and isUpdata = '0'" withString:@""];
- }
-
- FMResultSet *s=[shareDataBase executeQuery:sql];
-
- while ([s next]) {
-
- NSString *questId = [s stringForColumn:@"eq_id"];
-
- [array addObject:questId];
- }
-
- [shareDataBase close];
- }
- //NSLog(@"题目---><>%@",array);
- return array;
- }
- + (NSInteger)queryGZPZ_EXAM_CYRYMarkQuestionWithMarkType:(NSString *)markType {
- NSInteger cnt = 0;
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- cnt = [shareDataBase intForQuery:[NSString stringWithFormat:@"select count(*) from GZPT_EXAM_CYRY_MARK_QUESTION where sfzhm = '%@' and type = '%@'",sfzhm,markType]];
-
- [shareDataBase close];
- }
- return cnt;
- }
- + (BOOL)setGZPZ_EXAM_CYRYIsUpdateWithType:(NSString *)markType {
- BOOL isOk = NO;
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- NSString *sql;
- if ([markType isEqualToString:@"0"]) {
-
- sql = [NSString stringWithFormat:@"update GZPT_EXAM_CYRY_MARK_QUESTION set isUpdata = '1' where sfzhm = '%@'",sfzhm];
- }else{
- sql = [NSString stringWithFormat:@"update GZPT_EXAM_CYRY_MARK_QUESTION set isUpdata = '1' where type = '%@' and sfzhm = '%@'",markType,sfzhm];
- }
-
- isOk = [shareDataBase executeUpdate:sql];
-
- [shareDataBase close];
- }
-
- return isOk;
- }
- + (BOOL)setGZPZ_EXAM_CYRYIsUpdateWithArray:(NSArray<NSString *> *)array {
- BOOL isOk = NO;
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- NSString *sql;
-
- NSString *sub1 = @"";
- NSString *sub4 = @"";
- for (NSString *tagStr in array) {
- NSInteger tag = [tagStr integerValue];
- NSString *typeStr = @"1";
- if (tag == 3 || tag == 6) {
- typeStr = @"2";
- }
- if (tag == 4 || tag == 7) {
- typeStr = @"3";
- }
- if (tag < 5) {//科一
- sub1 = [sub1 stringByAppendingString:[NSString stringWithFormat:@"%@,",typeStr]];
- }else{//科四
- sub4 = [sub4 stringByAppendingString:[NSString stringWithFormat:@"%@,",typeStr]];
- }
- }
-
- if (sub1.length > 0) {
- sub1 = [sub1 substringToIndex:sub1.length - 1];
- sql = [NSString stringWithFormat:@"update GZPT_EXAM_CYRY_MARK_QUESTION set isUpdata = '1' where sfzhm = '%@' and type in (%@)",sfzhm,sub1];
- isOk = [shareDataBase executeUpdate:sql];
- }
-
- if (sub4.length > 0) {
- sub4 = [sub4 substringToIndex:sub4.length - 1];
- sql = [NSString stringWithFormat:@"update GZPT_EXAM_CYRY_MARK_QUESTION set isUpdata = '1' where sfzhm = '%@' and type in (%@)",sfzhm,sub4];
- isOk = [shareDataBase executeUpdate:sql];
- }
-
- [shareDataBase close];
- }
- return isOk;
- }
- + (BOOL)setGZPZ_EXAM_CYRYMarkQuestionWithArray:(NSArray *)questions {
- BOOL isOk = NO;
- BOOL allIsOK = YES;
-
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- //NSLog(@"-----><>%@",questions);
-
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- for (NSDictionary *obj in questions) {
- NSInteger qId = [obj[@"QID"] integerValue];
-
- NSString *kType = obj[@"TYPE"];
- NSString *markType;
- if ([kType isEqualToString:@"1"]){
- //收藏
- markType = @"2";
- }else if ([kType isEqualToString:@"2"]){
- //错题
- markType = @"1";
- }else{
- //排除
- markType = @"3";
- }
-
- NSString *cartype = defUser.car_type;
- if ([obj[@"CARTYPE"] length] > 0) {
- cartype = obj[@"CARTYPE"];
- }
-
- NSString *sub = myDelegate.subject;
- if ([obj[@"SUBJECT"] length] > 0) {
- sub = obj[@"SUBJECT"];
- }
-
-
- if ([markType isEqualToString:@"1"]) {
-
- NSInteger cnt = [shareDataBase intForQuery:[NSString stringWithFormat:@"select count(*) from GZPT_EXAM_CYRY_MARK_QUESTION where eq_id=%ld and type='4' and sfzhm = '%@'",(long)qId,sfzhm]];
- if (cnt == 0) {
- [shareDataBase executeUpdate:[NSString stringWithFormat:@"insert into GZPT_EXAM_CYRY_MARK_QUESTION (eq_id,type,isUpdata,sfzhm)values(%ld,'4','1','%@')",(long)qId,sfzhm]];
- }
- }
-
- //dansonmark这里的科目 车型应该来自服务器 如果服务器不返回 就要从本地题目库查
- isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"insert into GZPT_EXAM_CYRY_MARK_QUESTION (eq_id,type,isUpdata,sfzhm)values(%ld,'%@','1','%@')",(long)qId,markType,sfzhm]];
-
- if (isOk == NO) {
- allIsOK = NO;
- }
- }
- [shareDataBase close];
- }
- return allIsOK;
- }
- + (BOOL)deleteGZPZ_EXAM_CYRYAllMarkQuestion {
- BOOL isOk = NO;
- NSString *sfzhm = @"no";
- if (myDelegate.isLogin) {
- sfzhm = defUser.userDict[@"id"];
- }
-
- shareDataBase=[DB_Que_Helper createDataBase];
- if ([shareDataBase open]) {
-
- isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"delete from GZPT_EXAM_CYRY_MARK_QUESTION where type != '4' and sfzhm='%@'",sfzhm]];
- [shareDataBase close];
- }
- return isOk;
- }
- + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_A_Arr {
- NSMutableArray *arr = [NSMutableArray array];
- [arr addObjectsFromArray:[self getRandomNumber:self.JinZhou_GZPZ_EXAM_CYRY_A_Zero_Arr]];
- [arr addObjectsFromArray:[self getRandomNumber:self.JinZhou_GZPZ_EXAM_CYRY_A_One_Arr]];
- [arr addObjectsFromArray:[self getRandomNumber:self.JinZhou_GZPZ_EXAM_CYRY_A_Two_Arr]];
- return arr.mutableCopy;
- // return @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"41",@"42",@"43",
- // @"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"74",
- // @"77",@"79",@"84",@"86",@"89",@"92",@"95",@"96",@"97",@"103",
- // @"110",@"113",@"17",@"18",@"19",@"20",@"31",@"34",@"36",@"38",
- // @"39",@"40",@"114",@"117",@"119",@"120",@"123",@"124",@"125",@"126"];
- }
- + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_B_Arr {
- NSMutableArray *arr = [NSMutableArray array];
- [arr addObjectsFromArray:[self getRandomNumber:self.JinZhou_GZPZ_EXAM_CYRY_B_Zero_Arr]];
- [arr addObjectsFromArray:[self getRandomNumber:self.JinZhou_GZPZ_EXAM_CYRY_B_One_Arr]];
- [arr addObjectsFromArray:[self getRandomNumber:self.JinZhou_GZPZ_EXAM_CYRY_B_Two_Arr]];
- return arr.mutableCopy;
- // return @[@"53",@"54",@"55",@"56",@"57",@"58",@"59",@"60",@"61",@"62",
- // @"63",@"64",@"65",@"66",@"67",@"68",@"69",@"70",@"71",@"333",
- // @"334",@"338",@"399",@"402",@"408",@"414",@"416",@"420",@"436",@"325",
- // @"327",@"329",@"129",@"138",@"139",@"143",@"144",@"148",@"149",@"150",
- // @"151",@"157",@"198",@"199",@"201",@"202",@"203",@"205",@"263",@"264"];
- }
- + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_A_Zero_Arr {
- return @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52"];
- }
- + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_A_One_Arr {
- return @[@"74",@"77",@"79",@"84",@"86",@"89",@"92",@"95",@"96",@"97",@"103",@"110",@"113"];
- }
- + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_A_Two_Arr {
- return @[@"17",@"18",@"19",@"20",@"31",@"34",@"36",@"38",@"39",@"40",@"114",@"117",@"119",@"120",@"123",@"124",@"125",@"126"];
- }
- + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_B_Zero_Arr {
- return @[@"53",@"54",@"55",@"56",@"57",@"58",@"59",@"60",@"61",@"62",@"63",@"64",@"65",@"66",@"67",@"68",@"69",@"70",@"71"];
- }
- + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_B_One_Arr {
- return @[@"333",@"334",@"338",@"399",@"402",@"408",@"414",@"416",@"420",@"436",@"325",@"327",@"329"];
- }
- + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_B_Two_Arr {
- return @[@"129",@"138",@"139",@"143",@"144",@"148",@"149",@"150",@"151",@"157",@"198",@"199",@"201",@"202",@"203",@"205",@"263",@"264"];
- }
- + (NSMutableArray *)getRandomNumber:(NSArray * )temp {
- NSMutableArray *tempArray = [[NSMutableArray alloc] initWithArray:temp];
- NSMutableArray *resultArray = [[NSMutableArray alloc] init];
- int i;
- int count = temp.count;
- NSLog(@"count:%d",count);
- for (i = 0; i < count; i ++) {
- int index = arc4random() % (count - i);
- [resultArray addObject:[tempArray objectAtIndex:index]];
- NSLog(@"index:%d,xx:%@",index,[tempArray objectAtIndex:index]);
- [tempArray removeObjectAtIndex:index];
- }
- NSLog(@"resultArray is %@",resultArray);
- return resultArray;
- }
- @end
|