DB_Que_Helper.m 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873
  1. #import "DB_Que_Helper.h"
  2. #import "Question.h"
  3. #import "markGroup.h"
  4. #import "markInfo.h"
  5. #import "Grade.h"
  6. #import <sqlite3.h>
  7. @interface DB_Que_Helper ()
  8. @property (copy, readwrite, nonatomic) NSDictionary *updateDataDic;
  9. @property (copy, readwrite, nonatomic) NSArray *updateIdArr;
  10. @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_A_Arr;
  11. @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_B_Arr;
  12. @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_A_Zero_Arr;
  13. @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_A_One_Arr;
  14. @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_A_Two_Arr;
  15. @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_B_Zero_Arr;
  16. @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_B_One_Arr;
  17. @property (copy, readwrite, nonatomic) NSArray *JinZhou_GZPZ_EXAM_CYRY_B_Two_Arr;
  18. @end
  19. static FMDatabase *shareDataBase = nil;
  20. @implementation DB_Que_Helper
  21. /**
  22. 创建数据库类的单例对象
  23. **/
  24. + (FMDatabase *)createDataBase {
  25. if (![[NSFileManager defaultManager] fileExistsAtPath:dataBasePath2]) {
  26. //NSLog(@"拷贝数据库");
  27. [DB_Que_Helper copyFileDatabase];
  28. }
  29. /**线程安全的。
  30. 其实就是一个单例的方法
  31. 好处:
  32. 1 线程安全
  33. 2 很好满足静态分析器要求
  34. 3 和自动引用计数(ARC)兼容
  35. 4 仅需要少量代码
  36. 缺点:
  37. 仍可以创建非共享的实例
  38. */
  39. static dispatch_once_t onceToken;
  40. dispatch_once(&onceToken, ^{
  41. shareDataBase = [FMDatabase databaseWithPath:dataBasePath2];
  42. /// 升级函数
  43. FMDBMigrationManager * manager = [FMDBMigrationManager managerWithDatabaseAtPath:dataBasePath2 migrationsBundle:[NSBundle mainBundle]];
  44. BOOL resultState=NO;
  45. NSError * error=nil;
  46. if (!manager.hasMigrationsTable) {
  47. resultState=[manager createMigrationsTable:&error];
  48. }
  49. resultState = [manager migrateDatabaseToVersion:UINT64_MAX progress:nil error:&error];
  50. //添加成绩表
  51. [DB_Que_Helper createNewTable];
  52. //添加错题、收藏、排错、已做题表
  53. [DB_Que_Helper createNewQuestionTable];
  54. //添加大货车错题、收藏、排错、已做题表
  55. // [DB_Que_Helper createGZPY_EXAM_CYRYNewQuestionTable];
  56. //添加已做过字段 这个很早的版本都添加过了 不用再添加了 可以删除
  57. //[DB_Que_Helper addDone];
  58. });
  59. int version = [self getDataBaseVersion];//打开数据库(网上有说打开关闭数据库比较耗cpu,不建议关闭)
  60. switch (version) {
  61. case 1: {
  62. //更新题库
  63. BOOL isSuccess = [shareDataBase executeUpdate:@"update question set answer = 32 ,explain = '在暂住地初次申领机动车驾驶证的,是可以直接申领大型货车驾驶证的。\n根据2016年4月1日起开始实行的驾驶证新规,取消了异地考驾照对A/B证的限制,A/B也可以在暂住地申领了,但是需要有当地的居住证或者暂住证。' where _id=501"];
  64. NSLog(@"%d",isSuccess);
  65. //更新版本
  66. [shareDataBase executeUpdate:[NSString stringWithFormat:@"update db_versions set version = %d where id=1",version+1]];
  67. }
  68. break;
  69. default:
  70. break;
  71. }
  72. if ([shareDataBase open]) {
  73. int num = -1;
  74. FMResultSet *s = [shareDataBase executeQuery:@"SELECT * FROM db_versions WHERE id=1"];
  75. if ([s next]) {
  76. num=[[s stringForColumn:@"version"] intValue];
  77. if (num == 0) {
  78. for (NSString *idStr in self.updateIdArr) {
  79. [self updateQuestionWithId:idStr];
  80. }
  81. NSString *sqlStr = [NSString stringWithFormat:@"UPDATE db_versions SET version = 1 WHERE id=1"];
  82. BOOL isSuccess = [shareDataBase executeUpdate:sqlStr];
  83. NSLog(@"%@",isSuccess? @"Success!" : @"Failed!");
  84. }
  85. }
  86. [shareDataBase close];
  87. }
  88. return shareDataBase;
  89. }
  90. /**创建grade表。保存我的成绩
  91. */
  92. +(void)createNewTable
  93. {
  94. if ([shareDataBase open])
  95. {
  96. //创建表 如果表不存在
  97. [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);"];
  98. //判断字段是否存在 老学员的表中没有这个字段 这里判断添加 并赋初始值
  99. NSString *sfzhm = @"sfzhm";
  100. if (![shareDataBase columnExists:sfzhm inTableWithName:@"grade"])
  101. {
  102. NSString *sql;
  103. sql = [NSString stringWithFormat:@"ALTER TABLE grade ADD sfzhm text"];
  104. [shareDataBase executeUpdate:sql];
  105. [DB_Que_Helper setGradeDefaultValue];
  106. }else{
  107. //NSLog(@"sfzhm已存在");
  108. }
  109. [shareDataBase close];
  110. }
  111. }
  112. +(void)createNewQuestionTable
  113. {
  114. if ([shareDataBase open])
  115. {
  116. //创建错题类表 type:1、错题 2、收藏 3、排错 4、已做未做 isUpdata:是否上传
  117. [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);"];
  118. [shareDataBase close];
  119. }
  120. }
  121. +(void)insertGrade:(Grade*)gra
  122. {
  123. if ([shareDataBase open])
  124. {
  125. //将考试成绩存到数据库
  126. NSString *sfzhm = @"no";
  127. if (myDelegate.isLogin) {
  128. sfzhm = defUser.userDict[@"id"];
  129. }
  130. [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];
  131. [shareDataBase close];
  132. }
  133. }
  134. /**注意:表也是有题库名和科目的 按照题库和科目 找到对应的成绩
  135. */
  136. +(NSArray *)queryAllGrades
  137. {
  138. NSMutableArray *arr=[[NSMutableArray alloc]init];
  139. shareDataBase=[DB_Que_Helper createDataBase];
  140. if ([shareDataBase open]) {
  141. NSString *sfzhm = @"no";
  142. if (myDelegate.isLogin) {
  143. sfzhm = defUser.userDict[@"id"];
  144. }
  145. FMResultSet *s=[shareDataBase executeQuery:[NSString stringWithFormat:@"select * from grade where car_type = '%@' and subject = '%@' and sfzhm = '%@'",defUser.car_type,myDelegate.subject,sfzhm]];
  146. while ([s next]) {
  147. Grade *gra=[[Grade alloc]init];
  148. gra.graDate=[s stringForColumn:@"date"];
  149. gra.graHonor=[s stringForColumn:@"honor"];
  150. gra.graScore=[s stringForColumn:@"score"];
  151. gra.graTime=[s stringForColumn:@"time"];
  152. [arr addObject:gra];
  153. //NSLog(@"邪门---><>%@--->%@----.%@----->%@",gra.graDate,gra.graHonor,gra.graScore,gra.graTime);
  154. }
  155. }else{
  156. // NSLog(@"成绩数据库未打开----db unOpen");
  157. [LoadingView showMsg:@"读取成绩失败!"];
  158. }
  159. return arr;
  160. }
  161. /**添加done和favorite字段
  162. 现在用的 iscollect 和 isdone 字段 这个方法不用了吧 不过如果需要添加字段 可以使用这个方法
  163. 可以删除 --danson
  164. */
  165. +(void)addDone{
  166. //判断字段是否存在
  167. NSString* done = @"done";
  168. [shareDataBase open];
  169. if (![shareDataBase columnExists:done inTableWithName:@"question"])
  170. {
  171. NSString *sql;
  172. sql = [NSString stringWithFormat:@"ALTER TABLE question ADD done text"];
  173. [shareDataBase executeUpdate:sql];
  174. [DB_Que_Helper setDefaultValue];
  175. }else{
  176. //NSLog(@"done已存在");
  177. }
  178. [shareDataBase close];
  179. }
  180. +(void)addDoneAndFavorite{
  181. //判断字段是否存在
  182. NSString* done = @"done";
  183. [shareDataBase open];
  184. if (![shareDataBase columnExists:done inTableWithName:@"question"])
  185. {
  186. NSString *sql;
  187. sql = [NSString stringWithFormat:@"ALTER TABLE question ADD done text"];
  188. [shareDataBase executeUpdate:sql];
  189. sql = [NSString stringWithFormat:@"ALTER TABLE question ADD favorite text"];
  190. [shareDataBase executeUpdate:sql];
  191. [DB_Que_Helper setDefaultValue];
  192. }else{
  193. // NSLog(@"done&fav exist");
  194. }
  195. [shareDataBase close];
  196. }
  197. +(BOOL)setStateWithArray:(NSArray *)questions
  198. {
  199. BOOL isOk = NO;
  200. BOOL allIsOK = YES;
  201. shareDataBase=[DB_Que_Helper createDataBase];
  202. if ([shareDataBase open]) {
  203. for (NSDictionary* obj in questions) {
  204. NSInteger qId = [obj[@"QID"] integerValue];
  205. NSString *kType = obj[@"TYPE"];
  206. NSString *sql;
  207. if ([kType isEqualToString:@"1"])
  208. {
  209. //收藏
  210. sql = [NSString stringWithFormat:@"update question set iscollect = %@ where _id=%ld",@"1",(long)qId];
  211. }
  212. else if ([kType isEqualToString:@"2"])
  213. {
  214. //错题
  215. sql = [NSString stringWithFormat:@"update question set state = %@ where _id=%ld",@"1",(long)qId];
  216. }
  217. else
  218. {
  219. //排除
  220. sql = [NSString stringWithFormat:@"update question set isdone = %@ where _id=%ld",@"1",(long)qId];
  221. }
  222. isOk=[shareDataBase executeUpdate:sql];
  223. if (isOk == NO) {
  224. allIsOK = NO;
  225. }
  226. }
  227. //同步数据后 查询错题数量
  228. NSString *sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = '1' and subject = '1'",defUser.car_type];
  229. int cnt1 = [shareDataBase intForQuery:sql];
  230. sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = '1' and subject = '4'",defUser.car_type];
  231. int cnt2 = [shareDataBase intForQuery:sql];
  232. sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = '1'",defUser.car_type];
  233. int cnt3 = [shareDataBase intForQuery:sql];
  234. myDelegate.faultArray = [NSMutableArray arrayWithObjects:[NSString stringWithFormat:@"%d",cnt1],[NSString stringWithFormat:@"%d",cnt2],[NSString stringWithFormat:@"%d",cnt3], nil];
  235. [shareDataBase close];
  236. }
  237. //NSLog(@"数据库数据更新%@",allIsOK == 1 ? @"成功" : @"失败");
  238. //NSLog(@"错题书------>%@",myDelegate.faultArray);
  239. return allIsOK;
  240. }
  241. //如果同步失败 或无数据做的操作
  242. +(void)getFaultIfNotNet
  243. {
  244. shareDataBase=[DB_Que_Helper createDataBase];
  245. if ([shareDataBase open]) {
  246. NSString *sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = 1 and subject = 1",defUser.car_type];
  247. int cnt1 = [shareDataBase intForQuery:sql];
  248. sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = 1 and subject = 4",defUser.car_type];
  249. int cnt2 = [shareDataBase intForQuery:sql];
  250. sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = 1",defUser.car_type];
  251. int cnt3 = [shareDataBase intForQuery:sql];
  252. myDelegate.faultArray = [NSMutableArray arrayWithObjects:[NSString stringWithFormat:@"%d",cnt1],[NSString stringWithFormat:@"%d",cnt2],[NSString stringWithFormat:@"%d",cnt3], nil];
  253. [shareDataBase close];
  254. }
  255. }
  256. +(BOOL)setState:(NSString*)state withId:(NSInteger)qid withType:(NSString *)type
  257. {
  258. NSString *sql;
  259. if ([type isEqualToString:@"1"])
  260. {
  261. //收藏
  262. sql = [NSString stringWithFormat:@"update question set iscollect = %@ where _id=%ld",state,(long)qid];
  263. }
  264. else if ([type isEqualToString:@"2"])
  265. {
  266. //错题
  267. sql = [NSString stringWithFormat:@"update question set state = %@ where _id=%ld",state,(long)qid];
  268. }
  269. else
  270. {
  271. //排除
  272. // NSLog(@"数据库更改排错状态");
  273. sql = [NSString stringWithFormat:@"update question set isdone = %@ where _id=%ld",state,(long)qid];
  274. }
  275. BOOL isOk = NO;
  276. shareDataBase=[DB_Que_Helper createDataBase];
  277. if ([shareDataBase open]) {
  278. isOk=[shareDataBase executeUpdate:sql];
  279. [shareDataBase close];
  280. }
  281. //NSLog(@"数据库数据更新%@",isOk == 1 ? @"成功" : @"失败");
  282. return isOk;
  283. }
  284. //如果新加了字段 要有这个操作置零 --danson
  285. +(void)setDefaultValue
  286. {
  287. /**fmdb一定要重新开。因为刚才没有2个字段。现在有了2个字段。
  288. */
  289. static dispatch_once_t onceToken;
  290. dispatch_once(&onceToken, ^{
  291. shareDataBase = [FMDatabase databaseWithPath:dataBasePath2];
  292. });
  293. if ([shareDataBase open]) {
  294. [shareDataBase executeUpdate:[NSString stringWithFormat:@"update question set done = 0"]];
  295. }
  296. [shareDataBase close];
  297. }
  298. +(void)setGradeDefaultValue
  299. {
  300. /**fmdb一定要重新开。因为刚才没有2个字段。现在有了2个字段。
  301. */
  302. //这样会进死循环
  303. //shareDataBase=[DB_Que_Helper createDataBase];
  304. //这个会导致打开多个数据库
  305. //shareDataBase = [FMDatabase databaseWithPath:dataBasePath2];
  306. //dansonmark
  307. static dispatch_once_t onceToken;
  308. dispatch_once(&onceToken, ^{
  309. shareDataBase = [FMDatabase databaseWithPath:dataBasePath2];
  310. });
  311. if ([shareDataBase open]) {
  312. //ALTER TABLE grade ADD sfzhm text
  313. NSString *sfzhm = @"no";
  314. if (myDelegate.isLogin) {
  315. sfzhm = defUser.userDict[@"id"];
  316. }
  317. [shareDataBase executeUpdate:[NSString stringWithFormat:@"update grade set sfzhm = '%@'",sfzhm]];
  318. //NSLog(@"写入----><>%d",isok);
  319. }
  320. [shareDataBase close];
  321. }
  322. /**不要判断是否存在,直接写入覆盖。
  323. */
  324. +(void)removeDB
  325. {
  326. NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,NSUserDomainMask, YES);
  327. //NSLog(@"documentsDirectory数组路径----><>%@",paths);
  328. NSString *documentsDirectory = [paths firstObject];
  329. NSString *documentLibraryFolderPath = [documentsDirectory stringByAppendingPathComponent:dataBaseName2];
  330. [[NSFileManager defaultManager] removeItemAtPath:documentLibraryFolderPath error:nil];
  331. }
  332. /**
  333. **关闭数据库
  334. **/
  335. + (void)closeDataBase {
  336. if(![shareDataBase close]) {
  337. NSLog(@"数据库关闭异常,请检查");
  338. return;
  339. }
  340. }
  341. //拷贝数据库
  342. +(void)copyFileDatabase {
  343. NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,NSUserDomainMask, YES);
  344. NSString *documentsDirectory = [paths objectAtIndex:0];
  345. NSString *documentLibraryFolderPath = [documentsDirectory stringByAppendingPathComponent:dataBaseName2];
  346. if ([[NSFileManager defaultManager] fileExistsAtPath:documentLibraryFolderPath]) {
  347. // NSLog(@"文件已经存在了");
  348. }else {
  349. NSString *resourceSampleImagesFolderPath =[[NSBundle mainBundle]pathForResource:@"miaxis" ofType:@"db"];
  350. //NSLog(@"%@",resourceSampleImagesFolderPath);
  351. NSData *mainBundleFile = [NSData dataWithContentsOfFile:resourceSampleImagesFolderPath];
  352. [[NSFileManager defaultManager] createFileAtPath:documentLibraryFolderPath
  353. contents:mainBundleFile
  354. attributes:nil];
  355. }
  356. }
  357. +(NSArray *)queryAllQuestion
  358. {
  359. NSMutableArray *questions=[[NSMutableArray alloc]init];
  360. shareDataBase=[DB_Que_Helper createDataBase];
  361. if ([shareDataBase open]) {
  362. FMResultSet *s=[shareDataBase executeQuery:[NSString stringWithFormat:@"select * from question where car_type = '%@' ",defUser.car_type]];
  363. while ([s next]) {
  364. Question *question=[[Question alloc]init];
  365. question._id=[s stringForColumn:@"_id"];
  366. question.option_type=[s stringForColumn:@"option_type"];
  367. question.media_type=[s stringForColumn:@"media_type"];
  368. question.chapter=[s stringForColumn:@"chapter"];
  369. question.questionLabel=[s stringForColumn:@"question_label"];
  370. question.question=[s stringForColumn:@"question"];
  371. question.media=[s stringForColumn:@"media"];
  372. question.answer=[s stringForColumn:@"answer"];
  373. question.optionA=[s stringForColumn:@"option_a"];
  374. question.optionB=[s stringForColumn:@"option_b"];
  375. question.optionC=[s stringForColumn:@"option_c"];
  376. question.optionD=[s stringForColumn:@"option_d"];
  377. question.explain=[s stringForColumn:@"explain"];
  378. question.state=[s stringForColumn:@"state"];
  379. question.subject=[s stringForColumn:@"subject"];
  380. [questions addObject:question];
  381. }
  382. }else{
  383. NSLog(@"题库获取失败,数据库未打开");
  384. }
  385. return questions;
  386. }
  387. +(NSArray*)queryArea
  388. {
  389. /**从数据库找地址信息
  390. */
  391. NSMutableArray *questions=[[NSMutableArray alloc] init];
  392. shareDataBase=[DB_Que_Helper createDataBase];
  393. if ([shareDataBase open]) {
  394. FMResultSet *s=[shareDataBase executeQuery:[NSString stringWithFormat:@"select * from area"]];
  395. while ([s next]) {
  396. NSMutableDictionary* question = [NSMutableDictionary dictionary];
  397. question[@"name"] = [s stringForColumn:@"name"];
  398. question[@"code"] = [s stringForColumn:@"code"];
  399. question[@"parent_code"] = [s stringForColumn:@"parent_code"];
  400. [questions addObject:question];
  401. }
  402. }else{
  403. NSLog(@"ERROR: db unOpen");
  404. }
  405. return questions;
  406. }
  407. +(NSArray *)queryQuestion:(NSString *)where
  408. {
  409. NSMutableArray *questions=[[NSMutableArray alloc]init];
  410. shareDataBase=[DB_Que_Helper createDataBase];
  411. if ([shareDataBase open]) {
  412. NSString *sql = @"";
  413. //章节考试用到
  414. if ([where rangeOfString:@"subject = '1'"].location != NSNotFound)
  415. {
  416. sql=[NSString stringWithFormat:@"select * from question where car_type = '%@' and %@",defUser.car_type,where];
  417. }
  418. if ([where rangeOfString:@"subject = '4'"].location != NSNotFound)
  419. {
  420. sql=[NSString stringWithFormat:@"select * from question where car_type = 'C1' and %@",where ];
  421. if ([defUser.car_type isEqualToString:@"D"]) {
  422. sql=[NSString stringWithFormat:@"select * from question where car_type = 'D' and %@",where ];
  423. }
  424. }
  425. //资格证 非强化 非全部题
  426. 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"])
  427. {
  428. if (![where isEqualToString:@"strong"])
  429. {
  430. if (where.length > 12) {
  431. where = [where substringFromIndex:13];
  432. }
  433. sql=[NSString stringWithFormat:@"select * from question where car_type = '%@'%@",defUser.car_type,where];
  434. }
  435. }
  436. if ([where isEqualToString:@"strong"])//代表强化练习
  437. {
  438. sql=[NSString stringWithFormat:@"select * from question where %@",myDelegate.where];
  439. }
  440. FMResultSet *s=[shareDataBase executeQuery:sql];
  441. questions = [Question questionsWithFMResultSet:s];
  442. //NSLog(@"这里找出要显示的题目sql-->%@-------where-->%@------count-->%d",sql,where,(int)questions.count);
  443. [shareDataBase close];
  444. }
  445. return questions;
  446. }
  447. //查找章节列表
  448. +(NSArray *)queryList:(NSString *)where
  449. {
  450. NSMutableArray *lists=[[NSMutableArray alloc]init];
  451. shareDataBase=[DB_Que_Helper createDataBase];
  452. if ([shareDataBase open]) {
  453. FMResultSet *s=[shareDataBase executeQuery:where];
  454. while ([s next])
  455. {
  456. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[s stringForColumn:@"title"],@"title",[s stringForColumn:@"ID"],@"chapter", nil];
  457. [lists addObject:dic];
  458. }
  459. [shareDataBase close];
  460. }
  461. return lists;
  462. }
  463. //查找标识
  464. +(NSArray *)queryMark:(NSString *)where
  465. {
  466. NSMutableArray *markArray = [NSMutableArray array];
  467. shareDataBase=[DB_Que_Helper createDataBase];
  468. if ([shareDataBase open]) {
  469. FMResultSet *s=[shareDataBase executeQuery:[NSString stringWithFormat:@"select * from APP_MARK_GROUP where MG_PARENT = '%@'",where]];
  470. markArray = [markGroup markGroupWithFMResultSet:s];
  471. [shareDataBase close];
  472. }
  473. return markArray;
  474. }
  475. +(NSArray *)queryDetailMark:(NSString *)where
  476. {
  477. NSMutableArray *markArray = [NSMutableArray array];
  478. shareDataBase=[DB_Que_Helper createDataBase];
  479. if ([shareDataBase open]) {
  480. FMResultSet *s=[shareDataBase executeQuery:[NSString stringWithFormat:@"select * from APP_MARK_INFO where %@",where]];
  481. markArray = [markInfo markInfoWithFMResultSet:s];
  482. [shareDataBase close];
  483. }
  484. return markArray;
  485. }
  486. +(BOOL)updateDB:(NSString *)sql
  487. {
  488. shareDataBase=[DB_Que_Helper createDataBase];
  489. BOOL isOk = NO;
  490. if ([shareDataBase open])
  491. {
  492. isOk=[shareDataBase executeUpdate:sql];
  493. [shareDataBase close];
  494. }
  495. return isOk;
  496. }
  497. //添加已做的题
  498. +(void)addToDoneQue:(NSInteger)ID
  499. {
  500. shareDataBase=[DB_Que_Helper createDataBase];
  501. if ([shareDataBase open]) {
  502. [shareDataBase executeUpdate:[NSString stringWithFormat:@"update question set done = 1 where _id=%d",(int)ID]];
  503. [shareDataBase close];
  504. }
  505. }
  506. //这里也错了 和数据库字段不符 delete --数据库问题--danson
  507. +(BOOL)addToStrengthenQue:(NSInteger)ID
  508. {
  509. BOOL isOk = NO;
  510. shareDataBase=[DB_Que_Helper createDataBase];
  511. if ([shareDataBase open]) {
  512. isOk=[shareDataBase executeUpdate:[NSString stringWithFormat:@"update question set state = 1 where _id=%d",(int)ID]];
  513. [shareDataBase close];
  514. }
  515. return isOk;
  516. }
  517. +(BOOL)removeToStrengthenQue:(NSInteger)ID
  518. {
  519. BOOL isOk = NO;
  520. shareDataBase=[DB_Que_Helper createDataBase];
  521. if ([shareDataBase open]) {
  522. isOk=[shareDataBase executeUpdate:[NSString stringWithFormat:@"update question set state = 0 where _id=%d",(int)ID]];
  523. [shareDataBase close];
  524. }
  525. return isOk;
  526. }
  527. /**
  528. 抽考试题
  529. */
  530. +(NSArray *)queryExamQuestion
  531. {
  532. NSMutableArray *questions=[[NSMutableArray alloc]init];
  533. shareDataBase=[DB_Que_Helper createDataBase];
  534. if ([shareDataBase open]) {
  535. //模拟考试中....
  536. //从数据库中随机抽取相应数目的题目 应该不用考虑题目存放数组位置问题吧 因为不是耗时操作 按代码先后顺序来排序
  537. /*
  538. 车型 科目 题目数量 总分数 合格分数 考试时间 错误题自动交卷 单选题数 每题分数 多选题数 多选题分数 判断题数量 判断题分数
  539. C1 1 100 100 90 45 10 60 1 0 0 40 1
  540. C1 4 50 100 90 30 5 20 2 5 2 25 2
  541. A1 1 100 100 90 45 10 60 1 0 0 40 1
  542. A1 4 50 100 90 30 5 20 2 5 2 25 2
  543. A2 1 100 100 90 45 10 60 1 0 0 40 1
  544. A2 4 50 100 90 30 5 20 2 5 2 25 2
  545. D 1 50 100 90 30 5 30 2 0 0 20 2
  546. D 4 50 100 90 30 5 30 2 0 0 20 2
  547. 1 1 90 100 80 60 9 40 1 10 2 40 1
  548. 2 1 90 100 80 90 9 40 1 10 2 40 1
  549. 3 1 100 100 90 90 10 57 1 0 0 43 1
  550. 4 1 100 100 80 60 10 19 1 36 1 45 1
  551. 5 1 90 100 80 45 9 50 1 10 2 30 1
  552. */
  553. int chooseNum = 0;
  554. int chooseMoreNum = 0;
  555. int judgeNum = 0;
  556. //@"C1",@"A2",@"A1",@"D",@"4",@"1",@"2",@"3",@"5"
  557. if ([defUser.car_type isEqualToString:@"C1"]) {
  558. if ([myDelegate.subject isEqualToString:@"1"]) {
  559. chooseNum = 60;
  560. chooseMoreNum = 0;
  561. judgeNum = 40;
  562. }else {
  563. chooseNum = 20;
  564. chooseMoreNum = 10;
  565. judgeNum = 20;
  566. }
  567. }else if ([defUser.car_type isEqualToString:@"A2"]) {
  568. if ([myDelegate.subject isEqualToString:@"1"]) {
  569. chooseNum = 60;
  570. chooseMoreNum = 0;
  571. judgeNum = 40;
  572. }else {
  573. chooseNum = 20;
  574. chooseMoreNum = 5;
  575. judgeNum = 25;
  576. }
  577. }else if ([defUser.car_type isEqualToString:@"A1"]) {
  578. if ([myDelegate.subject isEqualToString:@"1"]) {
  579. chooseNum = 60;
  580. chooseMoreNum = 0;
  581. judgeNum = 40;
  582. }else {
  583. chooseNum = 20;
  584. chooseMoreNum = 5;
  585. judgeNum = 25;
  586. }
  587. }else if ([defUser.car_type isEqualToString:@"D"]) {
  588. if ([myDelegate.subject isEqualToString:@"1"]) {
  589. chooseNum = 30;
  590. chooseMoreNum = 0;
  591. judgeNum = 20;
  592. }else {
  593. chooseNum = 30;
  594. chooseMoreNum = 0;
  595. judgeNum = 20;
  596. }
  597. }else if ([defUser.car_type isEqualToString:@"1"]) {
  598. chooseNum = 40;
  599. chooseMoreNum = 10;
  600. judgeNum = 40;
  601. }else if ([defUser.car_type isEqualToString:@"2"]) {
  602. chooseNum = 40;
  603. chooseMoreNum = 10;
  604. judgeNum = 40;
  605. }else if ([defUser.car_type isEqualToString:@"3"]) {
  606. chooseNum = 57;
  607. chooseMoreNum = 0;
  608. judgeNum = 43;
  609. }else if ([defUser.car_type isEqualToString:@"4"]) {
  610. chooseNum = 19;
  611. chooseMoreNum = 36;
  612. judgeNum = 45;
  613. }else if ([defUser.car_type isEqualToString:@"5"]) {
  614. chooseNum = 50;
  615. chooseMoreNum = 10;
  616. judgeNum = 30;
  617. }else if ([defUser.car_type isEqualToString:@"6"]) {
  618. chooseNum = 50;
  619. chooseMoreNum = 10;
  620. judgeNum = 30;
  621. }
  622. /*
  623. for (int i = 0; i < 3; i ++) {
  624. //i=0判断 i=1单选 i=2多选
  625. 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];
  626. //除了摩托车 其他的公用C1科四题库
  627. if ([myDelegate.subject isEqualToString:@"4"] && ![defUser.car_type isEqualToString:@"D"]) {
  628. 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];
  629. }
  630. 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"])
  631. {
  632. sql = [NSString stringWithFormat:@"select * from question where car_type = '%@' and option_type = %d order by random() limit %d",defUser.car_type,i,chooseNum];
  633. }
  634. FMResultSet *s=[shareDataBase executeQuery:sql];
  635. [questions addObjectsFromArray:[Question questionsWithFMResultSet:s]];
  636. }
  637. */
  638. //判断0
  639. if (judgeNum > 0) {
  640. 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];
  641. //除了摩托车 其他的公用C1科四题库
  642. if ([myDelegate.subject isEqualToString:@"4"] && ![defUser.car_type isEqualToString:@"D"]) {
  643. sql = [NSString stringWithFormat:@"select * from question where car_type = 'C1' and subject = %@ and option_type = 0 order by random() limit %d",myDelegate.subject,judgeNum];
  644. }
  645. 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"])
  646. {
  647. sql = [NSString stringWithFormat:@"select * from question where car_type = '%@' and option_type = 0 order by random() limit %d",defUser.car_type,judgeNum];
  648. }
  649. FMResultSet *s=[shareDataBase executeQuery:sql];
  650. [questions addObjectsFromArray:[Question questionsWithFMResultSet:s]];
  651. }
  652. //单选1
  653. if (chooseNum > 0) {
  654. 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];
  655. //除了摩托车 其他的公用C1科四题库
  656. if ([myDelegate.subject isEqualToString:@"4"] && ![defUser.car_type isEqualToString:@"D"]) {
  657. sql = [NSString stringWithFormat:@"select * from question where car_type = 'C1' and subject = %@ and option_type = 1 order by random() limit %d",myDelegate.subject,chooseNum];
  658. }
  659. 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"])
  660. {
  661. sql = [NSString stringWithFormat:@"select * from question where car_type = '%@' and option_type = 1 order by random() limit %d",defUser.car_type,chooseNum];
  662. }
  663. FMResultSet *s2=[shareDataBase executeQuery:sql];
  664. [questions addObjectsFromArray:[Question questionsWithFMResultSet:s2]];
  665. }
  666. //多选2
  667. if (chooseMoreNum > 0) {
  668. 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];
  669. //除了摩托车 其他的公用C1科四题库
  670. if ([myDelegate.subject isEqualToString:@"4"] && ![defUser.car_type isEqualToString:@"D"]) {
  671. sql = [NSString stringWithFormat:@"select * from question where car_type = 'C1' and subject = %@ and option_type = 2 order by random() limit %d",myDelegate.subject,chooseMoreNum];
  672. }
  673. 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"])
  674. {
  675. sql = [NSString stringWithFormat:@"select * from question where car_type = '%@' and option_type = 2 order by random() limit %d",defUser.car_type,chooseMoreNum];
  676. }
  677. FMResultSet *s3=[shareDataBase executeQuery:sql];
  678. [questions addObjectsFromArray:[Question questionsWithFMResultSet:s3]];
  679. }
  680. [shareDataBase close];
  681. }
  682. return questions;
  683. }
  684. //清空错题、收藏、排错
  685. +(void)clearFavInfo
  686. {
  687. //每次进程序都要有这样的操作
  688. shareDataBase=[DB_Que_Helper createDataBase];
  689. if([shareDataBase open])
  690. {
  691. [shareDataBase executeUpdate:@"update question set state = 0 where state = 1"];
  692. [shareDataBase executeUpdate:@"update question set state = 0 where iscollect = 1"];
  693. [shareDataBase executeUpdate:@"update question set state = 0 where isdone = 1"];
  694. [shareDataBase close];
  695. return;
  696. }else{
  697. NSLog(@"db error");
  698. return;
  699. }
  700. }
  701. /**
  702. 从选择页面过来查询多少题目
  703. */
  704. +(NSInteger)countForQuery:(NSString *)where
  705. {
  706. shareDataBase=[DB_Que_Helper createDataBase];
  707. if ([shareDataBase open]) {
  708. NSString *sql;
  709. if ([where isEqualToString:@"subject = 1"])
  710. {
  711. sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and %@",defUser.car_type,where];
  712. }
  713. else if ([where isEqualToString:@"subject = 4"])
  714. {
  715. //NSLog(@"摩托车科是--%@",defUser.car_type);
  716. if ([defUser.car_type isEqualToString:@"D"]) {
  717. sql=[NSString stringWithFormat:@"select count(*) from question where car_type = 'D' and %@",where];
  718. }else{
  719. sql=[NSString stringWithFormat:@"select count(*) from question where car_type = 'C1' and %@",where];
  720. }
  721. }
  722. else if ([where isEqualToString:@"nil"])
  723. {
  724. 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]);
  725. }
  726. else if ([where isEqualToString:@"state = 1 and subject = 1"])
  727. {
  728. sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and %@",defUser.car_type,where];
  729. }
  730. else if ([where isEqualToString:@"state = 1 and subject = 4"])
  731. {
  732. sql=[NSString stringWithFormat:@"select count(*) from question where car_type = 'C1' and %@",where ];
  733. }
  734. else
  735. {
  736. sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and state = 1",defUser.car_type];
  737. }
  738. if ([where rangeOfString:@"strong"].location != NSNotFound)
  739. {
  740. sql=[NSString stringWithFormat:@"select count(*) from question where %@",myDelegate.where];
  741. }
  742. // if ([where isEqualToString:@"done"])
  743. // {
  744. // sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and done = 1 and %@",defUser.car_type,myDelegate.where];
  745. // if ([myDelegate.where isEqualToString:@"done"])
  746. // {
  747. // sql=[NSString stringWithFormat:@"select count(*) from question where car_type = '%@' and done = 1",defUser.car_type];
  748. // }
  749. // }
  750. NSInteger cnt = [shareDataBase intForQuery:sql];
  751. [shareDataBase close];
  752. //NSLog(@"这里查题目数量--sql-->%@-------where-->%@------count-->%d",sql,where,(int)cnt);
  753. return cnt;
  754. }
  755. return 0;
  756. }
  757. +(NSArray *)queryColumnNameWithTable:(NSString *)tableName
  758. {
  759. sqlite3 *database;
  760. sqlite3_open([dataBasePath2 UTF8String], &database);
  761. sqlite3_stmt *statement;
  762. //获取数据库的表的名字
  763. // const char *getTableInfo = "select * from sqlite_master where type='table' order by name";
  764. // sqlite3_prepare_v2(database, getTableInfo, -1, &statement, nil);
  765. // while (sqlite3_step(statement) == SQLITE_ROW) {
  766. // char *nameData = (char *)sqlite3_column_text(statement, 1);
  767. // NSString *tableName = [[NSString alloc] initWithUTF8String:nameData];
  768. // NSLog(@"name:%@",tableName);
  769. // }
  770. NSMutableArray *array = [NSMutableArray array];
  771. NSString *columnName = @"";
  772. //获取某表中字段的名字
  773. const char *getColumn = "PRAGMA table_info(question)";
  774. sqlite3_prepare_v2(database, getColumn, -1, &statement, nil);
  775. while (sqlite3_step(statement) == SQLITE_ROW) {
  776. char *nameData = (char *)sqlite3_column_text(statement, 1);
  777. columnName = [[NSString alloc] initWithUTF8String:nameData];
  778. //NSLog(@"columnName:%@",columnName);
  779. [array addObject:columnName];
  780. }
  781. sqlite3_finalize(statement);
  782. return array;
  783. }
  784. #pragma mark markQuestion
  785. //(_id integer PRIMARY KEY, type text, isUpdata text, subject text ,car_type text ,sfzhm text)
  786. +(BOOL)setMarkQuestionWithQuestion:(NSInteger)qId Type:(NSString *)markType State:(NSInteger)state
  787. {
  788. BOOL isOk = NO;
  789. shareDataBase=[DB_Que_Helper createDataBase];
  790. state = [markType isEqualToString:@"4"]? 0 : [self queryIsHaveWithQuestion:qId Type:markType];
  791. if ([shareDataBase open]) {
  792. if (state == 0) {
  793. //添加
  794. NSString *sfzhm = @"no";
  795. if (myDelegate.isLogin) {
  796. sfzhm = defUser.userDict[@"id"];
  797. }
  798. //在调这个方法前已经判断过 是否已经存在
  799. 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]];
  800. }
  801. if (state == 1) {
  802. //删除
  803. NSString *sfzhm = @"no";
  804. if (myDelegate.isLogin) {
  805. sfzhm = defUser.userDict[@"id"];
  806. }
  807. isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"delete from markQuestion where _id=%ld and type='%@' and sfzhm='%@'",(long)qId,markType,sfzhm]];
  808. }
  809. [shareDataBase close];
  810. }
  811. return isOk;
  812. }
  813. +(BOOL)queryIsHaveWithQuestion:(NSInteger)qId Type:(NSString *)markType
  814. {
  815. BOOL isOk = NO;
  816. shareDataBase=[DB_Que_Helper createDataBase];
  817. if ([shareDataBase open]) {
  818. NSString *sfzhm = @"no";
  819. if (myDelegate.isLogin) {
  820. sfzhm = defUser.userDict[@"id"];
  821. }
  822. 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]];
  823. if (cnt > 0) {
  824. isOk = YES;
  825. }
  826. [shareDataBase close];
  827. }
  828. return isOk;
  829. }
  830. +(NSArray *)queryMarkQuestionWithType:(NSString *)markType
  831. {
  832. NSMutableArray *questions = [[NSMutableArray alloc]init];
  833. shareDataBase=[DB_Que_Helper createDataBase];
  834. if ([shareDataBase open]) {
  835. NSString *sfzhm = @"no";
  836. if (myDelegate.isLogin) {
  837. sfzhm = defUser.userDict[@"id"];
  838. }
  839. NSString *sql;//1、错题 2、收藏 3、排错 4、已做未做 5、除去排除的题
  840. if ([markType isEqualToString:@"4"]){
  841. 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];
  842. }else if ([markType isEqualToString:@"5"]){
  843. //除去排错剩下的所有题
  844. 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];
  845. if ([myDelegate.subject isEqualToString:@"4"])
  846. {
  847. 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];
  848. if ([defUser.car_type isEqualToString:@"D"]) {
  849. 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];
  850. }
  851. }
  852. }else{
  853. 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];
  854. }
  855. //如果是资格证 就将科目的判断去掉
  856. 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"])
  857. {
  858. if ([sql containsString:[NSString stringWithFormat:@"subject = '%@' and",myDelegate.subject]]) {
  859. sql = [sql stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"subject = '%@' and",myDelegate.subject] withString:@""];
  860. }
  861. }
  862. FMResultSet *s=[shareDataBase executeQuery:sql];
  863. questions = [Question questionsWithFMResultSet:s];
  864. //NSLog(@"这里找出要显示的题目sql-->%@------------count-->%d",sql,(int)questions.count);
  865. [shareDataBase close];
  866. }
  867. return questions;
  868. }
  869. +(NSArray *)queryMarkQuestionWithUpData:(NSInteger)isUpdata MarkType:(NSString *)markType Subject:(NSString *)sub
  870. {
  871. NSMutableArray<NSString *> *array = [NSMutableArray array];
  872. shareDataBase=[DB_Que_Helper createDataBase];
  873. if ([shareDataBase open]) {
  874. NSString *sfzhm = @"no";
  875. if (myDelegate.isLogin) {
  876. sfzhm = defUser.userDict[@"id"];
  877. }
  878. NSString *sql;
  879. sql=[NSString stringWithFormat:@"select * from markQuestion where subject = '%@' and car_type = '%@' and type = '%@' and isUpdata = '0' and sfzhm = '%@'",sub,defUser.car_type,markType,sfzhm];
  880. if (isUpdata == 1) {
  881. sql = [sql stringByReplacingOccurrencesOfString:@" and isUpdata = '0'" withString:@""];
  882. }
  883. FMResultSet *s=[shareDataBase executeQuery:sql];
  884. while ([s next]) {
  885. NSString *questId = [s stringForColumn:@"_id"];
  886. [array addObject:questId];
  887. }
  888. [shareDataBase close];
  889. }
  890. //NSLog(@"题目---><>%@",array);
  891. return array;
  892. }
  893. +(NSInteger)queryMarkQuestionWithMarkType:(NSString *)markType
  894. {
  895. NSInteger cnt = 0;
  896. shareDataBase=[DB_Que_Helper createDataBase];
  897. if ([shareDataBase open]) {
  898. NSString *sfzhm = @"no";
  899. if (myDelegate.isLogin) {
  900. sfzhm = defUser.userDict[@"id"];
  901. }
  902. 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]];
  903. [shareDataBase close];
  904. }
  905. return cnt;
  906. }
  907. +(BOOL)setIsUpdateWithType:(NSString *)markType
  908. {
  909. BOOL isOk = NO;
  910. shareDataBase=[DB_Que_Helper createDataBase];
  911. if ([shareDataBase open]) {
  912. NSString *sfzhm = @"no";
  913. if (myDelegate.isLogin) {
  914. sfzhm = defUser.userDict[@"id"];
  915. }
  916. NSString *sql;
  917. if ([markType isEqualToString:@"0"]) {
  918. sql = [NSString stringWithFormat:@"update markQuestion set isUpdata = '1' where subject = '%@' and car_type = '%@' and sfzhm = '%@'",myDelegate.subject,defUser.car_type,sfzhm];
  919. }else{
  920. sql = [NSString stringWithFormat:@"update markQuestion set isUpdata = '1' where type = '%@' and subject = '%@' and car_type = '%@' and sfzhm = '%@'",markType,myDelegate.subject,defUser.car_type,sfzhm];
  921. }
  922. isOk = [shareDataBase executeUpdate:sql];
  923. [shareDataBase close];
  924. }
  925. return isOk;
  926. }
  927. +(BOOL)setIsUpdateWithArray:(NSArray<NSString *> *)array
  928. {
  929. BOOL isOk = NO;
  930. shareDataBase=[DB_Que_Helper createDataBase];
  931. if ([shareDataBase open]) {
  932. NSString *sfzhm = @"no";
  933. if (myDelegate.isLogin) {
  934. sfzhm = defUser.userDict[@"id"];
  935. }
  936. NSString *sql;
  937. NSString *sub1 = @"";
  938. NSString *sub4 = @"";
  939. for (NSString *tagStr in array) {
  940. NSInteger tag = [tagStr integerValue];
  941. NSString *typeStr = @"1";
  942. if (tag == 3 || tag == 6) {
  943. typeStr = @"2";
  944. }
  945. if (tag == 4 || tag == 7) {
  946. typeStr = @"3";
  947. }
  948. if (tag < 5) {//科一
  949. sub1 = [sub1 stringByAppendingString:[NSString stringWithFormat:@"%@,",typeStr]];
  950. }else{//科四
  951. sub4 = [sub4 stringByAppendingString:[NSString stringWithFormat:@"%@,",typeStr]];
  952. }
  953. }
  954. if (sub1.length > 0) {
  955. sub1 = [sub1 substringToIndex:sub1.length - 1];
  956. sql = [NSString stringWithFormat:@"update markQuestion set isUpdata = '1' where subject = '1' and car_type = '%@' and sfzhm = '%@' and type in (%@)",defUser.car_type,sfzhm,sub1];
  957. isOk = [shareDataBase executeUpdate:sql];
  958. }
  959. if (sub4.length > 0) {
  960. sub4 = [sub4 substringToIndex:sub4.length - 1];
  961. sql = [NSString stringWithFormat:@"update markQuestion set isUpdata = '1' where subject = '4' and car_type = '%@' and sfzhm = '%@' and type in (%@)",defUser.car_type,sfzhm,sub4];
  962. isOk = [shareDataBase executeUpdate:sql];
  963. }
  964. [shareDataBase close];
  965. }
  966. return isOk;
  967. }
  968. +(BOOL)setMarkQuestionWithArray:(NSArray *)questions
  969. {
  970. BOOL isOk = NO;
  971. BOOL allIsOK = YES;
  972. NSString *sfzhm = @"no";
  973. if (myDelegate.isLogin) {
  974. sfzhm = defUser.userDict[@"id"];
  975. }
  976. //NSLog(@"-----><>%@",questions);
  977. shareDataBase=[DB_Que_Helper createDataBase];
  978. if ([shareDataBase open]) {
  979. for (NSDictionary *obj in questions) {
  980. NSInteger qId = [obj[@"QID"] integerValue];
  981. NSString *kType = obj[@"TYPE"];
  982. NSString *markType;
  983. if ([kType isEqualToString:@"1"]){
  984. //收藏
  985. markType = @"2";
  986. }else if ([kType isEqualToString:@"2"]){
  987. //错题
  988. markType = @"1";
  989. }else{
  990. //排除
  991. markType = @"3";
  992. }
  993. NSString *cartype = defUser.car_type;
  994. if ([obj[@"CARTYPE"] length] > 0) {
  995. cartype = obj[@"CARTYPE"];
  996. }
  997. NSString *sub = myDelegate.subject;
  998. if ([obj[@"SUBJECT"] length] > 0) {
  999. sub = obj[@"SUBJECT"];
  1000. }
  1001. if ([markType isEqualToString:@"1"]) {
  1002. 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]];
  1003. if (cnt == 0) {
  1004. [shareDataBase executeUpdate:[NSString stringWithFormat:@"insert into markQuestion (_id,type,isUpdata,subject,car_type,sfzhm)values(%ld,'4','1','%@','%@','%@')",(long)qId,sub,cartype,sfzhm]];
  1005. }
  1006. }
  1007. //dansonmark这里的科目 车型应该来自服务器 如果服务器不返回 就要从本地题目库查
  1008. isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"insert into markQuestion (_id,type,isUpdata,subject,car_type,sfzhm)values(%ld,'%@','1','%@','%@','%@')",(long)qId,markType,sub,cartype,sfzhm]];
  1009. if (isOk == NO) {
  1010. allIsOK = NO;
  1011. }
  1012. }
  1013. [shareDataBase close];
  1014. }
  1015. return allIsOK;
  1016. }
  1017. +(BOOL)deleteAllMarkQuestion
  1018. {
  1019. BOOL isOk = NO;
  1020. NSString *sfzhm = @"no";
  1021. if (myDelegate.isLogin) {
  1022. sfzhm = defUser.userDict[@"id"];
  1023. }
  1024. shareDataBase=[DB_Que_Helper createDataBase];
  1025. if ([shareDataBase open]) {
  1026. isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"delete from markQuestion where type != '4' and sfzhm='%@'",sfzhm]];
  1027. [shareDataBase close];
  1028. }
  1029. return isOk;
  1030. }
  1031. +(void)moveIsDoneToMarkQuestion
  1032. {
  1033. //等以后就版本没有了 就不用管这个了
  1034. NSArray *columnArray = [DB_Que_Helper queryColumnNameWithTable:@"question"];
  1035. if (![columnArray containsObject:@"done"]) {
  1036. //说明是新版 没有了done字段。不需要转移已做题
  1037. return;
  1038. }
  1039. NSString *sfzhm = @"no";
  1040. if (myDelegate.isLogin) {
  1041. sfzhm = defUser.userDict[@"id"];
  1042. }
  1043. shareDataBase=[DB_Que_Helper createDataBase];
  1044. if ([shareDataBase open]) {
  1045. FMResultSet *s=[shareDataBase executeQuery:@"select * from question where done = 1"];
  1046. NSMutableArray *questions = [Question questionsWithFMResultSet:s];
  1047. for (Question *question in questions) {
  1048. //NSLog(@"插入已做题");
  1049. [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]];
  1050. }
  1051. [shareDataBase close];
  1052. }
  1053. }
  1054. #pragma mark - miaxis.db数据库升级
  1055. + (int)getDataBaseVersion {
  1056. //避免多线程操作带来的弊端 (互斥锁)
  1057. @synchronized([DB_Que_Helper class]) {
  1058. int num=0;
  1059. if ([shareDataBase open]) {
  1060. FMResultSet *s = [shareDataBase executeQuery:@"SELECT * FROM db_versions WHERE id=1"];
  1061. if ([s next]) {
  1062. num = [[s stringForColumn:@"version"] intValue];
  1063. }
  1064. }
  1065. return num;
  1066. }
  1067. }
  1068. + (void)updateQuestionWithId:(NSString *)idStr {
  1069. NSString *sqlStr0 = [NSString stringWithFormat:@"UPDATE question SET question = '%@' WHERE _id = %ld",self.updateDataDic[idStr][@"question"],(long)idStr.integerValue];
  1070. NSString *sqlStr1 = [NSString stringWithFormat:@"UPDATE question SET explain = '%@' WHERE _id = %ld",self.updateDataDic[idStr][@"explain"],(long)idStr.integerValue];
  1071. BOOL isSuccess0 = [shareDataBase executeUpdate:sqlStr0];
  1072. BOOL isSuccess1 = [shareDataBase executeUpdate:sqlStr1];
  1073. NSLog(@"%@ %@",isSuccess0? @"Success!" : @"Failed!",isSuccess1? @"Success!" : @"Failed!");
  1074. }
  1075. + (NSDictionary *)updateDataDic {
  1076. return @{
  1077. @"332" : @{
  1078. @"question" : @"年龄在70周岁以上的驾驶人多长时间提交一次身体条件证明?",
  1079. @"explain" : @"新修改的《机动车驾驶证申领和使用规定》还放宽了未体检注销驾驶证后恢复驾驶资格的年龄,规定:年龄在70周岁以上的驾驶人,在一个记分周期结束后一年内未提交身体条件证明的,车辆管理所将注销其机动车驾驶证。",
  1080. },
  1081. @"466" : @{
  1082. @"question" : @"年龄在70周岁以上,在一个记分周期结束后一年内未提交身体条件证明的,其机动车驾驶证将会被车辆管理所注销。",
  1083. @"explain" : @"新修改的《机动车驾驶证申领和使用规定》还放宽了未体检注销驾驶证后恢复驾驶资格的年龄,规定:年龄在70周岁以上的驾驶人,在一个记分周期结束后一年内未提交身体条件证明的,车辆管理所将注销其机动车驾驶证。",
  1084. },
  1085. @"521" : @{
  1086. @"question" : @"年龄在70周岁以上的机动车驾驶人,应当每年进行一次身体检查的目的是什么?",
  1087. @"explain" : @"新修改的《机动车驾驶证申领和使用规定》还放宽了未体检注销驾驶证后恢复驾驶资格的年龄,规定:年龄在70周岁以上的驾驶人,在一个记分周期结束后一年内未提交身体条件证明的,车辆管理所将注销其机动车驾驶证。",
  1088. },
  1089. @"3960" : @{
  1090. @"question" : @"申请小型汽车准驾车型驾驶证的人年龄条件是多少?",
  1091. @"explain" : @"《公安部令第123号》第十一条:申请小型汽车、小型自动挡汽车、残疾人专用小型自动挡载客汽车、轻便摩托车准驾车型的,在18周岁以上、70周岁以下。",
  1092. },
  1093. @"3962" : @{
  1094. @"question" : @"申请小型汽车汽车驾驶证的,年龄应在18周岁以上70周岁以下。",
  1095. @"explain" : @"《公安部令第123号》第十一条:申请小型汽车、小型自动挡汽车、残疾人专用小型自动挡载客汽车、轻便摩托车准驾车型的,在18周岁以上、70周岁以下。",
  1096. },
  1097. @"3976" : @{
  1098. @"question" : @"年龄在70周岁以上的驾驶人多长时间提交一次身体条件证明?",
  1099. @"explain" : @"新修改的《机动车驾驶证申领和使用规定》还放宽了未体检注销驾驶证后恢复驾驶资格的年龄,规定:年龄在70周岁以上的驾驶人,在一个记分周期结束后一年内未提交身体条件证明的,车辆管理所将注销其机动车驾驶证。",
  1100. },
  1101. @"2738" : @{
  1102. @"question" : @"申请小型汽车准驾车型驾驶证的人年龄条件是多少?",
  1103. @"explain" : @"《公安部令第123号》第十一条:申请小型汽车、小型自动挡汽车、残疾人专用小型自动挡载客汽车、轻便摩托车准驾车型的,在18周岁以上、70周岁以下。",
  1104. },
  1105. @"2740" : @{
  1106. @"question" : @"申请小型汽车汽车驾驶证的,年龄应在18周岁以上70周岁以下。",
  1107. @"explain" : @"《公安部令第123号》第十一条:申请小型汽车、小型自动挡汽车、残疾人专用小型自动挡载客汽车、轻便摩托车准驾车型的,在18周岁以上、70周岁以下。",
  1108. },
  1109. @"2754" : @{
  1110. @"question" : @"年龄在70周岁以上的驾驶人多长时间提交一次身体条件证明?",
  1111. @"explain" : @"新修改的《机动车驾驶证申领和使用规定》还放宽了未体检注销驾驶证后恢复驾驶资格的年龄,规定:年龄在70周岁以上的驾驶人,在一个记分周期结束后一年内未提交身体条件证明的,车辆管理所将注销其机动车驾驶证。",
  1112. },
  1113. @"3627" : @{
  1114. @"question" : @"年龄在70周岁以上,在1个记分周期结束后,( )内未提交身体检查结果的,车辆管理所注销其驾驶证。",
  1115. @"explain" : @"新修改的《机动车驾驶证申领和使用规定》还放宽了未体检注销驾驶证后恢复驾驶资格的年龄,规定:年龄在70周岁以上的驾驶人,在一个记分周期结束后一年内未提交身体条件证明的,车辆管理所将注销其机动车驾驶证。",
  1116. },
  1117. @"3631" : @{
  1118. @"question" : @"年龄在60岁以上,超过机动车驾驶证有效期一年以上未换证的,车辆管理所将注销其驾驶证。",
  1119. @"explain" : @"《公安部令第123号》第六十七条:机动车驾驶人具有下列情形之一的,车辆管理所应当注销其机动车驾驶证:(七)超过机动车驾驶证有效期一年以上未换证的。",
  1120. },
  1121. @"3595" : @{
  1122. @"question" : @"年龄在60岁以上持有准驾车型为大型客车的驾驶人,应当到驾驶证核发地车辆管理所换领准驾车型为小型汽车或小型自动挡汽车的驾驶证。",
  1123. @"explain" : @"《公安部令第123号》第五十条:年龄在60周岁以上的,不得驾驶大型客车、牵引车、城市公交车、中型客车、大型货车、无轨电车和有轨电车;持有大型客车、牵引车、城市公交车、中型客车、大型货车驾驶证的,应当到机动车驾驶证核发地车辆管理所换领准驾车型为小型汽车或者小型自动挡汽车的机动车驾驶证。",
  1124. },
  1125. };
  1126. }
  1127. + (NSArray *)updateIdArr {
  1128. return @[@"332", @"466", @"521", @"3960", @"3962", @"3976", @"2738", @"2740", @"2754", @"3627", @"3631", @"3595"];
  1129. }
  1130. #pragma mark - 2021年2月18新增功能大车考试
  1131. +(void)createGZPY_EXAM_CYRYNewQuestionTable
  1132. {
  1133. if ([shareDataBase open])
  1134. {
  1135. //创建错题类表 type:1、错题 2、收藏 3、排错 4、已做未做 isUpdata:是否上传
  1136. [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);"];
  1137. [shareDataBase close];
  1138. }
  1139. }
  1140. //得到考题
  1141. + (NSArray *)queryGZPZ_EXAM_CYRYExamQuestion {
  1142. NSMutableArray *questions = [[NSMutableArray alloc]init];
  1143. shareDataBase = [DB_Que_Helper createDataBase];
  1144. // if ([defUser.userDict[@"city"] isEqualToString:@"2101"]) {
  1145. /// cykhModal: 1启用AB试卷, 0普通模式
  1146. if ([defUser.userDict[@"cykhModal"] isEqualToString:@"1"]) {
  1147. int x = arc4random() % 2;
  1148. NSArray *chooseArr = (x == 0)? self.JinZhou_GZPZ_EXAM_CYRY_A_Arr : self.JinZhou_GZPZ_EXAM_CYRY_B_Arr;
  1149. NSMutableArray *strArr = [NSMutableArray array];
  1150. [chooseArr.rac_sequence.signal subscribeNext:^(NSString *idStr) {
  1151. NSString *sql = [NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY where eq_id = %@",idStr];
  1152. [strArr addObject:sql];
  1153. } completed:^{
  1154. if ([shareDataBase open]) {
  1155. [shareDataBase executeStatements:[strArr componentsJoinedByString:@";"] withResultBlock:^int(NSDictionary * _Nonnull resultsDictionary) {
  1156. Question *question = [[Question alloc]init];
  1157. question._id = !([resultsDictionary[@"eq_id"] isKindOfClass:[NSNull class]])? resultsDictionary[@"eq_id"] : @"";
  1158. question.option_type = !([resultsDictionary[@"option_type"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_type"] : @"";
  1159. question.media_type = !([resultsDictionary[@"media_type"] isKindOfClass:[NSNull class]])? resultsDictionary[@"media_type"] : @"";
  1160. question.chapter = !([resultsDictionary[@"chapter"] isKindOfClass:[NSNull class]])? resultsDictionary[@"chapter"] : @"";
  1161. question.questionLabel = !([resultsDictionary[@"question_label"] isKindOfClass:[NSNull class]])? resultsDictionary[@"question_label"] : @"";
  1162. question.question = !([resultsDictionary[@"question"] isKindOfClass:[NSNull class]])? resultsDictionary[@"question"] : @"";
  1163. question.media = !([resultsDictionary[@"media"] isKindOfClass:[NSNull class]])? resultsDictionary[@"media"] : @"";
  1164. question.answer = !([resultsDictionary[@"answer"] isKindOfClass:[NSNull class]])? resultsDictionary[@"answer"] : @"";
  1165. question.optionA = !([resultsDictionary[@"option_a"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_a"] : @"";
  1166. question.optionB = !([resultsDictionary[@"option_b"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_b"] : @"";
  1167. question.optionC = !([resultsDictionary[@"option_c"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_c"] : @"";
  1168. question.optionD = !([resultsDictionary[@"option_d"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_d"] : @"";
  1169. question.state = !([resultsDictionary[@"state"] isKindOfClass:[NSNull class]])? resultsDictionary[@"state"] : @"";
  1170. question.move = !([resultsDictionary[@"isdone"] isKindOfClass:[NSNull class]])? resultsDictionary[@"isdone"] : @"";
  1171. question.favorite = !([resultsDictionary[@"iscollect"] isKindOfClass:[NSNull class]])? resultsDictionary[@"iscollect"] : @"";
  1172. [questions addObject:question];
  1173. return 0;
  1174. }];
  1175. [shareDataBase close];
  1176. }
  1177. }];
  1178. } else {
  1179. /// 考试项目(chapter) 题量(num)
  1180. /// (option_type) 判断(0) 单选(1) 多选(2)
  1181. /// 1.驾驶员的职业道德、职业心理与职业健康 1 1 2
  1182. /// 2.道路货物运输从业相关法律法规 2 3 5
  1183. /// 3.道路货物运输相关标准 1 2 1
  1184. /// 4.道路货物运输专业知识 4 4 4
  1185. /// 5.汽车使用技术 3 2 3
  1186. /// 6.道路货物运输安全、应急处置(理论知识) 3 4 5
  1187. ///
  1188. ///合计 14 16 20
  1189. NSArray *chooseQuestionArr = @[
  1190. @{@"chapter" : @(1), @"option_type" : @(0), @"num" : @(1)},
  1191. @{@"chapter" : @(2), @"option_type" : @(0), @"num" : @(2)},
  1192. @{@"chapter" : @(3), @"option_type" : @(0), @"num" : @(1)},
  1193. @{@"chapter" : @(4), @"option_type" : @(0), @"num" : @(4)},
  1194. @{@"chapter" : @(5), @"option_type" : @(0), @"num" : @(3)},
  1195. @{@"chapter" : @(6), @"option_type" : @(0), @"num" : @(3)},
  1196. @{@"chapter" : @(1), @"option_type" : @(1), @"num" : @(1)},
  1197. @{@"chapter" : @(2), @"option_type" : @(1), @"num" : @(3)},
  1198. @{@"chapter" : @(3), @"option_type" : @(1), @"num" : @(2)},
  1199. @{@"chapter" : @(4), @"option_type" : @(1), @"num" : @(4)},
  1200. @{@"chapter" : @(5), @"option_type" : @(1), @"num" : @(2)},
  1201. @{@"chapter" : @(6), @"option_type" : @(1), @"num" : @(4)},
  1202. @{@"chapter" : @(1), @"option_type" : @(2), @"num" : @(2)},
  1203. @{@"chapter" : @(2), @"option_type" : @(2), @"num" : @(5)},
  1204. @{@"chapter" : @(3), @"option_type" : @(2), @"num" : @(1)},
  1205. @{@"chapter" : @(4), @"option_type" : @(2), @"num" : @(4)},
  1206. @{@"chapter" : @(5), @"option_type" : @(2), @"num" : @(3)},
  1207. @{@"chapter" : @(6), @"option_type" : @(2), @"num" : @(5)},
  1208. ];
  1209. NSMutableArray *strArr = [NSMutableArray array];
  1210. [chooseQuestionArr.rac_sequence.signal subscribeNext:^(NSDictionary *chooseQuestionDic) {
  1211. 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"]];
  1212. [strArr addObject:sql];
  1213. } completed:^{
  1214. if ([shareDataBase open]) {
  1215. [shareDataBase executeStatements:[strArr componentsJoinedByString:@";"] withResultBlock:^int(NSDictionary * _Nonnull resultsDictionary) {
  1216. Question *question = [[Question alloc]init];
  1217. question._id = !([resultsDictionary[@"eq_id"] isKindOfClass:[NSNull class]])? resultsDictionary[@"eq_id"] : @"";
  1218. question.option_type = !([resultsDictionary[@"option_type"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_type"] : @"";
  1219. question.media_type = !([resultsDictionary[@"media_type"] isKindOfClass:[NSNull class]])? resultsDictionary[@"media_type"] : @"";
  1220. question.chapter = !([resultsDictionary[@"chapter"] isKindOfClass:[NSNull class]])? resultsDictionary[@"chapter"] : @"";
  1221. question.questionLabel = !([resultsDictionary[@"question_label"] isKindOfClass:[NSNull class]])? resultsDictionary[@"question_label"] : @"";
  1222. question.question = !([resultsDictionary[@"question"] isKindOfClass:[NSNull class]])? resultsDictionary[@"question"] : @"";
  1223. question.media = !([resultsDictionary[@"media"] isKindOfClass:[NSNull class]])? resultsDictionary[@"media"] : @"";
  1224. question.answer = !([resultsDictionary[@"answer"] isKindOfClass:[NSNull class]])? resultsDictionary[@"answer"] : @"";
  1225. question.optionA = !([resultsDictionary[@"option_a"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_a"] : @"";
  1226. question.optionB = !([resultsDictionary[@"option_b"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_b"] : @"";
  1227. question.optionC = !([resultsDictionary[@"option_c"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_c"] : @"";
  1228. question.optionD = !([resultsDictionary[@"option_d"] isKindOfClass:[NSNull class]])? resultsDictionary[@"option_d"] : @"";
  1229. question.state = !([resultsDictionary[@"state"] isKindOfClass:[NSNull class]])? resultsDictionary[@"state"] : @"";
  1230. question.move = !([resultsDictionary[@"isdone"] isKindOfClass:[NSNull class]])? resultsDictionary[@"isdone"] : @"";
  1231. question.favorite = !([resultsDictionary[@"iscollect"] isKindOfClass:[NSNull class]])? resultsDictionary[@"iscollect"] : @"";
  1232. [questions addObject:question];
  1233. return 0;
  1234. }];
  1235. [shareDataBase close];
  1236. }
  1237. }];
  1238. }
  1239. return questions;
  1240. }
  1241. + (NSArray *)queryGZPZ_EXAM_CYRYAllQuestion {
  1242. NSMutableArray *questions=[[NSMutableArray alloc]init];
  1243. shareDataBase = [DB_Que_Helper createDataBase];
  1244. if ([shareDataBase open]) {
  1245. FMResultSet *s=[shareDataBase executeQuery:[NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY"]];
  1246. while ([s next]) {
  1247. Question *question=[[Question alloc]init];
  1248. question._id=[s stringForColumn:@"eq_id"];
  1249. question.option_type=[s stringForColumn:@"option_type"];
  1250. question.media_type=[s stringForColumn:@"media_type"];
  1251. question.chapter=[s stringForColumn:@"chapter"];
  1252. question.questionLabel=[s stringForColumn:@"question_label"];
  1253. question.question=[s stringForColumn:@"question"];
  1254. question.media=[s stringForColumn:@"media"];
  1255. question.answer=[s stringForColumn:@"answer"];
  1256. question.optionA=[s stringForColumn:@"option_a"];
  1257. question.optionB=[s stringForColumn:@"option_b"];
  1258. question.optionC=[s stringForColumn:@"option_c"];
  1259. question.optionD=[s stringForColumn:@"option_d"];
  1260. question.favorite=[s stringForColumn:@"favorite"];
  1261. question.done=[s stringForColumn:@"done"];
  1262. [questions addObject:question];
  1263. }
  1264. }else{
  1265. NSLog(@"题库获取失败,数据库未打开");
  1266. }
  1267. return questions;
  1268. }
  1269. //查找章节列表
  1270. + (NSArray *)queryGZPZ_EXAM_CYRYList:(NSString *)where {
  1271. NSMutableArray *lists=[[NSMutableArray alloc]init];
  1272. shareDataBase=[DB_Que_Helper createDataBase];
  1273. if ([shareDataBase open]) {
  1274. FMResultSet *s=[shareDataBase executeQuery:where];
  1275. while ([s next])
  1276. {
  1277. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:[s stringForColumn:@"name"],@"title",[s stringForColumn:@"id"],@"chapter", nil];
  1278. [lists addObject:dic];
  1279. }
  1280. [shareDataBase close];
  1281. }
  1282. return lists;
  1283. }
  1284. + (NSArray *)queryGZPZ_EXAM_CYRYQuestion:(NSString *)where {
  1285. NSMutableArray *questions=[[NSMutableArray alloc]init];
  1286. shareDataBase=[DB_Que_Helper createDataBase];
  1287. if ([shareDataBase open]) {
  1288. NSString *sql=[NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY where %@",where];
  1289. FMResultSet *s=[shareDataBase executeQuery:sql];
  1290. questions = [Question questionsForGZPZWithFMResultSet:s];
  1291. [shareDataBase close];
  1292. }
  1293. return questions;
  1294. }
  1295. + (NSArray *)queryGZPZ_EXAM_CYRYMarkQuestionWithType:(NSString *)markType {
  1296. NSMutableArray *questions = [[NSMutableArray alloc]init];
  1297. shareDataBase = [DB_Que_Helper createDataBase];
  1298. if ([shareDataBase open]) {
  1299. NSString *sfzhm = @"no";
  1300. if (myDelegate.isLogin) {
  1301. sfzhm = defUser.userDict[@"id"];
  1302. }
  1303. NSString *sql;//1、错题 2、收藏 3、排错 4、已做未做 5、除去排除的题
  1304. if ([markType isEqualToString:@"4"]){
  1305. 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];
  1306. }else if ([markType isEqualToString:@"5"]){
  1307. //除去排错剩下的所有题
  1308. 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];
  1309. }else{
  1310. 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];
  1311. }
  1312. FMResultSet *s = [shareDataBase executeQuery:sql];
  1313. questions = [Question questionsForGZPZWithFMResultSet:s];
  1314. //NSLog(@"这里找出要显示的题目sql-->%@------------count-->%d",sql,(int)questions.count);
  1315. [shareDataBase close];
  1316. }
  1317. return questions;
  1318. }
  1319. + (BOOL)setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:(NSInteger)qId Type:(NSString *)markType State:(NSInteger)state {
  1320. BOOL isOk = NO;
  1321. shareDataBase=[DB_Que_Helper createDataBase];
  1322. state = [markType isEqualToString:@"4"]? 0 : [self queryGZPZ_EXAM_CYRYIsHaveWithQuestion:qId Type:markType];
  1323. if ([shareDataBase open]) {
  1324. if (state == 0) {
  1325. //添加
  1326. NSString *sfzhm = @"no";
  1327. if (myDelegate.isLogin) {
  1328. sfzhm = defUser.userDict[@"id"];
  1329. }
  1330. //在调这个方法前已经判断过 是否已经存在
  1331. isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"insert into GZPT_EXAM_CYRY_MARK_QUESTION (eq_id,type,isUpdata,sfzhm)values(%ld,'%@','0','%@')",(long)qId,markType,sfzhm]];
  1332. }
  1333. if (state == 1) {
  1334. //删除
  1335. NSString *sfzhm = @"no";
  1336. if (myDelegate.isLogin) {
  1337. sfzhm = defUser.userDict[@"id"];
  1338. }
  1339. isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"delete from GZPT_EXAM_CYRY_MARK_QUESTION where eq_id=%ld and type='%@' and sfzhm='%@'",(long)qId,markType,sfzhm]];
  1340. }
  1341. [shareDataBase close];
  1342. }
  1343. return isOk;
  1344. }
  1345. + (BOOL)queryGZPZ_EXAM_CYRYIsHaveWithQuestion:(NSInteger)qId Type:(NSString *)markType {
  1346. BOOL isOk = NO;
  1347. shareDataBase=[DB_Que_Helper createDataBase];
  1348. if ([shareDataBase open]) {
  1349. NSString *sfzhm = @"no";
  1350. if (myDelegate.isLogin) {
  1351. sfzhm = defUser.userDict[@"id"];
  1352. }
  1353. 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]];
  1354. if (cnt > 0) {
  1355. isOk = YES;
  1356. }
  1357. [shareDataBase close];
  1358. }
  1359. return isOk;
  1360. }
  1361. + (NSArray *)queryGZPZ_EXAM_CYRYMarkQuestionWithUpData:(NSInteger)isUpdata MarkType:(NSString *)markType Subject:(NSString *)sub {
  1362. NSMutableArray<NSString *> *array = [NSMutableArray array];
  1363. shareDataBase=[DB_Que_Helper createDataBase];
  1364. if ([shareDataBase open]) {
  1365. NSString *sfzhm = @"no";
  1366. if (myDelegate.isLogin) {
  1367. sfzhm = defUser.userDict[@"id"];
  1368. }
  1369. NSString *sql;
  1370. sql=[NSString stringWithFormat:@"select * from GZPT_EXAM_CYRY_MARK_QUESTION where type = '%@' and isUpdata = '0' and sfzhm = '%@'",markType,sfzhm];
  1371. if (isUpdata == 1) {
  1372. sql = [sql stringByReplacingOccurrencesOfString:@" and isUpdata = '0'" withString:@""];
  1373. }
  1374. FMResultSet *s=[shareDataBase executeQuery:sql];
  1375. while ([s next]) {
  1376. NSString *questId = [s stringForColumn:@"eq_id"];
  1377. [array addObject:questId];
  1378. }
  1379. [shareDataBase close];
  1380. }
  1381. //NSLog(@"题目---><>%@",array);
  1382. return array;
  1383. }
  1384. + (NSInteger)queryGZPZ_EXAM_CYRYMarkQuestionWithMarkType:(NSString *)markType {
  1385. NSInteger cnt = 0;
  1386. shareDataBase=[DB_Que_Helper createDataBase];
  1387. if ([shareDataBase open]) {
  1388. NSString *sfzhm = @"no";
  1389. if (myDelegate.isLogin) {
  1390. sfzhm = defUser.userDict[@"id"];
  1391. }
  1392. cnt = [shareDataBase intForQuery:[NSString stringWithFormat:@"select count(*) from GZPT_EXAM_CYRY_MARK_QUESTION where sfzhm = '%@' and type = '%@'",sfzhm,markType]];
  1393. [shareDataBase close];
  1394. }
  1395. return cnt;
  1396. }
  1397. + (BOOL)setGZPZ_EXAM_CYRYIsUpdateWithType:(NSString *)markType {
  1398. BOOL isOk = NO;
  1399. shareDataBase=[DB_Que_Helper createDataBase];
  1400. if ([shareDataBase open]) {
  1401. NSString *sfzhm = @"no";
  1402. if (myDelegate.isLogin) {
  1403. sfzhm = defUser.userDict[@"id"];
  1404. }
  1405. NSString *sql;
  1406. if ([markType isEqualToString:@"0"]) {
  1407. sql = [NSString stringWithFormat:@"update GZPT_EXAM_CYRY_MARK_QUESTION set isUpdata = '1' where sfzhm = '%@'",sfzhm];
  1408. }else{
  1409. sql = [NSString stringWithFormat:@"update GZPT_EXAM_CYRY_MARK_QUESTION set isUpdata = '1' where type = '%@' and sfzhm = '%@'",markType,sfzhm];
  1410. }
  1411. isOk = [shareDataBase executeUpdate:sql];
  1412. [shareDataBase close];
  1413. }
  1414. return isOk;
  1415. }
  1416. + (BOOL)setGZPZ_EXAM_CYRYIsUpdateWithArray:(NSArray<NSString *> *)array {
  1417. BOOL isOk = NO;
  1418. shareDataBase=[DB_Que_Helper createDataBase];
  1419. if ([shareDataBase open]) {
  1420. NSString *sfzhm = @"no";
  1421. if (myDelegate.isLogin) {
  1422. sfzhm = defUser.userDict[@"id"];
  1423. }
  1424. NSString *sql;
  1425. NSString *sub1 = @"";
  1426. NSString *sub4 = @"";
  1427. for (NSString *tagStr in array) {
  1428. NSInteger tag = [tagStr integerValue];
  1429. NSString *typeStr = @"1";
  1430. if (tag == 3 || tag == 6) {
  1431. typeStr = @"2";
  1432. }
  1433. if (tag == 4 || tag == 7) {
  1434. typeStr = @"3";
  1435. }
  1436. if (tag < 5) {//科一
  1437. sub1 = [sub1 stringByAppendingString:[NSString stringWithFormat:@"%@,",typeStr]];
  1438. }else{//科四
  1439. sub4 = [sub4 stringByAppendingString:[NSString stringWithFormat:@"%@,",typeStr]];
  1440. }
  1441. }
  1442. if (sub1.length > 0) {
  1443. sub1 = [sub1 substringToIndex:sub1.length - 1];
  1444. sql = [NSString stringWithFormat:@"update GZPT_EXAM_CYRY_MARK_QUESTION set isUpdata = '1' where sfzhm = '%@' and type in (%@)",sfzhm,sub1];
  1445. isOk = [shareDataBase executeUpdate:sql];
  1446. }
  1447. if (sub4.length > 0) {
  1448. sub4 = [sub4 substringToIndex:sub4.length - 1];
  1449. sql = [NSString stringWithFormat:@"update GZPT_EXAM_CYRY_MARK_QUESTION set isUpdata = '1' where sfzhm = '%@' and type in (%@)",sfzhm,sub4];
  1450. isOk = [shareDataBase executeUpdate:sql];
  1451. }
  1452. [shareDataBase close];
  1453. }
  1454. return isOk;
  1455. }
  1456. + (BOOL)setGZPZ_EXAM_CYRYMarkQuestionWithArray:(NSArray *)questions {
  1457. BOOL isOk = NO;
  1458. BOOL allIsOK = YES;
  1459. NSString *sfzhm = @"no";
  1460. if (myDelegate.isLogin) {
  1461. sfzhm = defUser.userDict[@"id"];
  1462. }
  1463. //NSLog(@"-----><>%@",questions);
  1464. shareDataBase=[DB_Que_Helper createDataBase];
  1465. if ([shareDataBase open]) {
  1466. for (NSDictionary *obj in questions) {
  1467. NSInteger qId = [obj[@"QID"] integerValue];
  1468. NSString *kType = obj[@"TYPE"];
  1469. NSString *markType;
  1470. if ([kType isEqualToString:@"1"]){
  1471. //收藏
  1472. markType = @"2";
  1473. }else if ([kType isEqualToString:@"2"]){
  1474. //错题
  1475. markType = @"1";
  1476. }else{
  1477. //排除
  1478. markType = @"3";
  1479. }
  1480. NSString *cartype = defUser.car_type;
  1481. if ([obj[@"CARTYPE"] length] > 0) {
  1482. cartype = obj[@"CARTYPE"];
  1483. }
  1484. NSString *sub = myDelegate.subject;
  1485. if ([obj[@"SUBJECT"] length] > 0) {
  1486. sub = obj[@"SUBJECT"];
  1487. }
  1488. if ([markType isEqualToString:@"1"]) {
  1489. 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]];
  1490. if (cnt == 0) {
  1491. [shareDataBase executeUpdate:[NSString stringWithFormat:@"insert into GZPT_EXAM_CYRY_MARK_QUESTION (eq_id,type,isUpdata,sfzhm)values(%ld,'4','1','%@')",(long)qId,sfzhm]];
  1492. }
  1493. }
  1494. //dansonmark这里的科目 车型应该来自服务器 如果服务器不返回 就要从本地题目库查
  1495. isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"insert into GZPT_EXAM_CYRY_MARK_QUESTION (eq_id,type,isUpdata,sfzhm)values(%ld,'%@','1','%@')",(long)qId,markType,sfzhm]];
  1496. if (isOk == NO) {
  1497. allIsOK = NO;
  1498. }
  1499. }
  1500. [shareDataBase close];
  1501. }
  1502. return allIsOK;
  1503. }
  1504. + (BOOL)deleteGZPZ_EXAM_CYRYAllMarkQuestion {
  1505. BOOL isOk = NO;
  1506. NSString *sfzhm = @"no";
  1507. if (myDelegate.isLogin) {
  1508. sfzhm = defUser.userDict[@"id"];
  1509. }
  1510. shareDataBase=[DB_Que_Helper createDataBase];
  1511. if ([shareDataBase open]) {
  1512. isOk = [shareDataBase executeUpdate:[NSString stringWithFormat:@"delete from GZPT_EXAM_CYRY_MARK_QUESTION where type != '4' and sfzhm='%@'",sfzhm]];
  1513. [shareDataBase close];
  1514. }
  1515. return isOk;
  1516. }
  1517. + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_A_Arr {
  1518. NSMutableArray *arr = [NSMutableArray array];
  1519. [arr addObjectsFromArray:[self getRandomNumber:self.JinZhou_GZPZ_EXAM_CYRY_A_Zero_Arr]];
  1520. [arr addObjectsFromArray:[self getRandomNumber:self.JinZhou_GZPZ_EXAM_CYRY_A_One_Arr]];
  1521. [arr addObjectsFromArray:[self getRandomNumber:self.JinZhou_GZPZ_EXAM_CYRY_A_Two_Arr]];
  1522. return arr.mutableCopy;
  1523. // return @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"41",@"42",@"43",
  1524. // @"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"74",
  1525. // @"77",@"79",@"84",@"86",@"89",@"92",@"95",@"96",@"97",@"103",
  1526. // @"110",@"113",@"17",@"18",@"19",@"20",@"31",@"34",@"36",@"38",
  1527. // @"39",@"40",@"114",@"117",@"119",@"120",@"123",@"124",@"125",@"126"];
  1528. }
  1529. + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_B_Arr {
  1530. NSMutableArray *arr = [NSMutableArray array];
  1531. [arr addObjectsFromArray:[self getRandomNumber:self.JinZhou_GZPZ_EXAM_CYRY_B_Zero_Arr]];
  1532. [arr addObjectsFromArray:[self getRandomNumber:self.JinZhou_GZPZ_EXAM_CYRY_B_One_Arr]];
  1533. [arr addObjectsFromArray:[self getRandomNumber:self.JinZhou_GZPZ_EXAM_CYRY_B_Two_Arr]];
  1534. return arr.mutableCopy;
  1535. // return @[@"53",@"54",@"55",@"56",@"57",@"58",@"59",@"60",@"61",@"62",
  1536. // @"63",@"64",@"65",@"66",@"67",@"68",@"69",@"70",@"71",@"333",
  1537. // @"334",@"338",@"399",@"402",@"408",@"414",@"416",@"420",@"436",@"325",
  1538. // @"327",@"329",@"129",@"138",@"139",@"143",@"144",@"148",@"149",@"150",
  1539. // @"151",@"157",@"198",@"199",@"201",@"202",@"203",@"205",@"263",@"264"];
  1540. }
  1541. + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_A_Zero_Arr {
  1542. return @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50",@"51",@"52"];
  1543. }
  1544. + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_A_One_Arr {
  1545. return @[@"74",@"77",@"79",@"84",@"86",@"89",@"92",@"95",@"96",@"97",@"103",@"110",@"113"];
  1546. }
  1547. + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_A_Two_Arr {
  1548. return @[@"17",@"18",@"19",@"20",@"31",@"34",@"36",@"38",@"39",@"40",@"114",@"117",@"119",@"120",@"123",@"124",@"125",@"126"];
  1549. }
  1550. + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_B_Zero_Arr {
  1551. return @[@"53",@"54",@"55",@"56",@"57",@"58",@"59",@"60",@"61",@"62",@"63",@"64",@"65",@"66",@"67",@"68",@"69",@"70",@"71"];
  1552. }
  1553. + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_B_One_Arr {
  1554. return @[@"333",@"334",@"338",@"399",@"402",@"408",@"414",@"416",@"420",@"436",@"325",@"327",@"329"];
  1555. }
  1556. + (NSArray *)JinZhou_GZPZ_EXAM_CYRY_B_Two_Arr {
  1557. return @[@"129",@"138",@"139",@"143",@"144",@"148",@"149",@"150",@"151",@"157",@"198",@"199",@"201",@"202",@"203",@"205",@"263",@"264"];
  1558. }
  1559. + (NSMutableArray *)getRandomNumber:(NSArray * )temp {
  1560. NSMutableArray *tempArray = [[NSMutableArray alloc] initWithArray:temp];
  1561. NSMutableArray *resultArray = [[NSMutableArray alloc] init];
  1562. int i;
  1563. int count = temp.count;
  1564. NSLog(@"count:%d",count);
  1565. for (i = 0; i < count; i ++) {
  1566. int index = arc4random() % (count - i);
  1567. [resultArray addObject:[tempArray objectAtIndex:index]];
  1568. NSLog(@"index:%d,xx:%@",index,[tempArray objectAtIndex:index]);
  1569. [tempArray removeObjectAtIndex:index];
  1570. }
  1571. NSLog(@"resultArray is %@",resultArray);
  1572. return resultArray;
  1573. }
  1574. @end