MyGradeVC.m 7.3 KB

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