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