| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072 |
- /*
- 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
- //#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);
- //
- //}
- - (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;
-
-
-
-
-
-
-
- [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];
- UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector( onBackClick:)];
-
- // closeButton.tintColor = UIColorFromRGB(0x996633);
-
- self.navigationItem.leftBarButtonItem = closeButton;
-
- // return;
- // [self.backgroundView removeFromSuperview];
- //self.back = (ScannerControllerView*)self.view;
- self.backgroundView.highLightRect = CGRectInset(self.focusZone.frame,6,6);
- // self.backgroundView.autoresizingMask=0xff;
- self.handelOutput = false;
-
-
-
- // 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];
-
- 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
-
- }
- //#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;
- 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)
- 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
- _decodedMessage.text = [transformed stringValue];
-
- // Start the timer which will hide the overlay
- [self startOverlayHideTimer];
- [self playSound];
-
-
-
- self.handelOutput = false;
- [self StopScan];
-
-
-
- self.scan_val = [transformed stringValue];
-
- 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];
-
- dvc.use_model_name = true;
- 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
- {
- [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)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
- {
- 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 cursomer infomation." title:@"New Order" controller:vc];
- //
- // };
- // cvc.onReset = ^(){
- // [main_vc checklogin:true];
- // };
- //
- // [self.navigationController pushViewController:cvc animated:true];
- // }
- // else
- // {
- // [self neworder];
- // }
- //
- //
- // }
- //}
- @end
|