CreateOrderViewController.m 74 KB

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