Selaa lähdekoodia

161228

test version 1.0
Ray Zhang 9 vuotta sitten
vanhempi
commit
28737fdb45

+ 18 - 0
Ants Contract/common/ACNetwork.h

@@ -0,0 +1,18 @@
+//
+//  ACNetwork.h
+//  AntsContract
+//
+//  Created by Ray on 12/26/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "NetworkUtils.h"
+
+
+
+
+@interface ACNetwork : NetworkUtils
++(int)Authorize : (NSString*) user password:(NSString*) password;
++(NSString *) prepareUploadFile:(NSString*) file json:(NSMutableDictionary*)json;
++(NSDictionary*)logout;
+@end

+ 467 - 0
Ants Contract/common/ACNetwork.m

@@ -0,0 +1,467 @@
+//
+//  ACNetwork.m
+//  AntsContract
+//
+//  Created by Ray on 12/26/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "ACNetwork.h"
+#import "AppDelegate.h"
+
+#import "RAUtils.h"
+#import "ZipArchive.h"
+
+#import "config.h"
+
+
+@implementation ACNetwork
+
++(NSMutableDictionary*) prepare_addtional_params:(NSMutableDictionary* ) params
+{
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.user forKey:@"user"];
+    if(appDelegate.password!=nil)
+        [params setValue:appDelegate.password forKey:@"password"];
+    
+    
+    
+    
+    [params setValue:appDelegate.build forKey:@"app_ver"];
+    
+    NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
+    NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
+    [params setValue:short_version forKey:@"app_short_ver"];
+    
+    UIDevice * dev = [UIDevice currentDevice];
+    NSUUID* uuid =dev.identifierForVendor;
+#if TARGET_IPHONE_SIMULATOR//模拟器
+    [params setValue:@"simulator_uuid" forKey:@"deviceid"];
+#elif TARGET_OS_IPHONE//真机
+    [params setValue:uuid.UUIDString forKey:@"deviceid"];
+#endif
+    
+    return params;
+}
+
++(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
+{
+    
+    params = [self prepare_addtional_params:params];
+    
+    return [super get_json:url parameters:params err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
+        int result=[[jsobj valueForKey:@"result"] intValue];
+//        UIApplication * app = [UIApplication sharedApplication];
+//        AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+
+        switch (result) {
+            case 0:
+                [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
+                break;
+            case 1:
+                [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
+                break;
+            case 2:
+                [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
+                break;
+            case 8:
+                [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
+                break;
+            case 9:
+                [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
+                break;
+            case 99:
+                [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
+                break;
+            default:
+                [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
+                break;
+        }
+        
+        
+//        if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
+//        {
+//            [jsobj setValue:@"9" forKey:@"result"];
+//            [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
+//        }
+        return jsobj;
+    }];
+    
+    
+    /*
+
+
+     
+     */
+    return nil;
+}
++(NSDictionary*)logout
+{
+    
+    
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.user forKey:@"user"];
+    
+    
+    if(appDelegate.password!=nil)
+        [params setValue:appDelegate.password forKey:@"password"];
+    params[@"_operate"]=@"logout_zip";
+    
+    if(![self IsNetworkAvailable])
+    {
+        DebugLog(@"NET ERR");
+        
+        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+        //        return nil;
+    }
+    NSData* json=[self get_json:URL_LOGOUT parameters:params];
+    //if(json==nil)
+    
+    
+    if(json==nil)
+        return nil;
+    NSError *error=nil;
+    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+    int result = [[jsobj valueForKey:@"result"] intValue];
+    
+    if (result==2)
+    {
+        [appDelegate Logout];
+  
+    }
+    return jsobj;
+}
++(int)Authorize : (NSString*) user password:(NSString*) password{
+    
+    //    if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
+    //        return RESULT_NET_ERROR;
+    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+    long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
+    
+    
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//    if(appDelegate.duid !=nil)
+//        [params setValue:appDelegate.duid forKey:@"udid"];
+//    [params setValue:@"handset_login" forKey:@"action"];
+    //    [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
+    
+    [params setValue:user forKey:@"user"];
+    [params setValue:password forKey:@"password"];
+    [params setValue:[NSString stringWithFormat:@"%ld",ver]  forKey:@"auth_ver"];
+        [params setValue:@"login"  forKey:@"_operate"];
+    
+
+//#ifdef TEST
+//    [params setValue:@"true" forKey:@"is_debug"];
+//#else
+//    [params setValue:@"false" forKey:@"is_debug"];
+//#endif
+    
+    NSData* json= nil;
+//    if(appDelegate.offline_mode)
+//    {
+//        json= [OLDataProvider offline_login:params] ;
+//        
+//    }
+//    else
+    
+        if(![self IsNetworkAvailable])
+            return RESULT_NET_NOTAVAILABLE;
+        json =[self get_json:URL_UPDATE_AUTH parameters:params];
+        
+    
+    
+    if(json==nil)
+        return RESULT_NET_ERROR;
+    
+    
+    int ret = [self parse_authinfo:json user:user password:password];
+    DebugLog(@"parse_authinfo return %d ",ret);
+    
+    
+    return ret;
+    
+    
+}
++(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
+{
+    DebugLog(@"parse_authinfo");
+    NSError *error=nil;
+    
+    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+    if(jsobj)
+    {
+        
+        UIApplication * app = [UIApplication sharedApplication];
+        AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+        int result = [[jsobj valueForKey:@"result"] intValue];
+        
+        if (result<0)
+            return result;
+        if(result!=AP_USER_AUTH&& result!=9)
+        {
+            
+            
+            DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
+            [appDelegate Logout];
+            if(result==8)
+            {
+                return RESULT_LOGIN_DEVICE;
+            }
+            return RESULT_FALSE;
+            
+        }
+//        NSDictionary* objheader = [jsobj objectForKey:@"header"];
+//        
+//        NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
+//        user=[objheader objectForKey:@"username"] ;
+//        DebugLog(@"required_ver=%@ ",required_ver);
+//        //        NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
+//        //        NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
+//        //        versionNum = [NSString stringWithFormat:@"A%@",versionNum];
+//        int ibadge = [[objheader valueForKey:@"badge"] intValue];
+//        
+//        //        if([ibadge isEqual:[NSNull null]])
+//        //            strbadge=@"0";
+//        //        if(ibadge==nil)
+//        //            ibadge=@"0";
+//        //        if([strbadge isEqualToString:@"null"])
+//        //            strbadge=@"0";
+//        app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
+//        
+//        //  BOOL bigger = [appDelegate.build compare:required_ver] ;
+//        if([appDelegate.build intValue]<[required_ver intValue])
+//            return RESULT_VER_LOW;
+//        //        appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
+//        appDelegate.user = user;
+//        appDelegate.password = password;
+////        appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
+////        appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
+//        appDelegate.bLogin = true;
+        
+        
+        [appDelegate Login:user pwd:password];
+        
+        
+//        
+//        if(appDelegate.user_type==USER_ROLE_CUSTOMER)
+//        {
+//            appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
+//            appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
+//            //            appDelegate.order_code =[objheader valueForKey:@"orderCode"];
+//            //            appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
+//            //            [appDelegate SetSo:[objheader valueForKey:@"soId"]];
+//        }
+//        NSString* mode =[jsobj valueForKey:@"mode"] ;
+//        [appDelegate SetMode:mode];
+//        
+//        
+//        appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
+//        appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
+//        appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
+//        
+//        [appDelegate update_count_mark];
+//        
+//        
+//        
+//        appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
+//        appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
+//        appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
+//        appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
+//        
+//        appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
+//        appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
+//        appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
+//        appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
+//        appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
+//        appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
+//        
+//        appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
+//        appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
+//        
+//        appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
+//        
+//        
+//        
+//        appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
+//        
+//        NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
+//        
+//        
+//        
+//        appDelegate.OrderFilter= [[RAUtils string2dict:strfilter] mutableCopy];
+//        
+//        
+//        [appDelegate set_main_button_panel];
+//        
+//        if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
+//            
+//            // shop order status filter
+//            NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
+//            [Singleton sharedInstance].shop_order_status_filter = [[RAUtils string2dict:shopOrderStatusFilterStr] mutableCopy];
+//            
+//            // specialInstruction
+//            [Singleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
+//            
+//            //-价格类型
+//            [Singleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
+//            
+//            // 权限
+//            [Singleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
+//            [Singleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
+//            
+//            [Singleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
+//            
+//            [Singleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
+//            
+//            [Singleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
+//            [[Singleton sharedInstance] resetGlobalLock];
+//            [Singleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
+//        }
+        
+        //        DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
+        //        if ([[objheader valueForKey:@"update"] boolValue]==false)
+        //        {
+        //            // no update on the server;
+        //            return RESULT_TRUE;
+        //        }
+        //        int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
+        //        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+        //        [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
+        //       [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
+        //        [defaults synchronize];
+        //
+        //        NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
+        //        NSArray* keys= [objfuncs allKeys];
+        
+        
+        /*
+         
+         db.setTransactionSuccessful();
+         db.endTransaction();
+         */
+        return RESULT_TRUE;
+        
+    }
+    //    NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
+    //    txtView.text = [NSString stringWithFormat:@"今天是 %@  %@  %@  的天气状况是:%@  %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
+    //      DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
+    
+    
+    
+    return RESULT_USERAUTH_ERROR;
+}
++(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
+{
+//    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+//    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//    if(appDelegate.user!=nil)
+//        [params setValue:appDelegate.user forKey:@"user"];
+//    
+//    [params setValue:up_params forKey:@"upparam"];
+//    
+//    [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
+//    
+//    [params setValue:result forKey:@"result"];
+//    [params setValue:module forKey:@"interfac"];
+//    
+//    [params setValue:[RAUtils base64en:[RAUtils dict2string: [RAUtils device_info]]] forKey:@"device"];
+//    
+//    
+//    //     [params setValue:module forKey:@"module"];
+//    
+//    //  [[UIDevice currentDevice]  name];
+//    
+//    //    if(appDelegate.offline_mode)
+//    //    {
+//    //        return [OLDataProvider offline_notimpl];
+//    //    }
+//    if(![self IsNetworkAvailable])
+//        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//    
+//    NSData* json=[self get_json:URL_ERR_LOG parameters:params];
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+    NSMutableDictionary* jsobj = [@{@"result":@"2"} mutableCopy];
+    return jsobj;
+}
+
++(NSString *) prepareUploadFile:(NSString*) file json:(NSMutableDictionary*)json
+{
+    NSString* serial= [[NSUUID UUID] UUIDString];
+    
+    
+    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+    NSString *cachefolder = [paths objectAtIndex:0];
+    
+    NSString *upfolder = [cachefolder stringByAppendingPathComponent:@"upload_data"];
+    upfolder = [upfolder stringByAppendingPathComponent:serial];
+    
+    NSFileManager* fileManager = [NSFileManager defaultManager];
+    BOOL bdir=YES;
+    if(!  [fileManager fileExistsAtPath:upfolder isDirectory:&bdir])
+    {
+        
+        NSError *error = nil;
+        bool bsuccess=[fileManager createDirectoryAtPath:upfolder withIntermediateDirectories:YES attributes:nil error:&error];
+        
+        if(!bsuccess)
+            DebugLog(@"Create UPLOAD folder failed");
+        
+    }
+    
+//    NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
+//    ret[@"contact"]=[self prepareContact:serial];
+//    ret[@"wishlist"]=[self prepareWishlist:serial];
+//    ret[@"order"]=[self prepareOrder:serial soid:arr_order];
+//    ret[@"portfolio"] = [self preparePortfolio:serial];
+//    ret[@"view_portfolio"] = [self preparePDF:serial];
+    
+    NSString* str= [RAUtils dict2string:json];
+    
+    
+    
+    
+    
+    NSString * jsonpath= [upfolder stringByAppendingPathComponent:@"json.json"];
+    
+    NSString * zippath= [upfolder stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.zip",serial]];
+    
+    
+    NSError *error=nil;
+    
+    [str writeToFile:jsonpath atomically:true encoding:NSUTF8StringEncoding error:&error];
+    
+   // NSArray* arr_files=[RAUtils allFilesAtPath:upfolder];
+    
+    ZipArchive* zip = [[ZipArchive alloc] init];
+    
+    
+    BOOL result = [zip CreateZipFile2:zippath Password:nil];
+    
+
+        result = [zip addFileToZip:file newname:[file lastPathComponent]];
+    result = [zip addFileToZip:jsonpath newname:[jsonpath lastPathComponent]];
+
+    
+    if( ![zip CloseZipFile2] )
+    {
+        zippath = @"";
+    }
+    
+    
+    
+
+    
+    return zippath;
+}
+@end

+ 25 - 0
Ants Contract/common/AppDelegate.h

@@ -0,0 +1,25 @@
+//
+//  AppDelegate.h
+//  AntsContract
+//
+//  Created by Ray on 12/16/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
+
+@property (strong, nonatomic) UIWindow *window;
+
+@property bool bEnable_Cache;
+@property bool bLogin;
+@property (strong,nonatomic) NSString* user;
+@property (strong,nonatomic) NSString * password;
+@property (strong,nonatomic) NSString* build;
+-(void) Logout;
+-(void) Login:(NSString* )user pwd:(NSString*) pwd;
+@property (strong,nonatomic) NSString* printerURL;
+
+@end
+

+ 82 - 0
Ants Contract/common/AppDelegate.m

@@ -0,0 +1,82 @@
+//
+//  AppDelegate.m
+//  AntsContract
+//
+//  Created by Ray on 12/16/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "AppDelegate.h"
+
+@interface AppDelegate ()
+
+@end
+
+@implementation AppDelegate
+
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+    // Override point for customization after application launch.
+    
+    self.bEnable_Cache = true;
+    return YES;
+}
+
+
+- (void)applicationWillResignActive:(UIApplication *)application {
+    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
+}
+
+
+- (void)applicationDidEnterBackground:(UIApplication *)application {
+    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
+    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
+}
+
+
+- (void)applicationWillEnterForeground:(UIApplication *)application {
+    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
+}
+
+
+- (void)applicationDidBecomeActive:(UIApplication *)application {
+    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+}
+
+
+- (void)applicationWillTerminate:(UIApplication *)application {
+    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
+}
+-(void) Login:(NSString* )user pwd:(NSString*) pwd
+{
+    self.user = user;
+    self.password = pwd;
+    self.bLogin = true;
+}
+-(void) Logout
+{
+//    MainViewController * main_vc= (MainViewController*)self.main_vc;
+//    [main_vc logoutOrder];
+//    
+//    
+//    [main_vc hideMenu];
+//    [main_vc switchToHome];
+    self.user = nil;
+    self.password=nil;
+    self.bLogin = false;
+    
+    
+//    self.user_icon=nil;
+//    self.user_type = USER_ROLE_UNKNOWN;
+//    self.bLogin = false;
+//    self.contact_id=nil;
+//    self.customerInfo = nil;
+//    self.order_code = nil;
+//    
+//    [self.recent_model removeAllObjects];
+//    
+//    [self SetMode:nil];
+    
+}
+@end

+ 19 - 0
Ants Contract/common/CheckSelectorViewController.h

@@ -0,0 +1,19 @@
+//
+//  CheckSelectorViewController.h
+//  AntsContract
+//
+//  Created by Ray on 12/22/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface CheckSelectorViewController : UIViewController
+@property (strong, nonatomic) IBOutlet UITableView *tableView;
+
+@property (strong, nonatomic) NSArray* rowData;
+@property (strong, nonatomic) NSMutableArray* checkedData;
+@property bool single_select;
+@property bool show_detail;
+@property (nonatomic , copy) void (^blk_OK)(NSArray* checkedData);
+@end

+ 170 - 0
Ants Contract/common/CheckSelectorViewController.m

@@ -0,0 +1,170 @@
+//
+//  CheckSelectorViewController.m
+//  AntsContract
+//
+//  Created by Ray on 12/22/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "CheckSelectorViewController.h"
+
+@interface CheckSelectorViewController ()
+
+@end
+
+@implementation CheckSelectorViewController
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    // Do any additional setup after loading the view.
+}
+
+- (void)didReceiveMemoryWarning {
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+- (IBAction)OnOKClick:(id)sender {
+    [self dismissViewControllerAnimated:false completion:^{
+        if(self.blk_OK)
+            self.blk_OK(self.checkedData);
+    }];
+}
+- (IBAction)OnCancelClick:(id)sender {
+    
+    [self dismissViewControllerAnimated:false completion:nil];
+}
+
+/*
+#pragma mark - Navigation
+
+// In a storyboard-based application, you will often want to do a little preparation before navigation
+- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
+    // Get the new view controller using [segue destinationViewController].
+    // Pass the selected object to the new view controller.
+}
+*/
+
+#pragma mark - Table view data source
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
+{
+
+    return 44;
+    
+    
+}
+
+
+
+- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
+    
+    return @"";//[NSString stringWithFormat:@"Signature%ld",(long)section];
+    
+}
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+    return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    
+    return self.rowData.count;
+    
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    
+    
+
+    NSString *CellIdentifier = @"CheckItemCell";
+//    UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+    
+    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+    
+    if (cell == nil) {
+        if(self.show_detail)
+        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
+        else
+            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
+    }
+    
+    
+    NSArray *item_arr = self.rowData[indexPath.row];
+    
+    cell.textLabel.text = item_arr[0][0];
+    if(self.show_detail)
+    {
+        
+        cell.detailTextLabel.text=item_arr[0][1];
+    }
+
+    return cell;
+}
+- (UITableViewCellAccessoryType)tableView:(UITableView*)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath*)indexPath
+{
+    if([self.checkedData containsObject:[NSNumber numberWithLong:indexPath.row]])
+    {
+        return UITableViewCellAccessoryCheckmark;
+    }
+    else
+    {
+        return UITableViewCellAccessoryNone;
+    }
+}
+#pragma mark tableview delegate
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+        UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
+    if(self.single_select)
+    {
+        [self.checkedData removeAllObjects];
+        if(cell.accessoryType==UITableViewCellAccessoryNone)
+            [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ];
+        
+    }
+    else
+    {
+        if([self.checkedData containsObject:[NSNumber numberWithLong:indexPath.row]])
+        {
+            [self.checkedData removeObject:[NSNumber numberWithLong:indexPath.row]];
+            
+        }
+        else
+        {
+            [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ];
+        }
+        
+    }
+    
+
+   // cell.accessoryType=UITableViewCellAccessoryCheckmark;
+    
+    [tableView reloadData];
+    
+    
+
+//    if(self.blk_Select)
+//    {
+//        
+//        //        SignatureTableViewCell * cell= [tableView cellForRowAtIndexPath:indexPath];
+//        
+//        NSDictionary * item_json = self.signatureData[[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]];
+//        
+//        //        UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]];
+//        
+//        
+//        self.blk_Select(item_json[@"file"]);
+//        
+//    }
+//    
+//    [self dismissViewControllerAnimated:false completion:nil];
+    
+ 
+    
+    
+}
+
+
+
+@end

+ 24 - 0
Ants Contract/common/DocumentPageViewController.h

@@ -0,0 +1,24 @@
+//
+//  DocumentPageViewController.h
+//  AntsContract
+//
+//  Created by Ray on 12/16/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface DocumentPageViewController : UIViewController <UIPageViewControllerDelegate , UIPageViewControllerDataSource>
+
+@property (strong, nonatomic) UIPageViewController *pageViewController;
+@property (strong, nonatomic) NSMutableDictionary * controlTemplate;
+@property size_t total_page;
+@property CGPDFDocumentRef document;
+@property (strong, nonatomic) NSMutableDictionary* signatureData;
+
+
+@property (strong, nonatomic) NSString* pdfName;
+@property (strong, nonatomic) NSString* templateName;
+
+@property (nonatomic , copy) void (^OnSave)(NSString * file);
+@end

+ 501 - 0
Ants Contract/common/DocumentPageViewController.m

@@ -0,0 +1,501 @@
+//
+//  DocumentPageViewController.m
+//  AntsContract
+//
+//  Created by Ray on 12/16/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "DocumentPageViewController.h"
+#import "PageViewController.h"
+#import "SignatureListViewController.h"
+#import "SignatureViewController.h"
+#import "PDFUtils.h"
+#import "ACNetwork.h"
+
+#import "AFHTTPSessionManager.h"
+#import "AppDelegate.h"
+#import "ACNetwork.h"
+#import "RAUtils.h"
+#import "PDFViewController.h"
+#import "config.h"
+
+
+
+@interface DocumentPageViewController ()
+
+@end
+
+@implementation DocumentPageViewController
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    
+    
+    //    self.delegate = self;
+    //    self.dataSource = self;
+    
+    
+    self.signatureData= [[NSMutableDictionary alloc] init];
+    
+    
+    self.document = [PDFUtils OpenPDF:self.pdfName];
+    self.total_page = CGPDFDocumentGetNumberOfPages (self.document);
+    self.controlTemplate = [PDFUtils loadControl:self.templateName];
+    
+    
+    PageViewController* startingViewController=[self viewControllerAtIndex:0];
+    
+    // NSArray* viewControllers =[NSArray arrayWithObjects:page_0,nil];
+    
+    self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
+    self.pageViewController.delegate = self;
+    
+    //    PageViewController *startingViewController = [self viewControllerAtIndex:0 storyboard:self.storyboard];
+    NSArray *viewControllers = @[startingViewController];
+    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
+    
+    self.pageViewController.dataSource = self;
+    
+    [self addChildViewController:self.pageViewController];
+    [self.view addSubview:self.pageViewController.view];
+    
+    // Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages.
+    CGRect pageViewRect = self.view.bounds;
+    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
+        pageViewRect = pageViewRect;//CGRectInset(pageViewRect, 40.0, 40.0);
+    }
+    self.pageViewController.view.frame = pageViewRect;
+    
+    [self.pageViewController didMoveToParentViewController:self];
+    
+    // Do any additional setup after loading the view.
+}
+-(void) dealloc
+{
+    CFBridgingRelease(self.document);
+}
+- (void)didReceiveMemoryWarning {
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+- (IBAction)onSignatureClicked:(id)sender {
+    
+    //    CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:trigger];
+    //
+    //
+    //    CGRect rect1=[self.view convertRect:cellrect_screen fromView:[[[UIApplication sharedApplication] delegate] window]];
+    //
+    //    DebugLog(@"convert1 %@",NSStringFromCGRect(rect1));
+    SignatureListViewController *signatureVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureListViewController"];
+    signatureVC.title=@"Signatures";
+    signatureVC.signatureData = self.signatureData;
+    
+    
+    signatureVC.blk_Add = ^()
+    {
+        
+        __block UIImage* signimg=nil;
+        SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
+        
+        vc.onReturnImg = ^(UIImage* img)
+        {
+            
+            
+            signimg = img;
+            
+            if(signimg!=nil)
+                [PDFUtils addSignature:signimg to:self.signatureData];
+                //[self addSignature:signimg];
+                
+            
+            
+        };
+        //    orderinfoVC.url_type = URL_REMOTE;
+        //    orderinfoVC.request_url=URL_CARTDELIVERY;
+        //
+        //    orderinfoVC.params = params;
+        //
+        //    orderinfoVC.delegate=self;
+        //
+        //    if(checked.count==count)
+        //    {
+        //    orderinfoVC.have_tail = true
+        //    }
+        
+        [self.navigationController pushViewController:vc animated:true];
+        
+        
+        
+    };
+    
+    UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:signatureVC];
+    navi.modalPresentationStyle=UIModalPresentationPopover;
+    
+    UIPopoverPresentationController* popPc = navi.popoverPresentationController;
+    popPc.permittedArrowDirections = UIPopoverArrowDirectionUp;
+    popPc.barButtonItem = sender;
+    popPc.delegate = nil;
+    
+    
+    
+    [self presentViewController:navi animated:true completion:nil];
+    
+    ////    menu.selector = self.selector;
+    ////
+    ////    menu.selectordelegate = self;
+    //
+    //    // 1.创建一个UIPopover
+    //    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:[[UINavigationController alloc] initWithRootViewController:menu]];
+    //
+    //
+    //
+    //    UIPopoverPresentationController
+    //    // 2.设置尺寸
+    //    //    popover.popoverContentSize = CGSizeMake(320, 44 * 5);
+    //
+    //    // 3.从哪里显示出来 --> 指向item
+    //
+    //    [popover presentPopoverFromRect:self.view.frame   inView:self.view permittedArrowDirections:0 animated:YES];
+    //    //  [popover presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
+    //
+    ////    self.popover = popover;
+    //    popover pop
+    //
+    // [self performSegueWithIdentifier:@"selector_popover" sender:self];
+    
+}
+- (IBAction)onSaveClicked:(id)sender {
+    
+    __weak typeof(self) weakSelf = self;
+    NSString* pdffile = [PDFUtils SavePDF:self.controlTemplate source:self.document window_rect:CGRectMake(0, 0, 768, 960)];
+    
+    
+    NSString* zipfile=[ACNetwork prepareUploadFile:pdffile json:self.controlTemplate];
+    
+  //  return;
+    
+    {
+        
+        
+        UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Saving"];
+        
+
+//        self.uploadProgress.progress = 0;
+        
+        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+        
+
+        {
+            
+            //    UIAlertView * waitalert = [[UIAlertView alloc] initWithTitle:@"wait" message:@"uploading" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
+            //    [waitalert show];
+            
+//            NSData *imageData = UIImagePNGRepresentation(self.imgview.image);
+            
+            AFHTTPRequestSerializer* serializer=[AFHTTPRequestSerializer serializer] ;
+            
+            
+            
+            NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+            
+            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:@"deviceMain" forKey:@"_operate"];
+            
+            
+            UIDevice * dev = [UIDevice currentDevice];
+            NSUUID* uuid =dev.identifierForVendor;
+#if TARGET_IPHONE_SIMULATOR//模拟器
+            [params setValue:@"simulator_uuid" forKey:@"deviceid"];
+#elif TARGET_OS_IPHONE//真机
+            [params setValue:uuid.UUIDString forKey:@"deviceid"];
+#endif
+
+            
+            
+            NSMutableString *body=[[NSMutableString alloc]init];
+            //参数的集合的所有key的集合
+            NSArray *keys= [params allKeys];
+            DebugLog(@"================parms==================");
+            //遍历keys
+            for(int i=0;i<[keys count];i++)
+            {
+                //得到当前key
+                NSString *key=[keys objectAtIndex:i];
+                //如果key不是pic,说明value是字符类型,比如name:Boris
+                if(![key isEqualToString:@"pic"])
+                {
+//                    //添加分界线,换行
+//                    [body appendFormat:@"%@\r\n",MPboundary];
+                    //添加字段名称,换2行
+                    [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
+                    //添加字段的值
+                    [body appendFormat:@"%@\r\n",[params objectForKey:key]];
+                    DebugLog(@"parameter: key=%@   value=%@",key,[params objectForKey:key]);
+                }
+            }
+            DebugLog(@"================parms==================");
+            
+            NSData* data = [NSData dataWithContentsOfFile: zipfile];
+            
+            NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:URL_UPLOAD_PDF parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
+                [formData appendPartWithFileData:data name:@"upfile" fileName:[zipfile lastPathComponent] mimeType:@"application/zip"];
+            } error:nil];
+            
+            
+            //        NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
+            //            [formData appendPartWithFileData:imageData name:@"upfile" fileName:@"test" mimeType:@"image/png"];
+            //        } error:nil];
+            //
+            AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
+            
+            
+            
+            //manager.responseSerializer.acceptableContentTypes = [self.operationManager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
+            
+            //manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
+            
+            //
+            NSProgress *progress = nil;
+            
+            NSURLSessionUploadTask *uploadTask = [manager uploadTaskWithStreamedRequest:request progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
+                
+                //        [progress removeObserver:self forKeyPath:@"fractionCompleted"];
+                
+                
+                 [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+                
+                if (error) {
+                    
+                    NSString* err_msg = [error localizedDescription];
+                    DebugLog(@"%@",err_msg);// [self.view updateWithMessage:[NSString stringWithFormat:@"Error : %@!", error.debugDescription]];
+                    
+                    
+                    NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
+                    
+                    DebugLog(@"data string: %@",str);
+                    [RAUtils message_alert:@"Can not connect to server please try again." title:@"Upload Image" controller:self] ;
+                    
+                } else {
+                    DebugLog(@"response ");
+                    
+                    
+                    
+                    NSData *data = [NSJSONSerialization dataWithJSONObject:(NSDictionary*)responseObject options:kNilOptions error:nil];
+                    
+                    // 再将NSData转为字符串
+                    NSString *jsonStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+                    
+                    //            NSMutableString *str = [[NSMutableString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
+                    
+                    DebugLog(@"data string: %@",jsonStr);
+                    
+                    NSDictionary* json = responseObject;
+                    
+                    
+                    
+                    
+                    if([[json valueForKey:@"result"] intValue]==2)
+                    {
+
+                        [weakSelf.navigationController popToRootViewControllerAnimated:false];
+//
+//                        
+                        if(weakSelf.OnSave)
+                            weakSelf.OnSave(pdffile);
+
+                        
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
+                    }
+                    
+                    
+                }
+                //  [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+            }];
+            
+            
+            
+            
+          //  [self.uploadProgress setProgressWithUploadProgressOfTask:uploadTask animated:true];
+            //
+            
+            
+            
+            
+            
+            
+            [uploadTask resume];
+            
+        }
+    }
+    
+  //  [PDFUtils savep
+}
+
+
+-(void) addSignature :(UIImage*) img to:(NSMutableDictionary*)signatureData
+{
+    
+    
+    if(true)
+    {
+        NSString* newfile=[self saveTempSignature:UIImagePNGRepresentation(img)];
+        
+        int newidx = [self.signatureData[@"count"] intValue];
+        
+       // [@"file"]= newfile;
+        
+        NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
+        item[@"file"]=newfile;
+        signatureData[[NSString stringWithFormat:@"item_%d",newidx]] = item;
+        signatureData[@"count"]=[NSNumber numberWithInt:newidx+1];
+        
+        
+    
+    }
+    
+    
+    
+}
+-(NSString *) saveTempSignature:(NSData *) image
+{
+    NSString* tempDir = NSTemporaryDirectory();
+    
+    NSString *saveFileName=[NSString stringWithFormat:@"%@.png",[[NSUUID UUID ] UUIDString] ] ;
+    
+    NSString *newFilePath=[tempDir stringByAppendingPathComponent:saveFileName];
+    
+    
+       bool bsuccess=[image writeToFile:newFilePath atomically:YES];
+    if(bsuccess)
+    {
+
+        return newFilePath;
+    }
+    else
+    {
+        return nil;
+    }
+
+}
+/*
+ #pragma mark - Navigation
+ 
+ // In a storyboard-based application, you will often want to do a little preparation before navigation
+ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
+ // Get the new view controller using [segue destinationViewController].
+ // Pass the selected object to the new view controller.
+ }
+ */
+
+
+- (PageViewController *)viewControllerAtIndex:(NSUInteger)index
+{
+    //Return the PDFViewController for the given index.
+    if ((self.total_page == 0 )|| (index > self.total_page) ) {
+        return nil;
+    }
+    
+    //Create a new view controller and pass suitable data.
+    PageViewController *PageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
+    
+    PageViewController.pageRef =  CGPDFDocumentGetPage (self.document , index+1);
+    PageViewController.pageIndex = index;
+    
+    ;
+    PageViewController.controlTemplate = self.controlTemplate[[NSString stringWithFormat:@"page_%lu",(unsigned long)index]];
+    
+    PageViewController.signatureData = self.signatureData;
+    //PageViewController.pdfview = [self.pagePDF objectAtIndex:index];
+    
+    /*
+     PageViewController.pdfview = [[PDFView alloc]initWithFrame:self.view.frame atPage:index];
+     [PageViewController.view addSubview:PageViewController.pdfview];
+     NSLog(@"index = %d",index);
+     
+     
+     */
+    return PageViewController;
+}
+
+- (NSUInteger) indexOfViewController:(PageViewController *)viewController
+{
+    return viewController.pageIndex;//[self.pagePDF indexOfObject:viewController.pdfview];
+}
+
+
+#pragma mark - Page View Controller Data Source
+
+
+- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
+{
+    NSUInteger index = [self indexOfViewController:(PageViewController *)viewController];
+    if ((index == 0 ) || (index == NSNotFound)){
+        return nil;
+    }
+    
+    index--;
+    return  [self viewControllerAtIndex:index];
+}
+
+- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
+{
+    NSUInteger index = [self indexOfViewController:(PageViewController *)viewController];
+    if (index == NSNotFound)
+    {
+        return nil;
+    }
+    
+    index++;
+    
+    if (index == self.total_page){
+        return  nil;
+    }
+    
+    return [self viewControllerAtIndex:index];
+}
+
+
+#pragma mark - UIPageViewController delegate methods
+- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation {
+    if (true||UIInterfaceOrientationIsPortrait(orientation) || ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)) {
+        // In portrait orientation or on iPhone: Set the spine position to "min" and the page view controller's view controllers array to contain just one view controller. Setting the spine position to 'UIPageViewControllerSpineLocationMid' in landscape orientation sets the doubleSided property to YES, so set it to NO here.
+        
+        UIViewController *currentViewController = self.pageViewController.viewControllers[0];
+        NSArray *viewControllers = @[currentViewController];
+        [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
+        
+        self.pageViewController.doubleSided = NO;
+        return UIPageViewControllerSpineLocationMin;
+    }
+    
+//    // In landscape orientation: Set set the spine location to "mid" and the page view controller's view controllers array to contain two view controllers. If the current page is even, set it to contain the current and next view controllers; if it is odd, set the array to contain the previous and current view controllers.
+//    PageViewController *currentViewController = self.pageViewController.viewControllers[0];
+//    NSArray *viewControllers = nil;
+//    
+//    NSUInteger indexOfCurrentViewController = [self indexOfViewController:currentViewController];
+//    if (indexOfCurrentViewController == 0 || indexOfCurrentViewController % 2 == 0) {
+//        UIViewController *nextViewController = [self pageViewController:self.pageViewController viewControllerAfterViewController:currentViewController];
+//        viewControllers = @[currentViewController, nextViewController];
+//    } else {
+//        UIViewController *previousViewController = [self pageViewController:self.pageViewController viewControllerBeforeViewController:currentViewController];
+//        viewControllers = @[previousViewController, currentViewController];
+//    }
+//    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
+//    
+//    
+//    return UIPageViewControllerSpineLocationMid;
+}
+
+
+
+@end

+ 13 - 0
Ants Contract/common/EditControlView.h

@@ -0,0 +1,13 @@
+//
+//  EditControlView.h
+//  AntsContract
+//
+//  Created by Ray on 12/19/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface EditControlView : UIView
+
+@end

+ 21 - 0
Ants Contract/common/EditControlView.m

@@ -0,0 +1,21 @@
+//
+//  EditControlView.m
+//  AntsContract
+//
+//  Created by Ray on 12/19/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "EditControlView.h"
+
+@implementation EditControlView
+
+/*
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect {
+    // Drawing code
+}
+*/
+
+@end

+ 37 - 0
Ants Contract/common/LoginViewController.h

@@ -0,0 +1,37 @@
+//
+//  LoginViewController.h
+//  RedAnt ERP Mobile
+//
+//  Created by Ray on 14-6-20.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "ACNetwork.h"
+#import "AESCrypt.h"
+//#import "MyAutocompleteView.h"
+@class LoginViewController;
+@protocol LoginViewControllerDelegate <NSObject>
+
+-(void) LoginViewControllerDidLogin:(LoginViewController *)viewController;
+
+@end
+
+
+@interface LoginViewController : UIViewController
+@property (strong, nonatomic) IBOutlet UIButton *checkSavePassword;
+
+//@property (strong, nonatomic) IBOutlet UIButton *checkOfflineMode;
+@property (nonatomic, weak) id<LoginViewControllerDelegate> delegate;
+@property (strong, nonatomic) IBOutlet UIButton *btnLogin;
+
+@property (strong, nonatomic) IBOutlet UIBarButtonItem *bb_close;
+@property (strong, nonatomic) IBOutlet UITextField *edituser;
+@property (strong, nonatomic) IBOutlet UITextField *editpass;
+@property (nonatomic , copy) void (^returnValue)(bool blogin);
+
+@property (strong, nonatomic) IBOutlet UITableView *Loginlist;
+@property (strong, nonatomic)  NSArray *logindata;
+@property bool showList;
+//@property (strong,nonatomic) MyAutocompleteView * autocompleteView;
+@end

+ 396 - 0
Ants Contract/common/LoginViewController.m

@@ -0,0 +1,396 @@
+//
+//  LoginViewController.m
+//  RedAnt ERP Mobile
+//
+//  Created by Ray on 14-6-20.
+//  Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "LoginViewController.h"
+
+
+#import "RAUtils.h"
+#import "ACNetwork.h"
+#import "AppDelegate.h"
+
+
+//#import "RetrievePassViewController.h"
+//#import "UILabel+FontAppearance.h"
+//#import "OLDataProvider.h"
+//#import "NotificationNameCenter.h"
+//#import "OfflineSettingViewController.h"
+//#import "MainViewController.h"
+//#import "WebViewController.h"
+
+@interface LoginViewController ()
+@property (strong, nonatomic) IBOutlet UIButton *requestLoginBtn;
+
+@end
+
+@implementation LoginViewController
+
+- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+    if (self) {
+        // Custom initialization
+    }
+    return self;
+}
+
+- (void)viewDidLoad
+{
+    [super viewDidLoad];
+
+    self.title=@"Sign in";//@"Granite Expo";
+    self.showList = false;
+    
+    
+    self.bb_close.image=[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
+    
+    [self.checkSavePassword setImage:[UIImage imageNamed:@"checkbox"] forState:UIControlStateNormal];
+    [self.checkSavePassword setImage:[UIImage imageNamed:@"checkbox_check"] forState:UIControlStateSelected];
+    
+    
+    
+    
+    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+    NSString * user = [AESCrypt decrypt:[defaults stringForKey:@"user"] password:@"usai"];
+    
+    
+    NSString * password = [AESCrypt decrypt:[defaults stringForKey:@"password"] password:@"usai"];
+    
+    if(user.length>0&&password.length>0)
+    {
+        self.edituser.text=user;
+        self.editpass.text=password;
+        self.checkSavePassword.selected=true;
+        
+    }
+    //   NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+    //    [defaults removeObjectForKey:@"EnableOfflineMode"];
+    //    [defaults setBool:self.checkOfflineMode.selected forKey:@"EnableOfflineMode"];
+  
+    
+    [self.checkSavePassword addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
+//    self.checkOfflineMode.tag=999;
+    
+//    self.logindata = [iSalesDB get_saveduser];
+    
+    
+    
+    UIButton* combobutton=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
+    [combobutton setBackgroundImage:[UIImage imageNamed:@"combo_24"] forState:UIControlStateNormal];
+    [combobutton addTarget:self action:@selector(LoginList:) forControlEvents:UIControlEventTouchUpInside];
+    
+    self.edituser.rightView = combobutton;
+    self.edituser.rightViewMode=UITextFieldViewModeAlways;
+    
+    
+//    
+//    self.Loginlist.layer.borderColor = [UIColor lightGrayColor].CGColor;
+//    self.Loginlist.layer.borderWidth = 1.0;
+//    //  self.Loginlist.layer.cornerRadius=15;
+//    self.Loginlist.layer.masksToBounds=true;
+    // Do any additional setup after loading the view.
+}
+- (void)LoginList:(UIButton *)sender {
+    [self.edituser endEditing:true];
+    self.showList= !self.showList;
+//    self.Loginlist.hidden = !self.showList;
+    //    showList;
+}
+-(void)checkboxClick:(UIButton *)btn
+{
+    btn.selected = !btn.selected;
+
+    {
+        if(!btn.selected)
+        {
+            NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+            [defaults removeObjectForKey:@"user"];
+            [defaults removeObjectForKey:@"password"];
+            [defaults synchronize];
+            
+            
+            NSString* encryptu=[AESCrypt encrypt:self.edituser.text password:@"usai"];
+            
+//            NSString* sql=[NSString stringWithFormat:@"delete from login_info where name='%@'",encryptu];
+//            [iSalesDB execSql:sql];
+//            self.logindata = [iSalesDB get_saveduser];
+//            [self.Loginlist reloadData];
+        }
+        
+    }
+}
+- (IBAction)CloseClick:(id)sender {
+    
+    [self dismissViewControllerAnimated:true completion:nil];
+    if(self.returnValue)
+        self.returnValue(false);
+    
+    
+    
+}
+- (IBAction)onRetrievePassword:(id)sender {
+//    RetrievePassViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"RetrievePassViewController" ];
+//    //            dvc
+//    //    UINavigationController* nv = self.navigationController;
+//    
+//    [self.navigationController pushViewController:vc animated:true];
+}
+- (IBAction)onLoginClick:(UIButton *)sender {
+    NSString* user = self.edituser.text;
+    NSString* password = self.editpass.text;
+    
+    
+//    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+//    
+//    bool forcedownload = [defaults boolForKey:@"Forcedownload"];
+    
+//    if(forcedownload && self.checkOfflineMode.selected)
+//    {
+//        self.checkOfflineMode.selected = !self.checkOfflineMode.selected;
+//        
+//        [RAUtils alert_view:@"Detected incomplete sync, please finish sync first." title:@"Incomplete sync"];
+//        return;
+//    }
+    
+    if(user.length==0||password.length==0)
+    {
+        //        UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @"Error!" message:@"user or password can not be empty." delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil, nil];
+        //        //        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"User&Password can not be empty!" delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) , nil];
+        //
+        //
+        //        //[[UILabel appearanceWhenContainedIn:UIAlertView.class, nil] setAppearanceFont:[UIFont boldSystemFontOfSize:10]];
+        //        [alert show];
+        
+        
+        [RAUtils alert_view:@"Username or Password cannot be blank." title:@"Cannot sign-in"];
+        return;
+    }
+    DebugLog(@"Login...   user= %@ ; password= %@",user,password);
+    
+    
+    
+    
+    self.btnLogin.enabled = false;
+    UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Sign in"];
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        
+        
+        int ret=[ACNetwork  Authorize:user password:password];
+        
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+            self.btnLogin.enabled = true;
+            
+            if(ret==RESULT_TRUE)
+                
+            {
+               
+                //
+                //                NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
+                AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                //                appDelegate.contact_id=contactid;
+                //                appDelegate.contact_name =[self.content_data[indexPath.row] valueForKey:@"name"];
+                
+                NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                [defaults removeObjectForKey:@"user"];
+                [defaults removeObjectForKey:@"password"];
+                NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
+                NSString* encryptp=[AESCrypt encrypt:self.editpass.text password:@"usai"] ;
+                if(self.checkSavePassword.selected)
+                {
+                    
+                    [defaults setValue:encryptu forKey:@"user"];
+                    [defaults setValue:encryptp forKey:@"password"];
+//                    sqlite3 *db = [iSalesDB get_db];
+//                    
+//                    int count =[iSalesDB get_recordcount:db table:@"login_info" where:[NSString stringWithFormat:@"name='%@'",encryptu]];
+//                    
+//                    if(count==0)
+//                    {
+//                        
+//                        NSString * savelogin=[NSString stringWithFormat:@"insert into login_info(name,pwd) values('%@','%@')",encryptu,encryptp];
+//                        [iSalesDB execSql:savelogin db:db];
+//                    }
+//                    else
+//                    {
+//                        NSString * savelogin=[NSString stringWithFormat:@"update login_info set pwd='%@' where name='%@'",encryptp,encryptu];
+//                        [iSalesDB execSql:savelogin db:db];
+//                    }
+//                    
+//                    [iSalesDB close_db:db];
+                    
+                    //                    [defaults setBool:TRUE forKey:@"autologin"];
+                }
+//                else
+//                {
+//                    NSString* sql=[NSString stringWithFormat:@"delete from login_info where name='%@'",encryptu];
+//                    [iSalesDB execSql:sql];
+//                }
+                [defaults synchronize];
+                
+                [self dismissViewControllerAnimated:YES completion:^{
+                    
+                    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                    
+                    bool offline_dirty=[defaults boolForKey:@"OFFLINE_DIRTY"];
+//                    sqlite3* db = [iSalesDB get_db];
+//                    int offline_user_exist=[iSalesDB get_recordcount:db table:@"offline_login" where:[NSString stringWithFormat:@"username='%@'",appDelegate.user ]];
+//                    
+//                    [iSalesDB close_db:db];
+                    
+                    
+                    
+
+                  //  else
+                    {
+                    if(self.returnValue)
+                        self.returnValue(true);
+//                    [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
+                    }
+                        }];
+
+
+                
+                //                if (self.delegate && [self.delegate respondsToSelector:@selector(LoginViewControllerDidLogin:)]) {
+                //                    [self.delegate LoginViewControllerDidLogin:self];
+                //                }
+                
+//                [[NSNotificationCenter defaultCenter] postNotificationName:User_LoginOK_Notification object:nil];
+            }
+            else
+            {
+                NSString* msg=nil;
+                
+                switch (ret) {
+                        
+                    case RESULT_NET_NOTAVAILABLE:
+                        msg = MSG_NET_NOTAVAILABLE;
+                        break;
+                        
+                        
+                    case RESULT_NET_ERROR:
+                        msg = MSG_NET_ERROR;
+                        break;
+                        
+                        
+                    case RESULT_FALSE:
+                        msg = MSG_USERAUTH_ERROR;
+                        break;
+                        
+                    case RESULT_VER_LOW:
+                        msg = MSG_VER_LOW;
+                        break;
+                        
+                    case RESULT_LOGIN_DEVICE:
+                        msg= MSG_LOGIN_DEVICE;
+                        break;
+                    default:
+                        break;
+                }
+                
+                [RAUtils alert_view:msg title:@"Cannot sign-in"];
+                
+                
+                
+            }
+            
+            
+        });
+    });
+    
+    
+    
+}
+
+- (void)didReceiveMemoryWarning
+{
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+
+#pragma mark - Table view data source
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
+{
+    return 44;
+    
+    
+}
+
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+    return 1;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    return self.logindata.count;
+    
+    
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    
+    NSMutableDictionary* up = self.logindata[indexPath.row];
+    
+    
+    
+    NSString *CellIdentifier = @"LoginListCell";
+    UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+    NSString* name=up[@"name"];
+    cell.textLabel.text = name;
+    return cell;
+    
+}
+
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    
+//    NSMutableDictionary* up = self.logindata[indexPath.row];
+//    self.edituser.text = up[@"name"];
+//    self.editpass.text = up[@"pwd"];
+//    
+//    self.showList=false;
+//    self.Loginlist.hidden=true;
+//    self.checkSavePassword.selected=true;
+    
+}
+- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
+{
+    
+    return true;
+}
+- (void)textFieldDidBeginEditing:(UITextField *)textField
+{
+    
+    self.showList=false;
+//    self.Loginlist.hidden=true;
+    
+}
+
+#pragma mark - action
+
+//- (IBAction)requestLoginBtnClicked:(UIButton *)sender {
+//    
+//    WebViewController *webVC = [self.storyboard instantiateViewControllerWithIdentifier:@"WebViewController"];
+//    webVC.url = URL_REQUEST_LOGIN;
+//    webVC.title = @"Request Login";
+//    webVC.backItemDismiss = YES;
+//    
+//    
+//    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:webVC];
+//    nav.modalPresentationStyle = UIModalPresentationFormSheet;
+//    
+//    [self presentViewController:nav animated:YES completion:nil];
+//    
+//}
+
+
+
+@end

+ 14 - 0
Ants Contract/common/PDFPageView.h

@@ -0,0 +1,14 @@
+//
+//  PDFPageView.h
+//  AntsContract
+//
+//  Created by Ray on 12/16/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface PDFPageView : UIView
+@property size_t pageIndex;
+@property CGPDFPageRef pageRef;
+@end

+ 120 - 0
Ants Contract/common/PDFPageView.m

@@ -0,0 +1,120 @@
+//
+//  PDFPageView.m
+//  AntsContract
+//
+//  Created by Ray on 12/16/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "PDFPageView.h"
+
+@implementation PDFPageView
+
+
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect {
+    // Drawing code
+    
+            //CGPDFDocumentRef document = [self OpenPDF:@"GEIC - Home Improvement Contract 2016.pdf"];
+    
+    
+    
+
+
+    
+        CGContextRef context = UIGraphicsGetCurrentContext();
+    
+    [self MyDisplayPDFPage:context index:self.pageIndex ];//file:@"GEIC - Home Improvement Contract 2016.pdf"];
+}
+
+
+
+-(void) MyDisplayPDFPage:(CGContextRef) myContext index:(size_t)pageNumber //file:(NSString*) filename//(,  , const char *filename)
+{
+    
+    
+    {
+    CGPDFPageRef page = self.pageRef;
+
+    CGContextSaveGState (myContext);
+    
+                CGRect mediabox= CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
+        
+//                CGContextTranslateCTM(myContext, 0, mediabox.size.height);
+//                CGContextScaleCTM(myContext, 1, -1);
+
+        CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(page, kCGPDFMediaBox, self.frame, 0, true);
+        CGContextConcatCTM(myContext, pdfTransform);
+        
+        CGContextScaleCTM(myContext, 1, -1);
+        CGContextTranslateCTM(myContext, 0, -self.frame.size.height/pdfTransform.a);
+        
+
+    CGContextDrawPDFPage (myContext, page);
+    CGContextRestoreGState (myContext);
+    }
+    
+    
+    
+    
+    
+//    CGPDFPageRef page = self.pageRef;
+//
+//    CGContextSaveGState (myContext);
+//    
+//    CGRect mediabox= CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
+//    
+//    CGContextTranslateCTM(myContext, 0, mediabox.size.height);
+//    // Reverse the Y axis to grow from bottom to top.
+//    CGContextScaleCTM(myContext, 1, -1);
+//    
+//    CGContextDrawPDFPage (myContext, page);
+//    CGContextRestoreGState (myContext);
+//    return ;
+    
+//    {
+//        
+//        // CGPDFDocumentRef document;
+//        CGPDFPageRef page = self.pageRef;
+//
+//        CGContextSaveGState (myContext);
+//        
+//        
+//        CGRect mediabox= CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
+//        
+//        CGContextTranslateCTM(myContext, 0, mediabox.size.height);
+//        CGContextScaleCTM(myContext, 1, -1);
+//        
+//        CGContextDrawPDFPage (myContext, page);
+//        CGContextRestoreGState (myContext);
+//    }
+    
+    
+    
+    
+    
+ /*
+   // CGPDFDocumentRef document;
+    CGPDFPageRef page = self.pageRef;
+ //   document = [self OpenPDF:filename];                                   // 1 创建PDFDocument对象
+  //  page = CGPDFDocumentGetPage (document, pageNumber);           // 2 获取指定页的PDF文档
+    
+    
+//    CGAffineTransform m;
+//    m = CGPDFPageGetDrawingTransform (page, kCGPDFMediaBox, self.bounds, -180, true);
+    CGContextSaveGState (myContext);
+    
+    CGContextTranslateCTM(myContext, 80, self.frame.size.height);
+    CGContextScaleCTM(myContext, 1, -1);
+    
+ //   CGContextConcatCTM (myContext, m);
+  //  CGContextClipToRect (myContext,CGPDFPageGetBoxRect (page, kCGPDFCropBox));
+    CGContextDrawPDFPage (myContext, page);
+    CGContextRestoreGState (myContext);
+    */
+    
+  //  CGContextDrawPDFPage (myContext, page);                                       // 3 将PDF绘制到图形上下文中
+//    CGPDFDocumentRelease (document);
+}
+@end

+ 13 - 0
Ants Contract/common/PDFScrollView.h

@@ -0,0 +1,13 @@
+//
+//  PDFScrollView.h
+//  AntsContract
+//
+//  Created by Ray on 12/19/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface PDFScrollView : UIScrollView
+
+@end

+ 21 - 0
Ants Contract/common/PDFScrollView.m

@@ -0,0 +1,21 @@
+//
+//  PDFScrollView.m
+//  AntsContract
+//
+//  Created by Ray on 12/19/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "PDFScrollView.h"
+
+@implementation PDFScrollView
+
+/*
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect {
+    // Drawing code
+}
+*/
+
+@end

+ 28 - 0
Ants Contract/common/PageViewController.h

@@ -0,0 +1,28 @@
+//
+//  DocumentViewController.h
+//  AntsContract
+//
+//  Created by Ray on 12/16/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "PDFPageView.h"
+#import "PDFScrollView.h"
+#import "EditControlView.h"
+#import "TouchImageView.h"
+
+@interface PageViewController : UIViewController<UITextViewDelegate,TouchImageViewDelegate>
+
+@property (strong, nonatomic) IBOutlet PDFPageView *pdfPageView;
+@property (strong, nonatomic) IBOutlet EditControlView *editControlView;
+@property size_t pageIndex;
+@property CGPDFPageRef pageRef;
+@property (strong, nonatomic) IBOutlet PDFScrollView *pdfScrollView;
+
+
+
+@property (strong, nonatomic) NSMutableDictionary * controlTemplate;
+
+@property (strong, nonatomic) NSMutableDictionary * signatureData;
+@end

+ 510 - 0
Ants Contract/common/PageViewController.m

@@ -0,0 +1,510 @@
+//
+//  DocumentViewController.m
+//  AntsContract
+//
+//  Created by Ray on 12/16/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "PageViewController.h"
+
+#import "config.h"
+#import "const.h"
+
+#import "SignatureListViewController.h"
+#import "SignatureViewController.h"
+#import "PDFUtils.h"
+#import "ImageUtils.h"
+#import "CheckSelectorViewController.h"
+
+
+//#import "TouchImageView.h"
+@interface PageViewController ()
+
+@end
+
+@implementation PageViewController
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    
+    //   self.pageIndex=1;
+    
+    // self.pdfPageView.pageIndex=self.pageIndex;
+    self.pdfPageView.pageRef= self.pageRef;
+    
+    [self initControl];
+    
+    //    UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc]
+    //                                                        initWithTarget:self
+    //                                                        action:@selector(handlePinch:)];
+    //
+    //    [self.view addGestureRecognizer:pinchGestureRecognizer];
+    
+    // Do any additional setup after loading the view.
+}
+-(void) dealloc
+{
+ //   CFBridgingRelease(self.pageRef);
+}
+- (void)didReceiveMemoryWarning {
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+//- (void) handlePinch:(UIPinchGestureRecognizer*) recognizer
+//{
+////    recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
+////    recognizer.scale = 1;
+//
+//    CGSize contentsize =self.pdfScrollView.contentSize;
+//
+//    self.pdfScrollView.contentSize = CGSizeMake(contentsize.width*recognizer.scale, contentsize.height*recognizer.scale);
+//}
+
+
+-(void) initControl
+{
+    int count = [self.controlTemplate[@"count"] intValue];
+    for(int i=0;i<count;i++)
+    {
+        NSMutableDictionary * control =self.controlTemplate [[NSString stringWithFormat:@"control_%d",i] ];
+        if([control[@"type"] isEqualToString:@"TextView"])
+        {
+            [self addTextView:control destView:self.editControlView index:i];
+        }
+        else if([control[@"type"] isEqualToString:@"Button"])
+        {
+            [self addButton:control destView:self.editControlView index:i];
+            
+        }
+        else if([control[@"type"] isEqualToString:@"Check"])
+        {
+            [self addCheck:control destView:self.editControlView index:i];
+            
+        }
+        else if([control[@"type"] isEqualToString:@"Signature"])
+        {
+            [self addSignatureButton:control destView:self.editControlView index:i];
+            
+        }
+    }
+    
+}
+#pragma mark add controls
+-(void) addTextView:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
+{
+    UITextView* tv = [[UITextView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
+    float fontsize = [template[@"size"] floatValue];
+    if(fontsize==0)
+        fontsize=10;
+    [tv setFont:[UIFont systemFontOfSize:fontsize]];
+    
+    tv.text =template[@"value"];
+    
+    tv.tag = index+ CONTROL_BASE;
+    
+    
+    
+    //UIColorFromARGB(0x4066ccff);
+    
+    tv.backgroundColor = UIColorFromRGB(TV_BG);//[UIColor lightGrayColor];
+    //    tv.place
+    //    [btn setTitle:template[@"title"] forState:UIControlStateNormal];
+    //    ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
+    
+    
+    tv.delegate = self;
+    //    [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
+    if(DEBUG_PDFSIG)
+    {
+
+        
+        // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
+    }
+    [destView addSubview:tv];
+}
+-(void) addButton:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
+{
+    UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
+    [btn setTitle:template[@"title"] forState:UIControlStateNormal];
+    
+        btn.tag = index+ CONTROL_BASE;
+    //    ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
+    
+    [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
+    if(DEBUG_PDFSIG)
+    {
+        btn.backgroundColor = [UIColor lightGrayColor];
+        
+        // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
+    }
+    [destView addSubview:btn];
+}
+-(UIView*) createMarker:(int)size x:(int)x y:(int)y
+{
+    UIView* v=[[UIView alloc] initWithFrame:CGRectMake(x, y, size, size)];
+    return v;
+    
+}
+-(void) addCheck:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
+{
+    UIButton* btn = [[UIButton alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
+    
+    //    ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
+        btn.tag = index+ CONTROL_BASE;
+    [btn addTarget:self action:@selector(CheckButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
+    UIColor* marker_bg=UIColorFromRGB(CK_BG);//[UIColor clearColor];
+    if(DEBUG_PDFSIG)
+    {
+       // btn.backgroundColor = [UIColor lightGrayColor];
+
+        [btn setTitle:template[@"title"] forState:UIControlStateNormal];
+//        marker_bg = [UIColor redColor];
+        
+        // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
+    }
+    [destView addSubview:btn];
+    NSArray* cadedate = template[@"cadedate"];
+    
+    NSArray* checkedData = self.controlTemplate [[NSString stringWithFormat:@"control_%d",index] ][@"value"];
+
+
+//    if(checkedData.count>0)
+//        marker_bg = [UIColor clearColor];
+//    else
+        marker_bg=UIColorFromRGB(CK_BG);
+    
+    for(int i=0;i<cadedate.count;i++)
+    {
+        NSArray* item = cadedate[i];
+        
+        UIView* marker=[self createMarker:[template[@"marker_size"] intValue] x:[item[1][0] intValue] y:[item[1][1] intValue]];
+        
+        marker.backgroundColor = marker_bg;
+        marker.tag = CHECK_BASE+index*1000+i;
+        
+        
+        if([checkedData containsObject:[NSNumber numberWithLong:i]])
+        {
+            
+            marker.backgroundColor= UIColorFromRGB(CK_MK);
+            
+        }
+        else
+        {
+            marker.backgroundColor= marker_bg;
+        }
+        
+        [destView addSubview:marker];
+        
+    }
+    
+}
+-(void) addSignatureButton:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
+{
+    TouchImageView* btn = [[TouchImageView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
+    
+    btn.contentMode = UIViewContentModeScaleAspectFit;
+    btn.delegate = self;
+    btn.layer.borderColor = [UIColor clearColor].CGColor;
+    btn.layer.borderWidth = 0;
+        btn.tag = index+ CONTROL_BASE;
+    
+    NSString* file =template[@"value"];
+    
+    NSData* img_data=[ImageUtils load_img:file];
+    
+    if(img_data!=nil)
+    {
+        
+        UIImage* image=[UIImage imageWithData:img_data];
+        btn.image = image;
+        
+    }
+    
+
+    btn.backgroundColor = UIColorFromRGB(SIG_BG);
+
+    if(DEBUG_PDFSIG)
+    {
+        
+        
+        // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
+    }
+    [destView addSubview:btn];
+}
+
+#pragma mark UIScrollView delegate
+
+- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
+    
+    
+    UIView *subView = [scrollView viewWithTag:1024];
+    return subView;
+    
+}
+//- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
+//
+//
+//
+//}
+#pragma mark Button Click
+- (void)ControlButtonClicked:(UIButton *)sender {
+    //    DebugLog(@"cart sort button clicked");
+    
+    NSLog(@"button clicked;");
+    //    [self.view addSubview:self.sortItemController.view];
+}
+- (void)CheckButtonClicked:(UIButton *)sender {
+    //    DebugLog(@"cart sort button clicked");
+    
+    NSLog(@"check clicked;");
+    
+    long index = sender.tag - CONTROL_BASE;
+    
+
+    bool single_select = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"single_select"] boolValue];
+    bool show_detail = [self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"show_detail"] boolValue];
+    NSArray* rowData = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"cadedate"];
+    NSArray* checkedData = self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"];
+    CheckSelectorViewController *checkVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"CheckSelectorViewController"];
+    
+    checkVC.blk_OK = ^(NSArray* checkedData){
+        for(int i=0;i<rowData.count;i++)
+        {
+            long tag=CHECK_BASE+index*1000+i;
+           // UIView* v= sender;
+            if([checkedData containsObject:[NSNumber numberWithLong:i]])
+            {
+               // [checkedData removeObject:[NSNumber numberWithLong:indexPath.row]];
+                
+                [sender.superview viewWithTag:tag].backgroundColor= [UIColor blackColor];
+                
+            }
+            else
+            {
+               // [self.checkedData addObject:[NSNumber numberWithLong:indexPath.row] ];
+                [sender.superview viewWithTag:tag].backgroundColor= [UIColor clearColor];
+            }
+            self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"]=checkedData;
+            
+        }
+    };
+    checkVC.rowData = rowData;
+    checkVC.checkedData = [checkedData mutableCopy];
+    checkVC.single_select = single_select;
+    checkVC.show_detail = show_detail;
+    
+    checkVC.title=@"abcdefg";
+    checkVC.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
+    [self presentViewController:checkVC animated:YES completion:nil];
+    
+}
+
+#pragma mark TextViewDelegate
+- (void)textViewDidEndEditing:(UITextView *)textView
+{
+    
+    long index = textView.tag - CONTROL_BASE;
+    
+    NSString* text =textView.text;
+    if(text==nil)
+        text=@"";
+    self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = text;
+    
+//    int count = [self.controlTemplate[@"count"] intValue];
+//    for(int i=0;i<count;i++)
+//    {
+//        NSMutableDictionary * control =;
+    //[self update_newprice];
+}
+/*
+ #pragma mark - Navigation
+ 
+ // In a storyboard-based application, you will often want to do a little preparation before navigation
+ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
+ // Get the new view controller using [segue destinationViewController].
+ // Pass the selected object to the new view controller.
+ }
+ */
+#pragma mark signature clicked 
+//touchimageview Delegate
+- (void)TouchImageViewOnTouche:(TouchImageView *)touchImageView
+{
+    
+    NSLog(@"signature button clicked;");
+    
+    
+    {
+        
+        //    CGRect cellrect_screen = [RAUtils relativeFrameForScreenWithView:trigger];
+        //
+        //
+        //    CGRect rect1=[self.view convertRect:cellrect_screen fromView:[[[UIApplication sharedApplication] delegate] window]];
+        //
+        //    DebugLog(@"convert1 %@",NSStringFromCGRect(rect1));
+        SignatureListViewController *signatureVC = [ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureListViewController"];
+        signatureVC.title=@"Signatures";
+        signatureVC.signatureData = self.signatureData;
+        
+//        signatureVC.imageView = touchImageView;
+        
+        signatureVC.blk_Select =^(NSString* file)
+        {
+            
+            
+            
+//            NSString* file_name=[file lastPathComponent];
+            
+            NSData* img_data=[ImageUtils load_img:file];
+            
+            if(img_data!=nil)
+            {
+                
+                UIImage* image=[UIImage imageWithData:img_data];
+                touchImageView.image = image;
+                
+                long index = touchImageView.tag - CONTROL_BASE;
+                self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
+                
+            }
+
+        };
+        signatureVC.blk_Add = ^()
+        {
+            
+            __block UIImage* signimg=nil;
+            SignatureViewController * vc =[ [UIStoryboard storyboardWithName:@"signature" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"SignatureViewController"];
+            
+            vc.onReturnImg = ^(UIImage* img)
+            {
+                
+                
+                signimg = img;
+                
+                if(signimg!=nil)
+                {
+                    NSString* file=[PDFUtils addSignature:signimg to:self.signatureData];
+                        long index = touchImageView.tag - CONTROL_BASE;
+                        self.controlTemplate [[NSString stringWithFormat:@"control_%ld",index] ][@"value"] = file;
+                    touchImageView.image = signimg;
+                }
+                
+                
+            };
+            //    orderinfoVC.url_type = URL_REMOTE;
+            //    orderinfoVC.request_url=URL_CARTDELIVERY;
+            //
+            //    orderinfoVC.params = params;
+            //
+            //    orderinfoVC.delegate=self;
+            //
+            //    if(checked.count==count)
+            //    {
+            //    orderinfoVC.have_tail = true
+            //    }
+            
+            [self.navigationController pushViewController:vc animated:true];
+            
+            
+            
+        };
+        
+        UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:signatureVC];
+        navi.modalPresentationStyle=UIModalPresentationPopover;
+        
+        UIPopoverPresentationController* popPc = navi.popoverPresentationController;
+        popPc.permittedArrowDirections = UIPopoverArrowDirectionAny;
+        popPc.sourceView = touchImageView;
+        popPc.delegate = nil;
+        
+        
+        
+        [self presentViewController:navi animated:true completion:nil];
+        
+        ////    menu.selector = self.selector;
+        ////
+        ////    menu.selectordelegate = self;
+        //
+        //    // 1.创建一个UIPopover
+        //    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:[[UINavigationController alloc] initWithRootViewController:menu]];
+        //
+        //
+        //
+        //    UIPopoverPresentationController
+        //    // 2.设置尺寸
+        //    //    popover.popoverContentSize = CGSizeMake(320, 44 * 5);
+        //
+        //    // 3.从哪里显示出来 --> 指向item
+        //
+        //    [popover presentPopoverFromRect:self.view.frame   inView:self.view permittedArrowDirections:0 animated:YES];
+        //    //  [popover presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
+        //
+        ////    self.popover = popover;
+        //    popover pop
+        //
+        // [self performSegueWithIdentifier:@"selector_popover" sender:self];
+        
+    }
+    //    __block int tag = touchImageView.tag;
+    //    UIViewController* vc=[RAUtils getViewController :touchImageView];
+    //
+    //    if(self.editable==true)
+    //    {
+    //
+    //
+    //        ImageUploadViewController * uploadvc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageUploadViewController"];
+    //
+    //        //        UIImage* img =[self.buttonImg backgroundImageForState:UIControlStateNormal];;
+    //
+    //        if(self.img_validate)
+    //            uploadvc.img= touchImageView.image;
+    //
+    //        uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
+    //        {
+    //
+    //            self.imgs[tag] = url_up;
+    //
+    //            NSString* newurl=[RAUtils arr2string:self.imgs separator:@"," trim:false];
+    //
+    //            touchImageView.image=img;
+    //
+    //            if(self.imgChanged)
+    //                self.imgChanged(url_down,newurl,tag,url_up);
+    //
+    //        };
+    //
+    //        [vc.navigationController pushViewController:uploadvc animated:false];
+    //    }
+    //    else
+    //    {
+    //        if(touchImageView.image==nil)
+    //            return ;
+    //        ImageViewController * imagevc =[ vc.storyboard instantiateViewControllerWithIdentifier:@"ImageViewController"];
+    //
+    //
+    //        UIImage* img=touchImageView.image;
+    //
+    //        if(self.img_validate)
+    //            imagevc.image = img;//.imageView.image = [self.buttonImg backgroundImageForState:UIControlStateNormal];
+    //
+    //        //        uploadvc.returnValue = ^(NSString* url_down,NSString* url_up,UIImage* img)
+    //        //        {
+    //        //
+    //        //            [self.buttonImg setBackgroundImage:img forState:UIControlStateNormal];
+    //        //
+    //        //            if(self.imgChanged)
+    //        //                self.imgChanged(url_down,url_up);
+    //        //
+    //        //        };
+    //        
+    //        [vc.navigationController pushViewController:imagevc animated:false];
+    //    }
+    //    //    bundleVC.content_data = self.bundle_item;
+    //    
+    
+}
+
+
+
+@end

+ 20 - 0
Ants Contract/common/RootViewController.h

@@ -0,0 +1,20 @@
+//
+//  ViewController.h
+//  AntsContract
+//
+//  Created by Ray on 12/16/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface RootViewController : UIViewController
+@property (strong, nonatomic) IBOutlet UIButton *buttonHIC;
+
+@property (strong, nonatomic) IBOutlet UIButton *buttonSRL;
+@property (strong, nonatomic) IBOutlet UIView *coverView;
+@property (strong, nonatomic) IBOutlet UIBarButtonItem *ibSignin;
+@property (strong, nonatomic) IBOutlet UILabel *welcomeLabel;
+
+@end
+

+ 232 - 0
Ants Contract/common/RootViewController.m

@@ -0,0 +1,232 @@
+//
+//  ViewController.m
+//  AntsContract
+//
+//  Created by Ray on 12/16/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "RootViewController.h"
+#import "DocumentPageViewController.h"
+#import "LoginViewController.h"
+
+#import "AppDelegate.h"
+#import "RAUtils.h"
+#import "PDFViewController.h"
+
+@interface RootViewController ()
+
+@end
+
+@implementation RootViewController
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    self.title= @"eSign";
+    self.welcomeLabel.text=@"Not sign in";
+    self.buttonHIC.enabled = false;
+    self.buttonSRL.enabled = false;
+    self.coverView.hidden = false;
+    
+    [self OnSigninClick:self.ibSignin];
+    // Do any additional setup after loading the view, typically from a nib.
+}
+
+
+- (void)didReceiveMemoryWarning {
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+- (IBAction)OnSigninClick:(id)sender {
+    
+    
+    UIBarButtonItem* bbitem = sender;
+    
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    if(appDelegate.bLogin)
+    {
+            UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to sign out?" message:nil preferredStyle:UIAlertControllerStyleAlert];
+        
+        UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+            
+            
+            UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Sign out"];
+            
+            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                
+                NSDictionary* logout_json = nil;
+                
+
+                
+                logout_json = [ACNetwork logout];
+                
+                dispatch_async(dispatch_get_main_queue(), ^{
+                    
+                    
+                    [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+                    if([[logout_json valueForKey:@"result"] intValue]==2)
+                    {
+                        self.welcomeLabel.text=@"Not sign in";
+//                        [sender setTitle:@"Sign in" forState:UIControlStateNormal];
+                        [bbitem setTitle:@"Sign in"];
+                        
+                        self.buttonHIC.enabled = false;
+                        self.buttonSRL.enabled = false;
+                        self.coverView.hidden = false;
+                    }
+                    else
+                    {
+                        [RAUtils message_alert:[logout_json valueForKey:@"err_msg"] title:@"Sign out" controller:self] ;
+                    }
+                    
+                    
+                    
+                    
+                });
+            });
+            
+            
+            
+        }];
+        // [alertControl addAction:actionOne];
+        
+        [alertControl addAction:alertthree];
+        
+        
+        UIAlertAction *alertcancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
+        }];
+        [alertControl addAction:alertcancel];
+        //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
+        
+        
+        
+        
+        [self presentViewController:alertControl animated:YES completion:nil];
+        
+    }
+    else
+    {
+        LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
+        loginvc.returnValue = ^(bool blogin){
+            
+            //            [self checklogin :true];
+            
+            if(blogin)
+            {
+                
+                self.welcomeLabel.text=[NSString stringWithFormat:@"Welcome %@",appDelegate.user];
+                
+                [bbitem setTitle:@"Sign out"];
+                self.buttonHIC.enabled = true;
+                self.buttonSRL.enabled = true;
+                self.coverView.hidden = true;
+                
+            }
+            else
+            {
+                self.welcomeLabel.text=@"Not sign in";
+                self.buttonHIC.enabled = false;
+                self.buttonSRL.enabled = false;
+                self.coverView.hidden = false;
+            }
+            
+        };
+        
+        UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
+        
+        
+        
+        
+        
+        
+        navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
+        [self presentViewController:navi animated:YES completion:^{
+            
+            DebugLog(@"login present.........");
+            
+        }]; 
+    }
+
+    
+}
+
+-(void) previewPDF:(NSString*)file
+{
+    NSString* name=@"";//[self.content_data[indexPath.row] valueForKey:@"tear_name"];
+    NSString* url= file;//[self.content_data[indexPath.row] valueForKey:@"pdf_path"];
+    
+    
+    
+    NSString* isLocalFile= @"true";//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"];
+    
+    PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
+    ViewController.url = url;
+    ViewController.canSave = false;
+    ViewController.isLocalfile=isLocalFile;
+    ViewController.defaultStyle = true;
+    NSString* subject;
+    //                    if (company.length==0) {
+    
+    NSString* cur_time =[RAUtils current_date];
+    subject =name;//[NSString stringWithFormat:@"NPD Product List %@",cur_time];
+    
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    //    NSString* customer_email=    [appDelegate.customerInfo valueForKey:@"customer_email"];
+    
+    
+    NSMutableArray* send_to = [[NSMutableArray alloc]init];
+    //    if(customer_email.length>0)
+    //    {
+    //        send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
+    //        //                            customer_email compo
+    //        //                            [send_to addObject:customer_email];
+    //    }
+    ViewController.mail_to = send_to;
+    
+    //                    }
+    //                    else
+    //                    {
+    //                        subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
+    //                    }
+    ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
+    ViewController.mail_subject = subject;
+    
+    ViewController.hidenavi = false;
+    [self.navigationController pushViewController:ViewController animated:YES];
+}
+- (IBAction)OnHICClick:(id)sender {
+    
+    
+    __weak typeof(self) weakSelf = self;
+    
+    
+    DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
+    
+    dvc.templateName = @"GEIC - Home Improvement Contract 2016.json";
+    dvc.pdfName = @"GEIC - Home Improvement Contract 2017.pdf";
+    
+    dvc.OnSave=^(NSString* file)
+    {
+        [weakSelf previewPDF:file];
+    };
+    
+    [self.navigationController pushViewController:dvc animated:true];
+}
+- (IBAction)OnSRLClick:(id)sender {
+    
+    DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
+    
+    dvc.templateName = @"SUBCONTRACTORS REFERRAL LIST.json";
+    dvc.pdfName = @"SUBCONTRACTORS REFERRAL LIST.pdf";
+    dvc.OnSave=^(NSString* file)
+    {
+        
+        //[self previewPDF:file];
+    };
+    
+    [self.navigationController pushViewController:dvc animated:true];
+}
+
+
+
+@end

+ 20 - 0
Ants Contract/common/SignatureListViewController.h

@@ -0,0 +1,20 @@
+//
+//  SignatureListViewController.h
+//  AntsContract
+//
+//  Created by Ray on 12/19/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface SignatureListViewController : UIViewController
+
+@property (strong, nonatomic) IBOutlet UITableView *tableView;
+
+@property (strong, nonatomic) NSMutableDictionary* signatureData;
+
+//@property (strong, nonatomic)  UIImageView *imageView;
+@property (nonatomic , copy) void (^blk_Add)();
+@property (nonatomic , copy) void (^blk_Select)(NSString* file);
+@end

+ 397 - 0
Ants Contract/common/SignatureListViewController.m

@@ -0,0 +1,397 @@
+//
+//  SignatureListViewController.m
+//  AntsContract
+//
+//  Created by Ray on 12/19/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "SignatureListViewController.h"
+#import "SignatureTableViewCell.h"
+
+@interface SignatureListViewController ()
+
+@end
+
+@implementation SignatureListViewController
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    // Do any additional setup after loading the view.
+}
+
+- (void)didReceiveMemoryWarning {
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+- (IBAction)onAddClick:(id)sender {
+    
+    
+    [self dismissViewControllerAnimated:false completion:^{
+        
+        
+        if(self.blk_Add)
+            self.blk_Add();
+        
+     }];
+    
+
+    
+}
+
+/*
+#pragma mark - Navigation
+
+// In a storyboard-based application, you will often want to do a little preparation before navigation
+- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
+    // Get the new view controller using [segue destinationViewController].
+    // Pass the selected object to the new view controller.
+}
+*/
+
+
+#pragma mark - Table view data source
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
+{
+    //     NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
+    //    if([item_json objectForKey:@"combine"] == nil)
+    //    {
+    //        return 120;
+    //    }
+    //    else
+    //        return 150;
+    
+    
+    return 128;
+
+    
+}
+
+//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
+//{
+//    return 0;
+//}
+//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
+//{
+//    return 0;
+//}
+//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
+//{
+//        UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
+//    return myView;
+//
+//}
+
+//- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
+//{
+//    UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
+////    myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
+////    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
+////    titleLabel.textColor=[UIColor whiteColor];
+////    titleLabel.backgroundColor = [UIColor clearColor];
+////    if(section==0)
+////        titleLabel.text=NSLocalizedString(@"display_items", nil);
+////    else
+////        titleLabel.text=NSLocalizedString(@"hide_items", nil);
+////    [titleLabel sizeToFit];
+////    [myView addSubview:titleLabel];
+////
+//    return myView;
+//}
+//
+
+//- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
+//{
+//    
+//    
+//    NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
+//    
+//    if(value==nil)
+//        value=@"";
+//    unsigned long color = strtoul([value UTF8String],0,16);
+//    
+//    
+//    DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
+//    //  myView.backgroundColor = UIColorFromRGB(0x996633);;
+//    
+//    
+//    myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
+//    //    myView.layer.masksToBounds = false;
+//    //添加四个边阴影
+//    
+//    myView.layer.shadowColor = [UIColor blackColor].CGColor;
+//    myView.layer.shadowOffset = CGSizeMake(0, 0);
+//    myView.layer.shadowOpacity = 0.5;
+//    myView.layer.shadowRadius = 2.0;
+//    
+//    
+//    NSString*labeltitle = nil;
+//    switch (section) {
+//        case 0:
+//            labeltitle= @"Order Info";
+//            break;
+//        case 1:
+//        {
+//            labeltitle= @"More Info";
+//            
+//            NSString* btntitle=nil ;
+//            if(self.showMore)
+//            {
+//                btntitle=@"Hide";
+//                //        [section setValue:@"false" forKey:@"hide"];
+//                //        [sender setTitle:@"Show" forState:UIControlStateNormal];
+//            }
+//            else{
+//                btntitle=@"Show";
+//            }
+//            
+//            
+//            UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
+//            btn.tag=section;
+//            [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
+//            [btn setTitle:btntitle forState:UIControlStateNormal];
+//            [myView addSubview:btn];
+//            
+//        }
+//            break;
+//        case 2:{
+//            labeltitle= @"Models";
+//            
+//            NSString* btntitle=nil ;
+//            if(self.showModels)
+//            {
+//                btntitle=@"Hide";
+//            }
+//            else{
+//                btntitle=@"Show";
+//            }
+//            
+//            
+//            UIButton * btn =[[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width-50-15, 0, 50, 33)];
+//            btn.tag=section;
+//            
+//            [btn addTarget:self action:@selector(HideSction:) forControlEvents:UIControlEventTouchUpInside];
+//            
+//            [btn setTitle:btntitle forState:UIControlStateNormal];
+//            [myView addSubview:btn];
+//            
+//        }
+//            break;
+//        case 3:
+//            labeltitle= @"Price Info";
+//        default:
+//            break;
+//    }
+//    
+//    
+//    
+//    UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 5.5, 200, 20)];
+//    titlelabel.textColor=UIColorFromRGB(color);;
+//    titlelabel.backgroundColor = [UIColor clearColor];
+//    titlelabel.text=NSLocalizedString(labeltitle, nil);
+//    [titlelabel sizeToFit];
+//    [myView addSubview:titlelabel];
+//    
+//    //
+//    return myView;
+//}
+
+- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
+    
+    return [NSString stringWithFormat:@"Signature%ld",(long)section+1];
+    
+}
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+    return [self.signatureData[@"count"] intValue];
+}
+//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
+//{
+//    return 33;
+//}
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    
+    return 1;
+    
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    
+    
+    NSString *CellIdentifier = @"SignatureTableViewCell";
+    SignatureTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+    NSDictionary * item_json = self.signatureData[[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]];
+    
+    UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]];
+    
+    cell.signatureImageView.image = img;
+//    
+//    
+//    cell.webview.tag = indexPath.section;
+//    
+//    cell.webview.delegate = self;
+//    //        cell.webView.scrollView.contentSize.height = 0;
+//    cell.webview.scrollView.bounces=NO;
+//    cell.webview.scrollView.directionalLockEnabled = true;
+//    CGSize size= cell.webview.scrollView.contentSize;
+//    size.height=10;
+//    cell.webview.scrollView.contentSize=size;
+//    
+//    [cell.webview loadHTMLString:[self.content_data valueForKey:@"order_info"] baseURL:nil];
+//    
+//    cell.backgroundColor = [UIColor whiteColor];
+    return cell;
+
+
+    //    if(tableView==self.itemListTable)
+    //    {
+    //    NSString *CellIdentifier = @"CartItemCell";
+    //    ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+    //    NSDictionary * item_json = [self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
+    //    NSDictionary * combine_json =[item_json objectForKey:@"combine"];
+    //
+    //    cell.bundle_item=combine_json;
+    //    NSString* img_url = [item_json valueForKey:@"img_url"];
+    //    NSString* description = [item_json valueForKey:@"description"];
+    //    //    NSString* identifier = [item_json valueForKey:@"identifier"];
+    //    //    NSString* attribute = [item_json valueForKey:@"attribute"];
+    //    NSString* currency = [item_json valueForKey:@"currency"];
+    //    int count =[[item_json valueForKey:@"count"] intValue];
+    //
+    //    int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
+    //
+    //    double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
+    //
+    //    double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
+    //    cell.unit_price = unitprice;
+    //    //    cell.labelAttribute.text = attribute;
+    //    //    cell.labelCurrency.text = currency;
+    //    cell.labelDescription.text = description;
+    //    //   cell.labelIdentifier.text = identifier;
+    //    cell.labelPrice.text = [NSString stringWithFormat:@"%.2f",totalprice];
+    //
+    //    cell.labelUnitPrice.text = [NSString stringWithFormat:@"%.2f",unitprice];
+    //
+    //
+    //
+    //    NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
+    //    cell.cart_id = cart_item_id;
+    //    [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
+    //
+    //
+    //
+    //    [cell set_Count:count];
+    //
+    //    NSString* file_name=[img_url lastPathComponent];
+    //    NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
+    //    if(img_data!=nil)
+    //    {
+    //
+    //        UIImage * img =[UIImage imageWithData:img_data];
+    //        [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
+    //    }
+    //    else
+    //    {
+    //
+    //        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+    //
+    //            NSData*  downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
+    //
+    //            dispatch_async(dispatch_get_main_queue(), ^{
+    //
+    //
+    //
+    //                if(downloadimg_data!=nil)
+    //                {
+    //                    [iSalesDB cache_img:downloadimg_data :file_name ];
+    //
+    //                    UIImage * img =[UIImage imageWithData:downloadimg_data];
+    //                    [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
+    //                }
+    //
+    //            });
+    //        });
+    //
+    //
+    //    }
+    //    return cell;
+    //    }
+    //    else
+    //    {
+    //        NSString *CellIdentifier = @"OrderInfoListItem";
+    //        UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+    //        return cell;
+    //    }
+}
+#pragma mark tableview delegate
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    if(self.blk_Select)
+    {
+        
+//        SignatureTableViewCell * cell= [tableView cellForRowAtIndexPath:indexPath];
+        
+        NSDictionary * item_json = self.signatureData[[NSString stringWithFormat:@"item_%ld",(long)indexPath.section]];
+        
+//        UIImage* img = [UIImage imageWithContentsOfFile:item_json[@"file"]];
+        
+        
+        self.blk_Select(item_json[@"file"]);
+
+    }
+    
+    [self dismissViewControllerAnimated:false completion:nil];
+    
+//    if (tableView.isEditing) { // 编辑模式下不响应
+//        return;
+//    }
+//    //
+//    if(indexPath.row==self.content_data.count)
+//        return;
+//    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+//    
+//    if(appDelegate.user_type==USER_ROLE_CUSTOMER) { // Customer
+//        if ([Singleton sharedInstance].global_lock) { // Order list 被锁
+//            [RAUtils message_alert:@"App is locked,You can't view the order Detail" title:@"Warning" controller:self];
+//            return;
+//        }
+//    }
+//    
+//    NSString* orderid= [self.content_data[indexPath.row] valueForKey:@"order_id"];
+//    OrderDetailViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"OrderDetailViewController" ];
+//    
+//    //    int i =[[self.content_data[indexPath.row] valueForKey:@"order_code"];
+//    dvc.selectOrder=^(NSMutableDictionary* order_detail){
+//        
+//        [self.navigationController popViewControllerAnimated:false];
+//        if(self.selectOrder)
+//            self.selectOrder(order_detail);
+//        
+//        
+//        
+//    };
+//    NSString* order_code =[self.content_data[indexPath.row] valueForKey:@"order_code"];
+//    
+//    dvc.is_shoporder=(self.orderType == 0);
+//    dvc.order_code = order_code;
+//    dvc.order_status =[[self.content_data[indexPath.row] valueForKey:@"orderStatus"] intValue];
+//    //    bool temp_order = false ;
+//    //    NSString* order_status=[self.content_data[indexPath.row] valueForKey:@"order_status"];
+//    //    if([order_status isEqualToString:@"Saved"]||[order_status isEqualToString:@"Quoted"])
+//    //        temp_order=true;
+//    //
+//    //    dvc.isTempOrder = temp_order;
+//    
+//    //            dvc
+//    
+//    dvc.orderid=orderid;
+//    //    dvc.category_id=nil;
+//    //    dvc.ispush=true;
+//    //    [dvc reload];
+//    [self.navigationController pushViewController:dvc animated:true];
+    
+    
+}
+@end

+ 14 - 0
Ants Contract/common/SignatureTableViewCell.h

@@ -0,0 +1,14 @@
+//
+//  SignatureTableViewCell.h
+//  AntsContract
+//
+//  Created by Ray on 12/19/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface SignatureTableViewCell : UITableViewCell
+@property (strong, nonatomic) IBOutlet UIImageView *signatureImageView;
+
+@end

+ 24 - 0
Ants Contract/common/SignatureTableViewCell.m

@@ -0,0 +1,24 @@
+//
+//  SignatureTableViewCell.m
+//  AntsContract
+//
+//  Created by Ray on 12/19/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "SignatureTableViewCell.h"
+
+@implementation SignatureTableViewCell
+
+- (void)awakeFromNib {
+    [super awakeFromNib];
+    // Initialization code
+}
+
+- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
+    [super setSelected:selected animated:animated];
+
+    // Configure the view for the selected state
+}
+
+@end