DetailHeaderCell.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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(@"CreateOrderViewController 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. }
  156. }
  157. // self.offset = 0;
  158. // [self.content_data removeAllObjects];
  159. // [self loadpage];
  160. //
  161. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  162. };
  163. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  164. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  165. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  166. [vc presentViewController:navi animated:YES completion:^{
  167. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  168. NSLog(@"CreateOrderViewController present.........");
  169. // self.btop = false;
  170. // <#code#>
  171. }];
  172. }
  173. else
  174. {
  175. if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
  176. {
  177. [main_vc checklogin:false];
  178. if(appDelegate.can_create_order)
  179. {
  180. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"Do you want to add to a pending 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];
  181. // alert.
  182. [alert show];
  183. }
  184. else
  185. {
  186. 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];
  187. // alert.
  188. [alert show];
  189. }
  190. }
  191. else
  192. {
  193. if ([self.priceLabel.text isEqualToString:@"No Price."])
  194. {
  195. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Model No Price" message:@"Cannot add model without price." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  196. //
  197. //
  198. //
  199. // [alert show];
  200. [RAUtils alert_view:@"Cannot add model without price." title:@"Model No Price."];
  201. }
  202. else
  203. {
  204. int c=[self.count_Label.text intValue];
  205. NSLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
  206. NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  207. if(c<count)
  208. {
  209. 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];
  210. // alert.
  211. alert.tag = 1234;
  212. [alert show];
  213. }
  214. else
  215. {
  216. if(appDelegate.order_code==nil)
  217. [ self neworder];
  218. else
  219. [self addtocart:count];
  220. }
  221. }
  222. }
  223. }
  224. }
  225. -(void) addtocart:(int) count
  226. {
  227. if(self.cqty>0)
  228. {
  229. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",self.cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  230. //block代码块取代了delegate
  231. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  232. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  233. NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  234. dispatch_async(dispatch_get_main_queue(), ^{
  235. if([[return_json valueForKey:@"result"] intValue]==2)
  236. {
  237. // NSString* order_code = [return_json valueForKey:@"order_code"];
  238. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  239. // appDelegate.order_code = order_code;
  240. //
  241. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  242. // appDelegate.order_code = order_code;
  243. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  244. if(self.shopCartBlock!=nil)
  245. {
  246. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  247. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  248. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  249. iv.image = img;
  250. // [self.contentView addSubview:iv];
  251. self.shopCartBlock(iv);
  252. self.cqty +=count;
  253. if(self.set_cqty)
  254. self.set_cqty(self.cqty);
  255. }
  256. }
  257. else
  258. {
  259. UIViewController *vc= [RAUtils getViewController:self];
  260. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  261. }
  262. });
  263. });
  264. }];
  265. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  266. NSLog(@"No");
  267. }];
  268. [alertControl addAction:actionOne];
  269. [alertControl addAction:alertthree];
  270. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  271. UIViewController *vc= [RAUtils getViewController:self];
  272. [vc presentViewController:alertControl animated:YES completion:nil];
  273. }
  274. else
  275. {
  276. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  277. NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
  278. dispatch_async(dispatch_get_main_queue(), ^{
  279. if([[return_json valueForKey:@"result"] intValue]==2)
  280. {
  281. // NSString* order_code = [return_json valueForKey:@"order_code"];
  282. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  283. // appDelegate.order_code = order_code;
  284. //
  285. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  286. // appDelegate.order_code = order_code;
  287. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  288. if(self.shopCartBlock!=nil)
  289. {
  290. UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  291. CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  292. UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  293. iv.image = img;
  294. // [self.contentView addSubview:iv];
  295. self.shopCartBlock(iv);
  296. self.cqty +=count;
  297. if(self.set_cqty)
  298. self.set_cqty(self.cqty);
  299. }
  300. }
  301. else
  302. {
  303. UIViewController *vc= [RAUtils getViewController:self];
  304. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  305. }
  306. });
  307. });
  308. }
  309. }
  310. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  311. {
  312. [super setSelected:selected animated:animated];
  313. // Configure the view for the selected state
  314. }
  315. - (IBAction)selectorOnClick:(id)sender {
  316. NSLog(@"select click");
  317. [celldelegate SelectorClicked:(UIButton*) sender];
  318. // [self performSegueWithIdentifier:@"selector_popover" sender:self];
  319. }
  320. #pragma mark -
  321. #pragma mark Deck DataSource Protocol Methods
  322. -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack {
  323. return [self.photos count];
  324. }
  325. -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index {
  326. if(self.photos.count==0)
  327. return nil;
  328. return [self.photos objectAtIndex:index];
  329. }
  330. #pragma mark -
  331. #pragma mark Deck Delegate Protocol Methods
  332. -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index {
  333. // User started moving a photo
  334. }
  335. -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
  336. // User flicked the photo away, revealing the next one in the stack
  337. }
  338. -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index {
  339. self.pageControl.currentPage = index;
  340. }
  341. -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
  342. NSLog(@"selected %lu", (unsigned long)index);
  343. // NSMutableArray *imgList = [NSMutableArray arrayWithCapacity:_data.count];
  344. // for (int i = 0; i < _data.count; i++) {
  345. // UIImage *imgMod = _data[i];
  346. // [imgList addObject:imgMod];
  347. // }
  348. // 调用展示窗口
  349. ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index];
  350. UIViewController *vc= [RAUtils getViewController:self];
  351. [vc.navigationController pushViewController:imgShow animated:true];
  352. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:imgShow];
  353. // [self presentViewController:nav animated:YES completion:nil];
  354. // UIDocumentInteractionController
  355. // UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url];
  356. // preview.delegate = self;
  357. // [preview presentPreviewAnimated:YES];
  358. }
  359. -(void) neworder
  360. {
  361. UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
  362. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  363. NSDictionary* return_json = [iSalesNetwork new_Order];
  364. dispatch_async(dispatch_get_main_queue(), ^{
  365. [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
  366. if([[return_json valueForKey:@"result"] intValue]==2)
  367. {
  368. int result=[[return_json valueForKey:@"result"] intValue];
  369. if(result==2)
  370. {
  371. //successed.
  372. NSString* order_code = [return_json valueForKey:@"orderCode"];
  373. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  374. appDelegate.order_code = order_code;
  375. int count=[self.quantity_text.text intValue];
  376. [self addtocart:count];
  377. // [self ReloadData];
  378. // if(self.shopCartBlock!=nil)
  379. // {
  380. // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
  381. //
  382. //
  383. // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
  384. // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
  385. // iv.image = img;
  386. // // [self.contentView addSubview:iv];
  387. // self.shopCartBlock(iv);
  388. //
  389. // }
  390. }
  391. }
  392. else
  393. {
  394. UIViewController *vc= [RAUtils getViewController:self];
  395. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
  396. }
  397. });
  398. });
  399. }
  400. #pragma mark - UIAlertViewDelegate
  401. // Called when a button is clicked. The view will be automatically dismissed after this call returns
  402. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  403. {
  404. UIApplication * app = [UIApplication sharedApplication];
  405. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  406. if(alertView.tag==1234)//库存小于0
  407. {
  408. // availability warring;
  409. int count=[self.quantity_text.text intValue];
  410. if(buttonIndex!=alertView.cancelButtonIndex)
  411. {
  412. if(appDelegate.order_code==nil)
  413. {
  414. [self neworder];
  415. }
  416. else
  417. {
  418. [self addtocart:count];
  419. }
  420. }
  421. return;
  422. }
  423. // int count=[self.quantity_text.text intValue];
  424. MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
  425. if(buttonIndex==alertView.cancelButtonIndex)
  426. {
  427. }
  428. else if(buttonIndex==1)
  429. {
  430. //open exist
  431. UIViewController *vc= [RAUtils getViewController:self];
  432. OrderListViewController* ovc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
  433. ovc.showNavibar = true;
  434. ovc.selectOrder = ^(NSMutableDictionary* order_detail){
  435. if(appDelegate.order_code==nil)
  436. {
  437. [self neworder];
  438. }
  439. else
  440. {
  441. if(self.set_update_data)
  442. self.set_update_data(true);
  443. int model_count = [[order_detail valueForKey:@"model_count"] intValue];
  444. for(int i=0;i<model_count;i++)
  445. {
  446. NSDictionary* item = [order_detail objectForKey:[NSString stringWithFormat:@"item_%d",i]];
  447. NSString* product_id = [item valueForKey:@"product_id"];
  448. if([product_id isEqualToString:self.product_id])
  449. {
  450. self.cqty = [[item valueForKey:@"QTY"]intValue];
  451. if(self.set_cqty)
  452. self.set_cqty(self.cqty);
  453. break;
  454. }
  455. }
  456. int count=[self.quantity_text.text intValue];
  457. [self addtocart:count];
  458. [main_vc checklogin:true];
  459. }
  460. };
  461. ovc.init_style = OL_OPEN;
  462. ovc.onCancel = ^(){
  463. [main_vc checklogin:true];
  464. };
  465. [vc.navigationController pushViewController:ovc animated:true];
  466. }
  467. else
  468. {
  469. //create new;
  470. if(appDelegate.customerInfo==nil)// select contact if current contact not exist
  471. {
  472. UIViewController *vc= [RAUtils getViewController:self];
  473. ContactListViewController* cvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
  474. cvc.showNavibar = true;
  475. cvc.contact_type = @"Sales_Order_Customer";
  476. cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
  477. appDelegate.contact_id=[value valueForKey:@"customer_cid"];
  478. appDelegate.customerInfo = value;
  479. if(appDelegate.order_code==nil)
  480. [self neworder];
  481. [main_vc checklogin:true];
  482. // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
  483. //
  484. // if(self.returnValue)
  485. // self.returnValue(value);
  486. };
  487. cvc.onCancel = ^(){
  488. UIViewController *vc= [RAUtils getViewController:self];
  489. [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order Error." controller:vc];
  490. };
  491. cvc.onReset = ^(){
  492. [main_vc checklogin:true];
  493. };
  494. [vc.navigationController pushViewController:cvc animated:true];
  495. }
  496. else
  497. {
  498. [self neworder];
  499. }
  500. }
  501. }
  502. - (void)valueChanged:(UIStepper *)sender {
  503. self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
  504. [celldelegate stepClicked:(int)sender.value];
  505. // -(void) stepClicked:(int) value;
  506. }
  507. #pragma mark -
  508. #pragma mark Actions
  509. - (void)AddPhoto :(UIImage*)photo {
  510. NSMutableArray *photosMutable = [self.photos mutableCopy];
  511. [photosMutable addObject:photo];
  512. self.photos = photosMutable;
  513. [self.photoStack reloadData];
  514. self.pageControl.numberOfPages = [self.photos count];
  515. if(self.photos.count<2-1)//1 for qrcode;
  516. self.photoStack.showBorder=false;
  517. else
  518. self.photoStack.showBorder=true;
  519. }
  520. #pragma mark -
  521. #pragma mark Setup
  522. -(void)setup {
  523. self.stepper.minimumValue= self.step;
  524. self.stepper.stepValue= self.step;
  525. self.stepper.value= self.quantity;
  526. [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  527. if(true)//(self.photos==nil)
  528. {
  529. self.photos = [NSArray arrayWithObjects:
  530. nil];
  531. }
  532. if(true)//(self.photoStack==nil)
  533. {
  534. // if(self.photoStack!=nil)
  535. // [self.photoStack removeFromSuperview];
  536. // self.photoStack = [[PhotoStackView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
  537. // self.photoStack.backgroundColor =[UIColor redColor];
  538. // self.photoStack.center = CGPointMake(self.center.x, 220);
  539. self.photoStack.dataSource = self;
  540. self.photoStack.delegate = self;
  541. // [self addSubview:self.photoStack];
  542. self.pageControl.numberOfPages = [self.photos count];
  543. }
  544. }
  545. @end