RootViewController.m 9.4 KB

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