CreateOrderViewController.m 73 KB

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