123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- //
- // MyGradeVC.m
- // jiaPei
- //
- // Created by apple on 15/11/21.
- // Copyright (c) 2015年 JCZ. All rights reserved.
- //
- #import "MyGradeVC.h"
- #import "AFView.h"
- #define rateX kSize.width / 320
- #define rateY kSize.height / 480
- #define SGRectMake(x,y,width,height) CGRectMake(x * rateX, y * rateY, width * rateX, height * rateY)
- @interface MyGradeVC ()
- {
- AFView *afView;
- HolderView *holderV;
-
-
- /**保存各种考试成绩的称号。例如,赛车之神
- */
- NSArray *honors;
-
- NSArray *grades;
- }
- @end
- @implementation MyGradeVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self.view setBackgroundColor:[UIColor whiteColor]];
- [self goBackByNavigation];
- if (_stuName.length > 0) {
- [self setTitle:[NSString stringWithFormat:@"%@的成绩",_stuName]];
- }else{
- [self setTitle:[NSString stringWithFormat:@"学员成绩"]];
- }
-
- honors = @[@"马路杀手",@"驾考标兵",@"驾考牛人",@"驾考神人",@"外星人",@"幸运儿"];
-
-
- holderV = [[HolderView alloc] initWithFrame:kFrame];
- [holderV freshBlock:^{
- [self getMyStudentScore];
- }];
- [self.view addSubview:holderV];
-
- [self getMyStudentScore];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- #pragma mark - 初始化
- -(void)myInit{
-
- UILabel* label;
- CGFloat currentTop;
- CGFloat lblh ,lblw;
- CGFloat vh=160;
-
- NSInteger x = 0;
-
- //只显示最近的9条成绩。
- NSInteger lastestCnt = 9;
- if (grades.count < lastestCnt) {
- lastestCnt = grades.count;
- }
-
- NSMutableArray* points = [NSMutableArray array];
- for (int i = 0;i < lastestCnt;i++) {
- NSDictionary *dic = grades[lastestCnt - i - 1];
- [points addObject:[NSValue valueWithCGPoint:CGPointMake(++x, [dic[@"EI_SCORE"] intValue])]];
- }
-
-
- afView = [[AFView alloc] initWithFrame:SGRectMake(0, 64*480/kSize.height, 320, vh)];
- NSArray* xTitles = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
- [afView setX_labels:xTitles];
- [afView setMin_X:1];
- [afView setMax_X:xTitles.count];
- [afView setMin_Y:0];
- [afView setMax_Y:100];
- [afView setY_labels:@[@"0",@"20",@"40",@"60",@"80",@"100"]];
- [afView setData:points];//折线图的数据。
- [self.view addSubview:afView];
-
-
- currentTop = vh + 64*480/kSize.height + 10;
- lblh = 25;
- lblw = 320*.2;
-
- UIScrollView* scroll = [[UIScrollView alloc] initWithFrame:SGRectMake(0, currentTop, 320, 480- currentTop)];
- [self.view addSubview:scroll];
-
- for (int y =0; y<grades.count; y++)
- {
- label = [[UILabel alloc] initWithFrame:SGRectMake(0, lblh*y, 32+30, lblh)];
- [scroll addSubview:label];
- [label setTextAlignment:NSTextAlignmentCenter];
- [label setText:[NSString stringWithFormat:@"%d",(int)y+1]];
- [label setTextColor:KContentTextColor];
- [label addViewWithRect: SGRectMake(0, lblh*y, 320, .5)];
-
- NSDictionary *dic = grades[grades.count - 1 - y];
- for (int x=0; x<4; x++) {
- label = [[UILabel alloc] initWithFrame:SGRectMake(32+30+x*lblw, lblh*y, lblw, lblh)];
- [scroll addSubview:label];
- [label setTextAlignment:NSTextAlignmentCenter];
- switch (x) {
- case 0:
- {
- [label setTextColor:KContentTextColor];
- [label setTextAlignment:NSTextAlignmentLeft];
- NSString *dateStr = dic[@"EI_CRDATE"];
- if ([dateStr containsString:@" "]) {
- dateStr = [[dateStr componentsSeparatedByString:@" "] firstObject];
- }
-
- if (dateStr.length > 5) {
- dateStr = [dateStr substringFromIndex:5];
- }
-
- [label setText:dateStr];
- }
- break;
- case 1:
- [label setTextColor:[UIColor redColor]];
- [label setText:[NSString stringWithFormat:@"%@分",dic[@"EI_SCORE"]]];
- break;
- case 2:
- {
- [label setTextColor:KContentTextColor];
-
- int timeS = [dic[@"EI_TOTAL_TIME"] intValue];
- int min = timeS/60;
- int sec = timeS%60;
-
- NSString *minStr = [NSString stringWithFormat:@"%d",min];
- NSString *secStr = [NSString stringWithFormat:@"%d",sec];
-
- if (min < 10) {
- minStr = [NSString stringWithFormat:@"0%d",min];
- }
- if (sec < 10) {
- secStr = [NSString stringWithFormat:@"0%d",sec];
- }
-
- [label setText:[NSString stringWithFormat:@"%@:%@",minStr,secStr]];
- }
- break;
- case 3:
- {
- NSInteger score = [dic[@"EI_SCORE"] integerValue];
- NSString *graHonorStr = @"";
-
- if (score < 60) {
- graHonorStr = honors[0];
- }else if (score < 90){
- graHonorStr = honors[1];
- }else if (score < 93){
- graHonorStr = honors[2];
- }else if (score < 96){
- graHonorStr = honors[3];
- }else if (score < 98){
- graHonorStr = honors[4];
- }else{
- graHonorStr = honors[5];
- }
-
- [label setTextColor:defGreen];
- [label setText:graHonorStr];
- }
- break;
- default:
- break;
- }
- }
- }
-
- [label addViewWithRect:SGRectMake(0, lblh*grades.count, 320, .5)];
- [scroll setContentSize:CGSizeMake(0, lblh*(grades.count+2)*rateY)];
- [scroll setScrollEnabled:YES];
- }
- #pragma mark 数据请求
- //获取学员成绩详情
- - (void)getMyStudentScore
- {
- if (![NetManager connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSMutableDictionary * mDic = [NSMutableDictionary new];
-
- [mDic setObject:@"" forKey:@"idcard"];
- [mDic setObject:@"" forKey:@"subject"];
- [mDic setObject:@"" forKey:@"score"];
- [mDic setObject:@"" forKey:@"count"];
- [mDic setObject:@"" forKey:@"startTime"];
- [mDic setObject:@"" forKey:@"endTime"];
- [mDic setObject:@"" forKey:@"jxbh"];
-
- NSString* method = @"getStuExams";
- [NetManager requestAnythingWithURL:method dictionary:mDic dataArray:nil completion:^(NSDictionary *root) {
-
- [holderV setHidden:NO];
-
- if (!root) {
- ShowErrorMsg(@"请求失败!");
- return;
- }
- if ([root[@"code"] isEqualToString:@"1"]) {
- ShowErrorMsg(root[@"msg"]);
- return;
- }
-
- if ([root[@"body"] count] < 1) {
- ShowMsg(@"您的学员还未上传成绩");
- return;
- }
- grades = root[@"body"];
-
- [holderV setHidden:YES];
- [self myInit];
- }];
-
- }
- @end
|