123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- //
- // ChooseExLibVC.m
- // jiaPei
- //
- // Created by apple on 15/11/18.
- // Copyright (c) 2015年 JCZ. All rights reserved.
- //
- #import "ChooseExLibVC.h"
- #import "STButton.h"
- #import "CLButton.h"
- /**user default 里面保存的是 cartype的序号,
- 不是实际的cartype。
- */
- #define carTypeKey @"car_type"
- @interface ChooseExLibVC ()<UIAlertViewDelegate>
- @end
- @implementation ChooseExLibVC
- {
- /**题库名。
- 可以用来和defUser里面的car_type来比对。
- 选择提交题库时也要从里面选。
- */
- NSArray* car_types;
- /**√图标
- */
- UIImageView* img;
- /**所有汽车类型的按钮
- */
- NSMutableArray* carBtns;
- /**所有题库的名称
- */
- NSMutableArray* queLibs;
- NSInteger current_index;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self myInit];
- [self loadCarType];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- self.navigationController.navigationBarHidden = NO;
- }
- #pragma mark -
- -(void)myInit
- {
- if (!_isWelcome) {
- [self configNavigationBar];
- }
-
- self.navigationController.navigationBar.translucent = NO;
- [self.view setBackgroundColor:backGroundColor];
- [self setTitle:@"选择题库"];
-
- UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 20, kSize.width, kSize.height-20)];
- view.backgroundColor = backGroundColor;
- [self.view addSubview:view];
-
- /**
- 为每一个按钮设置tag值,表示该按钮对应的题库类型
- */
- car_types = @[@"C1",@"A2",@"A1",@"D",@"4",@"1",@"2",@"3",@"5",@"6"];//,@"4"
-
- int tag = 0;
-
- UILabel* label;
- STButton* btn;
- UIView* line;
- NSArray* titles;
-
- CGFloat dx = 20;
- CGFloat lblH = 30;
- CGFloat btnW = kSize.width/4-1;
- CGFloat btnH = btnW*8/9;
- CGFloat lineWid = .5;
-
- label = [[UILabel alloc] initWithFrame:CGRectMake(dx, 0, kSize.width, lblH)];
- [label setText:@"驾驶证"];
- [view addSubview:label];
-
- line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(label.frame), kSize.width, lineWid)];
- [line setBackgroundColor:KlineColor];
- [view addSubview:line];
-
- queLibs = [NSMutableArray array];
- titles = @[@"小车",@"货车",@"客车",@"摩托车"];
- [queLibs addObjectsFromArray:titles];
-
- NSArray* subTitles = @[@"C1/C2/C3",@"A2/B2",@"A1/A3/B1",@"D/E/F"];
- UIImage* image;
- carBtns = [NSMutableArray array];
- for (int i =0; i<titles.count; i++) {
- image = [UIImage imageNamed:[NSString stringWithFormat:@"car_type%d.png",tag+1]];
- btn = [[STButton alloc] initWithFrame:CGRectMake(btnW*i, CGRectGetMaxY(line.frame), btnW, btnH)];
- [btn setImage:image withTitle:titles[i] Font:13 forState:UIControlStateNormal];
- [btn addTarget:self action:@selector(carTypeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [btn setTitleColor:contentTextColor forState:UIControlStateNormal];
- [btn setBackgroundColor:[UIColor whiteColor]];
- [btn setSubTitle:subTitles[i]];
- [view addSubview:btn];
- [carBtns addObject:btn];
-
- if ([car_types[tag] isEqualToString:@""]) {
- btn.enabled = NO;
- }
- [btn setTag:tag++];
- }
-
- line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(btn.frame), kSize.width, lineWid)];
- [line setBackgroundColor:KlineColor];
- [view addSubview:line];
-
- label = [[UILabel alloc] initWithFrame:CGRectMake(dx, CGRectGetMaxY(line.frame)+10, kSize.width, lblH)];
- [label setText:@"资格证"];
- [view addSubview:label];
-
- line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(label.frame), kSize.width, lineWid)];
- [line setBackgroundColor:KlineColor];
- [view addSubview:line];
-
- titles = @[@"教练员",@"客运",@"货运",@"危险品",@"出租车",@"网约车"];//@"教练员",
- [queLibs addObjectsFromArray:titles];
- for (int i =0; i<titles.count; i++)
- {
- image = [UIImage imageNamed:[NSString stringWithFormat:@"car_type%d.png",tag+1]];
- btn = [[STButton alloc] initWithFrame:
- CGRectMake((btnW+1)*(i%4),CGRectGetMaxY(line.frame)+btnH*(i/4), btnW, btnH)];
- [btn setImage:image withTitle:titles[i] Font:13 forState:UIControlStateNormal];
- [btn addTarget:self action:@selector(carTypeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [btn setTitleColor:contentTextColor forState:UIControlStateNormal];
- [btn setBackgroundColor:[UIColor whiteColor]];
- [view addSubview:btn];
- [carBtns addObject:btn];
-
- if ([car_types[tag] isEqualToString:@""]) {
- btn.enabled = NO;
- }
- [btn setTag:tag++];
- }
-
- line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(btn.frame), btnW, lineWid)];
- [line setBackgroundColor:KlineColor];
- [view addSubview:line];
-
- UIButton* lastBtn = [[CLButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(line.frame), kSize.width, 27)];
- //这个btn只是为了做界面--无触发事件
- [lastBtn setImage:[UIImage imageNamed:@"right.png"] withTitle:@"已经更新为2022年最新官方题库" Font:13 forState:UIControlStateNormal];
- [lastBtn setBackgroundColor:[UIColor clearColor]];
- [lastBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
- [lastBtn setTitleColor:contentTextColor forState:UIControlStateNormal];
- [view addSubview:lastBtn];
- lastBtn.enabled = NO;
-
- CGFloat topY = CGRectGetMaxY(lastBtn.frame);
- lastBtn = nil;
-
- CGFloat boarder = 30;
- lastBtn = [[UIButton alloc] initWithFrame:CGRectMake(boarder,topY+20,kSize.width - boarder*2, 50)];
- [lastBtn setTitle:@"确定" textColor:[UIColor whiteColor] font:25 fotState:UIControlStateNormal];
- [lastBtn addTarget:self action:@selector(submit:) forControlEvents:UIControlEventTouchUpInside];
- [lastBtn setBackgroundColor:defGreen];
- [lastBtn.layer setCornerRadius:25];
- [view addSubview:lastBtn];
-
- CGFloat imgW = 15;
- img = [[UIImageView alloc] initWithFrame:CGRectMake(btnW-imgW, btnH-imgW, imgW, imgW)];
- [img setImage:[UIImage imageNamed:@"question_correct.png"]];
-
- current_index = -1;
- }
- /**从userDefault里面拿出,carType来。
- 其实。去defuser。里面取即可。
- */
- -(void)loadCarType
- {
- int index = 0;
- for (int i=0; i<car_types.count; i++) {
- if ([car_types[i] isEqualToString:defUser.car_type]) {
- index = i;
- break;
- }
- }
- [self chooseBtnAtIndex:index];
- }
- /**按钮点击事件
- */
- -(void)carTypeBtnClick:(UIButton *)sender
- {
- [self chooseBtnAtIndex:sender.tag];
- }
- /**根据索引值,设立选定。
- 选定之后,修改背景色和。右下角下角对勾。
- 主要是给初始化用的。
- */
- -(void)chooseBtnAtIndex:(NSInteger)index
- {
- UIButton* btn;
- if (current_index>=0)
- {
- btn = carBtns[current_index];
- [btn setBackgroundColor:[UIColor whiteColor]];
- }
- current_index = index;
- btn = carBtns[current_index];
- [btn setBackgroundColor:[UIColor clearColor]];
-
- [btn addSubview:img];
- }
- /**
- 确定按钮点击事件
- */
- -(void)submit:(UIButton*)sender
- {
- if (current_index >= 0)
- {
- NSString * oldStatus = defUser.isZhiGeZheng;
- NSString *theCarType = car_types[current_index];
- RQ_YDTQuestion_Module.carType = current_index;
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- if ([theCarType isEqualToString:@"1"] || [theCarType isEqualToString:@"2"] || [theCarType isEqualToString:@"3"] || [theCarType isEqualToString:@"4"] || [theCarType isEqualToString:@"5"] || [theCarType isEqualToString:@"6"]) {
-
- defUser.isZhiGeZheng = @"YES";
- }else{
-
- defUser.isZhiGeZheng = @"NO";
- }
- } else {
- if ([theCarType isEqualToString:@"1"] || [theCarType isEqualToString:@"3"] || [theCarType isEqualToString:@"4"] || [theCarType isEqualToString:@"5"] || [theCarType isEqualToString:@"6"]) {
-
- defUser.isZhiGeZheng = @"YES";
- }else{
-
- defUser.isZhiGeZheng = @"NO";
- }
- }
-
-
-
- myDelegate.subject = @"1";
- RQ_YDTQuestion_Module.subject = RQHomePageSubjectType_SubjectOne;
- if (!_isWelcome) {
- NSString *str = [defUser.isZhiGeZheng isEqualToString:oldStatus] ? @"NO":@"YES";
- NSNotification *notification =[NSNotification notificationWithName:@"Tiku_Change" object:nil userInfo:@{@"zhigezhengChanged":str}];
- [[NSNotificationCenter defaultCenter] postNotification:notification];
- }
-
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- defUser.car_type = theCarType;
- [self showSubmitAlert];
- } else {
- if ([theCarType isEqualToString:@"2"]) {
- if (!myDelegate.isLogin) {
- LoginViewController* vc = [[LoginViewController alloc] init];
- vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
- vc.modalPresentationStyle = UIModalPresentationFullScreen;
- [self.parentViewController presentViewController:vc animated:YES completion:nil];
- } else {
- [self doGetStudentActiveKhStatusWithResultBlock:^(BOOL isSuccessed) {
- if (isSuccessed) {
- //改变当前题库的类型
- defUser.isZhiGeZheng = @"YES";
- defUser.car_type = theCarType;
- [self showSubmitAlert];
- } else {
- defUser.isZhiGeZheng = oldStatus;
- }
- }];
- }
- } else {
- defUser.car_type = theCarType;
- [self showSubmitAlert];
- }
- }
- }
- }
- /**
- */
- -(void)showSubmitAlert
- {
- NSString* quesCntMsg ;
- if (0 == current_index)
- {
- NSInteger sub1 = [DB_Que_Helper countForQuery:@"subject = 1"];
- NSInteger sub4 = [DB_Que_Helper countForQuery:@"subject = 4"];
- quesCntMsg = [NSString stringWithFormat:@"科目一:%ld题\n科目四:%ld题",(long)sub1,(long)sub4];
- }
- else if (current_index == 1)
- {
- NSInteger sub1 = [DB_Que_Helper countForQuery:@"subject = 1"];
- NSInteger sub4 = [DB_Que_Helper countForQuery:@"subject = 4"];
- quesCntMsg = [NSString stringWithFormat:@"科目一:%ld题\n科目四:%ld题",(long)sub1,(long)sub4];
- }
- else if (current_index == 2)
- {
- NSInteger sub1 = [DB_Que_Helper countForQuery:@"subject = 1"];
- NSInteger sub4 = [DB_Que_Helper countForQuery:@"subject = 4"];
- quesCntMsg = [NSString stringWithFormat:@"科目一:%ld题\n科目四:%ld题",(long)sub1,(long)sub4];
- }
- else if (current_index == 3)
- {
- //摩托车数据
- NSInteger sub1 = [DB_Que_Helper countForQuery:@"subject = 1"];
- NSInteger sub4 = [DB_Que_Helper countForQuery:@"subject = 4"];
- quesCntMsg = [NSString stringWithFormat:@"科目一:%ld题\n科目四:%ld题",(long)sub1,(long)sub4];
- }
- else if (current_index == 4)
- {
- //数据库的顺序有问题 所以不得不这么写 麻烦 优化的时候可以考虑改变数据库数据 比如把某一列为1全改为3
- NSInteger sub = [DB_Que_Helper countForQuery:@"nil"];
- quesCntMsg = [NSString stringWithFormat:@"共%ld题",(long)sub];
- }
- else if (current_index == 5)
- {
- NSInteger sub = [DB_Que_Helper countForQuery:@"nil"];
- quesCntMsg = [NSString stringWithFormat:@"共%ld题",(long)sub];
- }
- else if (current_index == 6)
- {
- NSInteger sub = [DB_Que_Helper countForQuery:@"nil"];
- quesCntMsg = [NSString stringWithFormat:@"共%ld题",(long)sub];
- }
- else if (current_index == 7)
- {
- NSInteger sub = [DB_Que_Helper countForQuery:@"nil"];
- quesCntMsg = [NSString stringWithFormat:@"共%ld题",(long)sub];
- }
- else
- {
- NSInteger sub = [DB_Que_Helper countForQuery:@"nil"];
- quesCntMsg = [NSString stringWithFormat:@"共%ld题",(long)sub];
- }
-
- // NSString* msg =[NSString stringWithFormat: @"您选择的是:%@题库\n%@\n此题库为2018年\n最新题库,全国通用",queLibs[current_index],quesCntMsg];
- NSInteger sub1 = [RQ_YDTQuestion_Module getQuestionWithSubject:RQHomePageSubjectType_SubjectOne exerciseType:RQExerciseType_Sequential].count;
- NSInteger sub4 = [RQ_YDTQuestion_Module getQuestionWithSubject:RQHomePageSubjectType_SubjectFour exerciseType:RQExerciseType_Sequential].count;
- quesCntMsg = [NSString stringWithFormat:@"科目一:%ld题\n科目四:%ld题",(long)sub1,(long)sub4];
- if (current_index > 3 && current_index != 5) {
- quesCntMsg = [NSString stringWithFormat:@"共%ld题",(long)sub1];
- }
- NSString* msg =[NSString stringWithFormat: @"您选择的是:%@题库\n%@",queLibs[current_index],quesCntMsg];
-
- // if (current_index == 3)
- // {
- // msg = @"暂无数据";
- // }
- UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:msg delegate:self cancelButtonTitle:@"知道啦" otherButtonTitles: nil];
- [alert show];
- }
- -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- // if (current_index == 3)
- // {
- // return;
- // }
- if (_isWelcome) {
- [myDelegate gotoMain];
- }else{
- // [self.navigationController dismissViewControllerAnimated:YES completion:^{
- //
- // }];
- [self.navigationController popToRootViewControllerAnimated:YES];
- }
- }
- - (void)doGetStudentActiveKhStatusWithResultBlock:(void (^)(BOOL isSuccessed))resultBlock {
-
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- resultBlock(NO);
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
-
- NSString* method = @"doGetStudentActiveKhStatus";
- [arr addPro:@"stuIdCard" Value:(defUser.sfzmhm && ![defUser.sfzmhm isEqualToString:@""] && ![defUser.sfzmhm isEqualToString:@"(null)"])? defUser.sfzmhm : @"362324199302156513"];
- [arr addPro:@"stuOutId" Value:(defUser.sfzmhm && ![defUser.sfzmhm isEqualToString:@""] && ![defUser.sfzmhm isEqualToString:@"(null)"])? [NSString stringWithFormat:@"%@",defUser.userDict[@"outId"]] : @"2101000519225"];
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- if (!root) {
- ShowMsgFailed();
- resultBlock(NO);
- return ;
- }
-
- if ([root[@"code"] isEqualToString:@"0"]) {
- ShowMsg(root[@"body"]);
- resultBlock(YES);
- return;
- } else {
- ShowMsg(root[@"body"]);
- resultBlock(NO);
- return;
- }
- }];
- }
- @end
|