Преглед изворни кода

RA Image iOS

4 增加验证逻辑。
5 修复POP 模式没有验证扫码为数字的情况。
Ray Zhang пре 8 година
родитељ
комит
cbdc5374e7

BIN
RA Image/RA Image.xcodeproj/project.xcworkspace/xcuserdata/ray.xcuserdatad/UserInterfaceState.xcuserstate


+ 4 - 0
RA Image/RA Image/BasicModeViewController.h

@@ -16,7 +16,11 @@
 @property (nonatomic,copy) NSString *barcodeTitle;
 @property (nonatomic,assign) NSUInteger photoCount;
 @property (nonatomic,strong) NSMutableArray <NSMutableDictionary *> *photos;
+@property (nonatomic,copy) NSString *verify_msg0;
 
+- (void)addTasks;
+
+-(void) verify:(NSMutableDictionary*) params;
 - (void)showPhotoList;
 - (void)showScanner;
 - (void)clickCameraButton;

+ 45 - 0
RA Image/RA Image/BasicModeViewController.m

@@ -541,6 +541,51 @@
     
 }
 
+
+
+-(void) verify:(NSMutableDictionary*) params
+{
+     AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+//    appDelegate.address = self.address;
+    __weak typeof(self) weakself = self;
+//    UIAlertView *alert = [RAUtils waiting_alert:@"Please wait" title:@"Login"];
+    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+    //    if (weakself) {
+//            __strong typeof(weakself) strongself = weakself;
+            NSDictionary *result_json = [RAINetwork Verify:params];
+            dispatch_async(dispatch_get_main_queue(), ^{
+//                [alert dismissWithClickedButtonIndex:0 animated:YES];
+                int result = [[result_json objectForKey:@"result"] intValue];
+//                BOOL rememberLogin = [[strongself userDefaultsValue:kRememberLogin] boolValue];
+                switch (result) {
+                    case 0:
+                    {
+                        //code not exist;
+                        
+                            [weakself.view makeToast:weakself.verify_msg0 duration:3.0 position:CSToastPositionCenter];
+                        break;
+                    }
+                    case 1:
+                    {
+                                                    [weakself.view makeToast:@"Model/Manufacturer does not match" duration:3.0 position:CSToastPositionCenter];
+                        break;
+                    }
+                    case 2:
+                    {
+                        //upload;
+                        [self addTasks];
+                        break;
+                    }
+                    default:
+                        break;
+                }
+               
+            });
+            
+      //  }
+    });
+}
+
 @end
 
 #pragma clang diagnostic pop

+ 39 - 7
RA Image/RA Image/ModelModeViewController.m

@@ -35,6 +35,7 @@
 
 - (void)viewDidLoad {
     [super viewDidLoad];
+    self.verify_msg0=@"Model does not exist";
     // Do any additional setup after loading the view.
     self.noteTextView.layer.borderColor = [UIColor blackColor].CGColor;
     self.noteTextView.layer.borderWidth = 1.0f;    
@@ -103,13 +104,47 @@
         [RAUtils message_alert:@"You must take at least one photo." title:@"Warning" controller:self];
         return;
     }
-    AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
-    
-    NSString *manufacturer = self.manufacturer;
     if (self.manufacturerList.count && self.manufacturer.length == 0) {
         [RAUtils message_alert:@"Manufacturer does not set." title:@"Warning" controller:self];
         return;
     }
+    
+    AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
+    
+    NSString* encryptu=[AESCrypt AES128Encrypt:Appdelegate.user key:@"usai"];
+    NSString* encryptp=[AESCrypt AES128Encrypt:Appdelegate.password key:@"usai"];
+    
+    NSMutableDictionary* params = [@{
+                                     @"user" : encryptu,
+                                     @"password" : encryptp,
+                                     @"mode":self.name,
+                                     @"barcode":self.barcode,
+                                     @"_operate":@"valid_upload",
+                                     @"platform":@"ios",
+
+                                     } mutableCopy];
+    
+    NSString *manufacturer = self.manufacturer;
+
+    NSString *note = self.noteTextView.text;
+    if (manufacturer) {
+        [params setObject:manufacturer forKey:@"manufacturer"];
+    }
+    if (note) {
+        [params setObject:note forKey:@"note"];
+    }
+    [self verify:params];
+
+    
+//    UploadViewController *upVC = (UploadViewController *)[self viewControllerInStoryboard:@"Upload" withId:@"UploadViewController"];
+//    [self.navigationController pushViewController:upVC animated:YES];
+}
+-(void) addTasks
+{
+    AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
+    
+    NSString *manufacturer = self.manufacturer;
+
     NSString *note = self.noteTextView.text;
     
     //prepare upload
@@ -128,7 +163,7 @@
         
         task[@"url"]=Appdelegate.address;
         NSString *md5 = [photo objectForKey:@"md5"];
-
+        
         NSString* encryptu=[AESCrypt AES128Encrypt:Appdelegate.user key:@"usai"];
         NSString* encryptp=[AESCrypt AES128Encrypt:Appdelegate.password key:@"usai"];
         NSMutableDictionary* params = [@{
@@ -161,9 +196,6 @@
     [Appdelegate.uploadManager addTasks:tasks];
     
     [self clear];
-    
-//    UploadViewController *upVC = (UploadViewController *)[self viewControllerInStoryboard:@"Upload" withId:@"UploadViewController"];
-//    [self.navigationController pushViewController:upVC animated:YES];
 }
 - (IBAction)typeBtnClick:(UIButton *)sender {
     [self showBarcodeInput:UIKeyboardTypeDefault];

+ 45 - 9
RA Image/RA Image/PopModeViewController.m

@@ -27,7 +27,10 @@
 @implementation PopModeViewController
 
 - (void)viewDidLoad {
+    
     [super viewDidLoad];
+    
+    self.verify_msg0=@"Piid does not exist";
     // Do any additional setup after loading the view.
     
     self.imgBtn.layer.borderColor = [UIColor blackColor].CGColor;
@@ -79,6 +82,28 @@
         [RAUtils message_alert:@"You must take at least one photo." title:@"Warning" controller:self];
         return;
     }
+    
+    
+        AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
+    NSString* encryptu=[AESCrypt AES128Encrypt:Appdelegate.user key:@"usai"];
+    NSString* encryptp=[AESCrypt AES128Encrypt:Appdelegate.password key:@"usai"];
+    NSMutableDictionary* params = [@{
+                             @"user" : encryptu,
+                             @"password" : encryptp,
+                             @"mode":self.name,
+                             @"barcode":self.barcode,
+                             @"_operate":@"valid_upload",
+                             @"platform":@"ios",
+                             } mutableCopy];
+    [self verify:params];
+    
+//    UploadViewController *upVC = (UploadViewController *)[self viewControllerInStoryboard:@"Upload" withId:@"UploadViewController"];
+//    [self.navigationController pushViewController:upVC animated:YES];
+}
+
+-(void)addTasks
+{
+    
     AppDelegate* Appdelegate=(AppDelegate*)[UIApplication sharedApplication].delegate;
     
     
@@ -91,10 +116,10 @@
         
         NSMutableDictionary* task=[[NSMutableDictionary alloc]init];
         
-    
+        
         task[@"path"]=self.name;
         task[@"file"]=photo[@"file"];
-
+        
         task[@"url"]=Appdelegate.address;
         NSString *md5 = [photo objectForKey:@"md5"];
         
@@ -117,17 +142,14 @@
         [self moveTmpImageToCache:file];
         
         [tasks addObject:task];
-
+        
     }
-
     
- //    // add upload tasks;
+    
+    //    // add upload tasks;
     [Appdelegate.uploadManager addTasks:tasks];
-
-    [self clear];
     
-//    UploadViewController *upVC = (UploadViewController *)[self viewControllerInStoryboard:@"Upload" withId:@"UploadViewController"];
-//    [self.navigationController pushViewController:upVC animated:YES];
+    [self clear];
 }
 
 - (IBAction)typeBtnClick:(UIButton *)sender {
@@ -144,9 +166,23 @@
 
 - (void)setBarcode:(NSString *)barcode {
     [super setBarcode:barcode];
+
+        
+ 
     if (!barcode) {
         barcode = @"";
     }
+    else
+    {
+        if(![RAUtils isNumeric:barcode])
+        {
+            
+            
+                                        [self.view makeToast:@"Piid must be a number" duration:3.0 position:CSToastPositionCenter];
+            
+            barcode = @"";
+        }
+    }
     self.barcodeLabel.text = [NSString stringWithFormat:@"%@:%@",self.barcodeTitle,barcode];
 }
 

+ 1 - 1
RA Image/RA Image/RAINetwork.h

@@ -12,5 +12,5 @@
 @interface RAINetwork : NetworkUtils
 +(NSDictionary*)Login : (NSString*) user password:(NSString*) password;
 +(NSDictionary*)logout;
-
++(NSDictionary*)Verify : (NSMutableDictionary*) params;
 @end

+ 13 - 0
RA Image/RA Image/RAINetwork.m

@@ -122,6 +122,19 @@
     return resultDic;
 }
 
++(NSDictionary*)Verify : (NSMutableDictionary*) params
+{
+
+    
+
+   // params[@"_operate"]=@"valid_upload";
+    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
+    
+    NSData *data = [self get_json:appDelegate.address parameters:params file:nil];
+    NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
+    return resultDic;
+}
+
 + (NSDictionary *)logout {
 //    NSMutableDictionary *params = @{@"_operate":@"handset_logout"
 //                                    }.mutableCopy;

+ 1 - 0
RedAnt ERP Mobile/common/RAUtils.h

@@ -19,6 +19,7 @@
 
 
 @interface RAUtils : NSObject
++ (BOOL)isNumeric:(NSString*)string;
 +(NSData*) dict2data:(NSDictionary*) dict;
 +(NSString*) FloatFormat:(float)value;
 +(UIViewController*) getViewController:(UIView*) view;

+ 5 - 0
RedAnt ERP Mobile/common/RAUtils.m

@@ -783,6 +783,11 @@ begin:
     
     return ret;
 }
++ (BOOL)isNumeric:(NSString*)string{
+    NSScanner* scan = [NSScanner scannerWithString:string];
+    int val;
+    return[scan scanInt:&val] && [scan isAtEnd];
+}
 + (CGRect)relativeFrameForScreenWithView:(UIView *)v
 {
     UIWindow * window=[[[UIApplication sharedApplication] delegate] window];