CreateOrderViewController.m 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446
  1. //
  2. // CreateOrderViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 8/24/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "CreateOrderViewController.h"
  9. #import "iSalesNetwork.h"
  10. #import "MainViewController.h"
  11. #define SUBMIT_CONFIRM 123
  12. #define KEEP_TAIL 456
  13. #define CLOSE_ACTION 567
  14. @interface CreateOrderViewController ()
  15. // static const char associatedkey;
  16. @end
  17. @implementation CreateOrderViewController
  18. -(void) viewWillAppear:(BOOL)animated
  19. {
  20. [super viewWillAppear:animated];
  21. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  22. if(appDelegate.can_submit_order)
  23. {
  24. [self.btnSubmitOrder setImage:[UIImage imageNamed:@"commit"]];
  25. self.btnSubmitOrder.enabled = true;
  26. }
  27. else
  28. {
  29. [self.btnSubmitOrder setImage:nil];
  30. self.btnSubmitOrder.enabled = false;
  31. }
  32. self.navigationController.navigationBarHidden=false;
  33. }
  34. -(void) download_success
  35. {
  36. // 用于处理不同child,在成功去的数据后,需要附加的操作。
  37. self.have_tail=[[self.content_data_download valueForKey:@"has_reItem"] boolValue];
  38. NSString* order_customerid=[self getValue:@"customer_cid"];
  39. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  40. appDelegate.order_customer_id = order_customerid;
  41. }
  42. - (void)viewDidLoad {
  43. [super viewDidLoad];
  44. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
  45. style:UIBarButtonItemStylePlain
  46. target:self
  47. action:@selector(onCloseClick:)];
  48. //[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onCloseClick:)];
  49. // closeButton.title = @"Close";
  50. self.navigationItem.leftBarButtonItem = closeButton;
  51. NSMutableArray * items = [[NSMutableArray alloc]init];
  52. UIBarButtonItem *savebtn = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
  53. savebtn = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
  54. style:UIBarButtonItemStylePlain
  55. target:self
  56. action:@selector(onSaveClick:)];
  57. self.btnSubmitOrder = nil;
  58. self.btnSubmitOrder =[[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"commit"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  59. style:UIBarButtonItemStylePlain
  60. target:self
  61. action:@selector(onCommitOrderClick:)];
  62. self.btnSubmitOrder.tintColor= UIColorFromRGB(0x996633);
  63. //savebtn setBackgroundImage:(nullable UIImage *) forState:<#(UIControlState)#> style:<#(UIBarButtonItemStyle)#> barMetrics:<#(UIBarMetrics)#>
  64. //[savebtn setImage:[UIImage imageNamed:@"save"] ];
  65. /*
  66. UIBarMetricsDefault,
  67. UIBarMetricsCompact,
  68. UIBarMetricsDefaultPrompt = 101, // Applicable only in bars with the prompt property, such as UINavigationBar and UISearchBar
  69. UIBarMetricsCompactPrompt
  70. */
  71. // [savebtn setBackgroundImage:[UIImage imageNamed:@"save"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
  72. // UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
  73. // item1.title = @"item1";
  74. //// item1.image = [UIImage imageNamed:@"rect_setting"];
  75. // UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
  76. //// item2.image = [UIImage imageNamed:@"rect_about"];
  77. // item2.title = @"item2";
  78. UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  79. fixedItem.width = 20.0f;
  80. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  81. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  82. {
  83. [items addObject:savebtn];
  84. [items addObject:fixedItem];
  85. }
  86. [items addObject:self.btnSubmitOrder];
  87. // [items addObject:item2];
  88. self.navigationItem.rightBarButtonItems=items;
  89. // self.navigationItem.backBarButtonItem = backButton;
  90. // Do any additional setup after loading the view.
  91. }
  92. - (void)onCommitOrderClick:(id)sender {
  93. // get customer info
  94. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Submit Confirm.", nil) message:NSLocalizedString(@"Are you sure to submit order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  95. alert.tag = SUBMIT_CONFIRM;
  96. [alert show];
  97. }
  98. - (void)onCloseClick:(UIButton *)sender {
  99. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Choose your action", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Switch to cart", nil),@"Switch to order history",NSLocalizedString(@"Close and release order", nil), nil];
  100. alert.tag = CLOSE_ACTION;
  101. // alert.
  102. [alert show];
  103. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  104. // appDelegate.order_code = nil;
  105. //
  106. // }
  107. }
  108. - (void)didReceiveMemoryWarning {
  109. [super didReceiveMemoryWarning];
  110. // Dispose of any resources that can be recreated.
  111. }
  112. - (IBAction)onSaveClick:(id)sender {
  113. // add params check here.
  114. [self.lastedit endEditing:true];
  115. [self.lasttextview endEditing:true];
  116. self.cancommit=true;
  117. NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  118. [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  119. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  120. for(int i=0;i<section_count;i++)
  121. {
  122. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  123. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  124. for(int j=0;j<item_count;j++)
  125. {
  126. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  127. NSString* key = [itemjson valueForKey:@"name"];
  128. if(key==nil || key.length==0)
  129. continue;
  130. if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  131. {
  132. NSString* single_select = [itemjson valueForKey:@"single_select"];
  133. if([single_select isEqualToString:@"true"])
  134. {
  135. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  136. int count = [[cadejson valueForKey:@"count"] intValue];
  137. bool setvalue = false;
  138. for(int cc=0;cc<count;cc++)
  139. {
  140. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  141. if([[valjson valueForKey:@"check"]intValue]==1)
  142. {
  143. [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  144. setvalue=true;
  145. break;
  146. }
  147. }
  148. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  149. {
  150. self.cancommit = false;
  151. }
  152. }
  153. else
  154. {
  155. //not support multi select for now;
  156. }
  157. /*
  158. upparams setValue:itemjson forKey:<#(NSString *)#>
  159. */
  160. }else
  161. if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  162. {
  163. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  164. self.cancommit = false;
  165. }
  166. else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  167. {
  168. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"]==nil)
  169. self.cancommit = false;
  170. NSString* valuestr = [itemjson valueForKey:@"value"];
  171. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  172. }
  173. else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  174. {
  175. NSString* valuestr = [itemjson valueForKey:@"value"];
  176. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  177. NSString* value = [itemjson valueForKey:@"value"];
  178. NSMutableDictionary* boolitem=nil;
  179. NSMutableDictionary* subjson=nil;
  180. if([value isEqualToString:@"true"])
  181. {
  182. boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  183. }
  184. else
  185. {
  186. boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  187. }
  188. subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  189. if( subjson!=nil /*&& !active*/)
  190. {
  191. int sub_count = [[subjson valueForKey:@"count"] intValue];
  192. for(int l=0;l<sub_count;l++)
  193. {
  194. NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  195. if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  196. [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  197. else
  198. {
  199. if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  200. self.cancommit = false;
  201. }
  202. }
  203. }
  204. }
  205. else
  206. {
  207. if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  208. [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  209. else
  210. {
  211. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  212. self.cancommit = false;
  213. }
  214. }
  215. upparams= [self subitem_param:itemjson addto:upparams ];
  216. }
  217. }
  218. // save order 不检查必填项;
  219. self.cancommit=true;
  220. if(self.cancommit==false)
  221. {
  222. [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  223. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  224. //NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  225. //[self.editorTable reloadData ];
  226. [self.editorTable reloadData];
  227. return;
  228. }
  229. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"])
  230. upparams[@"shipping"] = nil;
  231. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Saving Order"];
  232. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  233. NSDictionary* editor_json = [iSalesNetwork save_Order:upparams];
  234. dispatch_async(dispatch_get_main_queue(), ^{
  235. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  236. if([[editor_json valueForKey:@"result"] intValue]==2)
  237. {
  238. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  239. NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  240. appDelegate.customerInfo = customerInfo;
  241. appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  242. [RAUtils message_alert:nil title:@"Order Saved" controller:self] ;
  243. if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.save_order_logout && appDelegate.user_type ==USER_ROLE_EMPLOYEE)
  244. {
  245. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  246. [self prepareReturn:nil];
  247. [self.navigationController popViewControllerAnimated:true];
  248. }
  249. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  250. // appDelegate.order_code = nil;
  251. //
  252. // }
  253. // // self.labelContact.text=appDelegate.contact_name;
  254. //
  255. // NSDictionary * customerinfo = appDelegate.customerInfo;
  256. // [self prepareReturn:nil];
  257. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  258. //
  259. //
  260. // ;
  261. // }];
  262. }
  263. else
  264. {
  265. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Save Order" controller:self] ;
  266. }
  267. });
  268. });
  269. }
  270. - (void)textFieldDidEndEditing:(UITextField *)textField
  271. {
  272. [super textFieldDidEndEditing:textField];
  273. UITableViewCell *cell = (UITableViewCell *) textField.superview.superview;
  274. NSIndexPath * indexPath = [self.editorTable indexPathForCell:cell];
  275. NSMutableDictionary* section_json=nil;
  276. // NSLog(@"endedit %d_%d",indexPath.section,indexPath.row);
  277. NSMutableDictionary* item_json =[((NSMutableArray*)self.content_data_control[indexPath.section])[indexPath.row] mutableCopy];
  278. NSString* name = [item_json valueForKey:@"name"];
  279. if([name isEqualToString:@"shipping"]|| [name isEqualToString:@"handling_fee_value"]||[name isEqualToString:@"lift_gate_value"])
  280. {
  281. float shipping = [self getprice:@"shipping" section:indexPath.section];
  282. float paymentsAndCredits = [self getprice:@"paymentsAndCredits" section:indexPath.section];
  283. float handling_fee_value = [self getprice:@"handling_fee_value" section:indexPath.section];
  284. float lift_gate =[self getprice:@"lift_gate_value" section:indexPath.section];
  285. float totalprice=shipping+paymentsAndCredits+handling_fee_value+lift_gate;
  286. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]] mutableCopy];
  287. int count=0;
  288. count=[[section_json valueForKey:@"count"] intValue];
  289. int total_row_idx=-1;
  290. for(int i=0;i<count;i++)
  291. {
  292. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  293. if([[olditem valueForKey:@"name"] isEqualToString:@"totalPrice" ])
  294. {
  295. [olditem setValue:[NSString stringWithFormat:@"%.2f",totalprice] forKey:@"value"];
  296. [olditem setValue:@"true" forKey:@"dirty"];
  297. [section_json setObject:olditem forKey:[NSString stringWithFormat:@"item_%d",i ]];
  298. total_row_idx=i;
  299. }
  300. }
  301. [self.content_data_download setObject:section_json forKey:[NSString stringWithFormat:@"section_%ld",(long)indexPath.section ]];
  302. self.content_data_control = [self translate_json:self.content_data_download changed: self.changed_data];
  303. if(total_row_idx>=0)
  304. {
  305. NSUInteger newIndex[] = {indexPath.section, total_row_idx};
  306. NSIndexPath *newPath = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
  307. // NSLog(@"before refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  308. [self.editorTable reloadRowsAtIndexPaths:@[newPath]withRowAnimation:UITableViewRowAnimationMiddle];
  309. // NSLog(@"after refresh %@",NSStringFromCGSize(self.editorTable.contentSize));
  310. // CGSize tablecontent =self.editorTable.contentSize;
  311. // tablecontent.height=tablecontent.height+self.keyboard_h;
  312. // self.editorTable.contentSize=tablecontent;
  313. //
  314. //
  315. // NSLog(@"resize to %@",NSStringFromCGSize(self.editorTable.contentSize));
  316. }
  317. // self.content_data = [editor_json mutableCopy];
  318. // self.content_data = [self translate_json:editor_json];
  319. // NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
  320. // [self.editorTable reloadData];
  321. }
  322. //
  323. // [item_json setValue:@"true" forKey:@"dirty"];
  324. // [item_json setValue:textField.text forKey:@"value"];
  325. }
  326. -(float) getprice:(NSString*) name section :(long) index
  327. {
  328. NSMutableDictionary* section_json=nil;
  329. section_json = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%ld",index ]] mutableCopy];
  330. int count=0;
  331. count=[[section_json valueForKey:@"count"] intValue];
  332. for(int i=0;i<count;i++)
  333. {
  334. NSDictionary * olditem=[[section_json objectForKey:[NSString stringWithFormat:@"item_%d",i ]] mutableCopy];
  335. if([[olditem valueForKey:@"name"] isEqualToString:name])
  336. {
  337. return [[olditem valueForKey:@"value"] floatValue];
  338. }
  339. }
  340. return 0;
  341. }
  342. /*
  343. #pragma mark - Navigation
  344. // In a storyboard-based application, you will often want to do a little preparation before navigation
  345. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  346. // Get the new view controller using [segue destinationViewController].
  347. // Pass the selected object to the new view controller.
  348. }
  349. */
  350. #pragma mark - UIAlertViewDelegate
  351. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  352. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  353. {
  354. if(buttonIndex!=alertView.cancelButtonIndex && alertView.tag == SUBMIT_CONFIRM)
  355. {
  356. // add params check here.
  357. [self.lastedit endEditing:true];
  358. [self.lasttextview endEditing:true];
  359. self.cancommit=true;
  360. NSMutableDictionary* upparams=[[NSMutableDictionary alloc] init];
  361. [upparams setValue:[self.params valueForKey:@"cart2Checkbox"] forKey:@"cart2Checkbox"];
  362. int section_count=[[self.content_data_download valueForKey:@"section_count"] intValue];
  363. for(int i=0;i<section_count;i++)
  364. {
  365. NSMutableDictionary * sectionjson = [[self.content_data_download objectForKey:[NSString stringWithFormat:@"section_%d",i ]] mutableCopy];
  366. int item_count = [[sectionjson valueForKey:@"count"] intValue];
  367. for(int j=0;j<item_count;j++)
  368. {
  369. NSMutableDictionary * itemjson=[[sectionjson objectForKey:[NSString stringWithFormat:@"item_%d",j ]] mutableCopy];
  370. NSString* key = [itemjson valueForKey:@"name"];
  371. if(key==nil || key.length==0)
  372. continue;
  373. if([[itemjson valueForKey:@"control"] isEqualToString:@"enum"])
  374. {
  375. NSString* single_select = [itemjson valueForKey:@"single_select"];
  376. if([single_select isEqualToString:@"true"])
  377. {
  378. NSDictionary* cadejson=[itemjson objectForKey:@"cadedate"];
  379. int count = [[cadejson valueForKey:@"count"] intValue];
  380. bool setvalue = false;
  381. for(int cc=0;cc<count;cc++)
  382. {
  383. NSDictionary* valjson=[cadejson objectForKey:[NSString stringWithFormat:@"val_%d",cc]];
  384. if([[valjson valueForKey:@"check"]intValue]==1)
  385. {
  386. [upparams setValue:[valjson valueForKey:@"value_id"] forKey:[itemjson valueForKey:@"name"]];
  387. setvalue=true;
  388. break;
  389. }
  390. }
  391. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && setvalue==false)
  392. {
  393. self.cancommit = false;
  394. }
  395. }
  396. else
  397. {
  398. //not support multi select for now;
  399. }
  400. /*
  401. upparams setValue:itemjson forKey:<#(NSString *)#>
  402. */
  403. }else
  404. if([[itemjson valueForKey:@"control"] isEqualToString:@"action"])
  405. {
  406. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"data"]==nil)
  407. self.cancommit = false;
  408. }
  409. else if([[itemjson valueForKey:@"control"] isEqualToString:@"signature"])
  410. {
  411. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] && [itemjson objectForKeyedSubscript:@"value"] ==nil)
  412. self.cancommit = false;
  413. NSString* valuestr = [itemjson valueForKey:@"value"];
  414. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  415. }
  416. else if([[itemjson valueForKey:@"control"] isEqualToString:@"switch"])
  417. {
  418. NSString* valuestr = [itemjson valueForKey:@"value"];
  419. [upparams setValue:valuestr forKey:[itemjson valueForKey:@"name"]];
  420. NSString* value = [itemjson valueForKey:@"value"];
  421. NSMutableDictionary* boolitem=nil;
  422. NSMutableDictionary* subjson=nil;
  423. if([value isEqualToString:@"true"])
  424. {
  425. boolitem =[[itemjson objectForKey:@"true"] mutableCopy];
  426. }
  427. else
  428. {
  429. boolitem =[[itemjson objectForKey:@"false"] mutableCopy];
  430. }
  431. subjson=[[boolitem objectForKey:@"sub_item"] mutableCopy];
  432. if( subjson!=nil /*&& !active*/)
  433. {
  434. int sub_count = [[subjson valueForKey:@"count"] intValue];
  435. for(int l=0;l<sub_count;l++)
  436. {
  437. NSMutableDictionary * modify_item=[[subjson objectForKey:[NSString stringWithFormat:@"item_%d",l ]] mutableCopy];
  438. if([modify_item valueForKey:@"value"]!=nil && ![[modify_item valueForKey:@"value"]isEqualToString:@""])
  439. [upparams setValue:[modify_item valueForKey:@"value"] forKey:[modify_item valueForKey:@"name"]];
  440. else
  441. {
  442. if([[modify_item valueForKey:@"required"] isEqualToString: @"true"] )
  443. self.cancommit = false;
  444. }
  445. }
  446. }
  447. }
  448. else
  449. {
  450. if([itemjson valueForKey:@"value"]!=nil && ![[itemjson valueForKey:@"value"]isEqualToString:@""])
  451. [upparams setValue:[itemjson valueForKey:@"value"] forKey:[itemjson valueForKey:@"name"]];
  452. else
  453. {
  454. if([[itemjson valueForKey:@"required"] isEqualToString: @"true"] )
  455. self.cancommit = false;
  456. }
  457. }
  458. upparams= [self subitem_param:itemjson addto:upparams ];
  459. }
  460. }
  461. if(self.cancommit==false)
  462. {
  463. [RAUtils alert_view:@"Fields with * mark cannot be empty." title:@"Some Requried Fields Are Missing."];
  464. self.content_data_control = [self translate_json:self.content_data_download changed:self.changed_data];
  465. //NSLog(@"CONTENT translate:%@",[iSalesNetwork DataTOjsonString:self.content_data]);
  466. //[self.editorTable reloadData ];
  467. [self.editorTable reloadData];
  468. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  469. return;
  470. }
  471. if(upparams[@"shipping"]==nil)
  472. goto commit_order;
  473. if([upparams[@"shipping"] isEqualToString:@"Shipping To Be Quoted"])
  474. {
  475. upparams[@"shipping"] = nil;
  476. goto commit_order;
  477. }
  478. else if([upparams[@"shipping"] doubleValue]==0)
  479. {
  480. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Shipping is $0.00, continue submit?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  481. //block代码块取代了delegate
  482. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action)
  483. {
  484. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  485. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  486. {
  487. if(/*!self.have_tail*/ true)
  488. {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  489. [upparams setValue:@"false" forKey:@"isHold"];
  490. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  491. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  492. dispatch_async(dispatch_get_main_queue(), ^{
  493. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  494. if([[editor_json valueForKey:@"result"] intValue]==2)
  495. {
  496. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  497. // debug aaa
  498. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  499. // appDelegate.customerInfo = customerInfo;
  500. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  501. // appDelegate.order_code = nil;
  502. [appDelegate closeOrder];
  503. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  504. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  505. [alert show];
  506. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  507. // if(pdf_url.length>0)
  508. // {
  509. //
  510. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  511. // //[self downloadpdf:pdf_url];
  512. //
  513. //
  514. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  515. // {
  516. // //bbb
  517. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  518. // }
  519. //
  520. // [self prepareReturn:nil];
  521. //
  522. // [self.navigationController popViewControllerAnimated:true];
  523. //
  524. // [appDelegate printPdf:pdf_url];
  525. //// if(self.printPdfCallback)
  526. //// self.printPdfCallback(pdf_url);
  527. // }
  528. // else
  529. {
  530. if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  531. {
  532. //bbb
  533. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  534. }
  535. [self prepareReturn:nil];
  536. [self.navigationController popViewControllerAnimated:true];
  537. if(pdf_url.length>0)
  538. {
  539. [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  540. [appDelegate printPdf:pdf_url];
  541. }
  542. }
  543. }
  544. else
  545. {
  546. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  547. }
  548. });
  549. });
  550. }
  551. else
  552. {
  553. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Retain models", nil) message:NSLocalizedString(@"There are some models left in cart,do you want to keep them?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  554. alert.tag = KEEP_TAIL;
  555. self.upparams = upparams;
  556. [alert show];
  557. }
  558. }
  559. else
  560. { //USER_ROLE_CUSTOMER
  561. // if(self.have_tail)
  562. // [upparams setValue:@"true" forKey:@"isHold"];
  563. // else
  564. // [upparams setValue:@"false" forKey:@"isHold"];
  565. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  566. [upparams setValue:@"true" forKey:@"isHold"];
  567. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  568. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  569. dispatch_async(dispatch_get_main_queue(), ^{
  570. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  571. if([[editor_json valueForKey:@"result"] intValue]==2)
  572. {
  573. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  574. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  575. // appDelegate.customerInfo = customerInfo;
  576. NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  577. appDelegate.order_code = orderCode;
  578. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  579. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  580. [alert show];
  581. // // self.labelContact.text=appDelegate.contact_name;
  582. //
  583. // NSDictionary * customerinfo = appDelegate.customerInfo;
  584. [self prepareReturn:nil];
  585. [self.navigationController popViewControllerAnimated:true];
  586. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  587. //
  588. //
  589. // ;
  590. // }];
  591. }
  592. else
  593. {
  594. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  595. }
  596. });
  597. });
  598. }
  599. }];
  600. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  601. //NSLog(@"Cancel");
  602. }];
  603. [alertControl addAction:actionOne];
  604. [alertControl addAction:alertthree];
  605. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  606. [self presentViewController:alertControl animated:YES completion:nil];
  607. }
  608. else
  609. {
  610. commit_order:
  611. {
  612. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  613. if(appDelegate.user_type ==USER_ROLE_EMPLOYEE )
  614. {
  615. if(/*!self.have_tail*/ true)
  616. {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  617. [upparams setValue:@"false" forKey:@"isHold"];
  618. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  619. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  620. dispatch_async(dispatch_get_main_queue(), ^{
  621. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  622. if([[editor_json valueForKey:@"result"] intValue]==2)
  623. {
  624. //debug bbb
  625. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  626. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  627. // appDelegate.customerInfo = customerInfo;
  628. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  629. // appDelegate.order_code = nil;
  630. [appDelegate closeOrder];
  631. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  632. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  633. [alert show];
  634. NSString* pdf_url = [editor_json valueForKey:@"pdf_url"];
  635. // if(pdf_url.length>0)
  636. // {
  637. //
  638. // [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  639. //// [self downloadpdf:pdf_url];
  640. //
  641. //
  642. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  643. // {
  644. // //bbb
  645. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  646. // }
  647. //
  648. // [self prepareReturn:nil];
  649. //
  650. // [self.navigationController popViewControllerAnimated:true];
  651. //
  652. // [appDelegate printPdf:pdf_url];
  653. //
  654. //// if(self.printPdfCallback)
  655. //// self.printPdfCallback(pdf_url);
  656. // }
  657. // else
  658. {
  659. if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  660. {
  661. //bbb
  662. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  663. }
  664. [self prepareReturn:nil];
  665. [self.navigationController popViewControllerAnimated:true];
  666. if(pdf_url.length>0)
  667. {
  668. [alert dismissWithClickedButtonIndex:0 animated:FALSE];
  669. [appDelegate printPdf:pdf_url];
  670. }
  671. }
  672. // // self.labelContact.text=appDelegate.contact_name;
  673. //
  674. // NSDictionary * customerinfo = appDelegate.customerInfo;
  675. }
  676. else
  677. {
  678. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  679. }
  680. });
  681. });
  682. }
  683. else
  684. {
  685. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Retain models", nil) message:NSLocalizedString(@"There are some models left in cart,do you want to keep them?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  686. alert.tag = KEEP_TAIL;
  687. self.upparams = upparams;
  688. [alert show];
  689. }
  690. }
  691. else
  692. { //USER_ROLE_CUSTOMER
  693. // if(self.have_tail)
  694. // [upparams setValue:@"true" forKey:@"isHold"];
  695. // else
  696. // [upparams setValue:@"false" forKey:@"isHold"];
  697. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  698. [upparams setValue:@"true" forKey:@"isHold"];
  699. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  700. NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:upparams];
  701. dispatch_async(dispatch_get_main_queue(), ^{
  702. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  703. if([[editor_json valueForKey:@"result"] intValue]==2)
  704. {
  705. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  706. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  707. // appDelegate.customerInfo = customerInfo;
  708. NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  709. appDelegate.order_code = orderCode;
  710. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  711. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  712. [alert show];
  713. // // self.labelContact.text=appDelegate.contact_name;
  714. //
  715. // NSDictionary * customerinfo = appDelegate.customerInfo;
  716. [self prepareReturn:nil];
  717. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  718. //
  719. //
  720. // ;
  721. // }];
  722. [self.navigationController popViewControllerAnimated:true];
  723. }
  724. else
  725. {
  726. [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  727. }
  728. });
  729. });
  730. }
  731. }
  732. }
  733. }
  734. // else if( alertView.tag == KEEP_TAIL)
  735. // {UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Submit Order"];
  736. // if(buttonIndex!=alertView.cancelButtonIndex)
  737. // {//keep tail;
  738. //
  739. // [self.upparams setValue:@"true" forKey:@"isHold"];
  740. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  741. //
  742. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:self.upparams];
  743. //
  744. // dispatch_async(dispatch_get_main_queue(), ^{
  745. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  746. //
  747. //
  748. // if([[editor_json valueForKey:@"result"] intValue]==2)
  749. // {
  750. // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  751. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  752. //
  753. // [alert show];
  754. //
  755. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  756. // appDelegate.customerInfo = customerInfo;
  757. // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  758. // NSString* orderCode = [editor_json valueForKey:@"orderCode"];
  759. // appDelegate.order_code = orderCode;
  760. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  761. // // // self.labelContact.text=appDelegate.contact_name;
  762. // //
  763. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  764. // [self prepareReturn:nil];
  765. //// [self.navigationController dismissViewControllerAnimated:true completion:^{
  766. ////
  767. ////
  768. //// ;
  769. //// }];
  770. // [self.navigationController popViewControllerAnimated:true];
  771. //
  772. // }
  773. // else
  774. // {
  775. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  776. // }
  777. //
  778. //
  779. //
  780. //
  781. // });
  782. // });
  783. // }
  784. // else
  785. // {// not keep tail;
  786. // [self.upparams setValue:@"false" forKey:@"isHold"];
  787. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  788. //
  789. // NSDictionary* editor_json = [iSalesNetwork saveandcommit_Order:self.upparams];
  790. //
  791. // dispatch_async(dispatch_get_main_queue(), ^{
  792. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  793. //
  794. //
  795. // if([[editor_json valueForKey:@"result"] intValue]==2)
  796. // {
  797. // // NSMutableDictionary * customerInfo=[self create_cusromer_info_from_table];
  798. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Submit successful." message:[NSString stringWithFormat:@"SO#: %@",[editor_json valueForKey:@"so#"]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  799. //
  800. // [alert show];
  801. //
  802. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  803. // // appDelegate.customerInfo = customerInfo;
  804. // // appDelegate.contact_id = [customerInfo valueForKey:@"customer_cid"];
  805. // // appDelegate.order_code = nil;
  806. // [appDelegate closeOrder];
  807. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  808. // // // self.labelContact.text=appDelegate.contact_name;
  809. // //
  810. // // NSDictionary * customerinfo = appDelegate.customerInfo;
  811. // [self prepareReturn:nil];
  812. //// [self.navigationController dismissViewControllerAnimated:true completion:^{
  813. ////
  814. ////
  815. //// ;
  816. //// }];
  817. // [self.navigationController popViewControllerAnimated:true];
  818. //
  819. // }
  820. // else
  821. // {
  822. // [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Submit Order" controller:self] ;
  823. // }
  824. //
  825. //
  826. //
  827. //
  828. // });
  829. // });
  830. // }
  831. // }
  832. else if(alertView.tag == CLOSE_ACTION)
  833. {
  834. if(buttonIndex==1)
  835. {
  836. [self.navigationController popViewControllerAnimated:true];
  837. // back to cart;
  838. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  839. // ;
  840. // }];
  841. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  842. // appDelegate.order_code = nil;
  843. //
  844. // }
  845. }
  846. if(buttonIndex==2)
  847. {
  848. [self.navigationController popViewControllerAnimated:true];
  849. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  850. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  851. [((MainViewController*)appDelegate.main_vc) switchToOrder];
  852. // back to cart;
  853. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  854. // ;
  855. // }];
  856. // if ([[upparams valueForKey:@"close_on_save"] boolValue]) {
  857. // appDelegate.order_code = nil;
  858. //
  859. // }
  860. }
  861. else if(buttonIndex==3)
  862. {
  863. // close order;
  864. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  865. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Release Order"];
  866. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  867. NSDictionary* order_json = [iSalesNetwork release_Order:appDelegate.order_code];
  868. dispatch_async(dispatch_get_main_queue(), ^{
  869. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  870. if([[order_json valueForKey:@"result"] intValue]==2)
  871. {
  872. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  873. // appDelegate.order_code = nil;
  874. [appDelegate closeOrder];
  875. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  876. [((MainViewController*)appDelegate.main_vc) switchToHome];
  877. if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  878. {
  879. [((MainViewController*)appDelegate.main_vc) Loginout:false];
  880. }
  881. [self prepareReturn:nil];
  882. [self.navigationController popViewControllerAnimated:true];
  883. // [self.navigationController dismissViewControllerAnimated:true completion:^{
  884. // ;
  885. // }];
  886. }
  887. else
  888. {
  889. [RAUtils message_alert:[order_json valueForKey:@"err_msg"] title:@"Open Order"controller:self] ;
  890. }
  891. });
  892. });
  893. //
  894. // }
  895. }
  896. }
  897. }
  898. //
  899. //
  900. //-(void) downloadpdf:(NSString* )url
  901. //{
  902. // UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Printing..."];
  903. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  904. //
  905. //
  906. // NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60*5];
  907. //
  908. // //设置请求方式为get
  909. //
  910. // [request setHTTPMethod:@"GET"];
  911. //
  912. // //添加用户会话id
  913. //
  914. // [request addValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
  915. //
  916. // //连接发送请求
  917. //
  918. //
  919. // NSHTTPURLResponse* urlResponse = nil;
  920. //
  921. // NSError *error = [[NSError alloc] init];
  922. //
  923. // NSData* content= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  924. //
  925. // // self.filename = [urlResponse suggestedFilename];
  926. //
  927. //
  928. // dispatch_async(dispatch_get_main_queue(), ^{
  929. // [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  930. // // self.navigationItem.title = self.save_name;
  931. // // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  932. // // self.content=nil;
  933. // if(content!=nil&&content.length>0)
  934. // {
  935. //
  936. //
  937. // [self startAirPrintWithData:content];
  938. //
  939. //
  940. // }
  941. // else
  942. // {
  943. // [RAUtils message_alert:nil title:@"Open PDF Failed" controller:self];
  944. // // self.content = [self.url dataUsingEncoding:NSUTF8StringEncoding];
  945. // }
  946. //
  947. // ;
  948. // // NSLog(@"%@",[[NSString alloc] initWithData:self.content encoding:NSASCIIStringEncoding]);
  949. // //
  950. //
  951. //
  952. // // [self.webView loadData:self.content MIMEType:urlResponse.MIMEType textEncodingName:nil baseURL:nil];
  953. //
  954. //
  955. //
  956. //
  957. // });
  958. // });
  959. //}
  960. //
  961. //- (void)startAirPrintWithData:(id )data
  962. //{
  963. //
  964. //
  965. //
  966. //
  967. // UIPrintInteractionController* airPrinterController=[UIPrintInteractionController sharedPrintController];
  968. // UIPrintInfo *printInfo = [UIPrintInfo printInfo];
  969. // printInfo.outputType = UIPrintInfoOutputGeneral;
  970. // printInfo.orientation = UIPrintInfoOrientationPortrait;
  971. // printInfo.jobName = @"CoolVisitAirPrint";
  972. // airPrinterController.printInfo = printInfo;
  973. // airPrinterController.printingItem = data;
  974. // airPrinterController.delegate = self;
  975. //
  976. //
  977. // airPrinterController.showsNumberOfCopies=true;
  978. // airPrinterController.showsPageRange = true;
  979. // airPrinterController.showsPaperSelectionForLoadedPapers=true;
  980. //
  981. // void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
  982. // if(completed && error)
  983. // NSLog(@"Printing failed due to error in domain %@ with error code %lu. Localized description: %@, and failure reason: %@", error.domain, (long)error.code, error.localizedDescription, error.localizedFailureReason);
  984. // };
  985. //
  986. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  987. //
  988. // UIPrinter *airPrinter = [UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL] ];///*self.printer;*/
  989. //
  990. //
  991. //
  992. //
  993. // [[UIPrinter printerWithURL:[NSURL URLWithString:appDelegate.printerURL]] contactPrinter:^(BOOL available)
  994. // {
  995. // if (available&& appDelegate.printerURL.length>0)
  996. // {
  997. //
  998. // [airPrinterController printToPrinter:airPrinter completionHandler:completionHandler];
  999. // NSLog(@"AIRPRINTER AVAILABLE");
  1000. // }
  1001. // else
  1002. // {
  1003. //
  1004. // // [airPrinterController presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1005. // //
  1006. // //
  1007. // //
  1008. // // // [printPicker presentAnimated:YES completionHandler:
  1009. // // ^(UIPrintInteractionController *printerController, BOOL userDidSelect, NSError *error)
  1010. // // {
  1011. // // if (userDidSelect)
  1012. // // {
  1013. // // NSString* sid= printerController.printInfo.printerID;
  1014. // // UIPrintPaper*paper= printerController.printPaper;
  1015. // //
  1016. // // }
  1017. // // }];
  1018. //
  1019. //
  1020. // NSLog(@"AIRPRINTER NOT AVAILABLE");
  1021. //
  1022. //
  1023. //
  1024. // if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1)
  1025. // {
  1026. // UIPrinterPickerController *printPicker = [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:nil];
  1027. // // [printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:yes completionHandler:
  1028. //
  1029. //
  1030. //
  1031. // [ printPicker presentFromBarButtonItem:self.btnSubmitOrder animated:YES completionHandler:
  1032. //
  1033. //
  1034. // // [printPicker presentFromRect:CGRectMake(0, 0, 300, 500) inView:self.view animated:YES completionHandler:
  1035. //
  1036. //
  1037. //
  1038. // // [printPicker presentAnimated:YES completionHandler:
  1039. // ^(UIPrinterPickerController *printerPicker, BOOL userDidSelect, NSError *error)
  1040. // {
  1041. // if (userDidSelect)
  1042. // {
  1043. // //User selected the item in the UIPrinterPickerController and got the printer details.
  1044. //
  1045. // [UIPrinterPickerController printerPickerControllerWithInitiallySelectedPrinter:printerPicker.selectedPrinter];
  1046. //
  1047. // //Here you will get the printer and printer details.ie,
  1048. // // printerPicker.selectedPrinter, printerPicker.selectedPrinter.displayName, printerPicker.selectedPrinter.URL etc. So you can display the printer name in your label text or button title.
  1049. //
  1050. //
  1051. //
  1052. //
  1053. // appDelegate.printerURL =printerPicker.selectedPrinter.URL.absoluteString;
  1054. //
  1055. // [self startAirPrintWithData:data];
  1056. //
  1057. // }
  1058. // else
  1059. // {
  1060. //
  1061. //
  1062. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1063. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1064. // {
  1065. //
  1066. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1067. // }
  1068. // [self prepareReturn:nil];
  1069. //
  1070. // [self.navigationController popViewControllerAnimated:true];
  1071. // }
  1072. // }];
  1073. // }
  1074. // }
  1075. // }];
  1076. //
  1077. //
  1078. //
  1079. //}
  1080. //
  1081. //#pragma mark - UIPrintInteractionControllerDelegate
  1082. //- (UIPrintPaper *)printInteractionController:(UIPrintInteractionController *)printInteractionController choosePaper:(NSArray<UIPrintPaper *> *)paperList
  1083. //{
  1084. //
  1085. // ;
  1086. //
  1087. // // (int) width = 29700
  1088. // // Printing description of (*( (int *)0x7caa3a40)):
  1089. // // (int) height = 42000
  1090. // //设置纸张大小
  1091. //
  1092. //
  1093. // for(UIPrintPaper* paper in paperList)
  1094. // {
  1095. // if (CGSizeEqualToSize(paper.paperSize, CGSizeMake(612, 792)))
  1096. // return paper;
  1097. //
  1098. // }
  1099. // CGSize paperSize = CGSizeMake(612, 792);
  1100. // UIPrintPaper * p=[UIPrintPaper bestPaperForPageSize:paperSize withPapersFromArray:paperList];
  1101. // return p;
  1102. //}
  1103. //- (void)printInteractionControllerWillPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1104. //{
  1105. //
  1106. //}
  1107. //- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1108. //{
  1109. //
  1110. //}
  1111. //- (void)printInteractionControllerWillDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1112. //{
  1113. //
  1114. //}
  1115. //- (void)printInteractionControllerDidDismissPrinterOptions:(UIPrintInteractionController *)printInteractionController
  1116. //{
  1117. //
  1118. //}
  1119. //
  1120. //- (void)printInteractionControllerWillStartJob:(UIPrintInteractionController *)printInteractionController
  1121. //{
  1122. //
  1123. //}
  1124. //- (void)printInteractionControllerDidFinishJob:(UIPrintInteractionController *)printInteractionController
  1125. //{
  1126. //
  1127. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1128. // if([appDelegate.mode isEqualToString:@"Trade Show Mode"]&& appDelegate.submit_order_logout)
  1129. // {
  1130. //
  1131. // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  1132. // }
  1133. //
  1134. // [self prepareReturn:nil];
  1135. //
  1136. // [self.navigationController popViewControllerAnimated:true];
  1137. //}
  1138. @end