| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798 |
- //
- // DetailHeaderCell.m
- // RedAnt ERP Mobile
- //
- // Created by Ray on 14-6-5.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "DetailHeaderCell.h"
- #import "RANetwork.h"
- #import "MainViewController.h"
- #import "LoginViewController.h"
- #import "ContactListViewController.h"
- #import "RAUtils.h"
- #import "OrderListViewController.h"
- #import "ImageScrollerViewController.h"
- #import "CartUtils.h"
- #import "CustomIOSAlertView.h"
- #import "TextUtils.h"
- #import "ContentPreviewController.h"
- #import "DetailViewController.h"
- #import "RAPDFViewController.h"
- @implementation DetailHeaderCell
- @synthesize celldelegate;
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- // Initialization code
- }
-
- // self.selector_imageView.layer.borderColor = [UIColorFromRGB(0x996633) CGColor];
- // self.selector_imageView.layer.borderWidth = 1;
- return self;
- }
- - (void)awakeFromNib
- {
- #ifdef BUILD_UWAVER
- // self.addPortfolioBtn.title = @"Add to Hang Tag";
- self.btn_hangtag.hidden=false;
- #else
-
- self.btn_hangtag.hidden=true;
- #endif
-
-
- // self.selector_imageView.layer.borderColor = [UIColorFromRGB(0x996633) CGColor];
- // self.selector_imageView.layer.borderWidth = 1;
-
- self.quantity_text.delegate = self;
-
- self.selector_Button.layer.borderWidth = 0.5;
- self.selector_Button.layer.borderColor = [[UIColor lightGrayColor] CGColor];
- self.selector_Button.layer.cornerRadius = 0;
-
-
- [self.descriptionRTLabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
- [self.descriptionRTLabel setTextAlignment:RTTextAlignmentCenter];
- [self.descriptionRTLabel setFont:[UIFont systemFontOfSize:22]];
- // self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
- // self.label_net_err.layer.borderWidth = 2.0;
- // self.label_net_err.layer.cornerRadius=15;
- // self.label_net_err.layer.masksToBounds=true;
- // Initialization code
-
- [self addObserver:self
- forKeyPath:@"stack_contents"
- options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
- context:@"content changed"];
-
-
- }
- -(void) dealloc
- {
- [self removeObserver:self forKeyPath:@"stack_contents"];
- }
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
- {
-
- if([keyPath isEqualToString:@"stack_contents"])
- {
- [self.playerView stopVideo];
-
- self.playerView.hidden=true;
-
- }
- }
- - (IBAction)create_HangTag:(id)sender {
-
- DetailViewController *vc= (DetailViewController *)[RAUtils getViewController:self];
-
- NSString *catelog_name = [NSString stringWithFormat:@"%@ Hang Tag",vc.groupName];
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Processing"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* editor_json = [RANetwork request_hangTag:vc.groupName];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[editor_json valueForKey:@"result"] intValue]==2)
- {
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-
- NSString* url = [editor_json valueForKey:@"pdf_path"];
- bool isLocalFile = [[editor_json valueForKey:@"isLocalFile"] boolValue];
- RAPDFViewController *ViewController = [vc.storyboard instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
- ViewController.url = url;
- ViewController.canSave = false;
- ViewController.isLocalfile=isLocalFile;
-
- ViewController.filename = [NSString stringWithFormat:@"%@.pdf",[TextUtils legalFilename:catelog_name]];
-
- NSString* company= [appDelegate.customerInfo valueForKey:@"customer_name"];
-
- if(company==nil)
- company=@"";
-
- NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
-
-
- NSMutableArray* send_to = [[NSMutableArray alloc]init];
- if(customer_email.length>0)
- {
- send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
- }
- ViewController.mail_to = send_to;
-
- NSString* subject;
-
- subject =catelog_name;
-
- ViewController.mail_subject = subject;
-
- ViewController.hidenavi = false;
- [vc.navigationController pushViewController:ViewController animated:YES];
-
- }
- else
- {
- [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Create Hang Tag" controller:vc];
- }
-
- });
- });
-
-
- }
- - (IBAction)add_toPortfolio:(id)sender {
-
- // int count=[self.quantity_text.text intValue];
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
- if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
- [[NSNotificationCenter defaultCenter] postNotificationName:No_Rights_Notification object:nil];
- return;
- }
-
-
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- if(appDelegate.bLogin==false)
- {
- UIViewController *vc= [RAUtils getViewController:self];
- LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
- // loginvc.delegate = self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
-
- loginvc.returnValue = ^(bool blogin){
-
-
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
-
-
- if(blogin)
- {
-
- if(self.set_update_data)
- self.set_update_data(true);
-
- [main_vc checklogin:true];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [RANetwork add_toPortfolio:self.product_id withScreen:ScreenCodeModelInfo];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
- // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
- #endif
-
- if(self.WatchlistBlock!=nil)
- {
- UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-
-
- CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
- UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- iv.image = img;
- // [self.contentView addSubview:iv];
- self.PortfolioBlock(iv);
-
- }
- }
- else
- {
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add to portfolio" controller:vc] ;
- }
-
-
-
- });
- });
-
-
- }
-
- // self.offset = 0;
- // [self.content_data removeAllObjects];
- // [self loadpage];
- //
- // [[self navigationController] setNavigationBarHidden:YES animated:NO];
-
- };
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [vc presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"LoginViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
- }
- else
- {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [RANetwork add_toPortfolio:self.product_id withScreen:ScreenCodeModelInfo];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
- #endif
- if(self.WatchlistBlock!=nil)
- {
- UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-
-
- CGRect iv_rect = CGRectMake(self.btnaddPortfolio.center.x-50, self.btnaddPortfolio.center.y-50, 100, 100);
- UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- iv.image = img;
- // [self.contentView addSubview:iv];
- self.PortfolioBlock(iv);
-
- }
- }
- else
- {
- UIViewController *vc= [RAUtils getViewController:self];
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add to portfolio" controller:vc] ;
- }
-
-
-
- });
- });
- }
- }
- - (IBAction)add_toWatchList:(id)sender {
-
- // int count=[self.quantity_text.text intValue];
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- if(appDelegate.bLogin==false)
- {
- UIViewController *vc= [RAUtils getViewController:self];
- LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
- // loginvc.delegate = self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
-
- loginvc.returnValue = ^(bool blogin){
-
-
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
-
-
- if(blogin)
- {
-
- if(self.set_update_data)
- self.set_update_data(true);
-
- [main_vc checklogin:true];
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [RANetwork add_toWatchList:self.product_id withScreen:ScreenCodeModelInfo];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
- // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
- #endif
-
- if(self.WatchlistBlock!=nil)
- {
- UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-
-
- CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
- UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- iv.image = img;
- // [self.contentView addSubview:iv];
- self.WatchlistBlock(iv);
-
- }
- }
- else
- {
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wish List" controller:vc] ;
- }
-
-
-
- });
- });
-
-
- }
-
- // self.offset = 0;
- // [self.content_data removeAllObjects];
- // [self loadpage];
- //
- // [[self navigationController] setNavigationBarHidden:YES animated:NO];
-
- };
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [vc presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"LoginViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
- }
- else
- {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [RANetwork add_toWatchList:self.product_id withScreen:ScreenCodeModelInfo];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"WatchListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
- #endif
-
- if(self.WatchlistBlock!=nil)
- {
- UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-
-
- CGRect iv_rect = CGRectMake(self.btnaddWish.center.x-50, self.btnaddWish.center.y-50, 100, 100);
- UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- iv.image = img;
- // [self.contentView addSubview:iv];
- self.WatchlistBlock(iv);
-
- }
- }
- else
- {
- UIViewController *vc= [RAUtils getViewController:self];
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add Wish List" controller:vc] ;
- }
-
-
-
- });
- });
- }
- }
- - (IBAction)add_toCart:(id)sender {
-
- UIViewController *vc= [RAUtils getViewController:self];
- [CartUtils add_to_cart:vc selectorholder:self selector:@selector(addtocart)];
- return;
-
-
- int count=[self.quantity_text.text intValue];
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- if(appDelegate.bLogin==false)
- {
- UIViewController *vc= [RAUtils getViewController:self];
- LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
- // loginvc.delegate = self;
- // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
-
- loginvc.returnValue = ^(bool blogin){
-
-
- // UIApplication * app = [UIApplication sharedApplication];
- // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-
-
-
-
- if(blogin)
- {
- if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/ true)
- {
- if(self.set_update_data)
- self.set_update_data(true);
- [main_vc checklogin:false];
- 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];
-
-
-
- // alert.
- [alert show];
- }
- else
- {
- [main_vc checklogin:true];
-
- int c=[self.count_Label.text intValue];
- DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
-
- NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
-
-
-
- if(!appDelegate.can_create_backorder && c<count)
- {
-
- NSString *msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.\nAdd to cart anyway?",COMPANY_SHORT_NAME];
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:NSLocalizedString(msg, nil) delegate:self cancelButtonTitle:NSLocalizedString(@"No", nil) otherButtonTitles:NSLocalizedString(@"Yes", nil), nil];
-
- // alert.
-
- alert.tag = 1234;
- [alert show];
- }
- else
- {
- if(appDelegate.order_code==nil)
- [ self neworder];
- else
- [self addtocart:count];
- }
-
-
- }
- }
-
- // self.offset = 0;
- // [self.content_data removeAllObjects];
- // [self loadpage];
- //
- // [[self navigationController] setNavigationBarHidden:YES animated:NO];
-
- };
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
-
-
-
-
-
- // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [vc presentViewController:navi animated:YES completion:^{
-
- // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
-
- DebugLog(@"LoginViewController present.........");
-
- // self.btop = false;
- // <#code#>
- }];
- }
- else
- {
-
-
- if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil)
- {
- [main_vc checklogin:false];
-
- if(appDelegate.can_create_order)
- {
- NSString* msg =@"";
- if(appDelegate.contact_id.length>0)
- {
- msg = [msg stringByAppendingString:@"\n\nCustomer:"];
- msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]];
-
- }
- 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];
-
- // alert.
- [alert show];
- }
- else
- {
- 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];
-
- // alert.
- [alert show];
- }
- }
- else
- {
-
- // if ([self.priceLabel.text isEqualToString:@"No Price."])
- // {
- //// UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Model No Price" message:@"Cannot add model without price." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
- ////
- ////
- ////
- //// [alert show];
- //
- //
- //
- // [RAUtils alert_view:@"Cannot add model without price." title:@"Model No Price."];
- // }
- // else
- {
-
- int c=[self.count_Label.text intValue];
- DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
-
- NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
-
-
-
- if(c<count)
- {
-
- 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];
-
- // alert.
-
- alert.tag = 1234;
- [alert show];
- }
- else
- {
- if(appDelegate.order_code==nil)
- [ self neworder];
- else
- [self addtocart:count];
- }
- }
-
- }
- }
-
-
-
-
-
-
-
-
- }
- -(void) addtocart
- {
- int count=[self.quantity_text.text intValue];
-
- #ifdef MPACK
-
- if (count % self.step != 0) {
- UIViewController *vc= [RAUtils getViewController:self];
- [RAUtils message_alert:[NSString stringWithFormat:@"Sold in quantities of %d",(int)(self.stepper.stepValue)] title:@"Add to cart" controller:vc];
- return;
- }
-
- #endif
-
- int c=[self.count_Label.text intValue];
- DebugLog(@"count label : %@ , convert:%d", self.count_Label.text ,c);
-
- NSString* ct=[self.count_Label.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
-
-
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if(/*c<count*/!appDelegate.can_create_backorder && c == 0)
- {
-
- NSString *msg = nil;
- BOOL continueAdd = YES;
- // #if defined(BUILD_NPD) || defined(BUILD_USAI)
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
-
- if ([Singleton sharedInstance].currentOrderIsMerged) { // Purchase Order不允许购买数量大于库存
- msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.",COMPANY_SHORT_NAME];
- continueAdd = NO;
- } else { // Shop Order购买数量大于库存需要确认
- msg = [NSString stringWithFormat:@"Item is OUT OF STOCK and not available to order from %@.\nAdd to cart anyway?",COMPANY_SHORT_NAME];
- continueAdd = YES;
- }
- }
- if (appDelegate.user_type == USER_ROLE_EMPLOYEE) { // Employee不允许购买数量大于库存
- msg = @"Item is OUT OF STOCK and not available to order.";
- continueAdd = NO;
- }
- // #endif
-
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Availability %@",ct ] message:msg preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
- if (continueAdd) {
- [self addtocart:count];
- }
- }];
-
- [alertControl addAction:alertthree];
-
-
- UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- }];
- if (continueAdd) {
- [alertControl addAction:alertcancel];
- }
- UIViewController *vc= [RAUtils getViewController:self];
-
-
- [vc presentViewController:alertControl animated:YES completion:nil];
- }
- else
- {
- [self addtocart:count];
- }
-
-
-
-
- }
- -(void)Hide_selector:(bool) bhide
- {
- self.selector_Button.hidden=bhide;
- self.selector_dorpdown.hidden=bhide;
- self.selector_imageView.hidden=bhide;
-
- }
- -(void) addtocart:(int) count
- {
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- if(self.cqty>0)
- {
-
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",self.cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-
- int c=self.cqty+count;
-
- int m=c%self.step;
- if(m!=0&&appDelegate.alert_sold_in_quantities)
- {
-
-
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
- // NSString* order_code = [return_json valueForKey:@"order_code"];
-
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- #endif
- if(self.shopCartBlock!=nil)
- {
- UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-
-
- CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
- UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- iv.image = img;
- // [self.contentView addSubview:iv];
- self.shopCartBlock(iv);
-
- self.cqty +=count;
- if(self.set_cqty)
- self.set_cqty(self.cqty);
-
- }
-
-
- }
- else
- {
- UIViewController *vc= [RAUtils getViewController:self];
- NSString *msg = [return_json valueForKey:@"err_msg"];
- NSString *title = @"Add To Cart";
- if ([msg hasPrefix:@"Out of Stock.\n"]) {
- title = @"Add To Cart: Out of Stock";
- msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
- self.btnNotifyMe.enabled = YES;
- self.btnaddCart.enabled = NO;
- }
-
- [RAUtils message_alert:msg title:title controller:vc] ;
- }
-
-
-
-
- });
- });
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- DebugLog(@"No");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
- UIViewController *vc= [RAUtils getViewController:self];
- [vc presentViewController:alertControl animated:YES completion:nil];
-
-
-
- }
- else
- {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
- // NSString* order_code = [return_json valueForKey:@"order_code"];
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- #endif
- if(self.shopCartBlock!=nil)
- {
- UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-
-
- CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
- UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- iv.image = img;
- // [self.contentView addSubview:iv];
- self.shopCartBlock(iv);
-
- self.cqty +=count;
- if(self.set_cqty)
- self.set_cqty(self.cqty);
-
- }
-
-
- }
- else
- {
- UIViewController *vc= [RAUtils getViewController:self];
- NSString *msg = [return_json valueForKey:@"err_msg"];
- NSString *title = @"Add To Cart";
- if ([msg hasPrefix:@"Out of Stock.\n"]) {
- title = @"Add To Cart: Out of Stock";
- msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
- self.btnNotifyMe.enabled = YES;
- self.btnaddCart.enabled = NO;
- }
-
- [RAUtils message_alert:msg title:title controller:vc] ;
- }
-
-
-
-
- });
- });
- }
-
-
- //
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- //
- //
- // if([[return_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // // NSString* order_code = [return_json valueForKey:@"order_code"];
- // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- //// appDelegate.order_code = order_code;
- ////
- //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //// appDelegate.order_code = order_code;
- // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- //
- //
- // if(self.shopCartBlock!=nil)
- // {
- // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
- //
- //
- // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
- // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- // iv.image = img;
- // // [self.contentView addSubview:iv];
- // self.shopCartBlock(iv);
- //
- // self.cqty +=count;
- // if(self.set_cqty)
- // self.set_cqty(self.cqty);
- //
- // }
- //
- //
- // }
- // else
- // {
- // UIViewController *vc= [RAUtils getViewController:self];
- // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
- // }
- //
- //
- //
- //
- // });
- // });
- //
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- DebugLog(@"No");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
- UIViewController *vc= [RAUtils getViewController:self];
- [vc presentViewController:alertControl animated:YES completion:nil];
-
-
- }
- else
- {
-
- int c=self.cqty+count;
-
- int m=c%self.step;
- if(m!=0&&appDelegate.alert_sold_in_quantities)
- {
-
-
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Sold in quantities of %d, Are you sure?",self.step] message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- // NSString* order_code = [return_json valueForKey:@"order_code"];
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- // appDelegate.order_code = order_code;
- //
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // appDelegate.order_code = order_code;
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- #endif
- if(self.shopCartBlock!=nil)
- {
- UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-
-
- CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
- UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- iv.image = img;
- // [self.contentView addSubview:iv];
- self.shopCartBlock(iv);
-
- self.cqty +=count;
- if(self.set_cqty)
- self.set_cqty(self.cqty);
-
- }
-
-
- }
- else
- {
- UIViewController *vc= [RAUtils getViewController:self];
- NSString *msg = [return_json valueForKey:@"err_msg"];
- NSString *title = @"Add To Cart";
- if ([msg hasPrefix:@"Out of Stock.\n"]) {
- title = @"Add To Cart: Out of Stock";
- msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
- self.btnNotifyMe.enabled = YES;
- self.btnaddCart.enabled = NO;
- }
-
- [RAUtils message_alert:msg title:title controller:vc] ;
- }
-
-
-
-
- });
- });
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
- DebugLog(@"No");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
- UIViewController *vc= [RAUtils getViewController:self];
- [vc presentViewController:alertControl animated:YES completion:nil];
-
-
-
- }
- else
- {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [RANetwork add_toCart:self.product_id count:count name:self.model_label.text];
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- #endif
- if(self.shopCartBlock!=nil)
- {
- UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
-
-
- CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
- UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- iv.image = img;
- // [self.contentView addSubview:iv];
- self.shopCartBlock(iv);
-
- self.cqty +=count;
- if(self.set_cqty)
- self.set_cqty(self.cqty);
-
- }
-
-
- }
- else
- {
- UIViewController *vc= [RAUtils getViewController:self];
-
- NSString *msg = [return_json valueForKey:@"err_msg"];
- NSString *title = @"Add To Cart";
- if ([msg hasPrefix:@"Out of Stock.\n"]) {
- title = @"Add To Cart: Out of Stock";
- msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
- self.btnNotifyMe.enabled = YES;
- self.btnaddCart.enabled = NO;
- }
-
- [RAUtils message_alert:msg title:title controller:vc] ;
- }
-
-
-
-
- });
- });
-
- }
-
-
- //
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* return_json = [iSalesNetwork add_toCart:self.product_id count:count];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- //
- //
- // if([[return_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // // NSString* order_code = [return_json valueForKey:@"order_code"];
- // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- //// appDelegate.order_code = order_code;
- ////
- //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- //// appDelegate.order_code = order_code;
- // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- //
- //
- // if(self.shopCartBlock!=nil)
- // {
- // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
- //
- //
- // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
- // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- // iv.image = img;
- // // [self.contentView addSubview:iv];
- // self.shopCartBlock(iv);
- //
- // self.cqty +=count;
- // if(self.set_cqty)
- // self.set_cqty(self.cqty);
- //
- // }
- //
- //
- // }
- // else
- // {
- // UIViewController *vc= [RAUtils getViewController:self];
- // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:vc] ;
- // }
- //
- //
- //
- //
- // });
- // });
- //
-
- }
-
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated
- {
- [super setSelected:selected animated:animated];
-
- // Configure the view for the selected state
- }
- - (IBAction)selectorOnClick:(id)sender {
- DebugLog(@"select click");
- [celldelegate SelectorClicked:(UIButton*) sender];
- // [self performSegueWithIdentifier:@"selector_popover" sender:self];
-
- }
- #pragma mark -
- #pragma mark Deck DataSource Protocol Methods
- -(NSUInteger)numberOfPhotosInPhotoStackView:(PhotoStackView *)photoStack {
- return [self.photos count];
- }
- -(UIImage *)photoStackView:(PhotoStackView *)photoStack photoForIndex:(NSUInteger)index {
-
-
- if(self.photos.count==0)
- return nil;
- return [self.photos objectAtIndex:index];
- }
- #pragma mark -
- #pragma mark Deck Delegate Protocol Methods
- -(void)photoStackView:(PhotoStackView *)photoStackView willStartMovingPhotoAtIndex:(NSUInteger)index {
- // User started moving a photo
- }
- -(void)photoStackView:(PhotoStackView *)photoStackView willFlickAwayPhotoFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
- // User flicked the photo away, revealing the next one in the stack
- }
- -(void)photoStackView:(PhotoStackView *)photoStackView didRevealPhotoAtIndex:(NSUInteger)index {
- self.pageControl.currentPage = index;
- }
- - (UIView *)createVideoView:(NSString*) videoID
- {
- UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 640, 360)];
-
- // UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 270, 180)];
- // [imageView setImage:[UIImage imageNamed:@"demo"]];
-
- UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 620, 10)];
- titleLabel.font = [UIFont boldSystemFontOfSize:20];
- titleLabel.text=@"a separated player will show here:";
- titleLabel.numberOfLines = 0;
- titleLabel.lineBreakMode =NSLineBreakByWordWrapping;
- // titleLabel.textAlignment = NSTextAlignmentRight;
- titleLabel.textAlignment = NSTextAlignmentCenter;
- CGSize constraintkey = CGSizeMake(620, 20000.0f);//key label width is 40% cell width;
- CGSize sizetitle = [@"a separated player will show here:" sizeWithFont:[UIFont systemFontOfSize:20.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- //[titleLabel sizeToFit];
- // titleLabel.center.x = demoView.center.x;
- titleLabel.frame = CGRectMake(10, 10, 620, sizetitle.height);
- [demoView addSubview:titleLabel];
-
- UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 610, 10)];
- lineLabel.font = [UIFont boldSystemFontOfSize:17];
- lineLabel.text=videoID;
- lineLabel.numberOfLines = 0;
- lineLabel.lineBreakMode =NSLineBreakByWordWrapping;
-
- CGSize sizemsg = [videoID sizeWithFont:[UIFont boldSystemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- lineLabel.frame = CGRectMake(15, titleLabel.frame.origin.y+ titleLabel.frame.size.height+20, 630, sizemsg.height);
- //[lineLabel sizeToFit];
-
- [demoView addSubview:lineLabel];
- demoView.frame = CGRectMake(0, 0, 640, lineLabel.frame.origin.y+lineLabel.frame.size.height+25);
- return demoView;
- }
- -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
- DebugLog(@"selected %lu", (unsigned long)index);
-
-
-
- NSDictionary* item= self.stack_contents[[NSString stringWithFormat:@"item_%ld",index]];
-
- if([item[@"type"] isEqualToString:@"video"])
- {
-
- NSString* video_code=item[@"code"];
-
-
-
- // [TextUtils expression_varable:video regex:<#(NSString *)#>]
-
- NSString* video_id=[self.playerView Embed2VID:video_code];
-
- NSDictionary *playerVars = @{
- @"playsinline" : @1,
- @"autoplay" : @(1),
- @"rel":@0,
- @"showinfo": @0,
- @"modestbranding":@0,
- @"enablejsapi":@1
- };
-
- [self.playerView loadWithVideoId:video_id playerVars:playerVars];
- for(UIView *v in self.playerView.subviews)
- {
- if([v isKindOfClass:[UIButton class] ])
- [self.playerView bringSubviewToFront:v];
- }
- self.playerView.webView.allowsPictureInPictureMediaPlayback=false;
- self.playerView.hidden=false;
-
- return;
- } else {
- if ([[self.stack_contents objectForKey:@"count"] integerValue] == 0) {
- return;
- }
- ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
- preVC.content = self.stack_contents;
- // preVC.currentIndex = index;
- [preVC setOffset:index];
- UIViewController *superVC= [RAUtils getViewController:self];
- [superVC.navigationController pushViewController:preVC animated:true];
- return;
- }
-
- // NSMutableArray *imgList = [NSMutableArray arrayWithCapacity:_data.count];
- // for (int i = 0; i < _data.count; i++) {
- // UIImage *imgMod = _data[i];
- // [imgList addObject:imgMod];
- // }
-
- // 调用展示窗口
- ImageScrollerViewController *imgShow = [[ImageScrollerViewController alloc] initWithSourceData:[self.photos mutableCopy] withIndex:index];
-
- UIViewController *vc= [RAUtils getViewController:self];
- [vc.navigationController pushViewController:imgShow animated:true];
- // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:imgShow];
-
- // [self presentViewController:nav animated:YES completion:nil];
- // UIDocumentInteractionController
- // UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url];
- // preview.delegate = self;
- // [preview presentPreviewAnimated:YES];
- }
- -(void) neworder
- {
-
- UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Create Order"];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- NSDictionary* return_json = [RANetwork new_Order];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-
-
- if([[return_json valueForKey:@"result"] intValue]==2)
- {
- int result=[[return_json valueForKey:@"result"] intValue];
- if(result==2)
- {
- //successed.
-
- NSString* order_code = [return_json valueForKey:@"orderCode"];
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- appDelegate.order_code = order_code;
-
- int count=[self.quantity_text.text intValue];
- [self addtocart:count];
-
-
- // [self ReloadData];
-
-
- // if(self.shopCartBlock!=nil)
- // {
- // UIImage* img=[self photoStackView:self.photoStack photoForIndex:0];
- //
- //
- // CGRect iv_rect = CGRectMake(self.btnaddCart.center.x-50, self.btnaddCart.center.y-50, 100, 100);
- // UIImageView* iv = [[UIImageView alloc] initWithFrame:iv_rect];
- // iv.image = img;
- // // [self.contentView addSubview:iv];
- // self.shopCartBlock(iv);
- //
- // }
-
- }
- }
- else
- {
- UIViewController *vc= [RAUtils getViewController:self];
- NSString *msg = [return_json valueForKey:@"err_msg"];
- NSString *title = @"Add To Cart";
- if ([msg hasPrefix:@"Out of Stock.\n"]) {
- title = @"Add To Cart: Out of Stock";
- msg = [msg substringFromIndex:[@"Out of Stock.\n" length]];
- self.btnNotifyMe.enabled = YES;
- self.btnaddCart.enabled = NO;
- }
-
- [RAUtils message_alert:msg title:title controller:vc] ;
- }
-
-
-
-
- });
- });
- }
- #pragma mark - UIAlertViewDelegate
- // Called when a button is clicked. The view will be automatically dismissed after this call returns
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- if(alertView.tag==1234)//库存小于0
- {
-
- // availability warring;
-
- int count=[self.quantity_text.text intValue];
- if(buttonIndex!=alertView.cancelButtonIndex)
- {
- if(appDelegate.order_code==nil)
- {
- [self neworder];
- }
- else
- {
- [self addtocart:count];
- }
- }
- return;
- }
- // int count=[self.quantity_text.text intValue];
-
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- if(buttonIndex==alertView.cancelButtonIndex)
- {
-
-
-
- }
- else if(buttonIndex==1)
- {
- //open exist
- UIViewController *vc= [RAUtils getViewController:self];
- OrderListViewController* ovc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"];
- ovc.showNavibar = true;
- ovc.selectOrder = ^(NSMutableDictionary* order_detail){
- if(appDelegate.order_code==nil)
- {
- [self neworder];
- }
- else
- {
- if(self.set_update_data)
- self.set_update_data(true);
-
- int model_count = [[order_detail valueForKey:@"model_count"] intValue];
- for(int i=0;i<model_count;i++)
- {
- NSDictionary* item = [order_detail objectForKey:[NSString stringWithFormat:@"item_%d",i]];
- NSString* product_id = [item valueForKey:@"product_id"];
- if([product_id isEqualToString:self.product_id])
- {
- self.cqty = [[item valueForKey:@"QTY"]intValue];
- if(self.set_cqty)
- self.set_cqty(self.cqty);
- break;
- }
-
- }
- int count=[self.quantity_text.text intValue];
- [self addtocart:count];
- [main_vc checklogin:true];
-
-
- }
-
- };
- ovc.init_style = OL_OPEN;
- ovc.onCancel = ^(){
-
- [main_vc checklogin:true];
-
- };
-
- [vc.navigationController pushViewController:ovc animated:true];
- }
- else
- {
- //create new;
- if(appDelegate.customerInfo==nil)// select contact if current contact not exist
- {
- UIViewController *vc= [RAUtils getViewController:self];
-
- ContactListViewController* cvc = [vc.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ];
- cvc.showNavibar = true;
- cvc.contact_type = @"Sales_Order_Customer";
- cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){
-
- appDelegate.contact_id=[value valueForKey:@"customer_cid"];
- appDelegate.customerInfo = value;
-
-
- if(appDelegate.order_code==nil)
- [self neworder];
-
- [main_vc checklogin:true];
- // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION];
-
- //
- // if(self.returnValue)
- // self.returnValue(value);
- };
-
- cvc.onCancel = ^(){
-
- UIViewController *vc= [RAUtils getViewController:self];
- [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"New Order" controller:vc];
-
- };
- cvc.onReset = ^(){
- [main_vc checklogin:true];
- };
-
- [vc.navigationController pushViewController:cvc animated:true];
- }
- else
- {
- [self neworder];
- }
-
-
- }
- }
- - (void)valueChanged:(UIStepper *)sender {
-
-
-
- self.quantity_text.text = [NSString stringWithFormat:@"%d",(int)sender.value ];
-
- [celldelegate stepClicked:(int)sender.value];
- // -(void) stepClicked:(int) value;
-
- // 检查缺货
- // NSString *cartQtyString = nil;
- // if (self.cqyt_label.text) {
- // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]];
- // }
- //
- // int availability = [self.count_Label.text intValue];
- // int buyQTY = [self.quantity_text.text intValue];
- // int cartQTY = [cartQtyString intValue];
- //
- // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY];
- }
- #pragma mark -
- #pragma mark Actions
- -(void)ClearPhotos
- {
- NSMutableArray *photosMutable = [self.photos mutableCopy];
- [photosMutable removeAllObjects];
- self.photos = photosMutable;
- [self.photoStack reloadData];
-
- }
- - (void)AddPhoto :(UIImage*)photo {
-
- NSMutableArray *photosMutable = [self.photos mutableCopy];
- [photosMutable addObject:photo];
- self.photos = photosMutable;
- [self.photoStack reloadData];
- self.pageControl.numberOfPages = [self.photos count];
- if(self.photos.count<2-1)//1 for qrcode;
- self.photoStack.showBorder=false;
- else
- self.photoStack.showBorder=true;
-
- }
- #pragma mark -
- #pragma mark Setup
- -(void)setup {
-
-
- // int availability = [self.count_Label.text intValue];
- self.stepper.minimumValue= self.step;
- self.stepper.maximumValue = INTMAX_MAX;
-
-
- self.stepper.stepValue= self.step;
-
- self.stepper.value= self.quantity;
-
-
-
- [self.stepper addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
-
- if(true)//(self.photos==nil)
- {
-
- self.photos = [NSArray array];
- }
- if(true)//(self.photoStack==nil)
- {
- // if(self.photoStack!=nil)
- // [self.photoStack removeFromSuperview];
- // self.photoStack = [[PhotoStackView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
- // self.photoStack.backgroundColor =[UIColor redColor];
- // self.photoStack.center = CGPointMake(self.center.x, 220);
- self.photoStack.dataSource = self;
- self.photoStack.delegate = self;
-
-
- // [self addSubview:self.photoStack];
- self.pageControl.numberOfPages = [self.photos count];
- }
- }
- - (IBAction)notifyMeButtonClicked:(UIButton *)sender {
-
- if (self.notifyMeBlock) {
- self.notifyMeBlock();
- }
-
- }
- #pragma mark - TextField Delegate
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
-
-
-
- NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
- // NSString *cartQtyString = nil;
- // if (self.cqyt_label.text) {
- // cartQtyString = [self.cqyt_label.text substringFromIndex:[@"Model QTY in Cart:" length]];
- // }
-
- // int availability = [self.count_Label.text intValue];
- int buyQTY = [newString intValue];
- // int cartQTY = [cartQtyString intValue];
-
- // [self checkAvailability:availability buyQTY:buyQTY cartQTY:cartQTY];
-
- self.stepper.value = buyQTY;
-
- return YES;
- }
- #pragma mark - Private
- /**检查是否缺货*/
- - (void)checkAvailability:(int)availability buyQTY:(int)buyQty cartQTY:(int)cartQty { // availability不可以通过textField.text取得
-
- //#if defined(BUILD_NPD) || defined(BUILD_USAI)
- AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- if (!appDelegate.bLogin || buyQty < 1) {
- return;
- }
-
- #ifdef OFFLINE_MODE
- if (appDelegate.offline_mode) {
- return;
- }
- #endif
-
-
- if (appDelegate.user_type == USER_ROLE_CUSTOMER) { // customer
-
- if (!appDelegate.order_code) { // 未打开订单状态
-
- if ((buyQty + cartQty) > availability) {
-
- self.btnaddCart.enabled = NO;
- self.btnNotifyMe.enabled = YES;
- } else {
-
- self.btnaddCart.enabled = YES;
- self.btnNotifyMe.enabled = NO;
- }
-
- } else {
- // 打开订单状态
- if (![Singleton sharedInstance].currentOrderIsMerged) {
- // Shop Order
- self.btnaddCart.enabled = YES;
- // 默认未缺货
- self.btnNotifyMe.enabled = NO;
-
- if ((buyQty + cartQty) > availability) { // 缺货
-
- self.btnNotifyMe.enabled = YES;
- }
-
-
- } else {
- // Purchase Order
- if ((buyQty + cartQty) > availability) { // 缺货
- self.btnaddCart.enabled = NO;
- self.btnNotifyMe.enabled = YES;
- } else { // 未缺货
- self.btnNotifyMe.enabled = NO;
- self.btnaddCart.enabled = YES;
- }
-
- }
-
-
- }
-
- } else { // empoyee
-
- if ((buyQty + cartQty) > availability) { // 缺货
- self.btnaddCart.enabled = NO;
- self.btnNotifyMe.enabled = YES;
- } else { // 未缺货
- self.btnNotifyMe.enabled = NO;
- self.btnaddCart.enabled = YES;
- }
-
- }
- //#endif
-
- }
- - (IBAction)introduceBtnClick:(UIButton *)sender {
-
- if (self.introduceBlock) {
- self.introduceBlock(sender);
- }
-
- }
- - (IBAction)descriptionBtnClick:(UIButton *)sender {
- if (self.descriptionBlock) {
- self.descriptionBlock(sender);
- }
- }
- - (IBAction)OnClosePlayer:(id)sender {
- [self.playerView stopVideo];
-
- self.playerView.hidden=true;
- }
- - (IBAction)noLoginBtnClick:(UIButton *)sender {
-
- UIApplication * app = [UIApplication sharedApplication];
- AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
-
- if(appDelegate.bLogin==false) {
- DetailViewController *vc= (DetailViewController *)[RAUtils getViewController:self];
- LoginViewController * loginvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
-
- loginvc.returnValue = ^(bool blogin){
-
- if(blogin) {
- [vc reload];
- [main_vc checklogin:true];
- }
-
-
- };
-
- UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
-
- navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- [vc presentViewController:navi animated:YES completion:^{
- }];
- }
-
- }
- @end
|