MyGradeVC.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. //
  2. // MyGradeVC.m
  3. // jiaPei
  4. //
  5. // Created by apple on 15/11/21.
  6. // Copyright (c) 2015年 JCZ. All rights reserved.
  7. //
  8. #import "MyGradeVC.h"
  9. #import "AFView.h"
  10. @interface MyGradeVC ()
  11. {
  12. AFView *afView;
  13. HolderView *holderV;
  14. /**保存各种考试成绩的称号。例如,赛车之神
  15. */
  16. NSArray *honors;
  17. NSArray *grades;
  18. }
  19. @end
  20. @implementation MyGradeVC
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self.view setBackgroundColor:[UIColor whiteColor]];
  24. [self configNavBar];
  25. if (_stuName.length > 0) {
  26. [self setTitle:[NSString stringWithFormat:@"%@的成绩",_stuName]];
  27. }else{
  28. [self setTitle:[NSString stringWithFormat:@"学员成绩"]];
  29. }
  30. honors = @[@"马路杀手",@"驾考标兵",@"驾考牛人",@"驾考神人",@"外星人",@"幸运儿"];
  31. holderV = [[HolderView alloc] initWithFrame:kFrame];
  32. [holderV freshBlock:^{
  33. [self getMyStudentScore];
  34. }];
  35. [self.view addSubview:holderV];
  36. [self getMyStudentScore];
  37. }
  38. - (void)didReceiveMemoryWarning {
  39. [super didReceiveMemoryWarning];
  40. }
  41. #pragma mark -
  42. -(void)myInit{
  43. UILabel* label;
  44. CGFloat currentTop;
  45. CGFloat lblh ,lblw;
  46. CGFloat vh=160;
  47. NSInteger x = 0;
  48. //只显示最近的9条成绩。
  49. NSInteger lastestCnt = 9;
  50. if (grades.count < lastestCnt) {
  51. lastestCnt = grades.count;
  52. }
  53. NSMutableArray* points = [NSMutableArray array];
  54. for (int i = 0;i < lastestCnt;i++) {
  55. NSDictionary *dic = grades[lastestCnt - i - 1];
  56. [points addObject:[NSValue valueWithCGPoint:CGPointMake(++x, [dic[@"EI_SCORE"] intValue])]];
  57. }
  58. afView = [[AFView alloc] initWithFrame:SGRectMake(0, 64*480/kSize.height, 320, vh)];
  59. NSArray* xTitles = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
  60. [afView setX_labels:xTitles];
  61. [afView setMin_X:1];
  62. [afView setMax_X:xTitles.count];
  63. [afView setMin_Y:0];
  64. [afView setMax_Y:100];
  65. [afView setY_labels:@[@"0",@"20",@"40",@"60",@"80",@"100"]];
  66. [afView setData:points];//折线图的数据。
  67. [self.view addSubview:afView];
  68. currentTop = vh + 64*480/kSize.height + 10;
  69. lblh = 25;
  70. lblw = 320*.2;
  71. UIScrollView* scroll = [[UIScrollView alloc] initWithFrame:SGRectMake(0, currentTop, 320, 480- currentTop)];
  72. [self.view addSubview:scroll];
  73. for (int y =0; y<grades.count; y++)
  74. {
  75. label = [[UILabel alloc] initWithFrame:SGRectMake(0, lblh*y, 32+30, lblh)];
  76. [scroll addSubview:label];
  77. [label setTextAlignment:NSTextAlignmentCenter];
  78. [label setText:[NSString stringWithFormat:@"%d",(int)y+1]];
  79. [label setTextColor:contentTextColor];
  80. [label addViewWithRect: SGRectMake(0, lblh*y, 320, .5)];
  81. NSDictionary *dic = grades[grades.count - 1 - y];
  82. for (int x=0; x<4; x++) {
  83. label = [[UILabel alloc] initWithFrame:SGRectMake(32+30+x*lblw, lblh*y, lblw, lblh)];
  84. [scroll addSubview:label];
  85. [label setTextAlignment:NSTextAlignmentCenter];
  86. switch (x) {
  87. case 0:
  88. {
  89. [label setTextColor:contentTextColor];
  90. [label setTextAlignment:NSTextAlignmentLeft];
  91. NSString *dateStr = dic[@"EI_CRDATE"];
  92. if ([dateStr containsString:@" "]) {
  93. dateStr = [[dateStr componentsSeparatedByString:@" "] firstObject];
  94. }
  95. if (dateStr.length > 5) {
  96. dateStr = [dateStr substringFromIndex:5];
  97. }
  98. [label setText:dateStr];
  99. }
  100. break;
  101. case 1:
  102. [label setTextColor:[UIColor redColor]];
  103. [label setText:[NSString stringWithFormat:@"%@分",dic[@"EI_SCORE"]]];
  104. break;
  105. case 2:
  106. {
  107. [label setTextColor:contentTextColor];
  108. int timeS = [dic[@"EI_TOTAL_TIME"] intValue];
  109. int min = timeS/60;
  110. int sec = timeS%60;
  111. NSString *minStr = [NSString stringWithFormat:@"%d",min];
  112. NSString *secStr = [NSString stringWithFormat:@"%d",sec];
  113. if (min < 10) {
  114. minStr = [NSString stringWithFormat:@"0%d",min];
  115. }
  116. if (sec < 10) {
  117. secStr = [NSString stringWithFormat:@"0%d",sec];
  118. }
  119. [label setText:[NSString stringWithFormat:@"%@:%@",minStr,secStr]];
  120. }
  121. break;
  122. case 3:
  123. {
  124. NSInteger score = [dic[@"EI_SCORE"] integerValue];
  125. NSString *graHonorStr = @"";
  126. if (score < 60) {
  127. graHonorStr = honors[0];
  128. }else if (score < 90){
  129. graHonorStr = honors[1];
  130. }else if (score < 93){
  131. graHonorStr = honors[2];
  132. }else if (score < 96){
  133. graHonorStr = honors[3];
  134. }else if (score < 98){
  135. graHonorStr = honors[4];
  136. }else{
  137. graHonorStr = honors[5];
  138. }
  139. [label setTextColor:defGreen];
  140. [label setText:graHonorStr];
  141. }
  142. break;
  143. default:
  144. break;
  145. }
  146. }
  147. }
  148. [label addViewWithRect:SGRectMake(0, lblh*grades.count, 320, .5)];
  149. [scroll setContentSize:SGSizeMake(0, lblh* (grades.count +2))];
  150. [scroll setScrollEnabled:YES];
  151. }
  152. #pragma mark 数据请求
  153. //获取学员成绩详情
  154. - (void)getMyStudentScore
  155. {
  156. [LoadingView showHUD];
  157. if (![Util connectedToNetWork]) {
  158. showMsgUnconnect();
  159. return;
  160. }
  161. NSMutableArray *arr=[NSMutableArray array];
  162. [arr addPro:@"userId" Value:_identifyNum];//ps 以前用的是zjhm,现在文档里是userid 但是我用zjhm也可以请求成功
  163. [arr addPro:@"kskm" Value:_kmString];
  164. NSString* method = @"getMyStudentScore";
  165. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  166. RemoveHUD();
  167. //NSLog(@"考试成绩---->%@----->%@",arr,root);
  168. [holderV setHidden:NO];
  169. if (!root) {
  170. [LoadingView showMsg:@"查询失败"];
  171. return;
  172. }
  173. NSString* code = root[@"code"];
  174. if (code.intValue > 0)
  175. {
  176. [LoadingView showMsg:root[@"body"]];
  177. return;
  178. }
  179. if ([root[@"body"] count] < 1) {
  180. [LoadingView showMsg:@"您的学员还未上传成绩"];
  181. return;
  182. }
  183. grades = root[@"body"];
  184. [holderV setHidden:YES];
  185. [self myInit];
  186. }];
  187. }
  188. @end