// // 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 () @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=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