RootViewController.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  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 "RAPDFViewController.h"
  14. #import "DocumentListViewController.h"
  15. #import "PendingDocumentsViewController.h"
  16. #import "RANetwork.h"
  17. #import "PDFUtils.h"
  18. #import "AddExtDocumentViewController.h"
  19. #import "config.h"
  20. #import "DocumentTemplateViewController.h"
  21. #import "WebViewController.h"
  22. @interface RootViewController ()
  23. @property (nonatomic,assign) BOOL hasShowLoginView;
  24. @end
  25. @implementation RootViewController
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. self.title= @"eSign";
  29. self.welcomeLabel.text=@"Not sign in";
  30. self.buttonHIC.enabled = false;
  31. self.buttonSRL.enabled = false;
  32. self.coverView.hidden = false;
  33. [self reloadBG];
  34. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  35. NSString* build =[infoDict objectForKey:@"CFBundleVersion"];
  36. NSString* version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  37. NSString* versionNum = [NSString stringWithFormat:@"VeS1.%@.%@",version,build];
  38. self.labelVer.text = versionNum;
  39. self.debugBtn.hidden = !DEBUG_PDFSIG;
  40. // Do any additional setup after loading the view, typically from a nib.
  41. }
  42. - (NSInteger)loadDocCount {
  43. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  44. NSArray *docArr = [defaults arrayForKey:@"pending_doc"];
  45. if (docArr) {
  46. return docArr.count;
  47. }
  48. return 0;
  49. }
  50. -(void) viewDidAppear:(BOOL)animated
  51. {
  52. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  53. if(appDelegate.accessMode == AppAccessModeOnline)
  54. {
  55. self.labelMode.text = @"Mode: Online";
  56. [self.switchMode setOn:true];
  57. self.navigationItem.rightBarButtonItem = self.ibSignin;
  58. }
  59. else
  60. {
  61. self.labelMode.text = @"Mode: Offline";
  62. [self.switchMode setOn:false];
  63. self.navigationItem.rightBarButtonItem = nil;
  64. }
  65. if(!appDelegate.bLogin)
  66. [self presentLogin:self.ibSignin];
  67. NSInteger docCount = [self loadDocCount];
  68. if (docCount > 0) {
  69. self.labelDocNumber.hidden = NO;
  70. self.labelDocNumber.text = [NSString stringWithFormat:@"%ld",docCount];
  71. } else {
  72. self.labelDocNumber.hidden = YES;
  73. self.labelDocNumber.text = [NSString stringWithFormat:@""];
  74. }
  75. }
  76. -(void) presentLogin:(id)sender
  77. {
  78. // 确保只Presnet LoginView一次.
  79. if (self.hasShowLoginView) return;
  80. self.hasShowLoginView = YES;
  81. UIBarButtonItem* bbitem = sender;
  82. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  83. {
  84. LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  85. loginvc.returnValue = ^(bool blogin){
  86. // [self checklogin :true];
  87. self.hasShowLoginView = NO;
  88. if(blogin)
  89. {
  90. self.welcomeLabel.text=[NSString stringWithFormat:@"Welcome %@",appDelegate.user];
  91. [bbitem setTitle:@"Sign out"];
  92. self.buttonHIC.enabled = true;
  93. self.buttonSRL.enabled = true;
  94. self.coverView.hidden = true;
  95. // 处理三方app 传入文件
  96. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  97. if(appDelegate.shareFile)
  98. {
  99. AddExtDocumentViewController * addVC;
  100. addVC = [ [UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"AddExtDocumentViewController"];
  101. addVC.is_present = true;
  102. addVC.doc_number = nil;
  103. addVC.arr_documents = [NSMutableArray arrayWithObjects:appDelegate.shareFile, nil];
  104. appDelegate.shareFile=nil;
  105. // notesVC.docNotes = notes;
  106. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:addVC] ;
  107. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  108. [self presentViewController:navi animated:YES completion:^{
  109. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  110. DebugLog(@"filter present.........");
  111. // self.btop = false;
  112. // <#code#>
  113. }];
  114. }
  115. }
  116. else
  117. {
  118. appDelegate.shareFile=nil;
  119. self.welcomeLabel.text=@"Not sign in";
  120. self.buttonHIC.enabled = false;
  121. self.buttonSRL.enabled = false;
  122. self.coverView.hidden = false;
  123. }
  124. };
  125. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  126. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  127. [self presentViewController:navi animated:YES completion:^{
  128. DebugLog(@"login present.........");
  129. }];
  130. }
  131. }
  132. //-(void) leak_debug
  133. //{
  134. //
  135. //
  136. // CGPDFDocumentRef document = [PDFUtils OpenPDF:@"GEIC - Home Improvement Contract 2017.pdf"];
  137. // // self.total_page = CGPDFDocumentGetNumberOfPages (self.document);
  138. //
  139. // NSMutableDictionary * controlTemplate = [self templateInit:[PDFUtils loadControl:@"GEIC - Home Improvement Contract 2017.json"]];
  140. //
  141. //
  142. // NSString* pdffile = [PDFUtils SavePDF:controlTemplate source:document window_rect:CGRectMake(0, 0, 768, 960)];
  143. //
  144. // CGPDFDocumentRelease(document);
  145. //
  146. // // CFRelease(document);
  147. //
  148. // NSString* zipfile=[ACNetwork prepareUploadFile:pdffile json:controlTemplate];
  149. //
  150. // [self previewPDF:pdffile];
  151. //
  152. //
  153. //
  154. //
  155. //
  156. //
  157. //}
  158. //-(NSMutableDictionary*) templateInit:(NSMutableDictionary*) template
  159. //{
  160. //
  161. //
  162. // NSString* temp = NSTemporaryDirectory();
  163. // NSString* filename =[NSString stringWithFormat:@"%@.png", [[NSUUID UUID] UUIDString]];
  164. // NSString* qrpath=[temp stringByAppendingPathComponent:filename];
  165. // UIImage* qrimg=[RAUtils generateBarCode:@"leak test" width:300 height:44];//[QRCodeGenerator qrImageForString:order_code imageSize:240];
  166. // bool bwrite=[UIImagePNGRepresentation(qrimg)writeToFile: qrpath atomically:YES];
  167. //
  168. //
  169. //
  170. // for(int i=0;i<[template[@"count"] intValue];i++)
  171. // {
  172. // NSMutableDictionary* page =template[[NSString stringWithFormat:@"page_%d",i]];
  173. // for(int j=0;j<[page[@"count"] intValue];j++)
  174. // {
  175. // NSMutableDictionary* control =page[[NSString stringWithFormat:@"control_%d",j]];
  176. // NSString* type = control[@"type"];
  177. // NSString* field =control[@"field"];
  178. // if([type isEqualToString:@"Label"])
  179. // {
  180. // if([field isEqualToString:@"doc_number"])
  181. // {
  182. // control[@"value"]= @"leak test";
  183. // }
  184. // }
  185. // else if([type isEqualToString:@"Image"])
  186. // {
  187. // NSString* name =control[@"name"];
  188. // if([name isEqualToString:@"BarCode"])
  189. // {
  190. // if(bwrite)
  191. // control[@"value"]= qrpath;
  192. // }
  193. // }
  194. // else if([type isEqualToString:@"DatePicker"])
  195. // {
  196. // NSString* name =control[@"aname"];
  197. // if([name isEqualToString:@"Today's Date"])
  198. // {
  199. // NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
  200. // [formatter setDateFormat:@"MM/dd/yyyy"];
  201. // NSString* date = [formatter stringFromDate:[NSDate date]] ;
  202. //
  203. // control[@"value"]= date;
  204. // }
  205. // }
  206. // }
  207. // }
  208. // return template;
  209. //}
  210. - (IBAction)onNewCustomerClick:(id)sender {
  211. // [self leak_debug];
  212. // return;
  213. __weak typeof(self) weakSelf = self;
  214. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  215. if(appDelegate.accessMode == AppAccessModeOffline)
  216. {
  217. __block NSString* offline_docnumber =[RANetwork offline_docnumber];
  218. if(offline_docnumber==nil)
  219. {
  220. [RAUtils message_alert:@"Offline document number prefix not found, Please check your user name and make sure you had signed in at least once." title:@"Create Customer" controller:self] ;
  221. return;
  222. }
  223. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  224. // dvc.templateName = @"debug.json";
  225. dvc.templatePath = [[NSBundle mainBundle] pathForResource:@"2021 GECI - Home Improvement Contract.json" ofType:nil];
  226. dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  227. dvc.docment_id = offline_docnumber;
  228. dvc.OnSave=^(NSString* file, NSString* subject)
  229. {
  230. [weakSelf previewPDF:file title:offline_docnumber subject:subject];
  231. };
  232. [self.navigationController pushViewController:dvc animated:true];
  233. }
  234. else
  235. {
  236. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Create customer"];
  237. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create customer" completion:^{
  238. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  239. NSMutableDictionary* json=[[RANetwork new_document] mutableCopy];
  240. dispatch_async(dispatch_get_main_queue(), ^{
  241. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  242. [waitalert dismissViewControllerAnimated:YES completion:^{
  243. if([json[@"result"] intValue]==RESULT_TRUE)
  244. {
  245. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  246. // dvc.templateName = @"debug.json";
  247. dvc.templatePath = [[NSBundle mainBundle] pathForResource:@"2021 GECI - Home Improvement Contract.json" ofType:nil];
  248. dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  249. dvc.docment_id = json[@"doc_number"];
  250. dvc.OnSave=^(NSString* file, NSString* subject)
  251. {
  252. [weakSelf previewPDF:file title:json[@"doc_number"] subject:subject];
  253. };
  254. [self.navigationController pushViewController:dvc animated:true];
  255. }
  256. else
  257. {
  258. // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Create Customer" controller:self] ;
  259. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Create Customer" message:@"Can not create new customer on server, do you want to create an offline document?" preferredStyle:UIAlertControllerStyleAlert];
  260. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  261. __block NSString* offline_docnumber =[RANetwork offline_docnumber];
  262. if(offline_docnumber==nil)
  263. {
  264. [RAUtils message_alert:@"Offline document number prefix not found, Please check your user name and make sure you had signed in at least once." title:@"Create Customer" controller:self] ;
  265. return;
  266. }
  267. [appDelegate SwitchToOffline:appDelegate.user];
  268. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  269. // dvc.templateName = @"debug.json";
  270. dvc.templatePath = [[NSBundle mainBundle] pathForResource:@"2021 GECI - Home Improvement Contract.json" ofType:nil];
  271. dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  272. dvc.docment_id = offline_docnumber;
  273. dvc.OnSave=^(NSString* file, NSString* subject)
  274. {
  275. [weakSelf previewPDF:file title:offline_docnumber subject:subject];
  276. };
  277. [self.navigationController pushViewController:dvc animated:true];
  278. }];
  279. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  280. DebugLog(@"Cancel");
  281. }];
  282. [alertControl addAction:actionOne];
  283. [alertControl addAction:alertthree];
  284. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  285. [self presentViewController:alertControl animated:YES completion:nil];
  286. }
  287. }];
  288. });
  289. });
  290. }];
  291. }
  292. }
  293. - (IBAction)onCustomerPerDocClick:(id)sender {
  294. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  295. if(appDelegate.accessMode == AppAccessModeOffline)
  296. {
  297. [RAUtils message_alert:@"You can only access this function onder online mode." title:@"Offline mode." controller:self];
  298. return;
  299. }
  300. DocumentListViewController* docVC =[self.storyboard instantiateViewControllerWithIdentifier:@"DocumentListViewController" ];
  301. [self.navigationController pushViewController:docVC animated:true];
  302. }
  303. - (IBAction)onPendingDocClick:(id)sender {
  304. PendingDocumentsViewController* docVC =[self.storyboard instantiateViewControllerWithIdentifier:@"PendingDocumentsViewController" ];
  305. [self.navigationController pushViewController:docVC animated:true];
  306. }
  307. - (IBAction)onModeSwitch:(id)sender {
  308. UISwitch* sw = sender;
  309. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  310. NSString * user = [AESCrypt decrypt:[defaults stringForKey:@"user"] password:@"usai"];
  311. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  312. if(sw.isOn)
  313. {
  314. self.navigationItem.rightBarButtonItem = self.ibSignin;
  315. self.labelMode.text = @"Mode: Online";
  316. [appDelegate Logout];
  317. [self.ibSignin setTitle:@"Sign in"];
  318. [self presentLogin:self.ibSignin];
  319. //
  320. // [self.switchMode setOn:true];
  321. }
  322. else
  323. {
  324. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Enter user name for offline mode." message:nil preferredStyle:UIAlertControllerStyleAlert];
  325. [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  326. textField.text = user;
  327. textField.keyboardType=UIKeyboardTypeDefault;
  328. textField.delegate = nil;
  329. }];
  330. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  331. UITextField *name = alertControl.textFields.firstObject;
  332. if(name.text.length==0)
  333. {
  334. self.navigationItem.rightBarButtonItem = self.ibSignin;
  335. [sw setOn: true];
  336. [RAUtils message_alert:@"User name is required." title:@"Can not switch to offline mode." controller:self];
  337. }
  338. else
  339. {
  340. self.navigationItem.rightBarButtonItem = nil;
  341. self.labelMode.text = @"Mode: Offline";
  342. [appDelegate SwitchToOffline:name.text];
  343. self.welcomeLabel.text=[NSString stringWithFormat:@"Welcome %@",appDelegate.user];
  344. self.coverView.hidden = true;
  345. }
  346. }];
  347. // [alertControl addAction:actionOne];
  348. [alertControl addAction:alertthree];
  349. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  350. [sw setOn: true];
  351. }];
  352. [alertControl addAction:alertcancel];
  353. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  354. [self presentViewController:alertControl animated:YES completion:nil];
  355. // [self.switchMode setOn:false];
  356. }
  357. }
  358. - (void)didReceiveMemoryWarning {
  359. [super didReceiveMemoryWarning];
  360. // Dispose of any resources that can be recreated.
  361. }
  362. -(void) reloadBG
  363. {
  364. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  365. switch (orientation) {
  366. case UIInterfaceOrientationPortrait:
  367. case UIInterfaceOrientationPortraitUpsideDown:
  368. {
  369. self.coverBG.image = [UIImage imageNamed:@"home_bg_p"];
  370. self.imageBG.image = [UIImage imageNamed:@"home_bg_p"];
  371. break;
  372. }
  373. case UIInterfaceOrientationLandscapeLeft:
  374. case UIInterfaceOrientationLandscapeRight:
  375. {
  376. self.coverBG.image = [UIImage imageNamed:@"home_bg_l"];
  377. self.imageBG.image = [UIImage imageNamed:@"home_bg_l"];
  378. break;
  379. }
  380. default:
  381. self.coverBG.image = [UIImage imageNamed:@"home_bg_p"];
  382. self.imageBG.image = [UIImage imageNamed:@"home_bg_p"];
  383. break;
  384. }
  385. }
  386. -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  387. {
  388. [self reloadBG];
  389. // [self initControl];
  390. // // [self.pdfPageView setNeedsLayout];
  391. // [self.pdfPageView setNeedsDisplay];
  392. // // UIDeviceOrientation dev_ori = [[UIDevice currentDevice]orientation];
  393. //
  394. // // UIApplication * app = [UIApplication sharedApplication];
  395. // // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  396. // // [appDelegate didRotated];
  397. //
  398. // // if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
  399. // // {
  400. // // self.orientation = orientation;
  401. // // [self.collectionview.collectionViewLayout invalidateLayout];
  402. // // DebugLog(@"routed");
  403. // // }
  404. }
  405. - (void)dealWithUILogout {
  406. self.welcomeLabel.text=@"Not sign in";
  407. // [sender setTitle:@"Sign in" forState:UIControlStateNormal];
  408. [self.ibSignin setTitle:@"Sign in"];
  409. self.buttonHIC.enabled = false;
  410. self.buttonSRL.enabled = false;
  411. self.coverView.hidden = false;
  412. }
  413. - (IBAction)onPrivacyClick:(id)sender {
  414. NSString* url = URL_PRIVACY;
  415. NSString* title = @"Privacy Policy";
  416. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  417. ViewController.url = url;
  418. ViewController.title = title;
  419. [self.navigationController pushViewController:ViewController animated:YES];
  420. }
  421. - (IBAction)OnSigninClick:(id)sender {
  422. UIBarButtonItem* bbitem = sender;
  423. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  424. if(appDelegate.bLogin)
  425. {
  426. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to sign out?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  427. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  428. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Sign out"];
  429. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out" completion:^{
  430. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  431. NSDictionary* logout_json = nil;
  432. logout_json = [RANetwork logout];
  433. dispatch_async(dispatch_get_main_queue(), ^{
  434. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  435. [waitalert dismissViewControllerAnimated:YES completion:^{
  436. if([[logout_json valueForKey:@"result"] intValue]==2)
  437. {
  438. self.welcomeLabel.text=@"Not sign in";
  439. // [sender setTitle:@"Sign in" forState:UIControlStateNormal];
  440. [bbitem setTitle:@"Sign in"];
  441. self.buttonHIC.enabled = false;
  442. self.buttonSRL.enabled = false;
  443. self.coverView.hidden = false;
  444. }
  445. else
  446. {
  447. [RAUtils message_alert:[logout_json valueForKey:@"err_msg"] title:@"Sign out" controller:self] ;
  448. }
  449. }];
  450. });
  451. });
  452. }];
  453. }];
  454. // [alertControl addAction:actionOne];
  455. [alertControl addAction:alertthree];
  456. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  457. }];
  458. [alertControl addAction:alertcancel];
  459. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  460. [self presentViewController:alertControl animated:YES completion:nil];
  461. }
  462. else
  463. [self presentLogin:sender];
  464. }
  465. -(void) previewPDF:(NSString*)file title:(NSString*)title subject:(NSString*)subject
  466. {
  467. // return;
  468. NSString* name=@"";//[self.content_data[indexPath.row] valueForKey:@"tear_name"];
  469. NSString* url= file;//[self.content_data[indexPath.row] valueForKey:@"pdf_path"];
  470. bool isLocalFile= true;//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"];
  471. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  472. ViewController.url = url;
  473. ViewController.canSave = false;
  474. ViewController.isLocalfile=isLocalFile;
  475. ViewController.defaultStyle = true;
  476. ViewController.save_name=title;
  477. ViewController.title = title;
  478. // NSString* subject;
  479. // if (company.length==0) {
  480. // NSString* cur_time =[RAUtils current_date];
  481. // subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  482. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  483. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  484. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  485. // if(customer_email.length>0)
  486. // {
  487. // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  488. // // customer_email compo
  489. // // [send_to addObject:customer_email];
  490. // }
  491. ViewController.mail_to = send_to;
  492. // }
  493. // else
  494. // {
  495. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  496. // }
  497. // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  498. ViewController.mail_subject = subject;
  499. ViewController.hidenavi = false;
  500. [self.navigationController pushViewController:ViewController animated:YES];
  501. }
  502. //- (IBAction)OnHICClick:(id)sender {
  503. //
  504. //
  505. // __weak typeof(self) weakSelf = self;
  506. //
  507. //
  508. // DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  509. //
  510. // dvc.templateName = @"GEIC - Home Improvement Contract 2016.json";
  511. // dvc.pdfName = @"GEIC - Home Improvement Contract 2017.pdf";
  512. //
  513. // dvc.OnSave=^(NSString* file)
  514. // {
  515. // // [weakSelf previewPDF:file];
  516. // };
  517. //
  518. // [self.navigationController pushViewController:dvc animated:true];
  519. //}
  520. //- (IBAction)OnSRLClick:(id)sender {
  521. //
  522. // DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  523. //
  524. // dvc.templateName = @"SUBCONTRACTORS REFERRAL LIST.json";
  525. // dvc.pdfName = @"SUBCONTRACTORS REFERRAL LIST.pdf";
  526. // dvc.OnSave=^(NSString* file)
  527. // {
  528. //
  529. // //[self previewPDF:file];
  530. // };
  531. //
  532. // [self.navigationController pushViewController:dvc animated:true];
  533. //}
  534. - (IBAction)debugBtnClick:(UIButton *)sender {
  535. DocumentTemplateViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentTemplateViewController" ];
  536. dvc.templatePath = [[NSBundle mainBundle] pathForResource:@"2021 GECI - Home Improvement Contract.json" ofType:nil];
  537. dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  538. dvc.docment_id = @"debug_template";
  539. dvc.OnSave=^(NSString* file, NSString* subject)
  540. {
  541. };
  542. [self.navigationController pushViewController:dvc animated:true];
  543. }
  544. @end