ChooseExLibVC.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. //
  2. // ChooseExLibVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/11/18.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "ChooseExLibVC.h"
  9. #import "STButton.h"
  10. #import "CLButton.h"
  11. /**user default 里面保存的是 cartype的序号,
  12. 不是实际的cartype。
  13. */
  14. #define carTypeKey @"car_type"
  15. @interface ChooseExLibVC ()<UIAlertViewDelegate>
  16. @end
  17. @implementation ChooseExLibVC
  18. {
  19. /**题库名。
  20. 可以用来和defUser里面的car_type来比对。
  21. 选择提交题库时也要从里面选。
  22. */
  23. NSArray* car_types;
  24. /**√图标
  25. */
  26. UIImageView* img;
  27. /**所有汽车类型的按钮
  28. */
  29. NSMutableArray* carBtns;
  30. /**所有题库的名称
  31. */
  32. NSMutableArray* queLibs;
  33. NSInteger current_index;
  34. }
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. [self myInit];
  38. [self loadCarType];
  39. }
  40. - (void)didReceiveMemoryWarning {
  41. [super didReceiveMemoryWarning];
  42. // Dispose of any resources that can be recreated.
  43. }
  44. -(void)viewWillAppear:(BOOL)animated
  45. {
  46. [super viewWillAppear:animated];
  47. self.navigationController.navigationBarHidden = NO;
  48. }
  49. #pragma mark -
  50. -(void)myInit
  51. {
  52. if (!_isWelcome) {
  53. [self configNavigationBar];
  54. }
  55. self.navigationController.navigationBar.translucent = NO;
  56. [self.view setBackgroundColor:backGroundColor];
  57. [self setTitle:@"选择题库"];
  58. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 20, kSize.width, kSize.height-20)];
  59. view.backgroundColor = backGroundColor;
  60. [self.view addSubview:view];
  61. /**
  62. 为每一个按钮设置tag值,表示该按钮对应的题库类型
  63. */
  64. car_types = @[@"C1",@"A2",@"A1",@"D",@"4",@"1",@"2",@"3",@"5",@"6"];//,@"4"
  65. int tag = 0;
  66. UILabel* label;
  67. STButton* btn;
  68. UIView* line;
  69. NSArray* titles;
  70. CGFloat dx = 20;
  71. CGFloat lblH = 30;
  72. CGFloat btnW = kSize.width/4-1;
  73. CGFloat btnH = btnW*8/9;
  74. CGFloat lineWid = .5;
  75. label = [[UILabel alloc] initWithFrame:CGRectMake(dx, 0, kSize.width, lblH)];
  76. [label setText:@"驾驶证"];
  77. [view addSubview:label];
  78. line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(label.frame), kSize.width, lineWid)];
  79. [line setBackgroundColor:KlineColor];
  80. [view addSubview:line];
  81. queLibs = [NSMutableArray array];
  82. titles = @[@"小车",@"货车",@"客车",@"摩托车"];
  83. [queLibs addObjectsFromArray:titles];
  84. NSArray* subTitles = @[@"C1/C2/C3",@"A2/B2",@"A1/A3/B1",@"D/E/F"];
  85. UIImage* image;
  86. carBtns = [NSMutableArray array];
  87. for (int i =0; i<titles.count; i++) {
  88. image = [UIImage imageNamed:[NSString stringWithFormat:@"car_type%d.png",tag+1]];
  89. btn = [[STButton alloc] initWithFrame:CGRectMake(btnW*i, CGRectGetMaxY(line.frame), btnW, btnH)];
  90. [btn setImage:image withTitle:titles[i] Font:13 forState:UIControlStateNormal];
  91. [btn addTarget:self action:@selector(carTypeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  92. [btn setTitleColor:contentTextColor forState:UIControlStateNormal];
  93. [btn setBackgroundColor:[UIColor whiteColor]];
  94. [btn setSubTitle:subTitles[i]];
  95. [view addSubview:btn];
  96. [carBtns addObject:btn];
  97. if ([car_types[tag] isEqualToString:@""]) {
  98. btn.enabled = NO;
  99. }
  100. [btn setTag:tag++];
  101. }
  102. line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(btn.frame), kSize.width, lineWid)];
  103. [line setBackgroundColor:KlineColor];
  104. [view addSubview:line];
  105. label = [[UILabel alloc] initWithFrame:CGRectMake(dx, CGRectGetMaxY(line.frame)+10, kSize.width, lblH)];
  106. [label setText:@"资格证"];
  107. [view addSubview:label];
  108. line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(label.frame), kSize.width, lineWid)];
  109. [line setBackgroundColor:KlineColor];
  110. [view addSubview:line];
  111. titles = @[@"教练员",@"客运",@"货运",@"危险品",@"出租车",@"网约车"];//@"教练员",
  112. [queLibs addObjectsFromArray:titles];
  113. for (int i =0; i<titles.count; i++)
  114. {
  115. image = [UIImage imageNamed:[NSString stringWithFormat:@"car_type%d.png",tag+1]];
  116. btn = [[STButton alloc] initWithFrame:
  117. CGRectMake((btnW+1)*(i%4),CGRectGetMaxY(line.frame)+btnH*(i/4), btnW, btnH)];
  118. [btn setImage:image withTitle:titles[i] Font:13 forState:UIControlStateNormal];
  119. [btn addTarget:self action:@selector(carTypeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  120. [btn setTitleColor:contentTextColor forState:UIControlStateNormal];
  121. [btn setBackgroundColor:[UIColor whiteColor]];
  122. [view addSubview:btn];
  123. [carBtns addObject:btn];
  124. if ([car_types[tag] isEqualToString:@""]) {
  125. btn.enabled = NO;
  126. }
  127. [btn setTag:tag++];
  128. }
  129. line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(btn.frame), btnW, lineWid)];
  130. [line setBackgroundColor:KlineColor];
  131. [view addSubview:line];
  132. UIButton* lastBtn = [[CLButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(line.frame), kSize.width, 27)];
  133. //这个btn只是为了做界面--无触发事件
  134. [lastBtn setImage:[UIImage imageNamed:@"right.png"] withTitle:@"已经更新为2022年最新官方题库" Font:13 forState:UIControlStateNormal];
  135. [lastBtn setBackgroundColor:[UIColor clearColor]];
  136. [lastBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  137. [lastBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
  138. [view addSubview:lastBtn];
  139. lastBtn.enabled = NO;
  140. CGFloat topY = CGRectGetMaxY(lastBtn.frame);
  141. lastBtn = nil;
  142. CGFloat boarder = 30;
  143. lastBtn = [[UIButton alloc] initWithFrame:CGRectMake(boarder,topY+20,kSize.width - boarder*2, 50)];
  144. [lastBtn setTitle:@"确定" textColor:[UIColor whiteColor] font:25 fotState:UIControlStateNormal];
  145. [lastBtn addTarget:self action:@selector(submit:) forControlEvents:UIControlEventTouchUpInside];
  146. [lastBtn setBackgroundColor:defGreen];
  147. [lastBtn.layer setCornerRadius:25];
  148. [view addSubview:lastBtn];
  149. CGFloat imgW = 15;
  150. img = [[UIImageView alloc] initWithFrame:CGRectMake(btnW-imgW, btnH-imgW, imgW, imgW)];
  151. [img setImage:[UIImage imageNamed:@"question_correct.png"]];
  152. current_index = -1;
  153. }
  154. /**从userDefault里面拿出,carType来。
  155. 其实。去defuser。里面取即可。
  156. */
  157. -(void)loadCarType
  158. {
  159. int index = 0;
  160. for (int i=0; i<car_types.count; i++) {
  161. if ([car_types[i] isEqualToString:defUser.car_type]) {
  162. index = i;
  163. break;
  164. }
  165. }
  166. [self chooseBtnAtIndex:index];
  167. }
  168. /**按钮点击事件
  169. */
  170. -(void)carTypeBtnClick:(UIButton *)sender
  171. {
  172. [self chooseBtnAtIndex:sender.tag];
  173. }
  174. /**根据索引值,设立选定。
  175. 选定之后,修改背景色和。右下角下角对勾。
  176. 主要是给初始化用的。
  177. */
  178. -(void)chooseBtnAtIndex:(NSInteger)index
  179. {
  180. UIButton* btn;
  181. if (current_index>=0)
  182. {
  183. btn = carBtns[current_index];
  184. [btn setBackgroundColor:[UIColor whiteColor]];
  185. }
  186. current_index = index;
  187. btn = carBtns[current_index];
  188. [btn setBackgroundColor:[UIColor clearColor]];
  189. [btn addSubview:img];
  190. }
  191. /**
  192. 确定按钮点击事件
  193. */
  194. -(void)submit:(UIButton*)sender
  195. {
  196. if (current_index >= 0)
  197. {
  198. NSString * oldStatus = defUser.isZhiGeZheng;
  199. NSString *theCarType = car_types[current_index];
  200. RQ_YDTQuestion_Module.carType = current_index;
  201. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  202. if ([theCarType isEqualToString:@"1"] || [theCarType isEqualToString:@"2"] || [theCarType isEqualToString:@"3"] || [theCarType isEqualToString:@"4"] || [theCarType isEqualToString:@"5"] || [theCarType isEqualToString:@"6"]) {
  203. defUser.isZhiGeZheng = @"YES";
  204. }else{
  205. defUser.isZhiGeZheng = @"NO";
  206. }
  207. } else {
  208. if ([theCarType isEqualToString:@"1"] || [theCarType isEqualToString:@"3"] || [theCarType isEqualToString:@"4"] || [theCarType isEqualToString:@"5"] || [theCarType isEqualToString:@"6"]) {
  209. defUser.isZhiGeZheng = @"YES";
  210. }else{
  211. defUser.isZhiGeZheng = @"NO";
  212. }
  213. }
  214. myDelegate.subject = @"1";
  215. RQ_YDTQuestion_Module.subject = RQHomePageSubjectType_SubjectOne;
  216. if (!_isWelcome) {
  217. NSString *str = [defUser.isZhiGeZheng isEqualToString:oldStatus] ? @"NO":@"YES";
  218. NSNotification *notification =[NSNotification notificationWithName:@"Tiku_Change" object:nil userInfo:@{@"zhigezhengChanged":str}];
  219. [[NSNotificationCenter defaultCenter] postNotification:notification];
  220. }
  221. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  222. defUser.car_type = theCarType;
  223. [self showSubmitAlert];
  224. } else {
  225. if ([theCarType isEqualToString:@"2"]) {
  226. if (!myDelegate.isLogin) {
  227. LoginViewController* vc = [[LoginViewController alloc] init];
  228. vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  229. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  230. [self.parentViewController presentViewController:vc animated:YES completion:nil];
  231. } else {
  232. [self doGetStudentActiveKhStatusWithResultBlock:^(BOOL isSuccessed) {
  233. if (isSuccessed) {
  234. //改变当前题库的类型
  235. defUser.isZhiGeZheng = @"YES";
  236. defUser.car_type = theCarType;
  237. [self showSubmitAlert];
  238. } else {
  239. defUser.isZhiGeZheng = oldStatus;
  240. }
  241. }];
  242. }
  243. } else {
  244. defUser.car_type = theCarType;
  245. [self showSubmitAlert];
  246. }
  247. }
  248. }
  249. }
  250. /**
  251. */
  252. -(void)showSubmitAlert
  253. {
  254. NSString* quesCntMsg ;
  255. if (0 == current_index)
  256. {
  257. NSInteger sub1 = [DB_Que_Helper countForQuery:@"subject = 1"];
  258. NSInteger sub4 = [DB_Que_Helper countForQuery:@"subject = 4"];
  259. quesCntMsg = [NSString stringWithFormat:@"科目一:%ld题\n科目四:%ld题",(long)sub1,(long)sub4];
  260. }
  261. else if (current_index == 1)
  262. {
  263. NSInteger sub1 = [DB_Que_Helper countForQuery:@"subject = 1"];
  264. NSInteger sub4 = [DB_Que_Helper countForQuery:@"subject = 4"];
  265. quesCntMsg = [NSString stringWithFormat:@"科目一:%ld题\n科目四:%ld题",(long)sub1,(long)sub4];
  266. }
  267. else if (current_index == 2)
  268. {
  269. NSInteger sub1 = [DB_Que_Helper countForQuery:@"subject = 1"];
  270. NSInteger sub4 = [DB_Que_Helper countForQuery:@"subject = 4"];
  271. quesCntMsg = [NSString stringWithFormat:@"科目一:%ld题\n科目四:%ld题",(long)sub1,(long)sub4];
  272. }
  273. else if (current_index == 3)
  274. {
  275. //摩托车数据
  276. NSInteger sub1 = [DB_Que_Helper countForQuery:@"subject = 1"];
  277. NSInteger sub4 = [DB_Que_Helper countForQuery:@"subject = 4"];
  278. quesCntMsg = [NSString stringWithFormat:@"科目一:%ld题\n科目四:%ld题",(long)sub1,(long)sub4];
  279. }
  280. else if (current_index == 4)
  281. {
  282. //数据库的顺序有问题 所以不得不这么写 麻烦 优化的时候可以考虑改变数据库数据 比如把某一列为1全改为3
  283. NSInteger sub = [DB_Que_Helper countForQuery:@"nil"];
  284. quesCntMsg = [NSString stringWithFormat:@"共%ld题",(long)sub];
  285. }
  286. else if (current_index == 5)
  287. {
  288. NSInteger sub = [DB_Que_Helper countForQuery:@"nil"];
  289. quesCntMsg = [NSString stringWithFormat:@"共%ld题",(long)sub];
  290. }
  291. else if (current_index == 6)
  292. {
  293. NSInteger sub = [DB_Que_Helper countForQuery:@"nil"];
  294. quesCntMsg = [NSString stringWithFormat:@"共%ld题",(long)sub];
  295. }
  296. else if (current_index == 7)
  297. {
  298. NSInteger sub = [DB_Que_Helper countForQuery:@"nil"];
  299. quesCntMsg = [NSString stringWithFormat:@"共%ld题",(long)sub];
  300. }
  301. else
  302. {
  303. NSInteger sub = [DB_Que_Helper countForQuery:@"nil"];
  304. quesCntMsg = [NSString stringWithFormat:@"共%ld题",(long)sub];
  305. }
  306. // NSString* msg =[NSString stringWithFormat: @"您选择的是:%@题库\n%@\n此题库为2018年\n最新题库,全国通用",queLibs[current_index],quesCntMsg];
  307. NSInteger sub1 = [RQ_YDTQuestion_Module getQuestionWithSubject:RQHomePageSubjectType_SubjectOne exerciseType:RQExerciseType_Sequential].count;
  308. NSInteger sub4 = [RQ_YDTQuestion_Module getQuestionWithSubject:RQHomePageSubjectType_SubjectFour exerciseType:RQExerciseType_Sequential].count;
  309. quesCntMsg = [NSString stringWithFormat:@"科目一:%ld题\n科目四:%ld题",(long)sub1,(long)sub4];
  310. if (current_index > 3 && current_index != 5) {
  311. quesCntMsg = [NSString stringWithFormat:@"共%ld题",(long)sub1];
  312. }
  313. NSString* msg =[NSString stringWithFormat: @"您选择的是:%@题库\n%@",queLibs[current_index],quesCntMsg];
  314. // if (current_index == 3)
  315. // {
  316. // msg = @"暂无数据";
  317. // }
  318. UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:self cancelButtonTitle:@"知道啦" otherButtonTitles: nil];
  319. [alert show];
  320. }
  321. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  322. {
  323. // if (current_index == 3)
  324. // {
  325. // return;
  326. // }
  327. if (_isWelcome) {
  328. [myDelegate gotoMain];
  329. }else{
  330. // [self.navigationController dismissViewControllerAnimated:YES completion:^{
  331. //
  332. // }];
  333. [self.navigationController popToRootViewControllerAnimated:YES];
  334. }
  335. }
  336. - (void)doGetStudentActiveKhStatusWithResultBlock:(void (^)(BOOL isSuccessed))resultBlock {
  337. if (![Util connectedToNetWork]) {
  338. showMsgUnconnect();
  339. resultBlock(NO);
  340. return;
  341. }
  342. NSMutableArray *arr=[NSMutableArray array];
  343. NSString* method = @"doGetStudentActiveKhStatus";
  344. [arr addPro:@"stuIdCard" Value:(defUser.sfzmhm && ![defUser.sfzmhm isEqualToString:@""] && ![defUser.sfzmhm isEqualToString:@"(null)"])? defUser.sfzmhm : @"362324199302156513"];
  345. [arr addPro:@"stuOutId" Value:(defUser.sfzmhm && ![defUser.sfzmhm isEqualToString:@""] && ![defUser.sfzmhm isEqualToString:@"(null)"])? [NSString stringWithFormat:@"%@",defUser.userDict[@"outId"]] : @"2101000519225"];
  346. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  347. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  348. [MBProgressHUD hideHUDForView:self.view animated:YES];
  349. if (!root) {
  350. ShowMsgFailed();
  351. resultBlock(NO);
  352. return ;
  353. }
  354. if ([root[@"code"] isEqualToString:@"0"]) {
  355. ShowMsg(root[@"body"]);
  356. resultBlock(YES);
  357. return;
  358. } else {
  359. ShowMsg(root[@"body"]);
  360. resultBlock(NO);
  361. return;
  362. }
  363. }];
  364. }
  365. @end