PageRenderTime 65ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/PR3PartPacingViewController.m

https://bitbucket.org/zayar/smqv2
Objective C | 278 lines | 140 code | 33 blank | 105 comment | 14 complexity | 97cfa24fd242a4ed34049e97c6409a4b MD5 | raw file
  1. //
  2. // PR3PartPacingViewController.m
  3. // zBox
  4. //
  5. // Created by Zayar on 5/9/13.
  6. //
  7. //
  8. #import "PR3PartPacingViewController.h"
  9. #import "ObjSubject.h"
  10. #import "ObjPacing.h"
  11. #import "StringTable.h"
  12. #import "ObjSessionDetail.h"
  13. #import "ObjSubSession.h"
  14. #import "ObjThreePartPacing.h"
  15. #import "zBoxAppDelegate.h"
  16. #import "SOAPRequest.h"
  17. //---size of keyboard---
  18. CGRect keyboardBounds;
  19. //---size of application screen---
  20. CGRect applicationFrame;
  21. //---original size of ScrollView---
  22. CGSize scrollViewOriginalSize;
  23. @interface PR3PartPacingViewController ()
  24. @end
  25. @implementation PR3PartPacingViewController
  26. @synthesize objSession,objSubject;
  27. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  28. {
  29. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  30. if (self) {
  31. // Custom initialization
  32. }
  33. return self;
  34. }
  35. - (void)viewDidLoad
  36. {
  37. [super viewDidLoad];
  38. // Do any additional setup after loading the view from its nib.
  39. NSString * strPath = [NSString stringWithFormat:@"%@/img_vs_bg.png", [[NSBundle mainBundle] resourcePath]];
  40. UIImage * imgBg = [[UIImage alloc] initWithContentsOfFile:strPath];
  41. [imgBgView setImage:imgBg];
  42. [imgBgView release];
  43. }
  44. - (void)viewWillAppear:(BOOL)animated{
  45. [self loadThe3PartView:objSession];
  46. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:self.view.window];
  47. [[NSNotificationCenter defaultCenter] addObserver:self
  48. selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  49. }
  50. //keyboard appear
  51. -(void) keyboardWillShow:(NSNotification *) notification {
  52. //---gets the size of the keyboard---
  53. NSDictionary *userInfo = [notification userInfo];
  54. NSValue *keyboardValue = [userInfo objectForKey:UIKeyboardBoundsUserInfoKey];
  55. [keyboardValue getValue:&keyboardBounds];
  56. }
  57. -(void) keyboardWillHide:(NSNotification *) notification {
  58. }
  59. -(void) textFieldDidBeginEditing:(UITextField *)textFieldView {
  60. [self moveScrollView:textFieldView];
  61. }
  62. -(void) textFieldDidEndEditing:(UITextField *) textFieldView {
  63. [UIView beginAnimations:@"back to original size" context:nil];
  64. scrollView.contentSize = scrollViewOriginalSize;
  65. [UIView commitAnimations];
  66. }
  67. -(void) moveScrollView:(UIView *) theView {
  68. //---scroll the ScrollView---
  69. [scrollView setContentOffset:CGPointMake(0, 216) animated:YES];
  70. }
  71. - (void) moveScrollViewDown:(UIView*) view {
  72. [scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
  73. }
  74. - (IBAction)onBack:(id)sender{
  75. [self dismissModalViewControllerAnimated:YES];
  76. }
  77. - (void)loadThe3PartView:(ObjSubSession *)obj{
  78. NSLog(@"arr pacing count %d",[objSubject.arrPacing count]);
  79. ObjSessionDetail * objSecDetail = [obj.arrSessionDetail objectAtIndex:0];
  80. ObjThreePartPacing * objThreeP = objSecDetail.objThreePartPacing;
  81. /*ObjSessionOther * objSessionOther = objSecDetail.objSessionOther;
  82. if ([objSubject.arrPacing count]>0) {
  83. NSMutableArray * arrAlertTopic=nil;
  84. NSMutableArray * arrGoodTopic =nil;
  85. NSMutableArray * arrMedioTopic=nil;
  86. for (ObjPacing * objPac in obj.arrPacing) {
  87. if ([objPac.strPacingValue isEqualToString:PROGRESS_STATUS_GOOD]) {
  88. if (arrGoodTopic == nil) {
  89. arrGoodTopic = [[NSMutableArray alloc]init];
  90. }
  91. [arrGoodTopic addObject:objPac];
  92. }
  93. else if ([objPac.strPacingValue isEqualToString:PROGRESS_STATUS_ALERT]) {
  94. if (arrAlertTopic == nil) {
  95. arrAlertTopic = [[NSMutableArray alloc]init];
  96. }
  97. [arrAlertTopic addObject:objPac];
  98. }
  99. else if ([objPac.strPacingValue isEqualToString:PROGRESS_STATUS_MEDIOCRE]) {
  100. if (arrMedioTopic == nil) {
  101. arrMedioTopic = [[NSMutableArray alloc]init];
  102. }
  103. [arrMedioTopic addObject:objPac];
  104. }
  105. }
  106. if([arrAlertTopic count]>0){
  107. int y=0;
  108. int i=0;
  109. for(ObjPacing * objPac in arrAlertTopic){
  110. UILabel * lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, y, scrollAlert.frame.size.width, 30)];
  111. if(i%2 == 0){
  112. lbl.backgroundColor = [UIColor lightGrayColor];
  113. }
  114. else{
  115. lbl.backgroundColor = [UIColor whiteColor];
  116. }
  117. lbl.text = objPac.strTopicName;
  118. lbl.font = [UIFont systemFontOfSize:13];
  119. [scrollAlert addSubview:lbl];
  120. y += lbl.frame.size.height;
  121. i++;
  122. [lbl release];
  123. }
  124. }
  125. if([arrGoodTopic count]>0){
  126. int y=0;
  127. int i=0;
  128. for(ObjPacing * objPac in arrGoodTopic){
  129. UILabel * lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, y, scrollGood.frame.size.width, 30)];
  130. if(i%2 == 0){
  131. lbl.backgroundColor = [UIColor lightGrayColor];
  132. }
  133. else{
  134. lbl.backgroundColor = [UIColor whiteColor];
  135. }
  136. lbl.text = objPac.strTopicName;
  137. lbl.font = [UIFont systemFontOfSize:13];
  138. [scrollGood addSubview:lbl];
  139. y += lbl.frame.size.height;
  140. i++;
  141. [lbl release];
  142. }
  143. }
  144. if([arrMedioTopic count]>0){
  145. int y=0;
  146. int i=0;
  147. for(ObjPacing * objPac in arrMedioTopic){
  148. UILabel * lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, y, scrollMediocre.frame.size.width, 30)];
  149. if(i%2 == 0){
  150. lbl.backgroundColor = [UIColor lightGrayColor];
  151. }
  152. else{
  153. lbl.backgroundColor = [UIColor whiteColor];
  154. }
  155. lbl.text = objPac.strTopicName;
  156. lbl.font = [UIFont systemFontOfSize:13];
  157. [scrollMediocre addSubview:lbl];
  158. y += lbl.frame.size.height;
  159. i++;
  160. [lbl release];
  161. }
  162. }
  163. }*/
  164. if (objThreeP.strObjective == nil) {
  165. lblObjectiveScore.text = [NSString stringWithFormat:@"%s", "70"];
  166. } else {
  167. lblObjectiveScore.text = [NSString stringWithFormat:@"%@", objThreeP.strObjective];
  168. }
  169. lblEastimateScore.text = [NSString stringWithFormat:@"%@",objThreeP.strEstimatedScore];
  170. NSString *goodString = objThreeP.strGood;
  171. goodString = [goodString stringByReplacingOccurrencesOfString:@","
  172. withString:@"\n\n"];
  173. lblGood.text = goodString;
  174. [lblGood sizeToFit];
  175. NSString *mediocreString = objThreeP.strMediocre;
  176. mediocreString = [mediocreString stringByReplacingOccurrencesOfString:@","
  177. withString:@"\n\n"];
  178. lblMedicro.text = mediocreString;
  179. [lblMedicro sizeToFit];
  180. NSString *alertString = objThreeP.strAlert;
  181. alertString = [alertString stringByReplacingOccurrencesOfString:@"," withString:@"\n\n"];
  182. lblAlert.text = alertString;
  183. [lblAlert sizeToFit];
  184. }
  185. - (void)didReceiveMemoryWarning
  186. {
  187. [super didReceiveMemoryWarning];
  188. // Dispose of any resources that can be recreated.
  189. }
  190. - (IBAction)updateScore:(id)sender {
  191. zBoxAppDelegate * delegate = [[UIApplication sharedApplication]delegate];
  192. [delegate showLoadingScreen];
  193. SOAPRequest* objScoreRequest = [[SOAPRequest alloc] initWithOwner:self];
  194. objScoreRequest.processId = 4;
  195. NSString * score = lblObjectiveScore.text;
  196. score = [score stringByReplacingOccurrencesOfString:@"%" withString:@""];
  197. [objScoreRequest syncSubmitObjectiveScore:score withProgressReportId:@"1"];
  198. [lblObjectiveScore resignFirstResponder];
  199. [self moveScrollViewDown:self.view];
  200. }
  201. - (void) onJsonLoaded:(NSMutableDictionary *)dics withProcessId:(int)processId{
  202. zBoxAppDelegate * delegate =[[UIApplication sharedApplication]delegate];
  203. if (processId == 4) {
  204. [delegate hideLoadingScreen];
  205. NSLog(@"arr count %d",[dics count]);
  206. int status = [[dics objectForKey:@"status"] intValue];
  207. NSString * strMessage;
  208. if (status == STATUS_ACTION_SUCCESS) {
  209. strMessage = [dics objectForKey:@"message"];
  210. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:APP_TITLE message:strMessage delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
  211. [alert show];
  212. [alert release];
  213. }
  214. else if(status == STATUS_ACTION_FAILED){
  215. strMessage = [dics objectForKey:@"message"];
  216. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:APP_TITLE message:strMessage delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
  217. [alert show];
  218. [alert release];
  219. }
  220. else if(status == STATUS_SESSION_EXPIRED){
  221. strMessage = [dics objectForKey:@"message"];
  222. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:APP_TITLE message:strMessage delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
  223. [alert show];
  224. [alert release];
  225. }
  226. }
  227. }
  228. - (void)dealloc{
  229. [lblGood release];
  230. [lblMedicro release];
  231. [lblAlert release];
  232. [lblObjectiveScore release];
  233. [imgBgView release];
  234. [lblTitle release];
  235. [objSession release];
  236. [objSubject release];
  237. [super dealloc];
  238. }
  239. @end