Explorar el Código

Homer Mobile

修复 扫描枪头文件报错
Ray Zhang hace 8 años
padre
commit
39b1745c22
Se han modificado 6 ficheros con 343 adiciones y 0 borrados
  1. 15 0
      common/FileCache.h
  2. 133 0
      common/FileCache.m
  3. 15 0
      common/NetworkUtils+Contact.h
  4. 139 0
      common/NetworkUtils+Contact.m
  5. 13 0
      common/RAConvertor.h
  6. 28 0
      common/RAConvertor.m

+ 15 - 0
common/FileCache.h

@@ -0,0 +1,15 @@
+//
+//  FileCache.h
+//  RedAnt Mobile
+//
+//  Created by Ray on 08/09/2017.
+//  Copyright © 2017 Ray. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface FileCache : NSObject
++ (NSData*) load_cached_img:(NSString*) filename loadFrom:(NSString*) path;
++ (void) cache_img: (NSData*) imgData filename:(NSString*) name saveTo:(NSString*) path;
+
+@end

+ 133 - 0
common/FileCache.m

@@ -0,0 +1,133 @@
+//
+//  FileCache.m
+//  RedAnt Mobile
+//
+//  Created by Ray on 08/09/2017.
+//  Copyright © 2017 Ray. All rights reserved.
+//
+
+#import "FileCache.h"
+#import "AppDelegate.h"
+#import "const.h"
+
+
+@implementation FileCache
+
+
++ (void) cache_img: (NSData*) imgData filename:(NSString*) name saveTo:(NSString*) path
+{
+    
+    path=[path stringByReplacingOccurrencesOfString:@"https://" withString:@""];
+    path=[path stringByReplacingOccurrencesOfString:@"http://" withString:@""];
+    path=[path stringByReplacingOccurrencesOfString:name withString:@""];
+    
+    //    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+    //    NSString *cachefolder = [paths objectAtIndex:0];
+    //    NSString *img_cache = [cachefolder stringByAppendingPathComponent:[NSString stringWithFormat:@"img_cache/%@",@"www.newpacificdirect.com/u/NPD/20160615/mytest/"]];
+    //    if ([[NSFileManager defaultManager] fileExistsAtPath:img_cache]) {
+    //
+    //        DebugLog(@"目录已经存在了");
+    //
+    //    }
+    //    else
+    //    {
+    //        NSError *error = nil;
+    //        bool bsuccess=[[NSFileManager defaultManager] createDirectoryAtPath:img_cache withIntermediateDirectories:YES attributes:nil error:&error];
+    //
+    //        if(!bsuccess)
+    //            DebugLog(@"Create temp folder failed");
+    //    }
+    
+    
+    if(path.length==0)
+        path=@"";
+    
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    
+    if(appDelegate.bEnable_Cache==false)
+        return ;
+    if(imgData==nil)
+        return;
+    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+    NSString *cachefolder = [paths objectAtIndex:0];
+    NSString *img_cache = [cachefolder stringByAppendingPathComponent:[NSString stringWithFormat:@"img_cache/%@",path]];
+    NSFileManager* fileManager = [NSFileManager defaultManager];
+    BOOL bdir=YES;
+    if(!  [fileManager fileExistsAtPath:img_cache isDirectory:&bdir])
+    {
+        
+        NSError *error = nil;
+        bool bsuccess=[fileManager createDirectoryAtPath:img_cache withIntermediateDirectories:YES attributes:nil error:&error];
+        
+        if(!bsuccess)
+            DebugLog(@"Create cache folder failed");
+        
+        //        if(bsuccess)
+        //        {
+        //            sqlite3 *db = [self get_db];
+        //
+        //            [self execSql:[NSString stringWithFormat:@"insert into img_cache(name) values('%@')",name] db:db];
+        //            [iSalesDB close_db:db];
+        //        }
+    }
+    NSString *filePath = [img_cache stringByAppendingPathComponent:name];
+    bool bsuccess=[imgData writeToFile:filePath atomically:YES];
+    
+    if(bsuccess)
+        DebugLog(@"IMG CACHE SUCCESS,%@",name);
+    else
+        DebugLog(@"IMG CACHE FAILED,%@",name);
+    
+}
++ (NSData*) load_cached_img:(NSString*) filename loadFrom:(NSString*) path
+{
+    if(path.length==0)
+        return nil;
+    
+    path=[path stringByReplacingOccurrencesOfString:@"https://" withString:@""];
+    path=[path stringByReplacingOccurrencesOfString:@"http://" withString:@""];
+    //    path=[path stringByReplacingOccurrencesOfString:filename withString:@""];
+    
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    
+    if(appDelegate.bEnable_Cache==false)
+        return nil;
+    
+    
+    NSData* data = nil;
+    
+    
+    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+    NSString *cachefolder = [paths objectAtIndex:0];
+    NSString *img_cache = [cachefolder stringByAppendingPathComponent:@"img_cache"];
+    NSString *filePath = [img_cache stringByAppendingPathComponent:path];
+    
+    NSFileManager* fileManager = [NSFileManager defaultManager];
+    if(  [fileManager fileExistsAtPath:filePath ])
+    {
+        data = [NSData dataWithContentsOfFile: filePath];
+    }
+    
+    //    NSString* sqliteQuery = [NSString stringWithFormat:@"SELECT img FROM img_cache WHERE name = '%@'", filename];
+    //    sqlite3_stmt* statement;
+    
+    //    sqlite3 *db = [self get_db];
+    //
+    ////    if( sqlite3_prepare_v2(db, [sqliteQuery UTF8String], -1, &statement, NULL) == SQLITE_OK )
+    ////    {
+    ////        if( sqlite3_step(statement) == SQLITE_ROW )
+    ////        {
+    ////            int length = sqlite3_column_bytes(statement, 0);
+    ////            data       = [NSData dataWithBytes:sqlite3_column_blob(statement, 0) length:length];
+    ////        }
+    ////    }
+    //
+    //    // Finalize and close database.
+    //    sqlite3_finalize(statement);
+    
+    
+    // [iSalesDB close_db:db];
+    return data;
+    
+}
+@end

+ 15 - 0
common/NetworkUtils+Contact.h

@@ -0,0 +1,15 @@
+//
+//  NetworkUtils+Contact.h
+//  RedAnt Mobile
+//
+//  Created by Ray on 08/09/2017.
+//  Copyright © 2017 Ray. All rights reserved.
+//
+
+#import "NetworkUtils.h"
+
+@interface NetworkUtils (Contact)
++(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams;
++(NSDictionary*)request_CustomerInfo:(NSString* ) contactid;
++(NSDictionary*)create_Address:(NSMutableDictionary*)params;
+@end

+ 139 - 0
common/NetworkUtils+Contact.m

@@ -0,0 +1,139 @@
+//
+//  NetworkUtils+Contact.m
+//  RedAnt Mobile
+//
+//  Created by Ray on 08/09/2017.
+//  Copyright © 2017 Ray. All rights reserved.
+//
+
+#import "NetworkUtils+Contact.h"
+#import "AppDelegate.h"
+
+@implementation NetworkUtils (Contact)
++(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
+{
+    NSAssert(true, @"未实现");
+    return nil;
+//    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+//    
+//    if(upparams!=nil)
+//        params = [upparams mutableCopy];
+//    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//    if(appDelegate.user!=nil)
+//        [params setValue:appDelegate.user forKey:@"user"];
+//    
+//    if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
+//        [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
+//    else
+//        [params setValue:appDelegate.contact_id forKey:@"contactId"];
+//    
+//    if(appDelegate.password!=nil)
+//        [params setValue:appDelegate.password forKey:@"password"];
+//    
+//    [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
+//    [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
+//    [params setValue:contact_type forKey:@"contactType"];
+//    [params setValue:keywords forKey:@"keyword"];
+//    
+//    [params setObject:ScreenCodeAccount forKey:kScreenName];
+//    if (keywords) {
+//        [params setObject:@"Search" forKey:kAction];
+//    }
+//    if (upparams) {
+//        [params setObject:@"Advance Search" forKey:kAction];
+//    }
+//    
+//    NSString* url=nil;
+//    if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
+//        url=URL_SHIPTO_LIST;
+//    else
+//        url=URL_CONTACT_LIST;
+//    
+//    if(appDelegate.offline_mode)
+//        return [OLDataProvider offline_contactlist:params];
+//    
+//    if(![self IsNetworkAvailable])
+//        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//    
+//    NSData* json=[self get_json:url parameters:params];
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+}
+
+
++(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
+{
+    NSAssert(true, @"未实现");
+    return nil;
+    
+    
+//    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+//    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//    if(appDelegate.user!=nil)
+//        [params setValue:appDelegate.user forKey:@"user"];
+//    //    if(appDelegate.contact_id!=nil)
+//    
+//    if(appDelegate.password!=nil)
+//        [params setValue:appDelegate.password forKey:@"password"];
+//    [params setValue:contactid forKey:@"contactId"];
+//    
+//    [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
+//    
+//    if(appDelegate.offline_mode)
+//        return [OLDataProvider offline_contactinfo:params];
+//    if(![self IsNetworkAvailable])
+//        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//    
+//    NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+    
+}
+
++(NSDictionary*)create_Address:(NSMutableDictionary*)params
+{
+    NSAssert(true, @"未实现");
+    return nil;
+//    //    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+//    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//    if(appDelegate.user!=nil)
+//        [params setValue:appDelegate.user forKey:@"user"];
+//    if(appDelegate.contact_id!=nil)
+//        [params setValue:appDelegate.contact_id forKey:@"contactId"];
+//    if(appDelegate.password!=nil)
+//        [params setValue:appDelegate.password forKey:@"password"];
+//    //    [params setValue:sourceid forKey:@"sourceid"];
+//    //    [params setValue:editor forKey:@"editor"];
+//    
+//    [params setValue:ScreenCodeNewAddress forKey:kScreenName];
+//    
+//    NSData* json=nil;
+//    
+//    if(appDelegate.offline_mode)
+//    {
+//        json= [OLDataProvider offline_saveaddr:params];
+//    }
+//    else
+//    {
+//        if(![self IsNetworkAvailable])
+//            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//        
+//        json =[self get_json:URL_ADDRESS_SAVE parameters:params];
+//    }
+//    if(json!=nil)
+//    {
+//        NSError *error=nil;
+//        NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//        return jsobj;
+//    }
+//    else
+//        return nil;
+    
+}
+@end

+ 13 - 0
common/RAConvertor.h

@@ -0,0 +1,13 @@
+//
+//  RAConvertor.h
+//  RedAnt Mobile
+//
+//  Created by Ray on 08/09/2017.
+//  Copyright © 2017 Ray. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface RAConvertor : NSObject
++(NSString*)DataTOjsonString:(id)object;
+@end

+ 28 - 0
common/RAConvertor.m

@@ -0,0 +1,28 @@
+//
+//  RAConvertor.m
+//  RedAnt Mobile
+//
+//  Created by Ray on 08/09/2017.
+//  Copyright © 2017 Ray. All rights reserved.
+//
+
+#import "RAConvertor.h"
+#import "const.h"
+
+@implementation RAConvertor
+
++(NSString*)DataTOjsonString:(id)object
+{
+    NSString *jsonString = nil;
+    NSError *error;
+    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
+                                                       options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
+                                                         error:&error];
+    if (! jsonData) {
+        DebugLog(@"Got an error: %@", error);
+    } else {
+        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
+    }
+    return jsonString;
+}
+@end