LoginViewController.m 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. //
  2. // LoginViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-20.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "LoginViewController.h"
  9. #import "RetrievePassViewController.h"
  10. #import "UILabel+FontAppearance.h"
  11. #import "OLDataProvider.h"
  12. #import "NotificationNameCenter.h"
  13. #import "OfflineSettingViewController.h"
  14. #import "MainViewController.h"
  15. #import "WebViewController.h"
  16. @interface LoginViewController ()
  17. @property (strong, nonatomic) IBOutlet UIButton *requestLoginBtn;
  18. @end
  19. @implementation LoginViewController
  20. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  21. {
  22. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  23. if (self) {
  24. // Custom initialization
  25. }
  26. return self;
  27. }
  28. - (void)viewDidLoad
  29. {
  30. [super viewDidLoad];
  31. #ifdef OFFLINE_MODE
  32. self.checkOfflineMode.hidden=false;
  33. #else
  34. self.checkOfflineMode.hidden=true;
  35. #endif
  36. #ifdef BUILD_HMLG
  37. self.title=COMPANY_SHORT_NAME;
  38. self.requestLoginBtn.hidden = YES;
  39. #endif
  40. #if defined(BUILD_HOMER) || defined(BUILD_GATIT) || defined(BUILD_UWAVER)
  41. self.title=COMPANY_SHORT_NAME;
  42. // self.checkOfflineMode.hidden = YES;
  43. self.requestLoginBtn.hidden = YES;
  44. #endif
  45. #if defined(BUILD_NPD) || defined(BUILD_USAI)|| defined (BUILD_CONTRAST)
  46. self.title=COMPANY_SHORT_NAME;
  47. // self.checkOfflineMode.hidden=false;
  48. #endif
  49. self.showList = false;
  50. self.bb_close.image=[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
  51. [self.checkSavePassword setImage:[UIImage imageNamed:@"checkbox"] forState:UIControlStateNormal];
  52. [self.checkSavePassword setImage:[UIImage imageNamed:@"checkbox_check"] forState:UIControlStateSelected];
  53. [self.checkOfflineMode setImage:[UIImage imageNamed:@"checkbox"] forState:UIControlStateNormal];
  54. [self.checkOfflineMode setImage:[UIImage imageNamed:@"checkbox_check"] forState:UIControlStateSelected];
  55. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  56. NSString * user = [AESCrypt decrypt:[defaults stringForKey:@"user"] password:@"usai"];
  57. NSString * password = [AESCrypt decrypt:[defaults stringForKey:@"password"] password:@"usai"];
  58. if(user.length>0&&password.length>0)
  59. {
  60. self.edituser.text=user;
  61. self.editpass.text=password;
  62. self.checkSavePassword.selected=true;
  63. }
  64. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  65. // [defaults removeObjectForKey:@"EnableOfflineMode"];
  66. // [defaults setBool:self.checkOfflineMode.selected forKey:@"EnableOfflineMode"];
  67. self.checkOfflineMode.selected=[defaults boolForKey:@"EnableOfflineMode"];
  68. [self.checkOfflineMode addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
  69. [self.checkSavePassword addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
  70. self.checkOfflineMode.tag=999;
  71. self.logindata = [iSalesDB get_saveduser];
  72. UIButton* combobutton=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
  73. [combobutton setBackgroundImage:[UIImage imageNamed:@"combo_24"] forState:UIControlStateNormal];
  74. [combobutton addTarget:self action:@selector(LoginList:) forControlEvents:UIControlEventTouchUpInside];
  75. self.edituser.rightView = combobutton;
  76. self.edituser.rightViewMode=UITextFieldViewModeAlways;
  77. self.Loginlist.layer.borderColor = [UIColor lightGrayColor].CGColor;
  78. self.Loginlist.layer.borderWidth = 1.0;
  79. // self.Loginlist.layer.cornerRadius=15;
  80. self.Loginlist.layer.masksToBounds=true;
  81. // Do any additional setup after loading the view.
  82. #ifdef SCANNER_ORDER
  83. self.btnGuest.hidden=false;
  84. #endif
  85. }
  86. - (void)LoginList:(UIButton *)sender {
  87. [self.edituser endEditing:true];
  88. self.showList= !self.showList;
  89. self.Loginlist.hidden = !self.showList;
  90. // showList;
  91. }
  92. -(void)checkboxClick:(UIButton *)btn
  93. {
  94. btn.selected = !btn.selected;
  95. if(btn.tag==999)
  96. {
  97. bool haveofflineData=[OLDataProvider check_offlinedata];
  98. if(btn.selected)
  99. {
  100. if(haveofflineData)
  101. {
  102. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  103. bool forcedownload = [defaults boolForKey:@"Forcedownload"];
  104. if(forcedownload)
  105. {
  106. btn.selected = !btn.selected;
  107. [RAUtils message_alert:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync" controller:self];
  108. [defaults removeObjectForKey:@"EnableOfflineMode"];
  109. [defaults setBool:false forKey:@"EnableOfflineMode"];
  110. [defaults synchronize];
  111. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  112. appDelegate.offline_mode = false;
  113. // [RAUtils alert_view:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync"];
  114. }
  115. else
  116. {
  117. [defaults removeObjectForKey:@"EnableOfflineMode"];
  118. [defaults setBool:self.checkOfflineMode.selected forKey:@"EnableOfflineMode"];
  119. [defaults synchronize];
  120. #ifdef OFFLINE_MODE
  121. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  122. appDelegate.offline_mode = self.checkOfflineMode.selected;
  123. #endif
  124. }
  125. }
  126. else
  127. {
  128. btn.selected = !btn.selected;
  129. [RAUtils message_alert:@"Offline data not found, you must login online and download offline data first." title:@"Offline data not found" controller:self];
  130. // [RAUtils alert_view:@"Offline data not found, you must login online and download offline data first." title:@"Offline data not found"];
  131. }
  132. }
  133. else
  134. {
  135. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  136. [defaults removeObjectForKey:@"EnableOfflineMode"];
  137. [defaults setBool:self.checkOfflineMode.selected forKey:@"EnableOfflineMode"];
  138. [defaults synchronize];
  139. #ifdef OFFLINE_MODE
  140. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  141. appDelegate.offline_mode = self.checkOfflineMode.selected;
  142. #endif
  143. }
  144. }
  145. else
  146. {
  147. if(!btn.selected)
  148. {
  149. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  150. [defaults removeObjectForKey:@"user"];
  151. [defaults removeObjectForKey:@"password"];
  152. [defaults synchronize];
  153. NSString* encryptu=[AESCrypt encrypt:self.edituser.text password:@"usai"];
  154. NSString* sql=[NSString stringWithFormat:@"delete from login_info where name='%@'",encryptu];
  155. [iSalesDB execSql:sql];
  156. self.logindata = [iSalesDB get_saveduser];
  157. [self.Loginlist reloadData];
  158. }
  159. }
  160. }
  161. - (IBAction)CloseClick:(id)sender {
  162. [self dismissViewControllerAnimated:true completion:^{
  163. if(self.returnValue)
  164. self.returnValue(false);
  165. }];
  166. }
  167. - (IBAction)onRetrievePassword:(id)sender {
  168. RetrievePassViewController* vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"RetrievePassViewController" ];
  169. // dvc
  170. // UINavigationController* nv = self.navigationController;
  171. [self.navigationController pushViewController:vc animated:true];
  172. }
  173. - (IBAction)onGuestClick:(id)sender {
  174. [OLDataProvider realguestLogin];
  175. [self dismissViewControllerAnimated:true completion:^{
  176. if(self.returnValue)
  177. self.returnValue(false);
  178. }];
  179. }
  180. - (IBAction)onLoginClick:(UIButton *)sender {
  181. NSString* user = self.edituser.text;
  182. NSString* password = self.editpass.text;
  183. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  184. bool forcedownload = [defaults boolForKey:@"Forcedownload"];
  185. if(forcedownload && self.checkOfflineMode.selected)
  186. {
  187. self.checkOfflineMode.selected = !self.checkOfflineMode.selected;
  188. [RAUtils message_alert:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync" controller:self];
  189. [RAUtils message_alert:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync" controller:self];
  190. [defaults removeObjectForKey:@"EnableOfflineMode"];
  191. [defaults setBool:false forKey:@"EnableOfflineMode"];
  192. [defaults synchronize];
  193. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  194. appDelegate.offline_mode = false;
  195. // [RAUtils alert_view:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync"];
  196. return;
  197. }
  198. if(user.length==0||password.length==0)
  199. {
  200. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Error!" message:@"user or password can not be empty." delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil, nil];
  201. // // UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
  202. //
  203. //
  204. // //[[UILabel appearanceWhenContainedIn:UIAlertView.class, nil] setAppearanceFont:[UIFont boldSystemFontOfSize:10]];
  205. // [alert show];
  206. [RAUtils message_alert:@"Username or Password cannot be blank." title:@"Cannot sign-in" controller:self];
  207. // [RAUtils alert_view:@"Username or Password cannot be blank." title:@"Cannot sign-in"];
  208. return;
  209. }
  210. DebugLog(@"Login... user= %@ ; password= %@",user,password);
  211. self.btnLogin.enabled = false;
  212. // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Sign in"];
  213. __block UIAlertController* waitalert= [RAUtils waiting_alert:self title:@"Sign in" completion:^{
  214. [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
  215. [waitalert dismissViewControllerAnimated:true completion:^{
  216. int ret=[result[@"result"] intValue];
  217. self.btnLogin.enabled = true;
  218. if(ret==RESULT_TRUE)
  219. {
  220. //
  221. // NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
  222. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  223. // appDelegate.contact_id=contactid;
  224. // appDelegate.contact_name =[self.content_data[indexPath.row] valueForKey:@"name"];
  225. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  226. [defaults removeObjectForKey:@"user"];
  227. [defaults removeObjectForKey:@"password"];
  228. NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
  229. NSString* encryptp=[AESCrypt encrypt:self.editpass.text password:@"usai"] ;
  230. if(self.checkSavePassword.selected)
  231. {
  232. [defaults setValue:encryptu forKey:@"user"];
  233. [defaults setValue:encryptp forKey:@"password"];
  234. sqlite3 *db = [iSalesDB get_db];
  235. int count =[iSalesDB get_recordcount:db table:@"login_info" where:[NSString stringWithFormat:@"name='%@'",encryptu]];
  236. if(count==0)
  237. {
  238. NSString * savelogin=[NSString stringWithFormat:@"insert into login_info(name,pwd) values('%@','%@')",encryptu,encryptp];
  239. [iSalesDB execSql:savelogin db:db];
  240. }
  241. else
  242. {
  243. NSString * savelogin=[NSString stringWithFormat:@"update login_info set pwd='%@' where name='%@'",encryptp,encryptu];
  244. [iSalesDB execSql:savelogin db:db];
  245. }
  246. [iSalesDB close_db:db];
  247. // [defaults setBool:TRUE forKey:@"autologin"];
  248. }
  249. else
  250. {
  251. NSString* sql=[NSString stringWithFormat:@"delete from login_info where name='%@'",encryptu];
  252. [iSalesDB execSql:sql];
  253. }
  254. [defaults synchronize];
  255. #ifdef SCANNER_ORDER
  256. [ActiveViewController Notify:@"ScanOrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  257. #endif
  258. [self dismissViewControllerAnimated:YES completion:^{
  259. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  260. bool offline_dirty=[defaults boolForKey:@"OFFLINE_DIRTY"];
  261. sqlite3* db = [iSalesDB get_db];
  262. int offline_user_exist=[iSalesDB get_recordcount:db table:@"offline_login" where:[NSString stringWithFormat:@"username='%@'",appDelegate.user ]];
  263. [iSalesDB close_db:db];
  264. BOOL condition = offline_dirty && offline_user_exist>0;
  265. #ifdef OFFLINE_MODE
  266. condition = condition && !appDelegate.offline_mode;
  267. #endif
  268. if(condition)
  269. {
  270. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Detected new offline data" message:@"Do you want to sync with server?" preferredStyle:UIAlertControllerStyleAlert];
  271. //block代码块取代了delegate
  272. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes(Recommended)" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  273. UIApplication * app = [UIApplication sharedApplication];
  274. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  275. //UIViewController* active_vc = appDelegate.active_controller;
  276. OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
  277. // loginvc.delegate = self;
  278. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  279. // appDelegate.active_controller = gunVC;
  280. // gunVC.onDismissVC = ^(){
  281. // appDelegate.active_controller = active_vc;
  282. // };
  283. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
  284. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  285. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  286. [appDelegate.main_vc presentViewController:navi animated:YES completion:^{
  287. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  288. [main_vc checklogin:true];
  289. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  290. DebugLog(@"about present.........");
  291. // self.btop = false;
  292. // <#code#>
  293. }];
  294. }];
  295. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  296. if(self.returnValue)
  297. self.returnValue(true);
  298. [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
  299. }];
  300. [alertControl addAction:actionTwo];
  301. [alertControl addAction:alertthree];
  302. [appDelegate.main_vc presentViewController:alertControl animated:YES completion:nil];
  303. }
  304. else
  305. {
  306. if(self.returnValue)
  307. self.returnValue(true);
  308. [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
  309. }
  310. }];
  311. // if (self.delegate && [self.delegate respondsToSelector:@selector(LoginViewControllerDidLogin:)]) {
  312. // [self.delegate LoginViewControllerDidLogin:self];
  313. // }
  314. [[NSNotificationCenter defaultCenter] postNotificationName:User_LoginOK_Notification object:nil];
  315. }
  316. else
  317. {
  318. NSString* msg=nil;
  319. switch (ret) {
  320. case RESULT_NET_NOTAVAILABLE:
  321. msg = MSG_NET_NOTAVAILABLE;
  322. break;
  323. case RESULT_NET_ERROR:
  324. msg = MSG_NET_ERROR;
  325. break;
  326. case RESULT_FALSE:
  327. msg = MSG_USERAUTH_ERROR;
  328. break;
  329. case RESULT_VER_LOW:
  330. msg = MSG_VER_LOW;
  331. break;
  332. case RESULT_LOGIN_DEVICE:
  333. msg= MSG_LOGIN_DEVICE;
  334. break;
  335. default:
  336. break;
  337. }
  338. [RAUtils message_alert:msg title:@"Cannot sign-in" controller:self];
  339. // [RAUtils alert_view:msg title:@"Cannot sign-in"];
  340. }
  341. }];
  342. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  343. }];
  344. }];
  345. return;
  346. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Sign in" message:@"Please wait..." preferredStyle:UIAlertControllerStyleAlert];
  347. // [self presentViewController:alertController animated:YES completion:nil];
  348. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  349. //
  350. //
  351. // int ret=[RANetwork Authorize:user password:password];
  352. //
  353. // dispatch_async(dispatch_get_main_queue(), ^{
  354. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  355. // self.btnLogin.enabled = true;
  356. //
  357. // if(ret==RESULT_TRUE)
  358. //
  359. // {
  360. //
  361. // //
  362. // // NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
  363. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  364. // // appDelegate.contact_id=contactid;
  365. // // appDelegate.contact_name =[self.content_data[indexPath.row] valueForKey:@"name"];
  366. //
  367. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  368. // [defaults removeObjectForKey:@"user"];
  369. // [defaults removeObjectForKey:@"password"];
  370. // NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
  371. // NSString* encryptp=[AESCrypt encrypt:self.editpass.text password:@"usai"] ;
  372. // if(self.checkSavePassword.selected)
  373. // {
  374. //
  375. // [defaults setValue:encryptu forKey:@"user"];
  376. // [defaults setValue:encryptp forKey:@"password"];
  377. // sqlite3 *db = [iSalesDB get_db];
  378. //
  379. // int count =[iSalesDB get_recordcount:db table:@"login_info" where:[NSString stringWithFormat:@"name='%@'",encryptu]];
  380. //
  381. // if(count==0)
  382. // {
  383. //
  384. // NSString * savelogin=[NSString stringWithFormat:@"insert into login_info(name,pwd) values('%@','%@')",encryptu,encryptp];
  385. // [iSalesDB execSql:savelogin db:db];
  386. // }
  387. // else
  388. // {
  389. // NSString * savelogin=[NSString stringWithFormat:@"update login_info set pwd='%@' where name='%@'",encryptp,encryptu];
  390. // [iSalesDB execSql:savelogin db:db];
  391. // }
  392. //
  393. // [iSalesDB close_db:db];
  394. //
  395. // // [defaults setBool:TRUE forKey:@"autologin"];
  396. // }
  397. // else
  398. // {
  399. // NSString* sql=[NSString stringWithFormat:@"delete from login_info where name='%@'",encryptu];
  400. // [iSalesDB execSql:sql];
  401. // }
  402. // [defaults synchronize];
  403. //
  404. // [self dismissViewControllerAnimated:YES completion:^{
  405. //
  406. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  407. //
  408. // bool offline_dirty=[defaults boolForKey:@"OFFLINE_DIRTY"];
  409. // sqlite3* db = [iSalesDB get_db];
  410. // int offline_user_exist=[iSalesDB get_recordcount:db table:@"offline_login" where:[NSString stringWithFormat:@"username='%@'",appDelegate.user ]];
  411. //
  412. // [iSalesDB close_db:db];
  413. //
  414. //
  415. // BOOL condition = offline_dirty && offline_user_exist>0;
  416. //
  417. //#ifdef OFFLINE_MODE
  418. // condition = condition && !appDelegate.offline_mode;
  419. //#endif
  420. // if(condition)
  421. // {
  422. //
  423. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Detected new offline data" message:@"Do you want to sync with server?" preferredStyle:UIAlertControllerStyleAlert];
  424. // //block代码块取代了delegate
  425. //
  426. //
  427. // UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes(Recommended)" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  428. //
  429. //
  430. //
  431. //
  432. // UIApplication * app = [UIApplication sharedApplication];
  433. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  434. // //UIViewController* active_vc = appDelegate.active_controller;
  435. // OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
  436. // // loginvc.delegate = self;
  437. // // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  438. // // appDelegate.active_controller = gunVC;
  439. // // gunVC.onDismissVC = ^(){
  440. // // appDelegate.active_controller = active_vc;
  441. // // };
  442. // UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
  443. //
  444. //
  445. //
  446. //
  447. //
  448. // // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  449. //
  450. // navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  451. // [appDelegate.main_vc presentViewController:navi animated:YES completion:^{
  452. //
  453. //
  454. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  455. //
  456. // [main_vc checklogin:true];
  457. // // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  458. //
  459. // DebugLog(@"about present.........");
  460. //
  461. // // self.btop = false;
  462. // // <#code#>
  463. // }];
  464. //
  465. //
  466. //
  467. //
  468. // }];
  469. //
  470. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  471. //
  472. // if(self.returnValue)
  473. // self.returnValue(true);
  474. // [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
  475. //
  476. // }];
  477. //
  478. // [alertControl addAction:actionTwo];
  479. // [alertControl addAction:alertthree];
  480. //
  481. //
  482. //
  483. // [appDelegate.main_vc presentViewController:alertControl animated:YES completion:nil];
  484. //
  485. //
  486. //
  487. //
  488. // }
  489. // else
  490. // {
  491. // if(self.returnValue)
  492. // self.returnValue(true);
  493. // [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
  494. // }
  495. // }];
  496. //
  497. //
  498. //
  499. // // if (self.delegate && [self.delegate respondsToSelector:@selector(LoginViewControllerDidLogin:)]) {
  500. // // [self.delegate LoginViewControllerDidLogin:self];
  501. // // }
  502. //
  503. // [[NSNotificationCenter defaultCenter] postNotificationName:User_LoginOK_Notification object:nil];
  504. // }
  505. // else
  506. // {
  507. // NSString* msg=nil;
  508. //
  509. // switch (ret) {
  510. //
  511. // case RESULT_NET_NOTAVAILABLE:
  512. // msg = MSG_NET_NOTAVAILABLE;
  513. // break;
  514. //
  515. //
  516. // case RESULT_NET_ERROR:
  517. // msg = MSG_NET_ERROR;
  518. // break;
  519. //
  520. //
  521. // case RESULT_FALSE:
  522. // msg = MSG_USERAUTH_ERROR;
  523. // break;
  524. //
  525. // case RESULT_VER_LOW:
  526. // msg = MSG_VER_LOW;
  527. // break;
  528. //
  529. // case RESULT_LOGIN_DEVICE:
  530. // msg= MSG_LOGIN_DEVICE;
  531. // break;
  532. // default:
  533. // break;
  534. // }
  535. //
  536. // [RAUtils alert_view:msg title:@"Cannot sign-in"];
  537. //
  538. //
  539. //
  540. // }
  541. //
  542. //
  543. // });
  544. // });
  545. }
  546. - (void)didReceiveMemoryWarning
  547. {
  548. [super didReceiveMemoryWarning];
  549. // Dispose of any resources that can be recreated.
  550. }
  551. #pragma mark - Table view data source
  552. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  553. {
  554. return 44;
  555. }
  556. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  557. {
  558. return 1;
  559. }
  560. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  561. {
  562. return self.logindata.count;
  563. }
  564. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  565. {
  566. NSMutableDictionary* up = self.logindata[indexPath.row];
  567. NSString *CellIdentifier = @"LoginListCell";
  568. UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  569. NSString* name=up[@"name"];
  570. cell.textLabel.text = name;
  571. return cell;
  572. }
  573. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  574. {
  575. NSMutableDictionary* up = self.logindata[indexPath.row];
  576. self.edituser.text = up[@"name"];
  577. self.editpass.text = up[@"pwd"];
  578. self.showList=false;
  579. self.Loginlist.hidden=true;
  580. self.checkSavePassword.selected=true;
  581. }
  582. //- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  583. //{
  584. //
  585. // return true;
  586. //}
  587. - (void)textFieldDidBeginEditing:(UITextField *)textField
  588. {
  589. self.showList=false;
  590. self.Loginlist.hidden=true;
  591. }
  592. #pragma mark - action
  593. - (IBAction)requestLoginBtnClicked:(UIButton *)sender {
  594. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  595. WebViewController *webVC = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
  596. webVC.url = URL_REQUEST_LOGIN;
  597. webVC.title = @"Request Login";
  598. webVC.backItemDismiss = YES;
  599. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:webVC];
  600. nav.modalPresentationStyle = UIModalPresentationFormSheet;
  601. [self presentViewController:nav animated:YES completion:nil];
  602. return;
  603. #endif
  604. #ifdef SCANNER_ORDER
  605. SignUpViewController * vc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"SignUpViewController"];
  606. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
  607. nav.modalPresentationStyle = UIModalPresentationFormSheet;
  608. nav.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  609. [self presentViewController:nav animated:YES completion:nil];
  610. return;
  611. #endif
  612. }
  613. @end