RootViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. #import "PDFUtils.h"
  17. @interface RootViewController ()
  18. @end
  19. @implementation RootViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.title= @"eSign";
  23. self.welcomeLabel.text=@"Not sign in";
  24. self.buttonHIC.enabled = false;
  25. self.buttonSRL.enabled = false;
  26. self.coverView.hidden = false;
  27. [self OnSigninClick:self.ibSignin];
  28. // Do any additional setup after loading the view, typically from a nib.
  29. }
  30. -(void) leak_debug
  31. {
  32. CGPDFDocumentRef document = [PDFUtils OpenPDF:@"GEIC - Home Improvement Contract 2017.pdf"];
  33. // self.total_page = CGPDFDocumentGetNumberOfPages (self.document);
  34. NSMutableDictionary * controlTemplate = [self templateInit:[PDFUtils loadControl:@"GEIC - Home Improvement Contract 2017.json"]];
  35. NSString* pdffile = [PDFUtils SavePDF:controlTemplate source:document window_rect:CGRectMake(0, 0, 768, 960)];
  36. CGPDFDocumentRelease(document);
  37. // CFRelease(document);
  38. NSString* zipfile=[ACNetwork prepareUploadFile:pdffile json:controlTemplate];
  39. [self previewPDF:pdffile];
  40. }
  41. -(NSMutableDictionary*) templateInit:(NSMutableDictionary*) template
  42. {
  43. NSString* temp = NSTemporaryDirectory();
  44. NSString* filename =[NSString stringWithFormat:@"%@.png", [[NSUUID UUID] UUIDString]];
  45. NSString* qrpath=[temp stringByAppendingPathComponent:filename];
  46. UIImage* qrimg=[RAUtils generateBarCode:@"leak test" width:300 height:44];//[QRCodeGenerator qrImageForString:order_code imageSize:240];
  47. bool bwrite=[UIImagePNGRepresentation(qrimg)writeToFile: qrpath atomically:YES];
  48. for(int i=0;i<[template[@"count"] intValue];i++)
  49. {
  50. NSMutableDictionary* page =template[[NSString stringWithFormat:@"page_%d",i]];
  51. for(int j=0;j<[page[@"count"] intValue];j++)
  52. {
  53. NSMutableDictionary* control =page[[NSString stringWithFormat:@"control_%d",j]];
  54. NSString* type = control[@"type"];
  55. NSString* field =control[@"field"];
  56. if([type isEqualToString:@"Label"])
  57. {
  58. if([field isEqualToString:@"doc_number"])
  59. {
  60. control[@"value"]= @"leak test";
  61. }
  62. }
  63. else if([type isEqualToString:@"Image"])
  64. {
  65. NSString* name =control[@"name"];
  66. if([name isEqualToString:@"BarCode"])
  67. {
  68. control[@"value"]= qrpath;
  69. }
  70. }
  71. else if([type isEqualToString:@"DatePicker"])
  72. {
  73. NSString* name =control[@"aname"];
  74. if([name isEqualToString:@"Today's Date"])
  75. {
  76. NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
  77. [formatter setDateFormat:@"MM/dd/yyyy"];
  78. NSString* date = [formatter stringFromDate:[NSDate date]] ;
  79. control[@"value"]= date;
  80. }
  81. }
  82. }
  83. }
  84. return template;
  85. }
  86. - (IBAction)onNewCustomerClick:(id)sender {
  87. // [self leak_debug];
  88. // return;
  89. __weak typeof(self) weakSelf = self;
  90. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Create customer"];
  91. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  92. NSMutableDictionary* json=[[ACNetwork new_document] mutableCopy];
  93. dispatch_async(dispatch_get_main_queue(), ^{
  94. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  95. if([json[@"result"] intValue]==RESULT_TRUE)
  96. {
  97. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  98. dvc.templateName = @"GEIC - Home Improvement Contract 2017.json";
  99. dvc.pdfName = @"GEIC - Home Improvement Contract 2017.pdf";
  100. dvc.docment_id = json[@"doc_number"];
  101. dvc.OnSave=^(NSString* file)
  102. {
  103. [weakSelf previewPDF:file];
  104. };
  105. [self.navigationController pushViewController:dvc animated:true];
  106. }
  107. else
  108. {
  109. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Create Customer" controller:self] ;
  110. }
  111. });
  112. });
  113. }
  114. - (IBAction)onCustomerPerDocClick:(id)sender {
  115. DocumentListViewController* docVC =[self.storyboard instantiateViewControllerWithIdentifier:@"DocumentListViewController" ];
  116. [self.navigationController pushViewController:docVC animated:true];
  117. }
  118. - (void)didReceiveMemoryWarning {
  119. [super didReceiveMemoryWarning];
  120. // Dispose of any resources that can be recreated.
  121. }
  122. - (IBAction)OnSigninClick:(id)sender {
  123. UIBarButtonItem* bbitem = sender;
  124. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  125. if(appDelegate.bLogin)
  126. {
  127. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to sign out?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  128. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  129. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Sign out"];
  130. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  131. NSDictionary* logout_json = nil;
  132. logout_json = [ACNetwork logout];
  133. dispatch_async(dispatch_get_main_queue(), ^{
  134. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  135. if([[logout_json valueForKey:@"result"] intValue]==2)
  136. {
  137. self.welcomeLabel.text=@"Not sign in";
  138. // [sender setTitle:@"Sign in" forState:UIControlStateNormal];
  139. [bbitem setTitle:@"Sign in"];
  140. self.buttonHIC.enabled = false;
  141. self.buttonSRL.enabled = false;
  142. self.coverView.hidden = false;
  143. }
  144. else
  145. {
  146. [RAUtils message_alert:[logout_json valueForKey:@"err_msg"] title:@"Sign out" controller:self] ;
  147. }
  148. });
  149. });
  150. }];
  151. // [alertControl addAction:actionOne];
  152. [alertControl addAction:alertthree];
  153. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  154. }];
  155. [alertControl addAction:alertcancel];
  156. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  157. [self presentViewController:alertControl animated:YES completion:nil];
  158. }
  159. else
  160. {
  161. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  162. loginvc.returnValue = ^(bool blogin){
  163. // [self checklogin :true];
  164. if(blogin)
  165. {
  166. self.welcomeLabel.text=[NSString stringWithFormat:@"Welcome %@",appDelegate.user];
  167. [bbitem setTitle:@"Sign out"];
  168. self.buttonHIC.enabled = true;
  169. self.buttonSRL.enabled = true;
  170. self.coverView.hidden = true;
  171. }
  172. else
  173. {
  174. self.welcomeLabel.text=@"Not sign in";
  175. self.buttonHIC.enabled = false;
  176. self.buttonSRL.enabled = false;
  177. self.coverView.hidden = false;
  178. }
  179. };
  180. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  181. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  182. [self presentViewController:navi animated:YES completion:^{
  183. DebugLog(@"login present.........");
  184. }];
  185. }
  186. }
  187. -(void) previewPDF:(NSString*)file
  188. {
  189. NSString* name=@"";//[self.content_data[indexPath.row] valueForKey:@"tear_name"];
  190. NSString* url= file;//[self.content_data[indexPath.row] valueForKey:@"pdf_path"];
  191. bool isLocalFile= true;//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"];
  192. PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
  193. ViewController.url = url;
  194. ViewController.canSave = false;
  195. ViewController.isLocalfile=isLocalFile;
  196. ViewController.defaultStyle = true;
  197. NSString* subject;
  198. // if (company.length==0) {
  199. NSString* cur_time =[RAUtils current_date];
  200. subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  201. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  202. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  203. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  204. // if(customer_email.length>0)
  205. // {
  206. // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  207. // // customer_email compo
  208. // // [send_to addObject:customer_email];
  209. // }
  210. ViewController.mail_to = send_to;
  211. // }
  212. // else
  213. // {
  214. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  215. // }
  216. // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  217. ViewController.mail_subject = subject;
  218. ViewController.hidenavi = false;
  219. [self.navigationController pushViewController:ViewController animated:YES];
  220. }
  221. - (IBAction)OnHICClick:(id)sender {
  222. __weak typeof(self) weakSelf = self;
  223. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  224. dvc.templateName = @"GEIC - Home Improvement Contract 2016.json";
  225. dvc.pdfName = @"GEIC - Home Improvement Contract 2017.pdf";
  226. dvc.OnSave=^(NSString* file)
  227. {
  228. // [weakSelf previewPDF:file];
  229. };
  230. [self.navigationController pushViewController:dvc animated:true];
  231. }
  232. - (IBAction)OnSRLClick:(id)sender {
  233. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  234. dvc.templateName = @"SUBCONTRACTORS REFERRAL LIST.json";
  235. dvc.pdfName = @"SUBCONTRACTORS REFERRAL LIST.pdf";
  236. dvc.OnSave=^(NSString* file)
  237. {
  238. //[self previewPDF:file];
  239. };
  240. [self.navigationController pushViewController:dvc animated:true];
  241. }
  242. @end