RootViewController.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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 %@",RASingleton.sharedInstance.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. [RAUtils message_box:@"Create Customer" message:@"Offline document number prefix not found, Please check your user name and make sure you had signed in at least once." completion:nil];
  222. return;
  223. }
  224. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  225. // dvc.templateName = @"debug.json";
  226. dvc.templatePath = [[NSBundle mainBundle] pathForResource:CONTRACT_TEMPLATE ofType:nil];
  227. dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  228. dvc.docment_id = offline_docnumber;
  229. dvc.OnSave=^(NSString* file, NSString* subject)
  230. {
  231. [weakSelf previewPDF:file title:offline_docnumber subject:subject];
  232. };
  233. [self.navigationController pushViewController:dvc animated:true];
  234. }
  235. else
  236. {
  237. PopWaitAlert* pop =[RAUtils waiting_pop:@"Create customer" completion:nil];
  238. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create customer" completion:^{
  239. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  240. NSMutableDictionary* json=[[RANetwork new_document] mutableCopy];
  241. dispatch_async(dispatch_get_main_queue(), ^{
  242. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  243. // [waitalert dismissViewControllerAnimated:YES completion:^{
  244. [pop hide];
  245. if([json[@"result"] intValue]==RESULT_TRUE)
  246. {
  247. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  248. // dvc.templateName = @"debug.json";
  249. dvc.templatePath = [[NSBundle mainBundle] pathForResource:CONTRACT_TEMPLATE ofType:nil];
  250. dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  251. dvc.docment_id = json[@"doc_number"];
  252. dvc.OnSave=^(NSString* file, NSString* subject)
  253. {
  254. [weakSelf previewPDF:file title:json[@"doc_number"] subject:subject];
  255. };
  256. [self.navigationController pushViewController:dvc animated:true];
  257. }
  258. else
  259. {
  260. // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Create Customer" controller:self] ;
  261. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Create Customer" message:@"Can not create new customer on server, do you want to create an offline document?" preferredStyle:UIAlertControllerStyleAlert];
  262. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  263. __block NSString* offline_docnumber =[RANetwork offline_docnumber];
  264. if(offline_docnumber==nil)
  265. {
  266. // [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] ;
  267. [RAUtils message_box:@"Create Customer" message:@"Offline document number prefix not found, Please check your user name and make sure you had signed in at least once." completion:nil];
  268. return;
  269. }
  270. [appDelegate SwitchToOffline:RASingleton.sharedInstance.user];
  271. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  272. // dvc.templateName = @"debug.json";
  273. dvc.templatePath = [[NSBundle mainBundle] pathForResource:CONTRACT_TEMPLATE ofType:nil];
  274. dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  275. dvc.docment_id = offline_docnumber;
  276. dvc.OnSave=^(NSString* file, NSString* subject)
  277. {
  278. [weakSelf previewPDF:file title:offline_docnumber subject:subject];
  279. };
  280. [self.navigationController pushViewController:dvc animated:true];
  281. }];
  282. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  283. DebugLog(@"Cancel");
  284. }];
  285. [alertControl addAction:actionOne];
  286. [alertControl addAction:alertthree];
  287. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  288. [self presentViewController:alertControl animated:YES completion:nil];
  289. }
  290. // }];
  291. });
  292. });
  293. // }];
  294. }
  295. }
  296. - (IBAction)onCustomerPerDocClick:(id)sender {
  297. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  298. if(appDelegate.accessMode == AppAccessModeOffline)
  299. {
  300. // [RAUtils message_alert:@"You can only access this function onder online mode." title:@"Offline mode." controller:self];
  301. [RAUtils message_box:@"Offline mode." message:@"You can only access this function onder online mode." completion:nil];
  302. return;
  303. }
  304. DocumentListViewController* docVC =[self.storyboard instantiateViewControllerWithIdentifier:@"DocumentListViewController" ];
  305. [self.navigationController pushViewController:docVC animated:true];
  306. }
  307. - (IBAction)onPendingDocClick:(id)sender {
  308. PendingDocumentsViewController* docVC =[self.storyboard instantiateViewControllerWithIdentifier:@"PendingDocumentsViewController" ];
  309. [self.navigationController pushViewController:docVC animated:true];
  310. }
  311. - (IBAction)onModeSwitch:(id)sender {
  312. UISwitch* sw = sender;
  313. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  314. NSString * user = [AESCrypt decrypt:[defaults stringForKey:@"user"] password:@"usai"];
  315. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  316. if(sw.isOn)
  317. {
  318. self.navigationItem.rightBarButtonItem = self.ibSignin;
  319. self.labelMode.text = @"Mode: Online";
  320. [appDelegate Logout];
  321. [self.ibSignin setTitle:@"Sign in"];
  322. [self presentLogin:self.ibSignin];
  323. //
  324. // [self.switchMode setOn:true];
  325. }
  326. else
  327. {
  328. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Enter user name for offline mode." message:nil preferredStyle:UIAlertControllerStyleAlert];
  329. [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  330. textField.text = user;
  331. textField.keyboardType=UIKeyboardTypeDefault;
  332. textField.delegate = nil;
  333. }];
  334. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  335. UITextField *name = alertControl.textFields.firstObject;
  336. if(name.text.length==0)
  337. {
  338. self.navigationItem.rightBarButtonItem = self.ibSignin;
  339. [sw setOn: true];
  340. // [RAUtils message_alert:@"User name is required." title:@"Can not switch to offline mode." controller:self];
  341. [RAUtils message_box:@"Can not switch to offline mode." message:@"User name is required." completion:nil];
  342. }
  343. else
  344. {
  345. self.navigationItem.rightBarButtonItem = nil;
  346. self.labelMode.text = @"Mode: Offline";
  347. [appDelegate SwitchToOffline:name.text];
  348. self.welcomeLabel.text=[NSString stringWithFormat:@"Welcome %@",RASingleton.sharedInstance.user];
  349. self.coverView.hidden = true;
  350. }
  351. }];
  352. // [alertControl addAction:actionOne];
  353. [alertControl addAction:alertthree];
  354. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  355. [sw setOn: true];
  356. }];
  357. [alertControl addAction:alertcancel];
  358. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  359. [self presentViewController:alertControl animated:YES completion:nil];
  360. // [self.switchMode setOn:false];
  361. }
  362. }
  363. - (void)didReceiveMemoryWarning {
  364. [super didReceiveMemoryWarning];
  365. // Dispose of any resources that can be recreated.
  366. }
  367. -(void) reloadBG
  368. {
  369. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  370. switch (orientation) {
  371. case UIInterfaceOrientationPortrait:
  372. case UIInterfaceOrientationPortraitUpsideDown:
  373. {
  374. self.coverBG.image = [UIImage imageNamed:@"home_bg_p"];
  375. self.imageBG.image = [UIImage imageNamed:@"home_bg_p"];
  376. break;
  377. }
  378. case UIInterfaceOrientationLandscapeLeft:
  379. case UIInterfaceOrientationLandscapeRight:
  380. {
  381. self.coverBG.image = [UIImage imageNamed:@"home_bg_l"];
  382. self.imageBG.image = [UIImage imageNamed:@"home_bg_l"];
  383. break;
  384. }
  385. default:
  386. self.coverBG.image = [UIImage imageNamed:@"home_bg_p"];
  387. self.imageBG.image = [UIImage imageNamed:@"home_bg_p"];
  388. break;
  389. }
  390. }
  391. -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  392. {
  393. [self reloadBG];
  394. // [self initControl];
  395. // // [self.pdfPageView setNeedsLayout];
  396. // [self.pdfPageView setNeedsDisplay];
  397. // // UIDeviceOrientation dev_ori = [[UIDevice currentDevice]orientation];
  398. //
  399. // // UIApplication * app = [UIApplication sharedApplication];
  400. // // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  401. // // [appDelegate didRotated];
  402. //
  403. // // if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
  404. // // {
  405. // // self.orientation = orientation;
  406. // // [self.collectionview.collectionViewLayout invalidateLayout];
  407. // // DebugLog(@"routed");
  408. // // }
  409. }
  410. - (void)dealWithUILogout {
  411. self.welcomeLabel.text=@"Not sign in";
  412. // [sender setTitle:@"Sign in" forState:UIControlStateNormal];
  413. [self.ibSignin setTitle:@"Sign in"];
  414. self.buttonHIC.enabled = false;
  415. self.buttonSRL.enabled = false;
  416. self.coverView.hidden = false;
  417. }
  418. - (IBAction)onPrivacyClick:(id)sender {
  419. NSString* url = URL_PRIVACY;
  420. NSString* title = @"Privacy Policy";
  421. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  422. ViewController.url = url;
  423. ViewController.title = title;
  424. [self.navigationController pushViewController:ViewController animated:YES];
  425. }
  426. - (IBAction)OnSigninClick:(id)sender {
  427. UIBarButtonItem* bbitem = sender;
  428. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  429. if(appDelegate.bLogin)
  430. {
  431. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to sign out?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  432. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  433. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out" completion:^{
  434. PopWaitAlert* pop =[RAUtils waiting_pop:@"Sign out" completion:nil];
  435. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  436. NSDictionary* logout_json = nil;
  437. logout_json = [RANetwork logout];
  438. dispatch_async(dispatch_get_main_queue(), ^{
  439. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  440. // [waitalert dismissViewControllerAnimated:YES completion:^{
  441. [pop hide];
  442. if([[logout_json valueForKey:@"result"] intValue]==2)
  443. {
  444. self.welcomeLabel.text=@"Not sign in";
  445. // [sender setTitle:@"Sign in" forState:UIControlStateNormal];
  446. [bbitem setTitle:@"Sign in"];
  447. self.buttonHIC.enabled = false;
  448. self.buttonSRL.enabled = false;
  449. self.coverView.hidden = false;
  450. }
  451. else
  452. {
  453. // [RAUtils message_alert:[logout_json valueForKey:@"err_msg"] title:@"Sign out" controller:self] ;
  454. [RAUtils message_box:@"Sign out" message:[logout_json valueForKey:@"err_msg"] completion:nil];
  455. }
  456. // }];
  457. });
  458. });
  459. // }];
  460. }];
  461. // [alertControl addAction:actionOne];
  462. [alertControl addAction:alertthree];
  463. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  464. }];
  465. [alertControl addAction:alertcancel];
  466. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  467. [self presentViewController:alertControl animated:YES completion:nil];
  468. }
  469. else
  470. [self presentLogin:sender];
  471. }
  472. -(void) previewPDF:(NSString*)file title:(NSString*)title subject:(NSString*)subject
  473. {
  474. // return;
  475. NSString* name=@"";//[self.content_data[indexPath.row] valueForKey:@"tear_name"];
  476. NSString* url= file;//[self.content_data[indexPath.row] valueForKey:@"pdf_path"];
  477. bool isLocalFile= true;//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"];
  478. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  479. ViewController.url = url;
  480. ViewController.canSave = false;
  481. ViewController.isLocalfile=isLocalFile;
  482. ViewController.defaultStyle = true;
  483. ViewController.save_name=title;
  484. ViewController.title = title;
  485. // NSString* subject;
  486. // if (company.length==0) {
  487. // NSString* cur_time =[RAUtils current_date];
  488. // subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  489. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  490. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  491. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  492. // if(customer_email.length>0)
  493. // {
  494. // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  495. // // customer_email compo
  496. // // [send_to addObject:customer_email];
  497. // }
  498. ViewController.mail_to = send_to;
  499. // }
  500. // else
  501. // {
  502. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  503. // }
  504. // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  505. ViewController.mail_subject = subject;
  506. ViewController.hidenavi = false;
  507. [self.navigationController pushViewController:ViewController animated:YES];
  508. }
  509. //- (IBAction)OnHICClick:(id)sender {
  510. //
  511. //
  512. // __weak typeof(self) weakSelf = self;
  513. //
  514. //
  515. // DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  516. //
  517. // dvc.templateName = @"GEIC - Home Improvement Contract 2016.json";
  518. // dvc.pdfName = @"GEIC - Home Improvement Contract 2017.pdf";
  519. //
  520. // dvc.OnSave=^(NSString* file)
  521. // {
  522. // // [weakSelf previewPDF:file];
  523. // };
  524. //
  525. // [self.navigationController pushViewController:dvc animated:true];
  526. //}
  527. //- (IBAction)OnSRLClick:(id)sender {
  528. //
  529. // DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  530. //
  531. // dvc.templateName = @"SUBCONTRACTORS REFERRAL LIST.json";
  532. // dvc.pdfName = @"SUBCONTRACTORS REFERRAL LIST.pdf";
  533. // dvc.OnSave=^(NSString* file)
  534. // {
  535. //
  536. // //[self previewPDF:file];
  537. // };
  538. //
  539. // [self.navigationController pushViewController:dvc animated:true];
  540. //}
  541. - (IBAction)debugBtnClick:(UIButton *)sender {
  542. DocumentTemplateViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentTemplateViewController" ];
  543. dvc.templatePath = [[NSBundle mainBundle] pathForResource:CONTRACT_TEMPLATE ofType:nil];
  544. dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  545. dvc.docment_id = @"debug_template";
  546. dvc.OnSave=^(NSString* file, NSString* subject)
  547. {
  548. };
  549. [self.navigationController pushViewController:dvc animated:true];
  550. }
  551. @end