| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445 |
- /*
- Copyright 2013 Scott Logic Ltd
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
- #import "ScannerViewController.h"
- @import AVFoundation;
- #import <AudioToolbox/AudioToolbox.h>
- #import "SCShapeView.h"
- #import "ScannerControllerView.h"
- #import "DetailViewController.h"
- #import "const.h"
- #import "AppDelegate.h"
- #import "MainViewController.h"
- #import "ContactListViewController.h"
- #import "CartUtils.h"
- #import "ERPUtils.h"
- #import "RANetwork.h"
- #define SCANNER_TARGET_DETAIL 0
- #define SCANNER_TARGET_CART 1
- #define SCANNER_TYPE_MODELNAME 0
- #define SCANNER_TYPE_UPCCODE 1
- //#import "ScannerControlViewController.h"
- @interface ScannerViewController () <AVCaptureMetadataOutputObjectsDelegate> {
- AVCaptureVideoPreviewLayer *_previewLayer;
- SCShapeView *_boundingBox;
- NSTimer *_boxHideTimer;
- UILabel *_decodedMessage;
- }
- @end
- @implementation ScannerViewController
- //- (UIInterfaceOrientationMask)supportedInterfaceOrientations
- //{
- // return UIInterfaceOrientationMaskPortrait;
- //}
- //- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
- //{
- //
- // return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
- //
- //}
- //- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
- // return UIInterfaceOrientationLandscapeRight;
- //// return UIInterfaceOrientationPortrait;
- //}
- - (BOOL)shouldAutorotate
- {
-
- return false;
-
- }
- #pragma mark routate
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
- [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
- // what ever you want to prepare
- } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
- CGRect rect=self.view.bounds;
-
- DebugLog(@"%@",NSStringFromCGRect(self.focusZone.frame));
- // rect.origin.y=rect.origin.y+40;
- // rect.size.height = rect.size.height-40;
-
-
- // self->_previewLayer
-
-
-
-
- [CATransaction begin];
- [CATransaction setAnimationDuration:0.5];
- [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
- // [self updatePreviewLayerForOrientation:toInterfaceOrientation];
- self->_previewLayer.position = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
-
- // self.backgroundView.highLightRect = CGRectInset(self.focusZone.frame,6,6);
- self->_previewLayer.bounds = rect;
-
- UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
- switch (orientation) {
-
-
-
- case UIInterfaceOrientationPortrait:
- // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(0)];
-
- self->_previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortrait;
- break;
- case UIInterfaceOrientationPortraitUpsideDown:
- //[_previewLayer setAffineTransform:CGAffineTransformMakeRotation(M_PI)];
- self->_previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortraitUpsideDown;
- break;
- case UIInterfaceOrientationLandscapeLeft:
- // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(M_PI/2)];
- self->_previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeLeft;
- break;
- case UIInterfaceOrientationLandscapeRight:
- // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(-M_PI/2)];
- self->_previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeRight;
- break;
- default:
- break;
- }
- [CATransaction commit];
- }];
- }
- //-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
- //{
- //
- //
- // [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
- // CGRect rect=self.view.bounds;
- //
- // DebugLog(@"%@",NSStringFromCGRect(self.focusZone.frame));
- // // rect.origin.y=rect.origin.y+40;
- // // rect.size.height = rect.size.height-40;
- //
- //
- //
- //
- //
- //
- //
- // [CATransaction begin];
- // [CATransaction setAnimationDuration:0.5];
- // [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
- //// [self updatePreviewLayerForOrientation:toInterfaceOrientation];
- // _previewLayer.position = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
- //
- // // self.backgroundView.highLightRect = CGRectInset(self.focusZone.frame,6,6);
- // _previewLayer.bounds = rect;
- //
- // UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
- // switch (orientation) {
- //
- //
- //
- // case UIInterfaceOrientationPortrait:
- // // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(0)];
- //
- // _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortrait;
- // break;
- // case UIInterfaceOrientationPortraitUpsideDown:
- // //[_previewLayer setAffineTransform:CGAffineTransformMakeRotation(M_PI)];
- // _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortraitUpsideDown;
- // break;
- // case UIInterfaceOrientationLandscapeLeft:
- // // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(M_PI/2)];
- // _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeLeft;
- // break;
- // case UIInterfaceOrientationLandscapeRight:
- // // [_previewLayer setAffineTransform:CGAffineTransformMakeRotation(-M_PI/2)];
- // _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeRight;
- // break;
- // default:
- // break;
- // }
- // [CATransaction commit];
- //
- //
- //}
- //- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
- //{
- // return UIInterfaceOrientationPortrait;
- //}
- -(void) playSound
- {
-
- /*
- SystemSoundID sameViewSoundID;
- // NSString *filePath = [[NSBundle mainBundle]pathForResource:@"sound" ofType:@"m4r"];
- // NSString *thesoundFilePath = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"]; //音乐文件路径
- NSString *path = @"/System/Library/Audio/UISounds/begin_video_record.caf";
- CFURLRef thesoundURL = (__bridge CFURLRef) [NSURL fileURLWithPath:path] ;
- AudioServicesCreateSystemSoundID(thesoundURL, &sameViewSoundID);
- //变量SoundID与URL对应
- DebugLog(@"%u",(unsigned int)sameViewSoundID);
- AudioServicesPlaySystemSound(1112); //播放SoundID声音
-
-
- */
- CFBundleRef mainBundle;
- SystemSoundID soundFileObject;
- mainBundle = CFBundleGetMainBundle ();
- CFURLRef soundFileURLRef = CFBundleCopyResourceURL (
- mainBundle,
- CFSTR ("softScanBeep" ),
- CFSTR ("wav" ),
- NULL
- );
- AudioServicesCreateSystemSoundID (
- soundFileURLRef,
- &soundFileObject
- );
- AudioServicesPlaySystemSound(soundFileObject);
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- [[self navigationController] setNavigationBarHidden:NO animated:NO];
-
-
- //
- //[ attemptRotationToDeviceOrientation];
-
- //[UIViewController attemptRotationToDeviceOrientation];
-
- //
- // [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
- // self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
- // CGRect frame = [UIScreen mainScreen].applicationFrame;
- // self.view.bounds = CGRectMake(0, 0, 768, 1024);
- }
- - (void)onBackClick:(UIButton *)sender {
-
-
- [self.navigationController popViewControllerAnimated:FALSE];
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- #ifdef SCANNER_ORDER
- #if TARGET_IPHONE_SIMULATOR//模拟器
-
- // if(RASingleton.sharedInstance.enable_OfflineOrder)
- {
- // self.scan_val = @"[[\"1111\",\"name0\",\"description\",\"10.1 X 20.2 X 30.3\",\"2\",\"12.34\",\"VIET\",\"VCSF\",\"May\",\"123.45\",\"234.56\",\"123.45\",\"234.56\",\"123.45\",\"234.56\",\"123.45\",\"234.56\",\"123.45\",\"234.56\",\"123.45\",\"234.56\",\"123.45\",\"234.56\",\"123.45\",\"234.56\"],[\"2222\",\"name1\",\"description\",\"10.1 X 20.2 X 30.3\",\"2\",\"12.34\",\"VIET\",\"VCSF\",\"May\",\"123.45\",\"234.56\",\"123.45\",\"234.56\",\"123.45\",\"234.56\",\"123.45\",\"234.56\",\"123.45\",\"234.56\",\"123.45\",\"234.56\",\"123.45\",\"234.56\",\"123.45\",\"234.56\"]]";
-
- self.scan_val =@"[\"1430K-1CK*\",\"1430K-1EK*\",\"1000A70WH\",\"1002A70BK\"]";// @"[\"1002A70BK\"]";//
- [self addtocart];
- }
- return;
- #endif
-
- #endif
-
- #ifdef SCANNER_ORDER
- self.auto_style = true;
- #else
- self.auto_style = false;
- #endif
-
- UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector( onBackClick:)];
- #ifdef SCANNER_ORDER
- closeButton.tintColor = [UIColor whiteColor];
- #endif
- // closeButton.tintColor = UIColorFromRGB(0x996633);
-
- self.navigationItem.leftBarButtonItem = closeButton;
-
- // return;
- // [self.backgroundView removeFromSuperview];
- //self.back = (ScannerControllerView*)self.view;
-
- if(self.auto_style)
- {
- // cgrectoff
- self.focusZone.frame = self.view.frame;
- self.backgroundView.auto_style = self.auto_style;
- self.backgroundView.highLightRect = self.view.frame;
- self.scanButton.hidden = true;
- self.handelOutput = true;
- }
- else
- {
- self.backgroundView.highLightRect = CGRectInset(self.focusZone.frame,6,6);
- self.handelOutput = false;
- }
-
-
- // self.backgroundView.autoresizingMask=0xff;
-
-
- #ifdef SCANNER_ORDER
-
- self.targetButton.hidden = true;
- #endif
-
-
- // Do any additional setup after loading the view, typically from a nib.
-
- // Create a new AVCaptureSession
- AVCaptureSession *session = [[AVCaptureSession alloc] init];
-
- session.sessionPreset = AVCaptureSessionPresetHigh;
-
- AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
-
- // float factor = device.videoZoomFactor;
- // float up = device.activeFormat.videoZoomFactorUpscaleThreshold;
- // [device lockForConfiguration:nil];
- // device.videoZoomFactor = device.activeFormat.videoZoomFactorUpscaleThreshold;
- // [device unlockForConfiguration];
- NSError *error = nil;
-
- // Want the normal device
- AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
-
- if(input) {
- // Add the input to the session
- [session addInput:input];
-
- } else {
- DebugLog(@"error: %@", error);
-
-
- return;
- }
-
-
-
- AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] init];
- // Have to add the output before setting metadata types
- [session addOutput:output];
- // What different things can we register to recognise?
- DebugLog(@"%@", [output availableMetadataObjectTypes]);
- // We're only interested in QR Codes
- [output setMetadataObjectTypes:@[AVMetadataObjectTypeUPCECode,AVMetadataObjectTypeCode39Code,AVMetadataObjectTypeCode39Mod43Code,AVMetadataObjectTypeEAN13Code,AVMetadataObjectTypeEAN8Code,AVMetadataObjectTypeCode93Code,AVMetadataObjectTypeCode128Code,AVMetadataObjectTypePDF417Code,AVMetadataObjectTypeQRCode,AVMetadataObjectTypeAztecCode]];
- DebugLog(@"%@", [output metadataObjectTypes]);
- // NSArray* supporttype=output.availableMetadataObjectTypes;
- // [output setMetadataObjectTypes:output.availableMetadataObjectTypes];
- // This VC is the delegate. Please call us on the main queue
- [output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
- //
- // CGRect rt1 = self.ScannerControl.scannerZone.frame;
-
-
-
- // Display on screen
- _previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
- _previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
-
- // _previewLayer.orientation= AVCaptureVideoOrientationLandscapeRight;
- UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
- switch (orientation) {
-
- // UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
- // UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
- // UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
- // UIInterfaceOrientationLandscapeRight
-
-
- // AVCaptureVideoOrientationPortrait = 1,
- // AVCaptureVideoOrientationPortraitUpsideDown = 2,
- // AVCaptureVideoOrientationLandscapeRight = 3,
- // AVCaptureVideoOrientationLandscapeLeft = 4,
- case UIInterfaceOrientationPortrait:
- _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortrait;
- break;
- case UIInterfaceOrientationPortraitUpsideDown:
- _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationPortraitUpsideDown;
- break;
- case UIInterfaceOrientationLandscapeLeft:
- _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeLeft;
- break;
- case UIInterfaceOrientationLandscapeRight:
- _previewLayer.connection.videoOrientation=AVCaptureVideoOrientationLandscapeRight;
- break;
- default:
- break;
- }
-
- CGRect rect=self.view.bounds;
- // rect.origin.y=rect.origin.y+40;
- // rect.size.height = rect.size.height-40;
-
- _previewLayer.bounds = rect;
- _previewLayer.position = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds));
- [self.view.layer addSublayer:_previewLayer];
-
-
-
- [self.view addSubview:self.backgroundView];
-
- // [self.view addSubview:self.ScannerControl.view];
- // CGRect rt = self.ScannerControl.scannerZone.bounds;
-
- // CGRect rt1 =output.rectOfInterest;
- // output.rectOfInterest = CGRectMake(0, 0, 300, 300); //self.ScannerControl.scannerZone.frame;
- // ScannerControllerView* view =[[ ScannerControllerView alloc] initWithFrame:self.view.frame];
- // view.backgroundColor = [UIColor clearColor];
-
-
-
- // ScannerLayer * layer = [[ScannerLayer alloc] init];
- // [self.view.layer addSublayer:layer];
-
-
- // Add the view to draw the bounding box for the UIView
- _boundingBox = [[SCShapeView alloc] initWithFrame:self.view.bounds];
- _boundingBox.backgroundColor = [UIColor clearColor];
- _boundingBox.hidden = YES;
- [self.view addSubview:_boundingBox];
-
- // Add a label to display the resultant message
- _decodedMessage = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.view.bounds) - 75, CGRectGetWidth(self.view.bounds), 75)];
- _decodedMessage.numberOfLines = 0;
- _decodedMessage.backgroundColor = [UIColor colorWithWhite:0.8 alpha:0.9];
- _decodedMessage.textColor = [UIColor darkGrayColor];
- _decodedMessage.textAlignment = NSTextAlignmentCenter;
-
- [self.view addSubview:_decodedMessage];
- #ifdef SCANNER_ORDER
- _decodedMessage.hidden = TRUE;
- #endif
-
-
- self.scanButton.layer.shadowColor = [UIColor blackColor].CGColor;
- self.scanButton.layer.shadowOffset = CGSizeMake(0, 0);
- self.scanButton.layer.shadowOpacity = 0.5;
- self.scanButton.layer.shadowRadius = 2.0;
- self.scanButton.layer.borderColor = [[UIColor darkGrayColor] CGColor];
- self.scanButton.layer.borderWidth = 15;
- // Start the AVSession running
- [session startRunning];
-
- #ifdef BUILD_UWAVER
-
- [self.targetButton setTitle:@"Target: Model Detail" forState:UIControlStateNormal];
- self.target = SCANNER_TARGET_DETAIL;
-
- #endif
-
- #ifdef BUILD_CONTRAST
- self.typeButton.hidden = false;
- [self.typeButton setTitle:@"Type: UPC Code" forState:UIControlStateNormal];
- self.type = SCANNER_TYPE_UPCCODE;
- #else
- self.typeButton.hidden = true;
- self.type = SCANNER_TYPE_MODELNAME;
- #endif
-
-
- }
- //#pragma mark - ScannerControllerDelegate
- //-(void)BeginScan:(bool)begin
- //{
- // self.handelOutput = begin;
- //}
- #pragma mark - AVCaptureMetadataOutputObjectsDelegate
- - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection
- {
- if(!self.handelOutput)
- return;
-
- // if(!self.auto_style)
- {
- self.handelOutput = false;
- [self StopScan];
- }
- AVMetadataObject * cadedate = nil;
- CGPoint centerzone =CGPointMake(CGRectGetMidX(self.focusZone.frame), CGRectGetMidY(self.focusZone.frame));
-
- float distance = MAXFLOAT;
- for (AVMetadataObject *metadata in metadataObjects) {
- DebugLog(@"%@",metadata);
- // if ([metadata.type isEqualToString:AVMetadataObjectTypeQRCode])
- {
- // Transform the meta-data coordinates to screen coords
- AVMetadataMachineReadableCodeObject *transformed = (AVMetadataMachineReadableCodeObject *)[_previewLayer transformedMetadataObjectForMetadataObject:metadata];
- // Update the frame on the _boundingBox view, and show it
- CGRect rt = transformed.bounds;
-
- CGRectGetMidX(rt);
- CGPoint centermeta =CGPointMake(CGRectGetMidX(rt), CGRectGetMidY(rt));
- if(CGRectContainsPoint(self.focusZone.frame, centermeta))
- {
- if(cadedate == nil)
- cadedate = metadata;
- float distancemeta = (centermeta.x-centerzone.x)*(centermeta.x-centerzone.x)+(centermeta.y-centerzone.y)*(centermeta.y-centerzone.y);
- if(distancemeta<distance)
- {
- distance = distancemeta;
- cadedate = metadata;
- }
-
- }
- }
- }
- if(cadedate==nil)
- {
- if (self.auto_style)
- self.handelOutput = true;
- return;
-
- }
- AVMetadataMachineReadableCodeObject *transformed = (AVMetadataMachineReadableCodeObject *)[_previewLayer transformedMetadataObjectForMetadataObject:cadedate];
- // Update the frame on the _boundingBox view, and show it
- // CGRect rt = transformed.bounds;
- _boundingBox.frame = transformed.bounds;
- // _boundingBox.hidden = NO;
- // Now convert the corners array into CGPoints in the coordinate system
- // of the bounding box itself
-
- // NSArray * corners = transformed.corners;
- NSArray *translatedCorners = [self translatePoints:transformed.corners
- fromView:self.view
- toView:_boundingBox];
-
- // Set the corners array
- _boundingBox.corners = translatedCorners;
-
- // Update the view with the decoded text
-
- // Start the timer which will hide the overlay
- [self startOverlayHideTimer];
- [self playSound];
-
-
-
-
-
- self.scan_val = [transformed stringValue];
- NSLog(@"scan result:%@",self.scan_val);
- #ifdef SCANNER_ORDER
- // if(RASingleton.sharedInstance.enable_OfflineOrder)
- {
- [self addtocart];
- // [CartUtils add_to_cart:self selectorholder:self selector:@selector(addtocart)];
- return;
- }
- #endif
-
- NSString *action = nil;
- switch (self.target) {
- case SCANNER_TARGET_DETAIL:
- {
- DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
- // dvc
-
- action = @"Open A Model";
- [ERPUtils googleAnalyticsSendRequestString:nil WithScreen:ScreenCodeCamScan Action:action Extra:nil];
-
- if(self.type== SCANNER_TYPE_MODELNAME)
- dvc.use_model_name = true;
- else
- {
- dvc.use_upc_code = true;
- dvc.upc_code =[transformed stringValue];
- }
- dvc.model_name=[transformed stringValue];
- dvc.category_id=nil;
- dvc.ispush = true;
- #ifdef BUILD_UWAVER
- if(!(transformed.type==AVMetadataObjectTypeQRCode))
- dvc.groupName = [transformed stringValue];
- #endif
- //
-
- [dvc reload];
- [self.navigationController pushViewController:dvc animated:true];
-
-
- }
- break;
- case SCANNER_TARGET_CART:
- {
-
- [CartUtils add_to_cart:self selectorholder:self selector:@selector(addtocart)];
- // return;
- // [self add_toCart];
- // DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
- // // dvc
- //
- //
- // dvc.use_model_name = true;
- // dvc.model_name=[transformed stringValue];
- // dvc.category_id=nil;
- // dvc.ispush = true;
- //
- // [dvc reload];
- // [self.navigationController pushViewController:dvc animated:true];
- }
- break;
- default:
- break;
- }
-
-
-
- }
- //
- //
- //-(void)add_toCart
- //{
- //
- // [CartUtils add_to_cart:self selectorholder:self selector:@selector(addtocart)];
- // return;
- //
- //// UIApplication * app = [UIApplication sharedApplication];
- //// AppDelegate *appDelegate = (AppDelegate *)[app delegate];
- //// MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- //// if(appDelegate.bLogin==false)
- //// {
- //// LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
- ////
- ////
- //// loginvc.returnValue = ^(bool blogin){
- ////
- ////
- ////
- ////
- ////
- //// if(blogin)
- //// {
- //// if(/*appDelegate.user_type==USER_ROLE_EMPLOYEE*/ true)
- //// {
- ////
- ////#ifdef RA_NOTIFICATION
- //// [ActiveViewController Notify:@"CategoryViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- ////#else
- ////
- //// [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
- ////#endif
- ////
- ////
- ////
- //// [main_vc checklogin:false];
- ////
- ////
- ////
- //// UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Add to cart" message:@"Do you want to add to pending a order or a new order" preferredStyle:UIAlertControllerStyleAlert];
- ////
- ////
- //// UIAlertAction *action_1 = [UIAlertAction actionWithTitle:@"Add to pending order" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- ////
- ////
- ////
- //// }];
- ////
- //// UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"Add to new order" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- ////
- ////
- ////
- //// }];
- //// UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- ////
- ////
- ////
- //// }];
- ////
- //// [alertController addAction:action_1];
- //// [alertController addAction:action_2];
- //// [alertController addAction:action_3];
- ////
- ////
- //// [self presentViewController:alertController animated:YES completion:nil];
- ////
- ////// 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];
- //// }
- //// }
- ////
- ////
- ////
- //// };
- ////
- //// UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
- ////
- ////
- ////
- ////
- ////
- //// // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
- ////
- //// navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
- //// [self 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)
- //// if(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(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil];
- ////
- //// // alert.
- //// [alert show];
- //// }
- //// }
- //// else
- //// {
- ////
- ////
- //// if(appDelegate.order_code==nil)
- //// [ self neworder];
- //// else
- //// [self addtocart];
- ////
- ////
- //// }
- //// }
- ////
- ////
- ////
- ////
- ////
- ////
- ////
- ////
- //}
- -(void) neworder
- {
-
- __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Create Order" completion:^{
- [RANetwork request_create_order:^(NSMutableDictionary *result) {
- NSMutableDictionary* return_json = result;
-
- [waitalert dismissViewControllerAnimated:YES completion:^{
-
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
-
-
- 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;
- appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
-
-
- [self addtocart];
-
-
-
- }
- }
- else
- {
-
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
- }
- }];
-
-
-
-
-
-
- }];
- }];
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* return_json = [RANetwork new_Order];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- //
- // 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;
- // appDelegate.order_status = [[return_json valueForKey:@"orderStatus"] intValue];
- //
- //
- // [self addtocart];
- //
- //
- //
- // }
- // }
- // else
- // {
- //
- // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
- // }
- //
- //
- //
- //
- // });
- // });
- }
- -(void) addtocart
- {
-
- #ifdef SCANNER_ORDER
- // if(RASingleton.sharedInstance.enable_OfflineOrder)
- {
-
-
-
- NSString* key =@"usai2010";
-
- //
- // NSString* str1 = @"[[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"123.45\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"],[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"123.45\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"],[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"123.45\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"],[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"123.45\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"],[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"123.45\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"],[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"123.45\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"],[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"123.45\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"],[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"123.45\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"],[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"123.45\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"],[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"123.45\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"],[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"123.45\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"],[\"5688\",\"5808-68\",\"DINING TBL, ACACIA VNER\",\"123.45\",\"1\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"123.45\",\"1\",\"10.96\",\"viet\",\"vcsf\",\"42 X 68 x 30.5H\",\"234.56\"]]";
- //
- // NSString* str2 = [AESCrypt encrypt:self.scan_val password:key];
- // NSString * cart_item = [AESCrypt decrypt:self.scan_val password:key];
- //#if TARGET_IPHONE_SIMULATOR
- // cart_item = self.scan_val;
- //#endif
-
- NSString * cart_item = self.scan_val;
- if(cart_item == nil)
- {
- //二维码不是scan order的格式
- // [RAUtils message_alert:@"QR CODE incorrect." title:@"Add To Cart" controller:self] ;
- [RAUtils message_alert:@"QR CODE incorrect." title:@"Add To Cart" controller:self action_handler:^(UIAlertAction * _Nonnull action) {
- self.handelOutput = true;
- } completion:nil];
- return;
- }
-
-
-
- // NSMutableArray* item = [[RAConvertor string2dict:cart_item] mutableCopy];
-
- NSMutableArray* item = [[RADataProvider request_scan_model_by_names:cart_item] mutableCopy];
-
-
- // __block NSMutableDictionary* jitem = [NSMutableDictionary new];
- // jitem[@"product_id"]= item[0];
- // NSString* model =item[1];
- // NSString* description =item[2];
- // jitem[@"model"] =model;
- // jitem[@"description"] = [NSString stringWithFormat:@"%@ \r\n%@",model,description];
- // jitem[@"unit_price"] =@( [item[3] doubleValue]);
- // jitem[@"stockUom"] = @([item[4] intValue]);
- // jitem[@"count"] = @([item[4] intValue]);
- // jitem[@"subtotal_price"] = @([item[4] intValue]* [item[3] doubleValue]);
- //
- // jitem[@"check"]=@(true);
- //
-
- self.resultvc.scan_val = item;
- self.resultvc.modalPresentationStyle = UIModalPresentationFullScreen;//有三种状态,自己看看是哪种
- __weak typeof(self) weakself = self;
-
- __block NSMutableArray* modellist;
- self.resultvc.returnValue = ^(id _Nonnull val) {
- modellist = (NSMutableArray*)val;
- weakself.handelOutput=true;
- if(modellist==nil)
- return;
- // 加购物车
-
-
- if(RASingleton.sharedInstance.scan_cart ==nil)
- {
- // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
- NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
- RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
- }
- // 初始化为 whse;
- if(RASingleton.sharedInstance.scan_cart[@"price_type"] ==nil)
- {
- RASingleton.sharedInstance.scan_cart[@"price_type"] = @1;
- RASingleton.sharedInstance.price_type = 1;
- }
- NSMutableDictionary* section =[RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
- int count =[section[@"count"] intValue];
-
- for(int j=0;j<modellist.count;j++)
- {
-
- if([modellist[j][@"count"] intValue]==0)
- continue;
- NSMutableDictionary* jitem = nil;
- jitem = [modellist[j] mutableCopy];
-
- bool newitem = true;
- for(int i=0;i<count;i++)
- {
-
- NSMutableDictionary* litem = [section[[NSString stringWithFormat:@"item_%i",i]] mutableCopy];
-
- if([litem[@"product_id"] isEqualToString:jitem[@"product_id"]])
- {
-
- // int oldcount = [litem[@"stockUom"] intValue];
- newitem = false;
-
- litem[@"count"]=@([litem[@"count"] intValue] +[jitem[@"count"] intValue]);
- litem[@"cuft"]=@([litem[@"count"] intValue] * [litem[@"unit_cuft"] doubleValue]);
- section[[NSString stringWithFormat:@"item_%i",i]] = litem;
- break;
-
-
- }
-
- }
- if(newitem)
- {
- jitem[@"cart_item_id"]=[NSUUID UUID].UUIDString;
- section[[NSString stringWithFormat:@"item_%i",count]] = jitem;
- section[@"count"]= @(count+1);
- count++;
-
- }
-
-
-
- }
-
-
-
-
-
- RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
-
- //加list
-
-
-
-
-
- #ifdef RA_NOTIFICATION
- [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- #else
-
- AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- #endif
-
- [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
-
- return;
- };
-
- [self presentViewController:self.resultvc animated:YES completion:nil];
-
- return;
-
- }
-
- #endif
-
- if(self.type == SCANNER_TYPE_UPCCODE)
- {
- [RANetwork request_addto_cart_byupc:self.scan_val withScreen:ScreenCodeCamScan completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* return_json = result;
-
-
-
-
- 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) reloadOrder:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- #endif
-
-
- }
- else
- {
-
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
- }
-
-
-
-
-
- }];
- }
- else
- {
- [RANetwork request_addto_cart_byname:self.scan_val withScreen:ScreenCodeCamScan completionHandler:^(NSMutableDictionary *result) {
- NSDictionary* return_json = result;
-
-
-
-
- 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) reloadOrder:true immediately:false];
- [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- #endif
-
-
- }
- else
- {
-
- [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
- }
-
-
-
-
-
- }];
- }
-
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* return_json = [RANetwork add_toCart_byName: self.scan_val withScreen:ScreenCodeCamScan];
- //
- // 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) reloadOrder:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- //#endif
- //
- //
- // }
- // else
- // {
- //
- // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
- // }
- //
- //
- //
- //
- // });
- // });
-
-
- }
- - (IBAction)TypeButtonClick:(id)sender {
-
- BOOL shouldChangeTarget = NO;
- #ifdef BUILD_CONTRAST
- shouldChangeTarget = YES;
- #endif
-
- if (!shouldChangeTarget) {
- return;
- }
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Change code type to" message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Model Name" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- [self.typeButton setTitle:@"Type: Model Name" forState:UIControlStateNormal];
-
- self.type = SCANNER_TYPE_MODELNAME;
- // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Models From Cart"];
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- // if([[cart_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // [self end_edit];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
- // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
- // }
- // else
- // {
- // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
- // }
- //
- //
- //
- // });
- // });
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"UPC CODE" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
-
- [self.typeButton setTitle:@"Type: UPC Code" forState:UIControlStateNormal];
- self.type = SCANNER_TYPE_UPCCODE;
-
- DebugLog(@"No");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
-
-
- }
- - (IBAction)TargetButtonClick:(id)sender {
-
- BOOL shouldChangeTarget = YES;
- #ifdef BUILD_UWAVER
- shouldChangeTarget = NO;
- #endif
-
- if (!shouldChangeTarget) {
- return;
- }
-
- UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Change scanner target to" message:nil preferredStyle:UIAlertControllerStyleAlert];
- //block代码块取代了delegate
-
-
-
- UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Model Detail" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
- [self.targetButton setTitle:@"Target: Model Detail" forState:UIControlStateNormal];
-
- self.target = SCANNER_TARGET_DETAIL;
- // UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Models From Cart"];
- // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- //
- // NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
- //
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // [waitalert dismissViewControllerAnimated:YES completion:nil];
- //
- // if([[cart_json valueForKey:@"result"] intValue]==2)
- // {
- //
- // [self end_edit];
- // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
- // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
- // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
- // }
- // else
- // {
- // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
- // }
- //
- //
- //
- // });
- // });
-
-
- }];
-
- UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cart" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-
-
- [self.targetButton setTitle:@"Target: Cart" forState:UIControlStateNormal];
- self.target = SCANNER_TARGET_CART;
-
- DebugLog(@"No");
- }];
- [alertControl addAction:actionOne];
-
- [alertControl addAction:alertthree];
-
- //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
-
-
- [self presentViewController:alertControl animated:YES completion:nil];
-
-
-
-
-
- }
- - (IBAction)ScanButtonClick:(id)sender {
- self.scanButton.backgroundColor = [UIColor greenColor];
-
-
- [self.scanButton setTitle:@"Scanning" forState:UIControlStateNormal];
- // self.scanButton.layer.borderWidth = 1;
-
-
- self.handelOutput = true;
-
- // if (self.Scannerdelegate && [self.Scannerdelegate respondsToSelector:@selector(BeginScan:)]) {
- // [self.Scannerdelegate BeginScan:true];
- // }
- }
- -(void) StopScan
- {
- if(self.auto_style)
- return;
- self.scanButton.backgroundColor = [UIColor redColor];
- [self.scanButton setTitle:@"Tap" forState:UIControlStateNormal];
- }
- #pragma mark - Utility Methods
- - (void)startOverlayHideTimer
- {
- // Cancel it if we're already running
- if(_boxHideTimer) {
- [_boxHideTimer invalidate];
- }
-
- // Restart it to hide the overlay when it fires
- _boxHideTimer = [NSTimer scheduledTimerWithTimeInterval:0.2
- target:self
- selector:@selector(removeBoundingBox:)
- userInfo:nil
- repeats:NO];
- }
- - (void)removeBoundingBox:(id)sender
- {
- // Hide the box and remove the decoded text
- _boundingBox.hidden = YES;
- // _decodedMessage.text = @"";
- }
- - (NSArray *)translatePoints:(NSArray *)points fromView:(UIView *)fromView toView:(UIView *)toView
- {
- NSMutableArray *translatedPoints = [NSMutableArray new];
-
- // The points are provided in a dictionary with keys X and Y
- for (NSDictionary *point in points) {
- // Let's turn them into CGPoints
- CGPoint pointValue = CGPointMake([point[@"X"] floatValue], [point[@"Y"] floatValue]);
- // Now translate from one view to the other
- CGPoint translatedPoint = [fromView convertPoint:pointValue toView:toView];
- // Box them up and add to the array
- [translatedPoints addObject:[NSValue valueWithCGPoint:translatedPoint]];
- }
-
- return [translatedPoints copy];
- }
- //#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];
- //
- //
- // // int count=[self.quantity_text.text intValue];
- //
- // MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
- // if(buttonIndex==alertView.cancelButtonIndex)
- // {
- //
- //
- //
- // }
- // else if(buttonIndex==1)
- // {
- // //open exist
- // OrderListViewController* ovc =[ [UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderListViewController"];
- // ovc.showNavibar = true;
- // ovc.selectOrder = ^(NSMutableDictionary* order_detail){
- // if(appDelegate.order_code==nil)
- // {
- // [self neworder];
- // }
- // else
- // {
- //
- //
- //#ifdef RA_NOTIFICATION
- // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
- //#else
- // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
- // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
- //#endif
- // [self addtocart];
- // [main_vc checklogin:true];
- //
- //
- // }
- //
- // };
- // ovc.init_style = OL_OPEN;
- // ovc.onCancel = ^(){
- //
- // [main_vc checklogin:true];
- //
- // };
- //
- // [self.navigationController pushViewController:ovc animated:true];
- // }
- // else
- // {
- // //create new;
- // if(appDelegate.customerInfo==nil)// select contact if current contact not exist
- // {
- //
- //
- // ContactListViewController* cvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Contact" bundle:nil] 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 customer infomation." title:@"New Order" controller:vc];
- //
- // };
- // cvc.onReset = ^(){
- // [main_vc checklogin:true];
- // };
- //
- // [self.navigationController pushViewController:cvc animated:true];
- // }
- // else
- // {
- // [self neworder];
- // }
- //
- //
- // }
- //}
- @end
|