RootViewController.m 13 KB

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