Prechádzať zdrojové kódy

161228

Add new network interface new_doc
add document list & search function
add barcode & document number in the pdf edit
Ray Zhang 9 rokov pred
rodič
commit
e33e29e6c6

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

@@ -15,4 +15,6 @@
 +(int)Authorize : (NSString*) user password:(NSString*) password;
 +(NSString *) prepareUploadFile:(NSString*) file json:(NSMutableDictionary*)json;
 +(NSDictionary*)logout;
++(NSDictionary*)request_DocList:(NSMutableDictionary*) params;
++(NSDictionary*)new_document;
 @end

+ 88 - 6
Ants Contract/common/ACNetwork.m

@@ -13,6 +13,9 @@
 #import "ZipArchive.h"
 
 #import "config.h"
+#import "AESCrypt.h"
+
+
 
 
 @implementation ACNetwork
@@ -21,12 +24,11 @@
 {
     AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
     if(appDelegate.user!=nil)
-        [params setValue:appDelegate.user forKey:@"user"];
+        [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"usai2010"] forKey:@"user"];
     if(appDelegate.password!=nil)
-        [params setValue:appDelegate.password forKey:@"password"];
-    
-    
+        [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"usai2010"] forKey:@"password"];
     
+
     
     [params setValue:appDelegate.build forKey:@"app_ver"];
     
@@ -48,6 +50,12 @@
 +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
 {
     
+    
+    
+    
+//    NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
+//    DebugLog(e);
+//    NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
     params = [self prepare_addtional_params:params];
     
     return [super get_json:url parameters:params err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
@@ -86,6 +94,12 @@
 //            [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
 //        }
         return jsobj;
+    } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
+        
+        NSString* base64str = jsobj[@"str"];
+        NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
+        jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
+        return jsobj;
     }];
     
     
@@ -96,6 +110,41 @@
      */
     return nil;
 }
++(NSDictionary*)new_document
+{
+    
+    
+    
+    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"]=@"doc_id";
+    
+    if(![self IsNetworkAvailable])
+    {
+        DebugLog(@"NET ERR");
+        
+        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+        //        return nil;
+    }
+    NSData* json=[self get_json:URL_NEW_DOCUMENT 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];
+    
+
+    return jsobj;
+}
 +(NSDictionary*)logout
 {
     
@@ -151,8 +200,11 @@
 //    [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:[AESCrypt AES128Encrypt:user  key:@"usai2010"] forKey:@"user"];
+    [params setValue:[AESCrypt AES128Encrypt:password  key:@"usai2010"] forKey:@"password"];
     [params setValue:[NSString stringWithFormat:@"%ld",ver]  forKey:@"auth_ver"];
         [params setValue:@"login"  forKey:@"_operate"];
     
@@ -464,4 +516,34 @@
     
     return zippath;
 }
+
++(NSDictionary*)request_DocList:(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[@"_operate"]=@"listIpad";
+    
+    if(![self IsNetworkAvailable])
+    {
+        DebugLog(@"NET ERR");
+        
+        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+        //        return nil;
+    }
+    NSData* json=[self get_json:URL_REQUEST_DOC parameters:params];
+    //if(json==nil)
+    
+    
+    if(json==nil)
+        return nil;
+    NSError *error=nil;
+    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+
+    return jsobj;
+}
 @end

+ 23 - 0
Ants Contract/common/DocListTableViewCell.h

@@ -0,0 +1,23 @@
+//
+//  DocListTableViewCell.h
+//  Granite Expo eSign
+//
+//  Created by Ray on 12/29/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface DocListTableViewCell : UITableViewCell
+@property (strong, nonatomic) IBOutlet UILabel *labelDocID;
+@property (strong, nonatomic) IBOutlet UILabel *labelCustomer;
+
+@property (strong, nonatomic) IBOutlet UILabel *labelJobDate;
+
+
+@property (strong, nonatomic) IBOutlet UILabel *labelAgent;
+
+@property (strong, nonatomic) IBOutlet UILabel *labelSignDate;
+
+@property (strong, nonatomic) IBOutlet UILabel *labelExtInfo;
+@end

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

@@ -0,0 +1,24 @@
+//
+//  DocListTableViewCell.m
+//  Granite Expo eSign
+//
+//  Created by Ray on 12/29/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "DocListTableViewCell.h"
+
+@implementation DocListTableViewCell
+
+- (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

+ 48 - 0
Ants Contract/common/DocumentListViewController.h

@@ -0,0 +1,48 @@
+//
+//  DocumentListViewController.h
+//  Granite Expo eSign
+//
+//  Created by Ray on 12/28/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface DocumentListViewController : UIViewController
+@property (strong,nonatomic) NSMutableArray* table_data;
+@property (strong, nonatomic) IBOutlet UITableView *tableView;
+
+@property long offset;
+@property int limit;
+@property (strong,nonatomic) NSString* load_more_hint;
+//@property
+
+@property (strong, nonatomic) IBOutlet UILabel *label_net_err;
+
+@property bool reset_result;
+
+@property (strong,nonatomic) NSMutableDictionary* filterparams;
+
+@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *mum;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+@end

+ 849 - 0
Ants Contract/common/DocumentListViewController.m

@@ -0,0 +1,849 @@
+//
+//  DocumentListViewController.m
+//  Granite Expo eSign
+//
+//  Created by Ray on 12/28/16.
+//  Copyright © 2016 United Software Applications, Inc. All rights reserved.
+//
+
+#import "DocumentListViewController.h"
+#import "ACNetwork.h"
+#import "DocListTableViewCell.h"
+#import "RAUtils.h"
+#import "GEContractFilterViewController.h"
+#import "PDFViewController.h"
+#import "AppDelegate.h"
+
+
+@interface DocumentListViewController ()
+
+
+@property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
+
+@end
+
+@implementation DocumentListViewController
+- (NSOperationQueue *)dataOperationQueue {
+    if (!_dataOperationQueue) {
+        _dataOperationQueue = [[NSOperationQueue alloc] init];
+        _dataOperationQueue.maxConcurrentOperationCount = 1;
+    }
+    return _dataOperationQueue;
+}
+- (void)viewDidLoad {
+    [super viewDidLoad];
+    
+    self.offset = 0;
+    self.limit = 20;
+    
+    self.table_data = [[NSMutableArray alloc] init];
+    
+    self.filterparams = [[NSMutableDictionary alloc]init];
+    
+    self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
+    self.label_net_err.layer.borderWidth = 2.0;
+    self.label_net_err.layer.cornerRadius=15;
+    self.label_net_err.layer.masksToBounds=true;
+    
+    
+    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
+
+    [self.label_net_err addGestureRecognizer:tap];
+    
+    
+    
+    UIRefreshControl *ref = [[UIRefreshControl alloc]init];
+    ref.tag = 201 ;
+    ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
+    ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
+    //    ref.hidden = true;
+    [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
+    [self.tableView addSubview:ref];
+    
+//    NSMutableArray * arr = [[NSMutableArray alloc] init];
+//    for(int i=0;i<100;i++)
+//    {
+//        [arr addObject:[NSNumber numberWithInt:i]];
+//    }
+//    NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
+//    dict[@"arr"] = arr;
+//    DebugLog([RAUtils dict2string:dict]);
+    
+    
+    
+    [self loadpage];
+    // Do any additional setup after loading the view.
+}
+
+- (void)didReceiveMemoryWarning {
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+- (IBAction)onFilterClick:(id)sender {
+    
+    
+        GEContractFilterViewController * filterVC =[ self.storyboard instantiateViewControllerWithIdentifier:@"GEContractFilterViewController"];
+    filterVC.filterparams = self.filterparams;
+    
+    filterVC.OnSearch = ^(NSMutableDictionary* params)
+    {
+        //    [self reload_container_getdata:true];
+        self.reset_result=true;
+        //    self.norefresh=true;
+        [self loadpage];
+    };
+    
+    UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:filterVC] ;
+    
+    
+    
+    
+    
+    
+    navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
+    [self presentViewController:navi animated:YES completion:^{
+        
+        //        navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
+        
+        DebugLog(@"filter present.........");
+        
+        //   self.btop = false;
+        //  <#code#>
+    }];
+}
+
+-(void) previewPDF:(NSString*)url
+{
+    NSString* name=@"";//[self.content_data[indexPath.row] valueForKey:@"tear_name"];
+//    NSString* url= file;//[self.content_data[indexPath.row] valueForKey:@"pdf_path"];
+    
+    
+    
+    bool isLocalFile= false;//[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];
+}
+
+#pragma mark - OperationQueue request page data
+-(void) loadpage
+{
+    __weak typeof(self) weakself = self;
+    NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
+        
+        if (weakself) {
+            __strong typeof(weakself) strongself = weakself;
+            [strongself operation_loadPage];
+        }
+        
+    }];
+    
+    [self.dataOperationQueue addOperation:operation];
+    
+}
+- (void)loadmore
+{
+    //    self.btnrefresh.enabled = NO;
+    //    self.btnrefresh.titleLabel.text =NSLocalizedString(@"loading",nil);
+    
+    //    [self.btnrefresh setTitle:@"Loading..." forState:UIControlStateNormal];
+    [self loadpage];
+}
+-(void)manually_refresh
+{
+    UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
+//    if(self.isrefreshing)
+//    {
+//        [reF endRefreshing];
+//        return;
+//    }
+    reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
+    if ([self respondsToSelector:@selector(ReloadData)])
+        [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
+    
+}
+-(void)ReloadData
+{
+    
+    
+    //    [self.content_data removeAllObjects];
+    //    [self.table_order reloadData];
+    
+    
+    // self.table_order.hidden = true;
+    UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:201];
+    
+    [reF endRefreshing];
+    
+    reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
+    
+//    self.keywords=self.searchbar.text;
+//    //    self.offset = 0;
+    self.reset_result=true;
+    //    [self.content_data removeAllObjects];
+    //    [self.table_order reloadData];
+    
+    
+    [self loadpage];
+    
+    //   [self loadpage];
+    
+}
+-(void)refresh_btn_click:(UILongPressGestureRecognizer*)gestureRecognizer
+{
+//    [self reload_container_getdata:true];
+    self.reset_result=true;
+//    self.norefresh=true;
+    [self loadpage];
+}
+- (void)operation_loadPage {
+    
+    if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
+        return;
+    }
+        
+    dispatch_sync(dispatch_get_main_queue(), ^{
+        
+        //在主线程处理界面逻辑
+        
+        if(self.reset_result)
+        {
+            self.offset = 0;
+            //[self.filterparams removeAllObjects];
+            [self.table_data removeAllObjects];
+            [self.tableView reloadData];
+        }
+//
+//        //            NSMutableArray* arr_status = [[NSMutableArray alloc] init];
+//        
+//        NSMutableArray* arr_statusname = [[NSMutableArray alloc] init];
+//        int count = [[self.status_cadedate valueForKey:@"count"] intValue];
+//        for(int i=0;i<count;i++)
+//        {
+//            NSDictionary* val_json =[self.status_cadedate objectForKey:[NSString stringWithFormat:@"val_%d",i]];
+//            int check = [[val_json valueForKey:@"check"] intValue];
+//            if(check==1)
+//            {
+//                //                    [arr_status addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value_id"]]];
+//                [arr_statusname addObject:[NSString stringWithFormat:@"%@",[val_json valueForKey:@"value"]]];
+//                
+//                // break;
+//            }
+//        }
+//        
+//        //            NSString * str_status = [arr_status componentsJoinedByString:@","];
+//        NSString * str_statusname = [arr_statusname componentsJoinedByString:@","];
+//        if(str_statusname.length==0)
+//            str_statusname = @"All";
+//        self.label_filter.text = str_statusname;
+//        if(self.offset==0)
+//        {
+//            self.table_order.hidden = true;
+//            
+            self.mum.center = self.view.center;
+            
+            self.mum.hidden = false;
+            [self.mum startAnimating];
+//        }
+        self.label_net_err.hidden=true;
+        
+    });
+    
+    
+    NSMutableDictionary* content=nil;
+    
+   // NSMutableDictionary* params = [[NSMutableDictionary alloc]init];
+    
+    self.filterparams[@"offset"] = [NSNumber numberWithLong:self.offset];
+    
+    
+   // self.filterparams = params;
+    content=[[ACNetwork request_DocList:self.filterparams]mutableCopy];
+    
+    
+    dispatch_sync(dispatch_get_main_queue(), ^{
+        
+        
+        //在主线程处理界请求结果
+        
+        
+        [self.mum stopAnimating];
+//        self.isrefreshing=false;
+        if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
+            return ;
+        }
+        int result=[[content valueForKey:@"result"] intValue];
+        
+        if(result==2||result==0)
+        {
+            
+            
+            NSArray * arrlist = content[@"list"];
+            long count = arrlist.count ;
+            
+            
+
+            self.offset += count;
+            [self.table_data addObjectsFromArray:arrlist];
+//            for(int i=0;i<count;i++)
+//            {
+//                
+//                NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
+//                
+//                table_data
+//                
+//                [self.content_data addObject:[NSMutableDictionary dictionaryWithDictionary:objmsg]];
+//                
+//            }
+            if(count<self.limit)
+            {
+                
+                //                    int i =self.btnrefresh.state;
+                self.load_more_hint=@"All loaded";
+                //                    self.btnrefresh.titleLabel.text =NSLocalizedString(@"no_more", nil);
+                //                    [self.btnrefresh setTitle:@"No more" forState:UIControlStateNormal];
+            }
+            else
+            {
+                self.load_more_hint=@"Load more...";
+                //                    self.btnrefresh.enabled = true;
+                //                    self.btnrefresh.titleLabel.text =NSLocalizedString(@"load_more",nil);
+                //                    [self.btnrefresh setTitle:@"Load more" forState:UIControlStateNormal];
+            }
+            
+            
+            self.tableView.hidden = false;
+            self.reset_result=false;
+            [self.tableView reloadData ];
+        }
+        else if(result==RESULT_NET_ERROR &&self.offset==0)
+        {
+            self.label_net_err.hidden=false;
+            self.tableView.hidden = true;
+        }
+        else
+        {
+            [RAUtils message_alert:[content valueForKey:@"err_msg"]  title:@"Loading Document List" controller:self] ;
+        }
+
+        
+        
+        
+        
+        
+        //            NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+        //            bool autologin =[defaults boolForKey:@"autologin"];
+        //            if(!autologin)
+        //            {
+        //                TabBarController * viewController =[self.storyboard instantiateViewControllerWithIdentifier:@"LoginTabBar"];
+        //                [self presentViewController:viewController animated:YES completion:^{
+        //
+        //                }];
+        //            }
+        
+        
+    });
+    
+}
+
+/*
+#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;
+{
+
+    if(indexPath.row<self.table_data.count)
+    return 128;
+    else
+        return 44;
+    
+    
+}
+
+//- (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
+{
+    
+    NSString* value =nil;//[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
+    
+    if(value==nil)
+        value=@"";
+    unsigned long color = strtoul([value UTF8String],0,16);
+    
+    UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
+      myView.backgroundColor =  UIColorFromRGB(0xf7f7f7);
+    myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
+    myView.layer.shadowColor = [UIColor blackColor].CGColor;
+    myView.layer.shadowOffset = CGSizeMake(0, 0);
+    myView.layer.shadowOpacity = 0.5;
+    myView.layer.shadowRadius = 2.0;
+    
+    
+    UILabel *statuslabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 2, 130, 22)];
+    statuslabel.textColor=UIColorFromRGB(color);
+    statuslabel.backgroundColor = [UIColor clearColor];
+    statuslabel.text=NSLocalizedString(@"Document #", nil);
+    [statuslabel sizeToFit];
+    [myView addSubview:statuslabel];
+    
+    UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 21, 130, 22)];
+    solabel.textColor=UIColorFromRGB(color);
+    solabel.backgroundColor = [UIColor clearColor];
+    solabel.text=NSLocalizedString(@"Address", nil);
+    [solabel sizeToFit];
+    [myView addSubview:solabel];
+    
+    UILabel *userlabel = [[UILabel alloc] initWithFrame:CGRectMake(155, 11, 135, 22)];
+    userlabel.textColor=UIColorFromRGB(color);
+    userlabel.backgroundColor = [UIColor clearColor];
+    userlabel.text=NSLocalizedString(@"Customer", nil);
+    [userlabel sizeToFit];
+    [myView addSubview:userlabel];
+    
+//    UILabel *creatorlabel = [[UILabel alloc] initWithFrame:CGRectMake(155, 21, 135, 22)];
+//    creatorlabel.textColor=UIColorFromRGB(color);
+//    creatorlabel.backgroundColor = [UIColor clearColor];
+//    creatorlabel.text=NSLocalizedString(@"Create by", nil);
+//    [creatorlabel sizeToFit];
+//    [myView addSubview:creatorlabel];
+    
+    UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 11, 150, 22)];
+    
+    contactlabel.textColor=UIColorFromRGB(color);
+    contactlabel.backgroundColor = [UIColor clearColor];
+    contactlabel.text=NSLocalizedString(@"Job Date", nil);
+    [contactlabel sizeToFit];
+    [myView addSubview:contactlabel];
+    
+    //
+    //    UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(424, 11, 52, 22)];
+    //    modellabel.textColor=[UIColor whiteColor];
+    //    modellabel.backgroundColor = [UIColor clearColor];
+    //    modellabel.text=NSLocalizedString(@"Model", nil);
+    //    [modellabel sizeToFit];
+    //    [myView addSubview:modellabel];
+    
+    //    UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(self.table_order.frame.size.width-276, 2, 100, 22)];
+    //    modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
+    //    modellabel.textColor=[UIColor whiteColor];
+    //    modellabel.backgroundColor = [UIColor clearColor];
+    //    modellabel.text=NSLocalizedString(@"Items/QTY", nil);
+    //    [modellabel sizeToFit];
+    //    [myView addSubview:modellabel];
+    
+    UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(/*492*/self.tableView.frame.size.width-276, 11, 100, 22)];
+    pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
+    pricelabel.textColor=UIColorFromRGB(color);
+    pricelabel.backgroundColor = [UIColor clearColor];
+    pricelabel.text=NSLocalizedString(@"Agent Name", nil);
+    [pricelabel sizeToFit];
+    [myView addSubview:pricelabel];
+    
+    UILabel *timelabel = [[UILabel alloc] initWithFrame:CGRectMake(self.tableView.frame.size.width-163/*605*/,11, 148, 22)];
+    timelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
+    timelabel.textColor=UIColorFromRGB(color);
+    timelabel.backgroundColor = [UIColor clearColor];
+//    if(self.time_zone==nil)
+        timelabel.text=@"Sign Date";
+//    else
+//        timelabel.text=[NSString stringWithFormat:@"Create time (%@)",self.time_zone];
+    [timelabel sizeToFit];
+    [myView addSubview:timelabel];
+    
+    myView.autoresizesSubviews=true;
+    // [myView setAutoresizingMask:UIViewAutoresizingFlexibleWidth  | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
+    
+    
+    
+    
+    //    modellabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
+    //    pricelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
+    //    timelabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
+    myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+    //
+    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 1;
+}
+- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
+{
+    return 44;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    
+    if( self.table_data.count==0)
+        return 0;
+    return self.table_data.count+1;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    
+    
+
+    
+    
+    if(indexPath.row==self.table_data.count)
+    {
+        UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
+        UILabel *moreDataLabel=[[UILabel alloc] init];
+        
+        moreDataLabel.tag=200;
+        moreDataLabel.text=self.load_more_hint;
+        [moreDataLabel setFont:[UIFont systemFontOfSize:14.0f]];
+        [moreDataLabel setTextAlignment:NSTextAlignmentCenter];
+        moreDataLabel.frame=CGRectMake(0, 10, self.tableView.bounds.size.width, 20);
+        [moreDataLabel setBackgroundColor:[UIColor clearColor]];
+        //        [moreDataLabel addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
+        
+        [moreCell.contentView addSubview:moreDataLabel];
+        if([self.load_more_hint isEqualToString:@"Load more..."])
+            [self performSelector:@selector(loadmore) withObject:nil afterDelay:1];
+        //        DebugLog(@"更多...");
+        moreCell.backgroundColor = [UIColor whiteColor];
+        return moreCell;
+    }
+    else
+    {
+        NSString *CellIdentifier = @"DocListTableViewCell";
+        DocListTableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
+        NSDictionary * item_json = self.table_data[indexPath.row];
+        
+        cell.labelAgent.text = item_json[@"agent_name"];
+        NSString* sss =item_json[@"doc_number"];
+        
+        
+        //    if(sss.length==0)
+        //        sss=@"";
+        cell.labelDocID.text = item_json[@"doc_number"];//
+        cell.labelExtInfo.text =item_json[@"address"];
+        cell.labelJobDate.text =item_json[@"job_date"];
+        cell.labelCustomer.text =item_json[@"customer_name"];
+        cell.labelSignDate.text =item_json[@"signed_date"];
+        
+        
+        
+        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
+{
+    
+    
+    NSDictionary * item_json = self.table_data[indexPath.row];
+    
+    NSString* pdf_url = item_json[@"pdf_path1"];
+    
+    [self previewPDF:pdf_url];
+    
+//    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

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

@@ -20,5 +20,8 @@
 @property (strong, nonatomic) NSString* pdfName;
 @property (strong, nonatomic) NSString* templateName;
 
+@property (strong, nonatomic) NSString* docment_id;
+
+
 @property (nonatomic , copy) void (^OnSave)(NSString * file);
 @end

+ 54 - 9
Ants Contract/common/DocumentPageViewController.m

@@ -19,6 +19,7 @@
 #import "RAUtils.h"
 #import "PDFViewController.h"
 #import "config.h"
+#import "AESCrypt.h"
 
 
 
@@ -28,6 +29,46 @@
 
 @implementation DocumentPageViewController
 
+-(NSMutableDictionary*) templateInit:(NSMutableDictionary*) template
+{
+    
+    
+    NSString* temp = NSTemporaryDirectory();
+    NSString* filename =[NSString stringWithFormat:@"%@.png", [[NSUUID UUID] UUIDString]];
+    NSString* qrpath=[temp stringByAppendingPathComponent:filename];
+    UIImage* qrimg=[RAUtils generateBarCode:self.docment_id width:200 height:44];//[QRCodeGenerator qrImageForString:order_code imageSize:240];
+    bool bwrite=[UIImagePNGRepresentation(qrimg)writeToFile: qrpath    atomically:YES];
+    
+    
+    
+    for(int i=0;i<[template[@"count"] intValue];i++)
+    {
+        NSMutableDictionary* page =template[[NSString stringWithFormat:@"page_%d",i]];
+        for(int j=0;j<[page[@"count"] intValue];j++)
+        {
+            NSMutableDictionary* control =page[[NSString stringWithFormat:@"control_%d",j]];
+            NSString* type = control[@"type"];
+            NSString* field =control[@"field"];
+            if([type isEqualToString:@"Label"])
+            {
+                if([field isEqualToString:@"doc_number"])
+                {
+                    control[@"value"]= self.docment_id;
+                }
+            }
+            else if([type isEqualToString:@"Image"])
+            {
+                NSString* name =control[@"name"];
+                if([name isEqualToString:@"BarCode"])
+                {
+                    control[@"value"]= qrpath;
+                }
+            }
+        }
+    }
+    return template;
+}
+
 - (void)viewDidLoad {
     [super viewDidLoad];
     
@@ -41,7 +82,7 @@
     
     self.document = [PDFUtils OpenPDF:self.pdfName];
     self.total_page = CGPDFDocumentGetNumberOfPages (self.document);
-    self.controlTemplate = [PDFUtils loadControl:self.templateName];
+    self.controlTemplate = [self templateInit:[PDFUtils loadControl:self.templateName]];
     
     
     PageViewController* startingViewController=[self viewControllerAtIndex:0];
@@ -199,12 +240,16 @@
             
             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"];
+//            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:[AESCrypt AES128Encrypt:appDelegate.user  key:@"usai2010"] forKey:@"user"];
+            [params setValue:[AESCrypt AES128Encrypt:appDelegate.password  key:@"usai2010"] forKey:@"password"];
             
             [params setValue:@"deviceMain" forKey:@"_operate"];
             
@@ -280,7 +325,7 @@
                     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] ;
+                    [RAUtils message_alert:@"Can not connect to server please try again." title:@"Save document" controller:self] ;
                     
                 } else {
                     DebugLog(@"response ");
@@ -314,7 +359,7 @@
                     }
                     else
                     {
-                        [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Upload Image" controller:self] ;
+                        [RAUtils message_alert:[json valueForKey:@"err_msg"] title:@"Save document" controller:self] ;
                     }
                     
                     

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

@@ -144,6 +144,8 @@
     NSString* password = self.editpass.text;
     
     
+    
+
 //    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
 //    
 //    bool forcedownload = [defaults boolForKey:@"Forcedownload"];

+ 79 - 4
Ants Contract/common/PageViewController.m

@@ -87,6 +87,16 @@
             [self addSignatureButton:control destView:self.editControlView index:i];
             
         }
+        else if([control[@"type"] isEqualToString:@"Image"])
+        {
+            [self addImage:control destView:self.editControlView index:i];
+            
+        }
+        else if([control[@"type"] isEqualToString:@"Label"])
+        {
+            [self addLabel:control destView:self.editControlView index:i];
+            
+        }
     }
     
 }
@@ -123,6 +133,39 @@
     }
     [destView addSubview:tv];
 }
+-(void) addLabel:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
+{
+    UILabel* label = [[UILabel 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;
+    [label setFont:[UIFont systemFontOfSize:fontsize]];
+    
+    label.text =template[@"value"];
+    
+    label.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)
+    {
+        
+        [label setBackgroundColor:[UIColor grayColor]];
+         
+    }
+    [destView addSubview:label];
+}
+
 -(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])];
@@ -130,11 +173,11 @@
     
         btn.tag = index+ CONTROL_BASE;
     //    ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged
-    
+    btn.backgroundColor = UIColorFromRGB(BT_BG);
     [btn addTarget:self action:@selector(ControlButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
     if(DEBUG_PDFSIG)
     {
-        btn.backgroundColor = [UIColor lightGrayColor];
+       // btn.backgroundColor = [UIColor lightGrayColor];
         
         // [btn setBackgroundImage:[UIColor grayColor] forState:UIControlStateNormal];
     }
@@ -156,7 +199,7 @@
     UIColor* marker_bg=UIColorFromRGB(CK_BG);//[UIColor clearColor];
     if(DEBUG_PDFSIG)
     {
-       // btn.backgroundColor = [UIColor lightGrayColor];
+        btn.backgroundColor = [UIColor lightGrayColor];
 
         [btn setTitle:template[@"title"] forState:UIControlStateNormal];
 //        marker_bg = [UIColor redColor];
@@ -233,7 +276,39 @@
     }
     [destView addSubview:btn];
 }
-
+-(void) addImage:(NSMutableDictionary*) template destView:(UIView*)destView index:(int) index
+{
+    UIImageView* btn = [[UIImageView alloc] initWithFrame:CGRectMake([template[@"pos_x"] floatValue], [template[@"pos_y"] floatValue], [template[@"width"] floatValue], [template[@"height"] floatValue])];
+    
+    btn.contentMode = UIViewContentModeScaleAspectFit;
+    
+    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 {

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

@@ -15,6 +15,8 @@
 @property (strong, nonatomic) IBOutlet UIView *coverView;
 @property (strong, nonatomic) IBOutlet UIBarButtonItem *ibSignin;
 @property (strong, nonatomic) IBOutlet UILabel *welcomeLabel;
+@property (strong, nonatomic) IBOutlet UIButton *btnNewCustomer;
+@property (strong, nonatomic) IBOutlet UIButton *btnCustomerPerDoc;
 
 @end
 

+ 64 - 7
Ants Contract/common/RootViewController.m

@@ -13,6 +13,8 @@
 #import "AppDelegate.h"
 #import "RAUtils.h"
 #import "PDFViewController.h"
+#import "DocumentListViewController.h"
+#import "ACNetwork.h"
 
 @interface RootViewController ()
 
@@ -32,11 +34,66 @@
     // Do any additional setup after loading the view, typically from a nib.
 }
 
+- (IBAction)onNewCustomerClick:(id)sender {
+    __weak typeof(self) weakSelf = self;
+    
+    
+    UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Create customer"];
+    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        
+        
+        NSMutableDictionary* json=[[ACNetwork  new_document] mutableCopy];
+        
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+            
+            
+            if([json[@"result"] intValue]==RESULT_TRUE)
+                
+            {
+                DocumentPageViewController* dvc = [self.storyboard instantiateViewControllerWithIdentifier:@"DocumentPageViewController" ];
+                
+                dvc.templateName = @"GEIC - Home Improvement Contract 2017.json";
+                dvc.pdfName = @"GEIC - Home Improvement Contract 2017.pdf";
+                dvc.docment_id = json[@"doc_number"];
+                dvc.OnSave=^(NSString* file)
+                {
+                    [weakSelf previewPDF:file];
+                };
+                
+                [self.navigationController pushViewController:dvc animated:true];
+            }
+            else
+            {
+                [RAUtils message_alert:[json valueForKey:@"err_msg"]  title:@"Create Customer" controller:self] ;
+            }
+            
+            
+        });
+    });
+    
+    
+    
+    
+    
+
+    
+    
+}
+- (IBAction)onCustomerPerDocClick:(id)sender {
+    
+    DocumentListViewController* docVC =[self.storyboard instantiateViewControllerWithIdentifier:@"DocumentListViewController" ];
+    
+    [self.navigationController pushViewController:docVC animated:true];
+}
 
 - (void)didReceiveMemoryWarning {
     [super didReceiveMemoryWarning];
     // Dispose of any resources that can be recreated.
 }
+
+
+
 - (IBAction)OnSigninClick:(id)sender {
     
     
@@ -45,7 +102,7 @@
     AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
     if(appDelegate.bLogin)
     {
-            UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to sign out?" message:nil preferredStyle:UIAlertControllerStyleAlert];
+        UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure to sign out?" message:nil preferredStyle:UIAlertControllerStyleAlert];
         
         UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
             
@@ -56,7 +113,7 @@
                 
                 NSDictionary* logout_json = nil;
                 
-
+                
                 
                 logout_json = [ACNetwork logout];
                 
@@ -67,7 +124,7 @@
                     if([[logout_json valueForKey:@"result"] intValue]==2)
                     {
                         self.welcomeLabel.text=@"Not sign in";
-//                        [sender setTitle:@"Sign in" forState:UIControlStateNormal];
+                        //                        [sender setTitle:@"Sign in" forState:UIControlStateNormal];
                         [bbitem setTitle:@"Sign in"];
                         
                         self.buttonHIC.enabled = false;
@@ -144,9 +201,9 @@
             
             DebugLog(@"login present.........");
             
-        }]; 
+        }];
     }
-
+    
     
 }
 
@@ -157,7 +214,7 @@
     
     
     
-    NSString* isLocalFile= @"true";//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"];
+    bool isLocalFile= true;//[self.content_data[indexPath.row] valueForKey:@"isLocalFile"];
     
     PDFViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PDFViewController"];
     ViewController.url = url;
@@ -188,7 +245,7 @@
     //                    {
     //                        subject = [NSString stringWithFormat:@"Tear sheet for %@",company ];
     //                    }
-    ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
+  //  ViewController.attachment_name = [NSString stringWithFormat:@"NPD_Product_List %@.pdf",cur_time];
     ViewController.mail_subject = subject;
     
     ViewController.hidenavi = false;