RootViewController.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. //
  2. // ViewController.m
  3. // AntsContract
  4. //
  5. // Created by Ray on 12/16/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RootViewController.h"
  9. #import "DocumentPageViewController.h"
  10. #import "LoginViewController.h"
  11. #import "AppDelegate.h"
  12. #import "RAUtils.h"
  13. #import "PDFViewController.h"
  14. @interface RootViewController ()
  15. @end
  16. @implementation RootViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.title= @"eSign";
  20. self.welcomeLabel.text=@"Not sign in";
  21. self.buttonHIC.enabled = false;
  22. self.buttonSRL.enabled = false;
  23. self.coverView.hidden = false;
  24. [self OnSigninClick:self.ibSignin];
  25. // Do any additional setup after loading the view, typically from a nib.
  26. }
  27. - (void)didReceiveMemoryWarning {
  28. [super didReceiveMemoryWarning];
  29. // Dispose of any resources that can be recreated.
  30. }
  31. - (IBAction)OnSigninClick:(id)sender {
  32. UIBarButtonItem* bbitem = sender;
  33. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  34. if(appDelegate.bLogin)
  35. {
  36. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to sign out?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  37. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  38. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Sign out"];
  39. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  40. NSDictionary* logout_json = nil;
  41. logout_json = [ACNetwork logout];
  42. dispatch_async(dispatch_get_main_queue(), ^{
  43. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  44. if([[logout_json valueForKey:@"result"] intValue]==2)
  45. {
  46. self.welcomeLabel.text=@"Not sign in";
  47. // [sender setTitle:@"Sign in" forState:UIControlStateNormal];
  48. [bbitem setTitle:@"Sign in"];
  49. self.buttonHIC.enabled = false;
  50. self.buttonSRL.enabled = false;
  51. self.coverView.hidden = false;
  52. }
  53. else
  54. {
  55. [RAUtils message_alert:[logout_json valueForKey:@"err_msg"] title:@"Sign out" controller:self] ;
  56. }
  57. });
  58. });
  59. }];
  60. // [alertControl addAction:actionOne];
  61. [alertControl addAction:alertthree];
  62. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  63. }];
  64. [alertControl addAction:alertcancel];
  65. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  66. [self presentViewController:alertControl animated:YES completion:nil];
  67. }
  68. else
  69. {
  70. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  71. loginvc.returnValue = ^(bool blogin){
  72. // [self checklogin :true];
  73. if(blogin)
  74. {
  75. self.welcomeLabel.text=[NSString stringWithFormat:@"Welcome %@",appDelegate.user];
  76. [bbitem setTitle:@"Sign out"];
  77. self.buttonHIC.enabled = true;
  78. self.buttonSRL.enabled = true;
  79. self.coverView.hidden = true;
  80. }
  81. else
  82. {
  83. self.welcomeLabel.text=@"Not sign in";
  84. self.buttonHIC.enabled = false;
  85. self.buttonSRL.enabled = false;
  86. self.coverView.hidden = false;
  87. }
  88. };
  89. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  90. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  91. [self presentViewController:navi animated:YES completion:^{
  92. DebugLog(@"login present.........");
  93. }];
  94. }
  95. }
  96. -(void) previewPDF:(NSString*)file
  97. {
  98. NSString* name=@"";//[self.content_data[indexPath.row] valueForKey:@"tear_name"];
  99. NSString* url= file;//[self.content_data[indexPath.row] valueForKey:@"pdf_path"];
  100. NSString* isLocalFile= @"true";//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"];
  101. PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
  102. ViewController.url = url;
  103. ViewController.canSave = false;
  104. ViewController.isLocalfile=isLocalFile;
  105. ViewController.defaultStyle = true;
  106. NSString* subject;
  107. // if (company.length==0) {
  108. NSString* cur_time =[RAUtils current_date];
  109. subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  110. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  111. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  112. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  113. // if(customer_email.length>0)
  114. // {
  115. // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  116. // // customer_email compo
  117. // // [send_to addObject:customer_email];
  118. // }
  119. ViewController.mail_to = send_to;
  120. // }
  121. // else
  122. // {
  123. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  124. // }
  125. ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  126. ViewController.mail_subject = subject;
  127. ViewController.hidenavi = false;
  128. [self.navigationController pushViewController:ViewController animated:YES];
  129. }
  130. - (IBAction)OnHICClick:(id)sender {
  131. __weak typeof(self) weakSelf = self;
  132. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  133. dvc.templateName = @"GEIC - Home Improvement Contract 2016.json";
  134. dvc.pdfName = @"GEIC - Home Improvement Contract 2017.pdf";
  135. dvc.OnSave=^(NSString* file)
  136. {
  137. [weakSelf previewPDF:file];
  138. };
  139. [self.navigationController pushViewController:dvc animated:true];
  140. }
  141. - (IBAction)OnSRLClick:(id)sender {
  142. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  143. dvc.templateName = @"SUBCONTRACTORS REFERRAL LIST.json";
  144. dvc.pdfName = @"SUBCONTRACTORS REFERRAL LIST.pdf";
  145. dvc.OnSave=^(NSString* file)
  146. {
  147. //[self previewPDF:file];
  148. };
  149. [self.navigationController pushViewController:dvc animated:true];
  150. }
  151. @end