RootViewController.m 15 KB

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