LoginViewController.m 33 KB

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