RootViewController.m 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  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. if (@available(iOS 13, *)) {
  127. navi.modalInPresentation = true;
  128. }
  129. navi.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  130. [self presentViewController:navi animated:YES completion:^{
  131. DebugLog(@"login present.........");
  132. }];
  133. }
  134. }
  135. //-(void) leak_debug
  136. //{
  137. //
  138. //
  139. // CGPDFDocumentRef document = [PDFUtils OpenPDF:@"GEIC - Home Improvement Contract 2017.pdf"];
  140. // // self.total_page = CGPDFDocumentGetNumberOfPages (self.document);
  141. //
  142. // NSMutableDictionary * controlTemplate = [self templateInit:[PDFUtils loadControl:@"GEIC - Home Improvement Contract 2017.json"]];
  143. //
  144. //
  145. // NSString* pdffile = [PDFUtils SavePDF:controlTemplate source:document window_rect:CGRectMake(0, 0, 768, 960)];
  146. //
  147. // CGPDFDocumentRelease(document);
  148. //
  149. // // CFRelease(document);
  150. //
  151. // NSString* zipfile=[ACNetwork prepareUploadFile:pdffile json:controlTemplate];
  152. //
  153. // [self previewPDF:pdffile];
  154. //
  155. //
  156. //
  157. //
  158. //
  159. //
  160. //}
  161. //-(NSMutableDictionary*) templateInit:(NSMutableDictionary*) template
  162. //{
  163. //
  164. //
  165. // NSString* temp = NSTemporaryDirectory();
  166. // NSString* filename =[NSString stringWithFormat:@"%@.png", [[NSUUID UUID] UUIDString]];
  167. // NSString* qrpath=[temp stringByAppendingPathComponent:filename];
  168. // UIImage* qrimg=[RAUtils generateBarCode:@"leak test" width:300 height:44];//[QRCodeGenerator qrImageForString:order_code imageSize:240];
  169. // bool bwrite=[UIImagePNGRepresentation(qrimg)writeToFile: qrpath atomically:YES];
  170. //
  171. //
  172. //
  173. // for(int i=0;i<[template[@"count"] intValue];i++)
  174. // {
  175. // NSMutableDictionary* page =template[[NSString stringWithFormat:@"page_%d",i]];
  176. // for(int j=0;j<[page[@"count"] intValue];j++)
  177. // {
  178. // NSMutableDictionary* control =page[[NSString stringWithFormat:@"control_%d",j]];
  179. // NSString* type = control[@"type"];
  180. // NSString* field =control[@"field"];
  181. // if([type isEqualToString:@"Label"])
  182. // {
  183. // if([field isEqualToString:@"doc_number"])
  184. // {
  185. // control[@"value"]= @"leak test";
  186. // }
  187. // }
  188. // else if([type isEqualToString:@"Image"])
  189. // {
  190. // NSString* name =control[@"name"];
  191. // if([name isEqualToString:@"BarCode"])
  192. // {
  193. // if(bwrite)
  194. // control[@"value"]= qrpath;
  195. // }
  196. // }
  197. // else if([type isEqualToString:@"DatePicker"])
  198. // {
  199. // NSString* name =control[@"aname"];
  200. // if([name isEqualToString:@"Today's Date"])
  201. // {
  202. // NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
  203. // [formatter setDateFormat:@"MM/dd/yyyy"];
  204. // NSString* date = [formatter stringFromDate:[NSDate date]] ;
  205. //
  206. // control[@"value"]= date;
  207. // }
  208. // }
  209. // }
  210. // }
  211. // return template;
  212. //}
  213. - (IBAction)onNewCustomerClick:(id)sender {
  214. // [self leak_debug];
  215. // return;
  216. __weak typeof(self) weakSelf = self;
  217. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  218. if(appDelegate.accessMode == AppAccessModeOffline)
  219. {
  220. __block NSString* offline_docnumber =[RANetwork offline_docnumber];
  221. if(offline_docnumber==nil)
  222. {
  223. // [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] ;
  224. [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];
  225. return;
  226. }
  227. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  228. // dvc.templateName = @"debug.json";
  229. dvc.templatePath = [[NSBundle mainBundle] pathForResource:CONTRACT_TEMPLATE ofType:nil];
  230. dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  231. dvc.docment_id = offline_docnumber;
  232. dvc.OnSave=^(NSString* file, NSString* subject)
  233. {
  234. [weakSelf previewPDF:file title:offline_docnumber subject:subject];
  235. };
  236. [self.navigationController pushViewController:dvc animated:true];
  237. }
  238. else
  239. {
  240. PopWaitAlert* pop =[RAUtils waiting_pop:@"Create customer" completion:nil];
  241. NSMutableDictionary* param = [NSMutableDictionary new];
  242. [RANetwork request_new_document:param completionHandler:^(NSMutableDictionary *result) {
  243. NSMutableDictionary* json= result;
  244. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  245. // [waitalert dismissViewControllerAnimated:YES completion:^{
  246. [pop hide];
  247. if([json[@"result"] intValue]==RESULT_TRUE)
  248. {
  249. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  250. // dvc.templateName = @"debug.json";
  251. dvc.templatePath = [[NSBundle mainBundle] pathForResource:CONTRACT_TEMPLATE ofType:nil];
  252. dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  253. dvc.docment_id = json[@"doc_number"];
  254. dvc.OnSave=^(NSString* file, NSString* subject)
  255. {
  256. [weakSelf previewPDF:file title:json[@"doc_number"] subject:subject];
  257. };
  258. [self.navigationController pushViewController:dvc animated:true];
  259. }
  260. else
  261. {
  262. // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Create Customer" controller:self] ;
  263. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Create Customer" message:@"Can not create new customer on server, do you want to create an offline document?" preferredStyle:UIAlertControllerStyleAlert];
  264. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  265. __block NSString* offline_docnumber =[RANetwork offline_docnumber];
  266. if(offline_docnumber==nil)
  267. {
  268. // [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] ;
  269. [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];
  270. return;
  271. }
  272. [appDelegate SwitchToOffline:RASingleton.sharedInstance.user];
  273. DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  274. // dvc.templateName = @"debug.json";
  275. dvc.templatePath = [[NSBundle mainBundle] pathForResource:CONTRACT_TEMPLATE ofType:nil];
  276. dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  277. dvc.docment_id = offline_docnumber;
  278. dvc.OnSave=^(NSString* file, NSString* subject)
  279. {
  280. [weakSelf previewPDF:file title:offline_docnumber subject:subject];
  281. };
  282. [self.navigationController pushViewController:dvc animated:true];
  283. }];
  284. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  285. DebugLog(@"Cancel");
  286. }];
  287. [alertControl addAction:actionOne];
  288. [alertControl addAction:alertthree];
  289. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  290. [self presentViewController:alertControl animated:YES completion:nil];
  291. }
  292. // }];
  293. }];
  294. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create customer" completion:^{
  295. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  296. //
  297. //
  298. // NSMutableDictionary* json=[[RANetwork new_document] mutableCopy];
  299. //
  300. // dispatch_async(dispatch_get_main_queue(), ^{
  301. //
  302. //
  303. //
  304. //// [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  305. //
  306. //
  307. //// [waitalert dismissViewControllerAnimated:YES completion:^{
  308. //
  309. // [pop hide];
  310. // if([json[@"result"] intValue]==RESULT_TRUE)
  311. //
  312. // {
  313. // DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  314. //
  315. // // dvc.templateName = @"debug.json";
  316. // dvc.templatePath = [[NSBundle mainBundle] pathForResource:CONTRACT_TEMPLATE ofType:nil];
  317. // dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  318. // dvc.docment_id = json[@"doc_number"];
  319. // dvc.OnSave=^(NSString* file, NSString* subject)
  320. // {
  321. //
  322. // [weakSelf previewPDF:file title:json[@"doc_number"] subject:subject];
  323. // };
  324. //
  325. // [self.navigationController pushViewController:dvc animated:true];
  326. // }
  327. // else
  328. // {
  329. // // [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Create Customer" controller:self] ;
  330. //
  331. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Create Customer" message:@"Can not create new customer on server, do you want to create an offline document?" preferredStyle:UIAlertControllerStyleAlert];
  332. //
  333. //
  334. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  335. // __block NSString* offline_docnumber =[RANetwork offline_docnumber];
  336. // if(offline_docnumber==nil)
  337. // {
  338. //// [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] ;
  339. // [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];
  340. // return;
  341. // }
  342. // [appDelegate SwitchToOffline:RASingleton.sharedInstance.user];
  343. // DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  344. //
  345. // // dvc.templateName = @"debug.json";
  346. // dvc.templatePath = [[NSBundle mainBundle] pathForResource:CONTRACT_TEMPLATE ofType:nil];
  347. // dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  348. //
  349. // dvc.docment_id = offline_docnumber;
  350. // dvc.OnSave=^(NSString* file, NSString* subject)
  351. // {
  352. //
  353. // [weakSelf previewPDF:file title:offline_docnumber subject:subject];
  354. // };
  355. //
  356. // [self.navigationController pushViewController:dvc animated:true];
  357. //
  358. //
  359. // }];
  360. //
  361. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  362. // DebugLog(@"Cancel");
  363. // }];
  364. // [alertControl addAction:actionOne];
  365. //
  366. // [alertControl addAction:alertthree];
  367. //
  368. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  369. //
  370. //
  371. // [self presentViewController:alertControl animated:YES completion:nil];
  372. //
  373. //
  374. // }
  375. //// }];
  376. //
  377. //
  378. //
  379. //
  380. // });
  381. // });
  382. // }];
  383. }
  384. }
  385. - (IBAction)onCustomerPerDocClick:(id)sender {
  386. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  387. if(appDelegate.accessMode == AppAccessModeOffline)
  388. {
  389. // [RAUtils message_alert:@"You can only access this function onder online mode." title:@"Offline mode." controller:self];
  390. [RAUtils message_box:@"Offline mode." message:@"You can only access this function onder online mode." completion:nil];
  391. return;
  392. }
  393. DocumentListViewController* docVC =[self.storyboard instantiateViewControllerWithIdentifier:@"DocumentListViewController" ];
  394. [self.navigationController pushViewController:docVC animated:true];
  395. }
  396. - (IBAction)onPendingDocClick:(id)sender {
  397. PendingDocumentsViewController* docVC =[self.storyboard instantiateViewControllerWithIdentifier:@"PendingDocumentsViewController" ];
  398. [self.navigationController pushViewController:docVC animated:true];
  399. }
  400. - (IBAction)onModeSwitch:(id)sender {
  401. UISwitch* sw = sender;
  402. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  403. NSString * user = [AESCrypt decrypt:[defaults stringForKey:@"user"] password:@"usai"];
  404. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  405. if(sw.isOn)
  406. {
  407. self.navigationItem.rightBarButtonItem = self.ibSignin;
  408. self.labelMode.text = @"Mode: Online";
  409. [appDelegate Logout];
  410. [self.ibSignin setTitle:@"Sign in"];
  411. [self presentLogin:self.ibSignin];
  412. //
  413. // [self.switchMode setOn:true];
  414. }
  415. else
  416. {
  417. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Enter user name for offline mode." message:nil preferredStyle:UIAlertControllerStyleAlert];
  418. [alertControl addTextFieldWithConfigurationHandler:^(UITextField *textField) {
  419. textField.text = user;
  420. textField.keyboardType=UIKeyboardTypeDefault;
  421. textField.delegate = nil;
  422. }];
  423. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  424. UITextField *name = alertControl.textFields.firstObject;
  425. if(name.text.length==0)
  426. {
  427. self.navigationItem.rightBarButtonItem = self.ibSignin;
  428. [sw setOn: true];
  429. // [RAUtils message_alert:@"User name is required." title:@"Can not switch to offline mode." controller:self];
  430. [RAUtils message_box:@"Can not switch to offline mode." message:@"User name is required." completion:nil];
  431. }
  432. else
  433. {
  434. self.navigationItem.rightBarButtonItem = nil;
  435. self.labelMode.text = @"Mode: Offline";
  436. [appDelegate SwitchToOffline:name.text];
  437. self.welcomeLabel.text=[NSString stringWithFormat:@"Welcome %@",RASingleton.sharedInstance.user];
  438. self.coverView.hidden = true;
  439. }
  440. }];
  441. // [alertControl addAction:actionOne];
  442. [alertControl addAction:alertthree];
  443. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  444. [sw setOn: true];
  445. }];
  446. [alertControl addAction:alertcancel];
  447. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  448. [self presentViewController:alertControl animated:YES completion:nil];
  449. // [self.switchMode setOn:false];
  450. }
  451. }
  452. - (void)didReceiveMemoryWarning {
  453. [super didReceiveMemoryWarning];
  454. // Dispose of any resources that can be recreated.
  455. }
  456. -(void) reloadBG
  457. {
  458. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  459. switch (orientation) {
  460. case UIInterfaceOrientationPortrait:
  461. case UIInterfaceOrientationPortraitUpsideDown:
  462. {
  463. self.coverBG.image = [UIImage imageNamed:@"home_bg_p"];
  464. self.imageBG.image = [UIImage imageNamed:@"home_bg_p"];
  465. break;
  466. }
  467. case UIInterfaceOrientationLandscapeLeft:
  468. case UIInterfaceOrientationLandscapeRight:
  469. {
  470. self.coverBG.image = [UIImage imageNamed:@"home_bg_l"];
  471. self.imageBG.image = [UIImage imageNamed:@"home_bg_l"];
  472. break;
  473. }
  474. default:
  475. self.coverBG.image = [UIImage imageNamed:@"home_bg_p"];
  476. self.imageBG.image = [UIImage imageNamed:@"home_bg_p"];
  477. break;
  478. }
  479. }
  480. //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  481. //{
  482. //
  483. // [self reloadBG];
  484. //
  485. //
  486. //// [self initControl];
  487. //// // [self.pdfPageView setNeedsLayout];
  488. //// [self.pdfPageView setNeedsDisplay];
  489. //// // UIDeviceOrientation dev_ori = [[UIDevice currentDevice]orientation];
  490. ////
  491. //// // UIApplication * app = [UIApplication sharedApplication];
  492. //// // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  493. //// // [appDelegate didRotated];
  494. ////
  495. //
  496. //
  497. //// // if (UIInterfaceOrientationIsLandscape(orientation)|| UIInterfaceOrientationIsPortrait(orientation))
  498. //// // {
  499. //// // self.orientation = orientation;
  500. //// // [self.collectionview.collectionViewLayout invalidateLayout];
  501. //// // DebugLog(@"routed");
  502. //// // }
  503. //
  504. //
  505. //
  506. //
  507. //}
  508. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  509. [self reloadBG];
  510. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  511. }
  512. - (void)dealWithUILogout {
  513. self.welcomeLabel.text=@"Not sign in";
  514. // [sender setTitle:@"Sign in" forState:UIControlStateNormal];
  515. [self.ibSignin setTitle:@"Sign in"];
  516. self.buttonHIC.enabled = false;
  517. self.buttonSRL.enabled = false;
  518. self.coverView.hidden = false;
  519. }
  520. - (IBAction)onPrivacyClick:(id)sender {
  521. NSString* url = URL_PRIVACY;
  522. NSString* title = @"Privacy Policy";
  523. WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  524. ViewController.url = url;
  525. ViewController.title = title;
  526. [self.navigationController pushViewController:ViewController animated:YES];
  527. }
  528. - (IBAction)OnSigninClick:(id)sender {
  529. UIBarButtonItem* bbitem = sender;
  530. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  531. if(appDelegate.bLogin)
  532. {
  533. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to sign out?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  534. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  535. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign out" completion:^{
  536. PopWaitAlert* pop =[RAUtils waiting_pop:@"Sign out" completion:nil];
  537. [RANetwork request_logout:^(NSMutableDictionary *result) {
  538. NSDictionary* logout_json = result;
  539. [pop hide];
  540. if([[logout_json valueForKey:@"result"] intValue]==2)
  541. {
  542. self.welcomeLabel.text=@"Not sign in";
  543. // [sender setTitle:@"Sign in" forState:UIControlStateNormal];
  544. [bbitem setTitle:@"Sign in"];
  545. self.buttonHIC.enabled = false;
  546. self.buttonSRL.enabled = false;
  547. self.coverView.hidden = false;
  548. }
  549. else
  550. {
  551. // [RAUtils message_alert:[logout_json valueForKey:@"err_msg"] title:@"Sign out" controller:self] ;
  552. [RAUtils message_box:@"Sign out" message:[logout_json valueForKey:@"err_msg"] completion:nil];
  553. }
  554. }];
  555. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  556. //
  557. // NSDictionary* logout_json = nil;
  558. //
  559. //
  560. //
  561. // logout_json = [RANetwork logout];
  562. //
  563. // dispatch_async(dispatch_get_main_queue(), ^{
  564. //
  565. //
  566. //// [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  567. //
  568. //// [waitalert dismissViewControllerAnimated:YES completion:^{
  569. //
  570. // [pop hide];
  571. // if([[logout_json valueForKey:@"result"] intValue]==2)
  572. // {
  573. // self.welcomeLabel.text=@"Not sign in";
  574. // // [sender setTitle:@"Sign in" forState:UIControlStateNormal];
  575. // [bbitem setTitle:@"Sign in"];
  576. //
  577. // self.buttonHIC.enabled = false;
  578. // self.buttonSRL.enabled = false;
  579. // self.coverView.hidden = false;
  580. // }
  581. // else
  582. // {
  583. //// [RAUtils message_alert:[logout_json valueForKey:@"err_msg"] title:@"Sign out" controller:self] ;
  584. //
  585. // [RAUtils message_box:@"Sign out" message:[logout_json valueForKey:@"err_msg"] completion:nil];
  586. // }
  587. //// }];
  588. //
  589. //
  590. //
  591. //
  592. //
  593. // });
  594. // });
  595. // }];
  596. }];
  597. // [alertControl addAction:actionOne];
  598. [alertControl addAction:alertthree];
  599. UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  600. }];
  601. [alertControl addAction:alertcancel];
  602. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  603. [self presentViewController:alertControl animated:YES completion:nil];
  604. }
  605. else
  606. [self presentLogin:sender];
  607. }
  608. -(void) previewPDF:(NSString*)file title:(NSString*)title subject:(NSString*)subject
  609. {
  610. // return;
  611. // NSString* name=@"";//[self.content_data[indexPath.row] valueForKey:@"tear_name"];
  612. NSString* url= file;//[self.content_data[indexPath.row] valueForKey:@"pdf_path"];
  613. bool isLocalFile= true;//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"];
  614. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  615. ViewController.url = url;
  616. ViewController.canSave = false;
  617. ViewController.isLocalfile=isLocalFile;
  618. ViewController.defaultStyle = true;
  619. ViewController.save_name=title;
  620. ViewController.title = title;
  621. // NSString* subject;
  622. // if (company.length==0) {
  623. // NSString* cur_time =[RAUtils current_date];
  624. // subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
  625. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  626. // NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  627. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  628. // if(customer_email.length>0)
  629. // {
  630. // send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  631. // // customer_email compo
  632. // // [send_to addObject:customer_email];
  633. // }
  634. ViewController.mail_to = send_to;
  635. // }
  636. // else
  637. // {
  638. // subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
  639. // }
  640. // ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
  641. ViewController.mail_subject = subject;
  642. ViewController.hidenavi = false;
  643. [self.navigationController pushViewController:ViewController animated:YES];
  644. }
  645. //- (IBAction)OnHICClick:(id)sender {
  646. //
  647. //
  648. // __weak typeof(self) weakSelf = self;
  649. //
  650. //
  651. // DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  652. //
  653. // dvc.templateName = @"GEIC - Home Improvement Contract 2016.json";
  654. // dvc.pdfName = @"GEIC - Home Improvement Contract 2017.pdf";
  655. //
  656. // dvc.OnSave=^(NSString* file)
  657. // {
  658. // // [weakSelf previewPDF:file];
  659. // };
  660. //
  661. // [self.navigationController pushViewController:dvc animated:true];
  662. //}
  663. //- (IBAction)OnSRLClick:(id)sender {
  664. //
  665. // DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
  666. //
  667. // dvc.templateName = @"SUBCONTRACTORS REFERRAL LIST.json";
  668. // dvc.pdfName = @"SUBCONTRACTORS REFERRAL LIST.pdf";
  669. // dvc.OnSave=^(NSString* file)
  670. // {
  671. //
  672. // //[self previewPDF:file];
  673. // };
  674. //
  675. // [self.navigationController pushViewController:dvc animated:true];
  676. //}
  677. - (IBAction)debugBtnClick:(UIButton *)sender {
  678. DocumentTemplateViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentTemplateViewController" ];
  679. dvc.templatePath = [[NSBundle mainBundle] pathForResource:CONTRACT_TEMPLATE ofType:nil];
  680. dvc.pdfPath = [[NSBundle mainBundle] pathForResource:@"GECI - Home Improvement Contract - Tan.pdf" ofType:nil];
  681. dvc.docment_id = @"debug_template";
  682. dvc.OnSave=^(NSString* file, NSString* subject)
  683. {
  684. };
  685. [self.navigationController pushViewController:dvc animated:true];
  686. }
  687. @end