MyGradeVC.m 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. #import "HolderView.h"
  11. @interface MyGradeVC ()
  12. {
  13. AFView* afView;
  14. }
  15. @property (nonatomic, readwrite, strong) NSMutableArray *grades;
  16. @end
  17. @implementation MyGradeVC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [self.view setBackgroundColor:[UIColor whiteColor]];
  21. [self configNavigationBar];
  22. [self setTitle:@"我的成绩"];
  23. [self getGrades];
  24. }
  25. - (void)didReceiveMemoryWarning {
  26. [super didReceiveMemoryWarning];
  27. }
  28. #pragma mark -
  29. -(void)myInit{
  30. if (self.grades.count == 0) {
  31. HolderView *holderv = [[HolderView alloc]initWithFrame:self.view.bounds];
  32. holderv.title = @"暂无成绩";
  33. [self.view addSubview:holderv];
  34. return;
  35. }
  36. UILabel* label;
  37. CGFloat currentTop;
  38. CGFloat lblh ,lblw;
  39. CGFloat vh=180;
  40. NSInteger x = 0;
  41. NSInteger i = 0;
  42. //只显示最近的9条成绩。
  43. NSInteger lastestCnt = 9;
  44. if (self.grades.count > lastestCnt) {
  45. i = self.grades.count - lastestCnt;
  46. }
  47. NSMutableArray *points = [NSMutableArray array];
  48. for (;i<self.grades.count;i++) {
  49. Grade* gra = self.grades[i];
  50. [points addObject:[NSValue valueWithCGPoint:CGPointMake(++x, gra.graScore.intValue)]];
  51. }
  52. afView = [[AFView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, vh)];
  53. NSArray* xTitles = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
  54. [afView setX_labels:xTitles];
  55. [afView setMin_X:1];
  56. [afView setMax_X:xTitles.count];
  57. [afView setMin_Y:0];
  58. [afView setMax_Y:100];
  59. [afView setY_labels:@[@"0",@"20",@"40",@"60",@"80",@"100"]];
  60. [afView setData:points];//折线图的数据。
  61. [self.view addSubview:afView];
  62. currentTop = vh + 10;
  63. lblh = 30;
  64. lblw = kSize.width*.2;
  65. UIScrollView* scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, currentTop, kSize.width, kSize.height- currentTop -kNavOffSet)];
  66. [self.view addSubview:scroll];
  67. for (int y =0; y<self.grades.count; y++)
  68. {
  69. label = [[UILabel alloc] initWithFrame:CGRectMake(0, lblh*y, 32, lblh)];
  70. [scroll addSubview:label];
  71. [label setTextAlignment:NSTextAlignmentRight];
  72. [label setText:[NSString stringWithFormat:@"%d",(int)y+1]];
  73. [label setTextColor:contentTextColor];
  74. [label addViewWithRect: CGRectMake(0, lblh*y, kSize.width, 1)];
  75. Grade* gra = self.grades[self.grades.count-1- y];
  76. for (int x=0; x<4; x++) {
  77. label = [[UILabel alloc] initWithFrame:CGRectMake(37+x*lblw, lblh*y, lblw, lblh)];
  78. [scroll addSubview:label];
  79. [label setTextAlignment:NSTextAlignmentCenter];
  80. switch (x) {
  81. case 0:
  82. [label setTextColor:contentTextColor];
  83. [label setTextAlignment:NSTextAlignmentRight];
  84. [label setText:[NSString stringWithFormat:@"%@",gra.graDate]];
  85. break;
  86. case 1:
  87. [label setTextColor:[UIColor redColor]];
  88. [label setText:[NSString stringWithFormat:@"%@分",gra.graScore]];
  89. break;
  90. case 2:
  91. [label setTextColor:contentTextColor];
  92. [label setText:[NSString stringWithFormat:@"%@",gra.graTime]];
  93. break;
  94. case 3:
  95. [label setText:[NSString stringWithFormat:@"%@",gra.graHonor] Font:NormalFont TextColor:defGreen];
  96. break;
  97. default:
  98. break;
  99. }
  100. }
  101. }
  102. [label addViewWithRect: CGRectMake(0, lblh*self.grades.count, kSize.width, .5)];
  103. [scroll setContentSize:CGSizeMake(0, lblh* (self.grades.count +2))];
  104. [scroll setScrollEnabled:YES];
  105. }
  106. - (void)getGrades {
  107. if (myDelegate.isLogin) {
  108. [self getMyStudentScore];
  109. } else {
  110. self.grades = [NSMutableArray arrayWithArray:[DB_Que_Helper queryAllGrades]];
  111. [self myInit];
  112. }
  113. }
  114. //获取学员成绩详情
  115. - (void)getMyStudentScore
  116. {
  117. @weakify(self)
  118. if (![Util connectedToNetWork]) {
  119. showMsgUnconnect();
  120. return;
  121. }
  122. if (!myDelegate.isLogin) {
  123. ShowMsg(@"您还未进行考试");
  124. return;
  125. }
  126. NSMutableArray *arr=[NSMutableArray array];
  127. [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
  128. [arr addPro:@"outId" Value:defUser.userStuId];
  129. [arr addPro:@"subject" Value:myDelegate.subject];
  130. [arr addPro:@"isPage" Value:@""];
  131. [arr addPro:@"pageSize" Value:@""];
  132. [arr addPro:@"currentPage" Value:@""];
  133. NSString* method = @"myScore";
  134. [MBProgressHUD showLoadToView:self.view];
  135. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * dict) {
  136. [MBProgressHUD hideHUDForView:self.view];
  137. //NSLog(@"考试成绩---->%@----->%@",arr,dict);
  138. if (!dict) {
  139. ShowMsg(@"您还未进行考试");
  140. [self myInit];
  141. return;
  142. }
  143. NSString* code = dict[@"code"];
  144. if (code.intValue > 0)
  145. {
  146. ShowMsg(@"您还未进行考试");
  147. [self myInit];
  148. return;
  149. }
  150. if ([dict[@"body"] count] < 1) {
  151. ShowMsg(@"您还未进行考试");
  152. [self myInit];
  153. return;
  154. }
  155. NSArray *array = dict[@"body"];
  156. for (NSDictionary *dic in array) {
  157. Grade *grade = [[Grade alloc] init];
  158. NSString *dateStr = dic[@"crdate"];
  159. grade.graDateTimeStamp = [RQ_SHARE_FUNCTION getTimeStampWithTimeStr:dateStr formatter:@"yyyy-MM-dd HH:mm:ss"];
  160. if ([dateStr containsString:@" "]) {
  161. dateStr = [[dateStr componentsSeparatedByString:@" "] firstObject];
  162. }
  163. if (dateStr.length > 5) {
  164. dateStr = [dateStr substringFromIndex:5];
  165. }
  166. grade.graDate = dateStr;
  167. grade.graScore = dic[@"score"];
  168. int timeS = [dic[@"totalTime"] intValue];
  169. int min = timeS/60;
  170. int sec = timeS%60;
  171. NSString *minStr = [NSString stringWithFormat:@"%d",min];
  172. NSString *secStr = [NSString stringWithFormat:@"%d",sec];
  173. if (min < 10) {
  174. minStr = [NSString stringWithFormat:@"0%d",min];
  175. }
  176. if (sec < 10) {
  177. secStr = [NSString stringWithFormat:@"0%d",sec];
  178. }
  179. grade.graTime = [NSString stringWithFormat:@"%@:%@",minStr,secStr];
  180. NSInteger score = [dic[@"score"] integerValue];
  181. NSArray *honors = @[@"马路杀手",@"驾考标兵",@"驾考牛人",@"驾考神人",@"外星人",@"幸运儿"];
  182. NSString *graHonorStr = @"";
  183. if (score < 60) {
  184. graHonorStr = honors[0];
  185. }else if (score < 90){
  186. graHonorStr = honors[1];
  187. }else if (score < 93){
  188. graHonorStr = honors[2];
  189. }else if (score < 96){
  190. graHonorStr = honors[3];
  191. }else if (score < 98){
  192. graHonorStr = honors[4];
  193. }else{
  194. graHonorStr = honors[5];
  195. }
  196. grade.graHonor = graHonorStr;
  197. @strongify(self)
  198. [self.grades addObject:grade];
  199. // [DB_Que_Helper insertGrade:grade];
  200. }
  201. NSSortDescriptor *graDateTimeStampDesc = [NSSortDescriptor sortDescriptorWithKey:@"graDateTimeStamp" ascending:YES];
  202. NSArray *descriptorArray = [NSArray arrayWithObjects:graDateTimeStampDesc, nil];
  203. self.grades = [self.grades sortedArrayUsingDescriptors:descriptorArray].mutableCopy;
  204. [self myInit];//前面为0的时候已经return
  205. }];
  206. }
  207. - (NSMutableArray *)grades {
  208. if (!_grades) {
  209. _grades = @[].mutableCopy;
  210. }
  211. return _grades;
  212. }
  213. @end