RootViewController.m 19 KB

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