RootViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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 = @"debug.json";
  99. dvc.templateName = @"GEIC - Home Improvement Contract 2017.json";
  100. dvc.pdfName = @"GEIC - Home Improvement Contract 2017.pdf";
  101. dvc.docment_id = json[@"doc_number"];
  102. dvc.OnSave=^(NSString* file)
  103. {
  104. [weakSelf previewPDF:file];
  105. };
  106. [self.navigationController pushViewController:dvc animated:true];
  107. }
  108. else
  109. {
  110. [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Create Customer" controller:self] ;
  111. }
  112. });
  113. });
  114. }
  115. - (IBAction)onCustomerPerDocClick:(id)sender {
  116. DocumentListViewController* docVC =[self.storyboard instantiateViewControllerWithIdentifier:@"DocumentListViewController" ];
  117. [self.navigationController pushViewController:docVC animated:true];
  118. }
  119. - (void)didReceiveMemoryWarning {
  120. [super didReceiveMemoryWarning];
  121. // Dispose of any resources that can be recreated.
  122. }
  123. - (IBAction)OnSigninClick:(id)sender {
  124. UIBarButtonItem* bbitem = sender;
  125. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  126. if(appDelegate.bLogin)
  127. {
  128. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to sign out?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  129. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  130. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Sign out"];
  131. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  132. NSDictionary* logout_json = nil;
  133. logout_json = [ACNetwork logout];
  134. dispatch_async(dispatch_get_main_queue(), ^{
  135. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  136. if([[logout_json valueForKey:@"result"] intValue]==2)
  137. {
  138. self.welcomeLabel.text=@"Not sign in";
  139. // [sender setTitle:@"Sign in" forState:UIControlStateNormal];
  140. [bbitem setTitle:@"Sign in"];
  141. self.buttonHIC.enabled = false;
  142. self.buttonSRL.enabled = false;
  143. self.coverView.hidden = false;
  144. }
  145. else
  146. {
  147. [RAUtils message_alert:[logout_json valueForKey:@"err_msg"] title:@"Sign out" controller:self] ;
  148. }
  149. });
  150. });
  151. }];
  152. // [alertControl addAction:actionOne];
  153. [alertControl addAction:alertthree];
  154. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  155. }];
  156. [alertControl addAction:alertcancel];
  157. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  158. [self presentViewController:alertControl animated:YES completion:nil];
  159. }
  160. else
  161. {
  162. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  163. loginvc.returnValue = ^(bool blogin){
  164. // [self checklogin :true];
  165. if(blogin)
  166. {
  167. self.welcomeLabel.text=[NSString stringWithFormat:@"Welcome %@",appDelegate.user];
  168. [bbitem setTitle:@"Sign out"];
  169. self.buttonHIC.enabled = true;
  170. self.buttonSRL.enabled = true;
  171. self.coverView.hidden = true;
  172. }
  173. else
  174. {
  175. self.welcomeLabel.text=@"Not sign in";
  176. self.buttonHIC.enabled = false;
  177. self.buttonSRL.enabled = false;
  178. self.coverView.hidden = false;
  179. }
  180. };
  181. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  182. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  183. [self presentViewController:navi animated:YES completion:^{
  184. DebugLog(@"login present.........");
  185. }];
  186. }
  187. }
  188. -(void) previewPDF:(NSString*)file
  189. {
  190. // return;
  191. NSString* name=@"";//[self.content_data[indexPath.row] valueForKey:@"tear_name"];
  192. NSString* url= file;//[self.content_data[indexPath.row] valueForKey:@"pdf_path"];
  193. bool isLocalFile= true;//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"];
  194. PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
  195. ViewController.url = url;
  196. ViewController.canSave = false;
  197. ViewController.isLocalfile=isLocalFile;
  198. ViewController.defaultStyle = true;
  199. NSString* subject;
  200. // if (company.length==0) {
  201. NSString* cur_time =[RAUtils current_date];
  202. subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  203. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  204. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  205. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  206. // if(customer_email.length>0)
  207. // {
  208. // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  209. // // customer_email compo
  210. // // [send_to addObject:customer_email];
  211. // }
  212. ViewController.mail_to = send_to;
  213. // }
  214. // else
  215. // {
  216. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  217. // }
  218. // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  219. ViewController.mail_subject = subject;
  220. ViewController.hidenavi = false;
  221. [self.navigationController pushViewController:ViewController animated:YES];
  222. }
  223. - (IBAction)OnHICClick:(id)sender {
  224. __weak typeof(self) weakSelf = self;
  225. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  226. dvc.templateName = @"GEIC - Home Improvement Contract 2016.json";
  227. dvc.pdfName = @"GEIC - Home Improvement Contract 2017.pdf";
  228. dvc.OnSave=^(NSString* file)
  229. {
  230. // [weakSelf previewPDF:file];
  231. };
  232. [self.navigationController pushViewController:dvc animated:true];
  233. }
  234. - (IBAction)OnSRLClick:(id)sender {
  235. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  236. dvc.templateName = @"SUBCONTRACTORS REFERRAL LIST.json";
  237. dvc.pdfName = @"SUBCONTRACTORS REFERRAL LIST.pdf";
  238. dvc.OnSave=^(NSString* file)
  239. {
  240. //[self previewPDF:file];
  241. };
  242. [self.navigationController pushViewController:dvc animated:true];
  243. }
  244. @end