DetailHeaderCell.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. //
  2. // DetailHeaderCell.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-5.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "DetailHeaderCell.h"
  9. #import "iSalesNetwork.h"
  10. #import "MainViewController.h"
  11. #import "LoginViewController.h"
  12. #import "ContactListViewController.h"
  13. #import "RAUtils.h"
  14. #import "OrderListViewController.h"
  15. #import "ImageScrollerViewController.h"
  16. @implementation DetailHeaderCell
  17. @synthesize celldelegate;
  18. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  19. {
  20. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  21. if (self) {
  22. // Initialization code
  23. }
  24. // self.selector_imageView.layer.borderColor = [UIColorFromRGB(0x996633) CGColor];
  25. // self.selector_imageView.layer.borderWidth = 1;
  26. return self;
  27. }
  28. - (void)awakeFromNib
  29. {
  30. // self.selector_imageView.layer.borderColor = [UIColorFromRGB(0x996633) CGColor];
  31. // self.selector_imageView.layer.borderWidth = 1;
  32. self.selector_Button.layer.borderWidth = 0.5;
  33. self.selector_Button.layer.borderColor = [[UIColor lightGrayColor] CGColor];
  34. self.selector_Button.layer.cornerRadius = 0;
  35. // self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  36. // self.label_net_err.layer.borderWidth = 2.0;
  37. // self.label_net_err.layer.cornerRadius=15;
  38. // self.label_net_err.layer.masksToBounds=true;
  39. // Initialization code
  40. }
  41. - (IBAction)add_toWatchList:(id)sender {
  42. // int count=[self.quantity_text.text intValue];
  43. UIApplication * app = [UIApplication sharedApplication];
  44. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  45. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  46. if(appDelegate.bLogin==false)
  47. {
  48. UIViewController *vc= [RAUtils getViewController:self];
  49. LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  50. // loginvc.delegate = self;
  51. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  52. loginvc.returnValue = ^(bool blogin){
  53. // UIApplication * app = [UIApplication sharedApplication];
  54. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  55. if(blogin)
  56. {
  57. if(self.set_update_data)
  58. self.set_update_data(true);
  59. [main_vc checklogin:true];
  60. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  61. NSDictionary* return_json = [iSalesNetwork add_toWatchList:self.product_id ];
  62. dispatch_async(dispatch_get_main_queue(), ^{
  63. if([[return_json valueForKey:@"result"] intValue]==2)
  64. {
  65. // NSLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  66. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  67. if(self.WatchlistBlock!=nil)
  68. {
  69. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  70. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  71. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  72. iv.image = img;
  73. // [self.contentView addSubview:iv];
  74. self.WatchlistBlock(iv);
  75. }
  76. }
  77. else
  78. {
  79. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wishlist" controller:vc] ;
  80. }
  81. });
  82. });
  83. }
  84. // self.offset = 0;
  85. // [self.content_data removeAllObjects];
  86. // [self loadpage];
  87. //
  88. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  89. };
  90. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  91. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  92. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  93. [vc presentViewController:navi animated:YES completion:^{
  94. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  95. NSLog(@"LoginViewController present.........");
  96. // self.btop = false;
  97. // <#code#>
  98. }];
  99. }
  100. else
  101. {
  102. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  103. NSDictionary* return_json = [iSalesNetwork add_toWatchList:self.product_id ];
  104. dispatch_async(dispatch_get_main_queue(), ^{
  105. if([[return_json valueForKey:@"result"] intValue]==2)
  106. {
  107. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  108. if(self.WatchlistBlock!=nil)
  109. {
  110. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  111. CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
  112. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  113. iv.image = img;
  114. // [self.contentView addSubview:iv];
  115. self.WatchlistBlock(iv);
  116. }
  117. }
  118. else
  119. {
  120. UIViewController *vc= [RAUtils getViewController:self];
  121. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wishlist" controller:vc] ;
  122. }
  123. });
  124. });
  125. }
  126. }
  127. - (IBAction)add_toCart:(id)sender {
  128. int count=[self.quantity_text.text intValue];
  129. UIApplication * app = [UIApplication sharedApplication];
  130. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  131. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  132. if(appDelegate.bLogin==false)
  133. {
  134. UIViewController *vc= [RAUtils getViewController:self];
  135. LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
  136. // loginvc.delegate = self;
  137. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  138. loginvc.returnValue = ^(bool blogin){
  139. // UIApplication * app = [UIApplication sharedApplication];
  140. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  141. if(blogin)
  142. {
  143. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  144. {
  145. if(self.set_update_data)
  146. self.set_update_data(true);
  147. [main_vc checklogin:false];
  148. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"Do you want to add to pending a order or a new order", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
  149. // alert.
  150. [alert show];
  151. }
  152. else
  153. {
  154. [main_vc checklogin:true];
  155. int c=[self.count_Label.text intValue];
  156. NSLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  157. NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  158. if(c<count)
  159. {
  160. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:NSLocalizedString(@"Confirm add to cart. ", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Confirm", nil), nil];
  161. // alert.
  162. alert.tag = 1234;
  163. [alert show];
  164. }
  165. else
  166. {
  167. if(appDelegate.order_code==nil)
  168. [ self neworder];
  169. else
  170. [self addtocart:count];
  171. }
  172. }
  173. }
  174. // self.offset = 0;
  175. // [self.content_data removeAllObjects];
  176. // [self loadpage];
  177. //
  178. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  179. };
  180. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  181. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  182. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  183. [vc presentViewController:navi animated:YES completion:^{
  184. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  185. NSLog(@"LoginViewController present.........");
  186. // self.btop = false;
  187. // <#code#>
  188. }];
  189. }
  190. else
  191. {
  192. if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  193. {
  194. [main_vc checklogin:false];
  195. if(appDelegate.can_create_order)
  196. {
  197. NSString* msg =@"Do you want to switch to a pending order or a new order?";
  198. if(appDelegate.contact_id.length>0)
  199. {
  200. msg = [msg stringByAppendingString:@"\n\nCustomer:"];
  201. msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
  202. }
  203. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil];
  204. // alert.
  205. [alert show];
  206. }
  207. else
  208. {
  209. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"Do you want to add to a pending order?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
  210. // alert.
  211. [alert show];
  212. }
  213. }
  214. else
  215. {
  216. // if ([self.priceLabel.text isEqualToString:@"No Price."])
  217. // {
  218. //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Model No Price" message:@"Cannot add model without price." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  219. ////
  220. ////
  221. ////
  222. //// [alert show];
  223. //
  224. //
  225. //
  226. // [RAUtils alert_view:@"Cannot add model without price." title:@"Model No Price."];
  227. // }
  228. // else
  229. {
  230. int c=[self.count_Label.text intValue];
  231. NSLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  232. NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  233. if(c<count)
  234. {
  235. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:NSLocalizedString(@"Confirm add to cart. ", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Confirm", nil), nil];
  236. // alert.
  237. alert.tag = 1234;
  238. [alert show];
  239. }
  240. else
  241. {
  242. if(appDelegate.order_code==nil)
  243. [ self neworder];
  244. else
  245. [self addtocart:count];
  246. }
  247. }
  248. }
  249. }
  250. }
  251. -(void) addtocart:(int) count
  252. {
  253. if(self.cqty>0)
  254. {
  255. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",self.cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  256. //block代码块取代了delegate
  257. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  258. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  259. NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  260. dispatch_async(dispatch_get_main_queue(), ^{
  261. if([[return_json valueForKey:@"result"] intValue]==2)
  262. {
  263. // NSString* order_code = [return_json valueForKey:@"order_code"];
  264. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  265. // appDelegate.order_code = order_code;
  266. //
  267. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  268. // appDelegate.order_code = order_code;
  269. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  270. if(self.shopCartBlock!=nil)
  271. {
  272. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  273. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  274. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  275. iv.image = img;
  276. // [self.contentView addSubview:iv];
  277. self.shopCartBlock(iv);
  278. self.cqty +=count;
  279. if(self.set_cqty)
  280. self.set_cqty(self.cqty);
  281. }
  282. }
  283. else
  284. {
  285. UIViewController *vc= [RAUtils getViewController:self];
  286. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  287. }
  288. });
  289. });
  290. }];
  291. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  292. NSLog(@"No");
  293. }];
  294. [alertControl addAction:actionOne];
  295. [alertControl addAction:alertthree];
  296. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  297. UIViewController *vc= [RAUtils getViewController:self];
  298. [vc presentViewController:alertControl animated:YES completion:nil];
  299. }
  300. else
  301. {
  302. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  303. NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  304. dispatch_async(dispatch_get_main_queue(), ^{
  305. if([[return_json valueForKey:@"result"] intValue]==2)
  306. {
  307. // NSString* order_code = [return_json valueForKey:@"order_code"];
  308. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  309. // appDelegate.order_code = order_code;
  310. //
  311. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  312. // appDelegate.order_code = order_code;
  313. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  314. if(self.shopCartBlock!=nil)
  315. {
  316. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  317. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  318. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  319. iv.image = img;
  320. // [self.contentView addSubview:iv];
  321. self.shopCartBlock(iv);
  322. self.cqty +=count;
  323. if(self.set_cqty)
  324. self.set_cqty(self.cqty);
  325. }
  326. }
  327. else
  328. {
  329. UIViewController *vc= [RAUtils getViewController:self];
  330. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  331. }
  332. });
  333. });
  334. }
  335. }
  336. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  337. {
  338. [super setSelected:selected animated:animated];
  339. // Configure the view for the selected state
  340. }
  341. - (IBAction)selectorOnClick:(id)sender {
  342. NSLog(@"select click");
  343. [celldelegate SelectorClicked:(UIButton*) sender];
  344. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  345. }
  346. #pragma mark -
  347. #pragma mark Deck DataSource Protocol Methods
  348. -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack {
  349. return [self.photos count];
  350. }
  351. -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index {
  352. if(self.photos.count==0)
  353. return nil;
  354. return [self.photos objectAtIndex:index];
  355. }
  356. #pragma mark -
  357. #pragma mark Deck Delegate Protocol Methods
  358. -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index {
  359. // User started moving a photo
  360. }
  361. -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
  362. // User flicked the photo away, revealing the next one in the stack
  363. }
  364. -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index {
  365. self.pageControl.currentPage = index;
  366. }
  367. -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
  368. NSLog(@"selected %lu", (unsigned long)index);
  369. // NSMutableArray *imgList = [NSMutableArray arrayWithCapacity:_data.count];
  370. // for (int i = 0; i < _data.count; i++) {
  371. // UIImage *imgMod = _data[i];
  372. // [imgList addObject:imgMod];
  373. // }
  374. // 调用展示窗口
  375. ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index];
  376. UIViewController *vc= [RAUtils getViewController:self];
  377. [vc.navigationController pushViewController:imgShow animated:true];
  378. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:imgShow];
  379. // [self presentViewController:nav animated:YES completion:nil];
  380. // UIDocumentInteractionController
  381. // UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url];
  382. // preview.delegate = self;
  383. // [preview presentPreviewAnimated:YES];
  384. }
  385. -(void) neworder
  386. {
  387. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  388. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  389. NSDictionary* return_json = [iSalesNetwork new_Order];
  390. dispatch_async(dispatch_get_main_queue(), ^{
  391. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  392. if([[return_json valueForKey:@"result"] intValue]==2)
  393. {
  394. int result=[[return_json valueForKey:@"result"] intValue];
  395. if(result==2)
  396. {
  397. //successed.
  398. NSString* order_code = [return_json valueForKey:@"orderCode"];
  399. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  400. appDelegate.order_code = order_code;
  401. int count=[self.quantity_text.text intValue];
  402. [self addtocart:count];
  403. // [self ReloadData];
  404. // if(self.shopCartBlock!=nil)
  405. // {
  406. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  407. //
  408. //
  409. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  410. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  411. // iv.image = img;
  412. // // [self.contentView addSubview:iv];
  413. // self.shopCartBlock(iv);
  414. //
  415. // }
  416. }
  417. }
  418. else
  419. {
  420. UIViewController *vc= [RAUtils getViewController:self];
  421. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  422. }
  423. });
  424. });
  425. }
  426. #pragma mark - UIAlertViewDelegate
  427. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  428. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  429. {
  430. UIApplication * app = [UIApplication sharedApplication];
  431. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  432. if(alertView.tag==1234)//库存小于0
  433. {
  434. // availability warring;
  435. int count=[self.quantity_text.text intValue];
  436. if(buttonIndex!=alertView.cancelButtonIndex)
  437. {
  438. if(appDelegate.order_code==nil)
  439. {
  440. [self neworder];
  441. }
  442. else
  443. {
  444. [self addtocart:count];
  445. }
  446. }
  447. return;
  448. }
  449. // int count=[self.quantity_text.text intValue];
  450. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  451. if(buttonIndex==alertView.cancelButtonIndex)
  452. {
  453. }
  454. else if(buttonIndex==1)
  455. {
  456. //open exist
  457. UIViewController *vc= [RAUtils getViewController:self];
  458. OrderListViewController* ovc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  459. ovc.showNavibar = true;
  460. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  461. if(appDelegate.order_code==nil)
  462. {
  463. [self neworder];
  464. }
  465. else
  466. {
  467. if(self.set_update_data)
  468. self.set_update_data(true);
  469. int model_count = [[order_detail valueForKey:@"model_count"] intValue];
  470. for(int i=0;i<model_count;i++)
  471. {
  472. NSDictionary* item = [order_detail objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  473. NSString* product_id = [item valueForKey:@"product_id"];
  474. if([product_id isEqualToString:self.product_id])
  475. {
  476. self.cqty = [[item valueForKey:@"QTY"]intValue];
  477. if(self.set_cqty)
  478. self.set_cqty(self.cqty);
  479. break;
  480. }
  481. }
  482. int count=[self.quantity_text.text intValue];
  483. [self addtocart:count];
  484. [main_vc checklogin:true];
  485. }
  486. };
  487. ovc.init_style = OL_OPEN;
  488. ovc.onCancel = ^(){
  489. [main_vc checklogin:true];
  490. };
  491. [vc.navigationController pushViewController:ovc animated:true];
  492. }
  493. else
  494. {
  495. //create new;
  496. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  497. {
  498. UIViewController *vc= [RAUtils getViewController:self];
  499. ContactListViewController* cvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  500. cvc.showNavibar = true;
  501. cvc.contact_type = @"Sales_Order_Customer";
  502. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  503. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  504. appDelegate.customerInfo = value;
  505. if(appDelegate.order_code==nil)
  506. [self neworder];
  507. [main_vc checklogin:true];
  508. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  509. //
  510. // if(self.returnValue)
  511. // self.returnValue(value);
  512. };
  513. cvc.onCancel = ^(){
  514. UIViewController *vc= [RAUtils getViewController:self];
  515. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error." controller:vc];
  516. };
  517. cvc.onReset = ^(){
  518. [main_vc checklogin:true];
  519. };
  520. [vc.navigationController pushViewController:cvc animated:true];
  521. }
  522. else
  523. {
  524. [self neworder];
  525. }
  526. }
  527. }
  528. - (void)valueChanged:(UIStepper *)sender {
  529. self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
  530. [celldelegate stepClicked:(int)sender.value];
  531. // -(void) stepClicked:(int) value;
  532. }
  533. #pragma mark -
  534. #pragma mark Actions
  535. - (void)AddPhoto :(UIImage*)photo {
  536. NSMutableArray *photosMutable = [self.photos mutableCopy];
  537. [photosMutable addObject:photo];
  538. self.photos = photosMutable;
  539. [self.photoStack reloadData];
  540. self.pageControl.numberOfPages = [self.photos count];
  541. if(self.photos.count<2-1)//1 for qrcode;
  542. self.photoStack.showBorder=false;
  543. else
  544. self.photoStack.showBorder=true;
  545. }
  546. #pragma mark -
  547. #pragma mark Setup
  548. -(void)setup {
  549. self.stepper.minimumValue= self.step;
  550. self.stepper.stepValue= self.step;
  551. self.stepper.value= self.quantity;
  552. [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  553. if(true)//(self.photos==nil)
  554. {
  555. self.photos = [NSArray arrayWithObjects:
  556. nil];
  557. }
  558. if(true)//(self.photoStack==nil)
  559. {
  560. // if(self.photoStack!=nil)
  561. // [self.photoStack removeFromSuperview];
  562. // self.photoStack = [[PhotoStackView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
  563. // self.photoStack.backgroundColor =[UIColor redColor];
  564. // self.photoStack.center = CGPointMake(self.center.x, 220);
  565. self.photoStack.dataSource = self;
  566. self.photoStack.delegate = self;
  567. // [self addSubview:self.photoStack];
  568. self.pageControl.numberOfPages = [self.photos count];
  569. }
  570. }
  571. @end