CustomerInfoViewController.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. //
  2. // CustomerInfoViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 9/10/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CustomerInfoViewController.h"
  9. #import "RANetwork.h"
  10. #import "CustomerEditViewController.h"
  11. #import "MainViewController.h"
  12. #import "JKTimerManager.h"
  13. @interface CustomerInfoViewController ()
  14. @end
  15. @implementation CustomerInfoViewController
  16. - (void)onEditClick:(id)sender {
  17. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  18. [params setValue:self.contactId forKey:@"contact_id"];
  19. CustomerEditViewController * cuseditVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CustomerEditViewController"];
  20. cuseditVC.bnewcustomer=false;
  21. cuseditVC.url_type = URL_REMOTE;
  22. cuseditVC.request_url=URL_EDIT_CUSTOMER;
  23. cuseditVC.params = params;
  24. cuseditVC.delegate=self;
  25. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  26. [self.navigationController pushViewController:cuseditVC animated:false];
  27. }
  28. - (void)onAssignClick:(id)sender {
  29. [self.lastedit endEditing:true];
  30. [self.lasttextview endEditing:true];
  31. // [self.navigationController popViewControllerAnimated:(false)];
  32. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  33. // NSMutableDictionary* data = [[self.data_init objectForKey:@"customerInfo"] mutableCopy];
  34. for(int i=0;i<section_count;i++)
  35. {
  36. NSDictionary * sectionjson= [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] ;
  37. int count = [[sectionjson valueForKey:@"count"] intValue];
  38. for(int j=0;j<count;j++)
  39. {
  40. NSDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]];
  41. //NSObject* obj=[itemjson valueForKey:@"name"];
  42. NSString* name = itemjson[@"name"];//[[ valueForKey:@"name"] stringValue];
  43. // DebugLog(@"%@",name.class);
  44. // DebugLog(@"%@",self.data_init.class);
  45. // DebugLog(@"%@",NSDictionary.class);
  46. NSString* value = itemjson[@"value"];//[[itemjson valueForKey:@""] stringValue];
  47. //[self.data_init setValue:value forKey:name];
  48. self.data_init[name]=value;
  49. }
  50. }
  51. //---------------- construct customer_contact----------------------
  52. NSString* customer_first_name = [self.data_init valueForKey:@"customer_first_name"];
  53. if(customer_first_name==nil)
  54. customer_first_name=@"";
  55. NSString* customer_last_name= [self.data_init valueForKey:@"customer_last_name"];
  56. if(customer_last_name==nil)
  57. customer_last_name=@"";
  58. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  59. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  60. [self.data_init setValue:customer_contact forKey:@"customer_contact"];
  61. //---------------- finish construct customer_contact----------------------
  62. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  63. if(self.update_order && appDelegate.order_code!=nil)
  64. {
  65. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  66. NSDictionary* editor_json = [RANetwork update_OrderCustomer:appDelegate.order_code customerinfo:self.data_init];
  67. dispatch_async(dispatch_get_main_queue(), ^{
  68. if([[editor_json valueForKey:@"result"] intValue]==2)
  69. {
  70. [self.navigationController popViewControllerAnimated:false];
  71. if(self.returnValue)
  72. {
  73. self.returnValue(self.data_init);
  74. }
  75. }
  76. else
  77. {
  78. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Update Order Customer Infomation" controller:self] ;
  79. }
  80. });
  81. });
  82. }
  83. else
  84. {
  85. [self.navigationController popViewControllerAnimated:false];
  86. if(self.returnValue)
  87. {
  88. self.returnValue(self.data_init);
  89. }
  90. }
  91. }
  92. - (void)onResetClick:(id)sender {
  93. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  94. if(appDelegate.order_code.length>0)
  95. {
  96. //当前已打开订单则关闭订单。
  97. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to release order and reset contact?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  98. //block代码块取代了delegate
  99. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  100. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  101. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  102. NSDictionary* order_json = [RANetwork release_Order:appDelegate.order_code withScreen:ScreenCodeCustomerInfo];
  103. dispatch_async(dispatch_get_main_queue(), ^{
  104. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  105. if([[order_json valueForKey:@"result"] intValue]==2)
  106. {
  107. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  108. // appDelegate.order_code = nil;
  109. [appDelegate closeOrder];
  110. #ifdef RA_NOTIFICATION
  111. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  112. [ActiveViewController Notify:@"ContactListViewController" Message:RA_NOTIFICATION_REFRESH_UI];
  113. #else
  114. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  115. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  116. [((MainViewController*)appDelegate.main_vc) reloadContact:false immediately:false];
  117. #endif
  118. [self.navigationController popToRootViewControllerAnimated:false];
  119. }
  120. else
  121. {
  122. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Release Order" controller:self] ;
  123. }
  124. });
  125. });
  126. }];
  127. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  128. DebugLog(@"Cancel");
  129. }];
  130. [alertControl addAction:actionOne];
  131. [alertControl addAction:alertthree];
  132. [self presentViewController:alertControl animated:YES completion:nil];
  133. }
  134. else
  135. {
  136. //询问并清空当前的全局contact_id、customer
  137. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to reset contact?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  138. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  139. if(appDelegate.user_type!=USER_ROLE_CUSTOMER)
  140. {
  141. appDelegate.contact_id=nil;
  142. appDelegate.customerInfo = nil;
  143. }
  144. [self.navigationController popViewControllerAnimated:(false)];
  145. }];
  146. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  147. DebugLog(@"Cancel");
  148. }];
  149. [alertControl addAction:actionOne];
  150. [alertControl addAction:alertthree];
  151. [self presentViewController:alertControl animated:YES completion:nil];
  152. }
  153. }
  154. - (void)viewDidLoad {
  155. [super viewDidLoad];
  156. [[self navigationController] setNavigationBarHidden:NO animated:NO];
  157. if(self.rightbtn_title!=nil)
  158. [ self.right_btn setTitle:self.rightbtn_title];
  159. // UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Back", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onBackClick:)];
  160. // // closeButton.title = @"Close";
  161. UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  162. style:UIBarButtonItemStylePlain
  163. target:self
  164. action:@selector( onBackClick:)];
  165. self.navigationItem.leftBarButtonItem = backButton;
  166. NSMutableArray * items = [[NSMutableArray alloc]init];
  167. self.btn_edit = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"edit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  168. style:UIBarButtonItemStylePlain
  169. target:self
  170. action:@selector(onEditClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
  171. // self.btn_edit.tintColor = UIColorFromRGB(0x996633);
  172. self.btn_assign = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"assign"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  173. style:UIBarButtonItemStylePlain
  174. target:self
  175. action:@selector(onAssignClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
  176. // self.btn_assign.tintColor = UIColorFromRGB(0x996633);
  177. self.btn_reset = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"reset"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  178. style:UIBarButtonItemStylePlain
  179. target:self
  180. action:@selector(onResetClick:)];//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Download", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onDownloadOrderClick:)];
  181. // self.btn_reset.tintColor = UIColorFromRGB(0x996633);
  182. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  183. if(self.edit_icon)
  184. [items addObject:self.btn_edit];
  185. if ((appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) && appDelegate.order_code.length > 0 && ![Singleton sharedInstance].currentOrderIsMerged) {
  186. // shop order 隐藏assign
  187. } else {
  188. if(self.assig_icon)
  189. [items addObject:self.btn_assign];
  190. }
  191. if(self.reset_icon)
  192. [items addObject:self.btn_reset];
  193. self.navigationItem.rightBarButtonItems=items;
  194. if (self.data_init==nil) {
  195. [self request_fill];
  196. }
  197. else
  198. {
  199. [self fillData];
  200. }
  201. // Do any additional setup after loading the view.
  202. }
  203. - (void)onBackClick:(UIButton *)sender {
  204. [self.lastedit endEditing:true];
  205. [self.lasttextview endEditing:true];
  206. NSMutableDictionary* back_data = [self.data_init mutableCopy];
  207. // [self.navigationController popViewControllerAnimated:(false)];
  208. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  209. // NSMutableDictionary* data = [[self.data_init objectForKey:@"customerInfo"] mutableCopy];
  210. for(int i=0;i<section_count;i++)
  211. {
  212. NSDictionary * sectionjson= [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] ;
  213. int count = [[sectionjson valueForKey:@"count"] intValue];
  214. for(int j=0;j<count;j++)
  215. {
  216. NSDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]];
  217. NSString* name = [itemjson valueForKey:@"name"];
  218. NSString* value = [itemjson valueForKey:@"value"];
  219. [back_data setValue:value forKey:name];
  220. }
  221. }
  222. //---------------- construct customer_contact----------------------
  223. NSString* customer_first_name = [back_data valueForKey:@"customer_first_name"];
  224. if(customer_first_name==nil)
  225. customer_first_name=@"";
  226. NSString* customer_last_name= [back_data valueForKey:@"customer_last_name"];
  227. if(customer_last_name==nil)
  228. customer_last_name=@"";
  229. NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  230. customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  231. [back_data setValue:customer_contact forKey:@"customer_contact"];
  232. if(self.onClose)
  233. {
  234. self.onClose(back_data);
  235. }
  236. [self.navigationController popViewControllerAnimated:(false)];
  237. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  238. // ;
  239. // }];
  240. }
  241. -(void) request_fill
  242. {
  243. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Loading Contact information"];
  244. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  245. NSDictionary* editor_json = [RANetwork request_CustomerInfo:self.contactId];
  246. dispatch_async(dispatch_get_main_queue(), ^{
  247. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  248. if([[editor_json valueForKey:@"result"] intValue]==2)
  249. {
  250. self.data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
  251. [self fillData];
  252. self.btn_assign.enabled=true;
  253. }
  254. else
  255. {
  256. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
  257. self.btn_assign.enabled=false;
  258. }
  259. });
  260. });
  261. }
  262. - (void) fillData
  263. {
  264. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  265. // NSDictionary* data = [self.data_init objectForKey:@"customerInfo"];
  266. for(int i=0;i<section_count;i++)
  267. {
  268. NSMutableDictionary * sectionjson= [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  269. int count = [[sectionjson valueForKey:@"count"] intValue];
  270. for(int j=0;j<count;j++)
  271. {
  272. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  273. NSString* control=[itemjson valueForKey:@"control"];
  274. NSString* name = [itemjson valueForKey:@"name"];
  275. NSString* value = [self.data_init valueForKey:name];
  276. [itemjson setValue:value forKey:@"value"];
  277. if([control isEqualToString:@"img"])
  278. {
  279. {
  280. NSString* img_url = [itemjson valueForKey:@"img_url_0"];
  281. NSString* url_value = [self.data_init valueForKey:img_url];
  282. [itemjson setValue:url_value forKey:@"img_url_0"];
  283. }
  284. {
  285. NSString* img_url = [itemjson valueForKey:@"img_url_1"];
  286. NSString* url_value = [self.data_init valueForKey:img_url];
  287. [itemjson setValue:url_value forKey:@"img_url_1"];
  288. }
  289. {
  290. NSString* img_url = [itemjson valueForKey:@"img_url_2"];
  291. NSString* url_value = [self.data_init valueForKey:img_url];
  292. [itemjson setValue:url_value forKey:@"img_url_2"];
  293. }
  294. }
  295. [sectionjson setObject:itemjson forKey:[NSString stringWithFormat:@"item_%d",j]];
  296. }
  297. [self.content_data_download setObject:sectionjson forKey:[NSString stringWithFormat:@"section_%d",i]];
  298. }
  299. self.content_data_control=[self translate_json:self.content_data_download changed:self.changed_data];
  300. // self.navigationItem.title = [self.content_data_download valueForKey:@"title"] ;
  301. [self.editorTable reloadData];
  302. }
  303. //- (IBAction)onEditClick:(id)sender {
  304. //
  305. //
  306. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  307. //
  308. //
  309. // [params setValue:self.contactId forKey:@"contactId"];
  310. // CustomerEditViewController * cuseditVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"CustomerEditViewController"];
  311. //
  312. // cuseditVC.bnewcustomer=false;
  313. // cuseditVC.url_type = URL_REMOTE;
  314. // cuseditVC.request_url=URL_EDIT_CUSTOMER;
  315. //
  316. // cuseditVC.params = params;
  317. //
  318. // cuseditVC.delegate=self;
  319. // //
  320. // // if(checked.count==count)
  321. // // {
  322. // // orderinfoVC.have_tail = true
  323. // // }
  324. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  325. // [self.navigationController pushViewController:cuseditVC animated:false];
  326. //
  327. //}
  328. //- (IBAction)onSetClick:(id)sender {
  329. //
  330. // [self.lastedit endEditing:true];
  331. // [self.lasttextview endEditing:true];
  332. //
  333. //
  334. //
  335. //
  336. //
  337. // // [self.navigationController popViewControllerAnimated:(false)];
  338. // int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  339. //// NSMutableDictionary* data = [[self.data_init objectForKey:@"customerInfo"] mutableCopy];
  340. //
  341. // for(int i=0;i<section_count;i++)
  342. // {
  343. // NSDictionary * sectionjson= [self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i]] ;
  344. // int count = [[sectionjson valueForKey:@"count"] intValue];
  345. // for(int j=0;j<count;j++)
  346. // {
  347. // NSDictionary * itemjson=[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j]];
  348. //
  349. // NSString* name = [itemjson valueForKey:@"name"];
  350. //
  351. // NSString* value = [itemjson valueForKey:@"value"];
  352. //
  353. // [self.data_init setValue:value forKey:name];
  354. //
  355. //
  356. //
  357. // }
  358. //
  359. // }
  360. // //---------------- construct customer_contact----------------------
  361. // NSString* customer_first_name = [self.data_init valueForKey:@"customer_first_name"];
  362. // if(customer_first_name==nil)
  363. // customer_first_name=@"";
  364. //
  365. // NSString* customer_last_name= [self.data_init valueForKey:@"customer_last_name"];
  366. // if(customer_last_name==nil)
  367. // customer_last_name=@"";
  368. // NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  369. // customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  370. // [self.data_init setValue:customer_contact forKey:@"customer_contact"];
  371. // //---------------- finish construct customer_contact----------------------
  372. //
  373. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  374. // if(self.update_order && appDelegate.order_code!=nil)
  375. // {
  376. //
  377. //
  378. //
  379. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  380. //
  381. // NSDictionary* editor_json = [iSalesNetwork update_OrderCustomer:appDelegate.order_code customerinfo:self.data_init];
  382. //
  383. // dispatch_async(dispatch_get_main_queue(), ^{
  384. //
  385. //
  386. // if([[editor_json valueForKey:@"result"] intValue]==2)
  387. // {
  388. //
  389. // [self.navigationController popViewControllerAnimated:false];
  390. // if(self.returnValue)
  391. // {
  392. //
  393. // self.returnValue(self.data_init);
  394. // }
  395. //
  396. //
  397. //
  398. // }
  399. // else
  400. // {
  401. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Update Order Customer Infomation" controller:self] ;
  402. // }
  403. //
  404. //
  405. //
  406. // });
  407. // });
  408. //
  409. //
  410. // }
  411. // else
  412. // {
  413. //
  414. // [self.navigationController popViewControllerAnimated:false];
  415. // if(self.returnValue)
  416. // {
  417. // self.returnValue(self.data_init);
  418. //
  419. // }
  420. // // [self.data_init setObject:data forKey:@"customerInfo"];
  421. //
  422. //
  423. // /*
  424. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  425. // appDelegate.contact_id=self.contactId;
  426. // appDelegate.customerInfo = self.data_init;
  427. // */
  428. //
  429. //// [self.navigationController popToRootViewControllerAnimated:false];
  430. // }
  431. //
  432. //
  433. //
  434. //}
  435. #pragma mark- img changed
  436. // image 改变时执行
  437. - (void) imgIsChanged:(NSString *)url_down url_up:(NSString *)url_up indexPath: (NSIndexPath *) indexPath{
  438. // int aaa = 0;
  439. // NSDictionary* aaa = self.content_data_download;
  440. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  441. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  442. NSString* cid=[self getValue:@"customer_cid"];
  443. NSDictionary* return_json = [RANetwork update_customer_img:cid img_url:url_up];
  444. dispatch_async(dispatch_get_main_queue(), ^{
  445. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  446. if([[return_json valueForKey:@"result"] intValue]==2)
  447. {
  448. int result=[[return_json valueForKey:@"result"] intValue];
  449. if(result==2)
  450. {
  451. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Upload successful." message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  452. [alert show];
  453. }
  454. }
  455. else
  456. {
  457. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  458. }
  459. });
  460. });
  461. // // DebugLog(@"Sender is = %@", url);
  462. //
  463. //
  464. //
  465. //
  466. // NSMutableDictionary* section_json=nil;
  467. //
  468. //
  469. // // DebugLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  470. // NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  471. //
  472. // int refresh = [[item_json valueForKey:@"refresh"] intValue];
  473. //
  474. // NSString* subid=[item_json valueForKey:@"subid"];
  475. //
  476. // item_json[@"img_url"]=url_down;
  477. // item_json[@"avalue"]=url_up;
  478. //
  479. // if(subid==nil)
  480. // {
  481. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  482. // int count=0;
  483. //
  484. // count=[[section_json valueForKey:@"count"] intValue];
  485. //
  486. // for(int i=0;i<count;i++)
  487. // {
  488. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]];
  489. // if([[olditem valueForKey:@"name"] isEqualToString:[item_json valueForKey:@"name" ]])
  490. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i ]];
  491. //
  492. //
  493. // }
  494. //
  495. // }
  496. // else
  497. // {
  498. // NSArray* idarr=[subid componentsSeparatedByString:@"_"];
  499. // int section = [(NSString*)idarr[0] intValue];
  500. // int item=[(NSString*)idarr[1] intValue];
  501. //
  502. //
  503. // section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d", section]] mutableCopy];
  504. // NSDictionary * olditem=[section_json objectForKey:[NSString stringWithFormat:@"item_%d",item ]];
  505. // item_json= [self enum_subitem_changed:[olditem mutableCopy] subid:idarr value:item_json step:2];
  506. // [item_json setValue:@"true" forKey:@"dirty"];
  507. // [section_json setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",item ]];
  508. // }
  509. //
  510. //
  511. //
  512. // [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  513. //
  514. // self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  515. //
  516. // NSRange range = NSMakeRange(indexPath.section, 1);
  517. // NSIndexSet *sectionToReload = [NSIndexSet indexSetWithIndexesInRange:range];
  518. // // [self.editorTable reloadSections:sectionToReload withRowAnimation:UITableViewRowAnimationAutomatic];
  519. //
  520. //
  521. // if(refresh==1)
  522. // {
  523. // [self refresh];
  524. // }
  525. }
  526. - (void)didReceiveMemoryWarning {
  527. [super didReceiveMemoryWarning];
  528. // Dispose of any resources that can be recreated.
  529. }
  530. /*
  531. #pragma mark - Navigation
  532. // In a storyboard-based application, you will often want to do a little preparation before navigation
  533. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  534. // Get the new view controller using [segue destinationViewController].
  535. // Pass the selected object to the new view controller.
  536. }
  537. */
  538. #pragma mark - Urgency
  539. - (void)viewWillAppear:(BOOL)animated {
  540. [super viewWillAppear:animated];
  541. [self start_urgency_timer];
  542. }
  543. -(void) viewWillDisappear:(BOOL)animated
  544. {
  545. [super viewWillDisappear:animated];
  546. [self cancel_urgency_timer];
  547. }
  548. - (void)dealloc {
  549. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  550. [appDelegate.urgencyDic removeObjectForKey:[NSString stringWithFormat:@"level_%d",self.level]];
  551. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:self.level] forKey:@"count"];
  552. }
  553. - (void)start_urgency_timer {
  554. if (!self.editable) {
  555. return;
  556. }
  557. __weak typeof(self) weakSelf = self;
  558. AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  559. [appDelegate.urgencyDic setValue:appDelegate.user forKey:@"user"];
  560. #ifdef OFFLINE_MODE
  561. [appDelegate.urgencyDic setValue:[NSNumber numberWithBool:appDelegate.offline_mode] forKey:@"offline_mode"];
  562. #endif
  563. [[JKTimerManager sharedTimerManager] scheduledDispatchTimerWithName:self.urgency_timer_name timeInterval:1 queue:nil repeats:YES action:^{
  564. NSMutableDictionary *urgencyDic = [NSMutableDictionary dictionary];
  565. // DebugLog(@"timer start....");
  566. [urgencyDic setValue:weakSelf.content_data_download forKey:[NSString stringWithFormat:@"%@_restored_data",self.class_name]];
  567. [urgencyDic setValue:weakSelf.class_name forKey:@"class_name"];
  568. [appDelegate.urgencyDic setValue:urgencyDic forKey:[NSString stringWithFormat:@"level_%d",weakSelf.level]];
  569. [appDelegate.urgencyDic setValue:[NSNumber numberWithInteger:weakSelf.level + 1] forKey:@"count"];
  570. }];
  571. }
  572. - (void)cancel_urgency_timer {
  573. [[JKTimerManager sharedTimerManager] cancelTimerWithName:self.urgency_timer_name];
  574. }
  575. @end