#import "ExamResultVC.h" #import "CLCell.h" @interface ExamResultVC () @end @implementation ExamResultVC /** 上传考试成绩是在这里做的。先保存到数据库里面。 有网络就,取出所有state为0的记录上传。 */ - (void)viewDidLoad { [super viewDidLoad]; [self myInit]; [self.view addViewWithRect:CGRectZero]; [DB_Helper saveGrade:_grade]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { [self saveStuScore:_grade]; } else { if ([defUser.car_type isEqualToString:@"2"]) { if (_grade.graScore.integerValue >= 80) { [self saveExamScore:_grade questionsArr:_questions]; } } else { [self saveStuScore:_grade]; } } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - -(void)myInit { //NSLog(@"gradeResult----%@,----%@,----%@,----%@",_grade.graTime,_grade.graScore,_grade.graDate,_grade.graHonor); [self.view setBackgroundColor:[UIColor orangeColor]]; [self configNavigationBarPopRoot]; [self setTitle:@"考试成绩"]; self.fd_interactivePopDisabled = YES; UIImageView* iv = [[UIImageView alloc] initWithFrame:kFrame]; [iv setImage:[UIImage imageNamed:@"result_bg.png"]]; [self.view addSubview:iv]; CGFloat x,y,wid,hei,bd; NSInteger tag = 0; bd=5; x = 50; y = 50; wid = 60; hei = wid; UIImageView *rdiv = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, wid, hei)]; [rdiv yy_setImageWithURL:[NSURL URLWithString:RQStringIsNotEmpty(defUser.userHeadImg)? defUser.userHeadImg : @""] placeholder:randomPortrait()]; rdiv.layer.cornerRadius = wid / 2.f; rdiv.layer.masksToBounds = YES; [self.view addSubview:rdiv]; x +=wid + bd; wid = 160 ; hei /= 2.0; UILabel* label; label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, wid, hei)]; [self.view addSubview:label]; [label setTextColor:kTitleColor]; if (myDelegate.isLogin) { [label setText:RQStringIsEmpty(defUser.userName)? @"驾考学员" : defUser.userName]; }else{ [label setText:@"驾考学员"]; } y += hei; label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, wid, hei)]; NSString* str = [NSString stringWithFormat:@"分数:%@分 用时:%@",_grade.graScore,_grade.graTime]; [label setText:str]; [label setFont:[UIFont scaleSize:12]]; [self.view addSubview:label]; [label setTextColor:contentTextColor]; UIButton* btn; x += wid; y -= hei; wid = hei; btn = [[UIButton alloc] initWithFrame:CGRectMake(x, y, wid, hei)]; [btn setImage:[[UIImage imageNamed:@"remove.png"] tint:[UIColor orangeColor]] forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [btn setTag:tag++]; [self.view addSubview:btn]; //在这里 设计图标 UIImageView *gradeImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, label.y + label.height , kSize.width, kSize.width* 4.0 / 5)]; NSString *imageName; if ([_grade.graScore intValue] < 60) { imageName = @"grade1"; }else if ([_grade.graScore intValue] < 90){ imageName = @"grade2"; }else if ([_grade.graScore intValue] < 93){ imageName = @"grade3"; }else if ([_grade.graScore intValue] < 96){ imageName = @"grade4"; }else if ([_grade.graScore intValue] < 98){ imageName = @"grade5"; }else{ imageName = @"grade6"; } gradeImage.image = [UIImage imageNamed:imageName]; [self.view addSubview:gradeImage]; } - (void)btnClick:(UIButton *)sender { [self.navigationController popToRootViewControllerAnimated:YES]; } -(void)saveStuScore:(Grade*)aGrade { if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { [DB_Helper updateGrade:_grade]; } else { if (!myDelegate.isLogin || ![Util connectedToNetWork]){ return; } if (![Util connectedToNetWork]) { return; } NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"jxbh" Value:defUser.userSchoolId]; [arr addPro:@"userName" Value:defUser.userDict[@"userName"]]; [arr addPro:@"userId" Value:defUser.userDict[@"id"]]; [arr addPro:@"outId" Value:defUser.userStuId]; [arr addPro:@"km" Value:myDelegate.subject]; [arr addPro:@"score" Value:aGrade.graScore]; [arr addPro:@"startDate" Value:aGrade.startDate]; [arr addPro:@"endDate" Value:aGrade.endDate]; [arr addPro:@"source" Value:@"2"]; // NSLog(@"saveStuScore调用保存 para----%@",arr); /// RQ_MARK /// NSMutableDictionary *reportDic = @{ @"jxbh" : defUser.userSchoolId , @"userName" : defUser.userDict[@"userName"], @"userId" :defUser.userDict[@"id"], @"outId" :defUser.userStuId, @"km" :myDelegate.subject, @"score" :aGrade.graScore, @"startDate" :aGrade.startDate, @"endDate" :aGrade.endDate, @"source" :@"2", }.mutableCopy; NSString* method = @"saveStuScore"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { if (!dict) { [Bugly reportException:[NSException exceptionWithName:method reason:[reportDic jsonStringEncoded] userInfo:@{@"error" : @"dict为空"}]]; return; } [Bugly reportException:[NSException exceptionWithName:method reason:[reportDic jsonStringEncoded] userInfo:dict]]; if ([dict[@"code"] isEqualToString:@"1"]) { return; } [DB_Helper updateGrade:_grade]; }]; } } //http://192.168.8.1:8081/lnappservice_mysql/uploadCyryScore - (void)saveExamScore:(Grade*)aGrade questionsArr:(NSArray*)questionsArr { if (!myDelegate.isLogin || ![Util connectedToNetWork]){ return; } if (![Util connectedToNetWork]) { return; } NSMutableString *questionsStr = [NSMutableString string]; [questionsArr.rac_sequence.signal subscribeNext:^(Question *question) { if ([questionsArr indexOfObject:question] == questionsArr.count - 1) { [questionsStr appendFormat:@"%@", [NSString stringWithFormat:@"%@,%@",question._id,question.state? : @"1"]]; } else { [questionsStr appendFormat:@"%@", [NSString stringWithFormat:@"%@,%@;",question._id,question.state? : @"1"]]; } } completed:^{ NSMutableArray *arr=[NSMutableArray array]; [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]]; [arr addPro:@"stuid" Value:defUser.userDict[@"outId"]]; [arr addPro:@"score" Value:aGrade.graScore]; [arr addPro:@"scoreTime" Value:RQ_SHARE_FUNCTION.getCurrentTimeString]; [arr addPro:@"duration" Value:[NSString stringWithFormat:@"%ld",[aGrade.graTime componentsSeparatedByString:@":"].firstObject.integerValue * 60 + [aGrade.graTime componentsSeparatedByString:@":"].lastObject.integerValue]]; [arr addPro:@"questions" Value:questionsStr.copy]; // NSLog(@"saveStuScore调用保存 para----%@",arr); NSString* method = @"uploadCyryScore"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { if (!dict) { return; } if ( [dict[@"code"] isEqualToString:@"1"]) { return; } [DB_Helper updateGrade:_grade]; }]; }]; } - (NSString *)pictureArrayToJSON:(NSArray *)picArr { NSData *data=[NSJSONSerialization dataWithJSONObject:picArr options:NSJSONWritingPrettyPrinted error:nil]; NSString *jsonStr=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; //去除空格和回车: jsonStr = [jsonStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@" " withString:@""]; jsonStr = [jsonStr stringByReplacingOccurrencesOfString:@"\n" withString:@""]; NSLog(@"jsonStr==%@",jsonStr); return jsonStr; } @end