OLOSettingViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. //
  2. // OLOSettingViewController.m
  3. // iSales-UWAVER
  4. //
  5. // Created by Rui Zhang on 1/7/22.
  6. // Copyright © 2022 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "OLOSettingViewController.h"
  9. #import "AppDelegate.h"
  10. #import "RASingleton.h"
  11. #import "ContactListViewController.h"
  12. #import "MainViewController.h"
  13. #import "CustomerEditViewController.h"
  14. #import "UploadCell.h"
  15. #import "UIView+Toast.h"
  16. //#import "ServerSettingViewController.h"
  17. #define OOC_OFFLINE_CONTACT 0
  18. #define OOC_ONLINE_CONTACT 1
  19. #define OOC_CREATE_ORDER 10
  20. @interface OLOSettingViewController ()
  21. @end
  22. @implementation OLOSettingViewController
  23. - (IBAction)onSetUnlockCode:(id)sender {
  24. }
  25. - (IBAction)onUpdateLocalData:(id)sender {
  26. }
  27. - (IBAction)onSetServer:(id)sender {
  28. // ServerSettingViewController *loginSettingVC = [[UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"ServerSettingViewController"];
  29. // __weak typeof(self) weakself = self;
  30. // loginSettingVC.returnValue = ^(NSString *name,NSString *address) {
  31. // if (weakself) {
  32. // __strong typeof(weakself) strongself = weakself;
  33. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  34. // appDelegate.address = address;
  35. // weakself.textfieldName.text = name;
  36. // weakself.textfieldServer.text = address;
  37. //// [strongself.loginTable reloadData];
  38. // }
  39. // };
  40. // UINavigationController *settingRootNav = [[UINavigationController alloc] initWithRootViewController:loginSettingVC];
  41. // [self presentViewController:settingRootNav animated:YES completion:nil];
  42. //
  43. }
  44. - (void)viewDidLoad {
  45. [super viewDidLoad];
  46. if(RASingleton.sharedInstance.enable_OfflineOrder)
  47. {
  48. self.switch_enable.on=true;
  49. }
  50. else
  51. {
  52. self.switch_enable.on=false;
  53. }
  54. // Do any additional setup after loading the view.
  55. }
  56. //- (IBAction)onEnableOLOChanged:(id)sender {
  57. //
  58. // RASingleton.sharedInstance.enable_OfflineOrder = [self.switch_enable isOn];
  59. //}
  60. - (IBAction)onCreateOO:(id)sender
  61. {
  62. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  63. if(appDelegate.user.length<=0)
  64. {
  65. [RAUtils message_alert:@"Please select a sales first" title:@"Create Offline Order" controller:self];
  66. return;
  67. }
  68. [self dismissViewControllerAnimated:NO completion:^{
  69. if(self.returnValue)
  70. self.returnValue(OOC_CREATE_ORDER);
  71. }];
  72. return;
  73. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  74. // __block bool abort = false;
  75. if(appDelegate.contact_id.length<=0)
  76. {
  77. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"New Offline Order" message:nil preferredStyle:UIAlertControllerStyleAlert];
  78. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Offline Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  79. // if(appDelegate.order_code && appDelegate.order_code.length>0)
  80. // {
  81. // [RAUtils message_alert:@"Please close current order and try again." title:@"" controller:self];
  82. // }
  83. // NSLog(@"new click");
  84. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  85. // NSString *path = [[NSBundle mainBundle] pathForResource:@"editContact.json" ofType:nil];
  86. CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  87. cuseditVC.bnewcustomer=true;
  88. cuseditVC.url_type = URL_LOCAL;
  89. cuseditVC.request_url=LOCAL_URL_CUSTOMER_INFO_EDIT;
  90. cuseditVC.params = params;
  91. // cuseditVC.delegate=self;
  92. //
  93. // if(checked.count==count)
  94. // {
  95. // orderinfoVC.have_tail = true
  96. // }
  97. [self dismissViewControllerAnimated:NO completion:^{
  98. [(UINavigationController*)[self parentViewController] pushViewController:cuseditVC animated:false];;
  99. }];
  100. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  101. // [self.navigationController pushViewController:cuseditVC animated:false];
  102. }];
  103. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"With Online Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  104. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  105. if(appDelegate.order_code && appDelegate.order_code.length>0)
  106. {
  107. // appDelegate.order_code= nil;
  108. // [appDelegate SetSo:nil];
  109. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  110. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  111. cvc.showNavibar = true;
  112. cvc.contact_type = @"Sales_Order_Customer";
  113. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  114. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  115. appDelegate.customerInfo = value;
  116. // self.norefresh = true;
  117. [self neworder];
  118. // [main_vc checklogin:true];
  119. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  120. //
  121. // if(self.returnValue)
  122. // self.returnValue(value);
  123. };
  124. cvc.onCancel = ^(){
  125. // self.norefresh = true;
  126. if(appDelegate.customerInfo==nil)
  127. {
  128. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  129. }
  130. else
  131. {
  132. [self neworder];
  133. }
  134. // [main_vc checklogin:true];
  135. };
  136. cvc.onReset = ^(){
  137. // [main_vc checklogin:true];
  138. };
  139. [self.navigationController pushViewController:cvc animated:true];
  140. }
  141. else
  142. {
  143. //create new;
  144. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  145. {
  146. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  147. ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  148. cvc.showNavibar = true;
  149. cvc.contact_type = @"Sales_Order_Customer";
  150. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  151. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  152. appDelegate.customerInfo = value;
  153. if(appDelegate.order_code==nil)
  154. [self neworder];
  155. // [main_vc checklogin:true];
  156. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  157. //
  158. // if(self.returnValue)
  159. // self.returnValue(value);
  160. };
  161. cvc.onCancel = ^(){
  162. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self];
  163. };
  164. cvc.onReset = ^(){
  165. [main_vc checklogin:true];
  166. };
  167. [self.navigationController pushViewController:cvc animated:true];
  168. }
  169. else
  170. {
  171. [self neworder];
  172. }
  173. }
  174. }];
  175. UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  176. }];
  177. [alertControl addAction:actionOne];
  178. [alertControl addAction:alertthree];
  179. [alertControl addAction:alertCancel];
  180. [self presentViewController:alertControl animated:YES completion:nil];
  181. }
  182. else
  183. {
  184. [self neworder];
  185. }
  186. //block代码块取代了delegate
  187. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  188. }
  189. -(void) neworder
  190. {
  191. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
  192. [RANetwork request_create_order:^(NSMutableDictionary *result) {
  193. NSMutableDictionary* return_json =result;
  194. [waitalert dismissViewControllerAnimated:YES completion:^{
  195. if([[return_json valueForKey:@"result"] intValue]==2)
  196. {
  197. int result=[[return_json valueForKey:@"result"] intValue];
  198. if(result==2)
  199. {
  200. //successed.
  201. NSString* order_code = [return_json valueForKey:@"orderCode"];
  202. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  203. appDelegate.order_code = order_code;
  204. appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  205. #ifdef RA_NOTIFICATION
  206. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  207. #else
  208. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  209. [main_vc reloadCart:true immediately:false];
  210. #endif
  211. // [self ReloadData];
  212. // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  213. // [self loadpage];
  214. // if(self.shopCartBlock!=nil)
  215. // {
  216. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  217. //
  218. //
  219. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  220. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  221. // iv.image = img;
  222. // // [self.contentView addSubview:iv];
  223. // self.shopCartBlock(iv);
  224. //
  225. // }
  226. }
  227. }
  228. else
  229. {
  230. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  231. }
  232. }];
  233. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  234. }];
  235. }];
  236. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  237. //
  238. // NSDictionary* return_json = [RANetwork new_Order];
  239. //
  240. // dispatch_async(dispatch_get_main_queue(), ^{
  241. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  242. //
  243. //
  244. // if([[return_json valueForKey:@"result"] intValue]==2)
  245. // {
  246. // int result=[[return_json valueForKey:@"result"] intValue];
  247. // if(result==2)
  248. // {
  249. // //successed.
  250. //
  251. // NSString* order_code = [return_json valueForKey:@"orderCode"];
  252. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  253. // appDelegate.order_code = order_code;
  254. // appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
  255. //
  256. //
  257. //#ifdef RA_NOTIFICATION
  258. // [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  259. //#else
  260. // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  261. // [main_vc reloadCart:true immediately:false];
  262. //#endif
  263. //
  264. // [self ReloadData];
  265. //
  266. //
  267. // // [self performSelector:@selector(loadpage) withObject:nil afterDelay:1];
  268. // // [self loadpage];
  269. //
  270. //
  271. // // if(self.shopCartBlock!=nil)
  272. // // {
  273. // // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  274. // //
  275. // //
  276. // // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  277. // // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  278. // // iv.image = img;
  279. // // // [self.contentView addSubview:iv];
  280. // // self.shopCartBlock(iv);
  281. // //
  282. // // }
  283. //
  284. // }
  285. // }
  286. // else
  287. // {
  288. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Create Order" controller:self] ;
  289. // }
  290. //
  291. //
  292. //
  293. //
  294. // });
  295. // });
  296. }
  297. - (IBAction)onSelectSales:(id)sender {
  298. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  299. appDelegate.user = @"OLOTEST";
  300. appDelegate.bLogin = true;
  301. }
  302. /*
  303. #pragma mark - Navigation
  304. // In a storyboard-based application, you will often want to do a little preparation before navigation
  305. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  306. // Get the new view controller using [segue destinationViewController].
  307. // Pass the selected object to the new view controller.
  308. }
  309. */
  310. @end