Просмотр исходного кода

完成ERP Mobile 登录的修改。
新增ERP Mobile contact list 数据访问接口,并修改相关调用。
新增ERP Mobile contact info 数据访问接口,并修改相关调用。
新增ERP Mobile common editor 数据访问接口,并修改相关调用。
新增ERP Mobile wishlist 数据访问接口,并修改相关调用。

Ray Zhang 6 лет назад
Родитель
Сommit
c43191d259

+ 8 - 2
RedAnt ERP Mobile/common/AppDelegateBase.m

@@ -748,9 +748,15 @@ void UncaughtExceptionHandler(NSException *exception) {
                             [self SetSo:so];
                             
                             if (userType != USER_ROLE_CUSTOMER) {
-                                self.customerInfo = [[[RANetwork request_CustomerInfo:order_customer_id] objectForKey:@"customerInfo"] mutableCopy];
                                 
-                                self.contact_id=[self.customerInfo valueForKey:@"customer_cid"];
+                                [RANetwork request_contactinfo:order_customer_id completionHandler:^(NSMutableDictionary *result) {
+                                    self.customerInfo = [result[@"customerInfo"] mutableCopy];
+                                    self.contact_id=[self.customerInfo valueForKey:@"customer_cid"];
+                                }];
+                                
+//                                self.customerInfo = [[[RANetwork request_CustomerInfo:order_customer_id] objectForKey:@"customerInfo"] mutableCopy];
+//                                
+//                                self.contact_id=[self.customerInfo valueForKey:@"customer_cid"];
                             }
                             
                             

+ 2 - 2
RedAnt ERP Mobile/common/CommonEditor/CommonEditorViewController.h

@@ -113,8 +113,8 @@
 
 @property (nonatomic,strong) IBOutlet CommonEditorTableContainerView *tableContainer;
 
-#pragma mark - request Editor
--(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params;
+//#pragma mark - request Editor
+//-(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params;
 
 // plae order 有调用
 -(NSMutableDictionary*) enum_subitem_changed:(NSMutableDictionary *) item subid:(NSArray*) subid value:(NSMutableDictionary*)value step:(int) step;

+ 112 - 29
RedAnt ERP Mobile/common/CommonEditor/CommonEditorViewController.m

@@ -402,11 +402,12 @@
     {
         
         UIAlertView * waitalert = [RAUtils waiting_alert:self.loading_msg title:self.loading_title];
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-            
-            NSDictionary* editor_json = [weakself request_Editor:weakself.request_url params:weakself.params];
+        
+        [RANetwork request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) {
+            NSMutableDictionary* editor_json = result;
             DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
-            dispatch_async(dispatch_get_main_queue(), ^{
+            
+            
                 
                 [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
                 
@@ -439,8 +440,48 @@
                 }
                 
                 
-            });
-        });
+            
+        }];
+        
+//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//
+//            NSDictionary* editor_json = [weakself request_Editor:weakself.request_url params:weakself.params];
+//            DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
+//            dispatch_async(dispatch_get_main_queue(), ^{
+//
+//                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+//
+//
+//                if([[editor_json valueForKey:@"result"] intValue]==2)
+//                {
+//
+//                    weakself.content_data_download = [editor_json mutableCopy];
+//
+//                    weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
+//
+//                    //                self.content_data = [editor_json mutableCopy];
+//                    //                    self.content_data = [self translate_json:editor_json];
+//
+//                    //                  NSMutableDictionary* content_data1 = [self translate_json:self.content_data];
+//
+//                    [weakself download_success];
+//
+//                    [weakself.editorTable reloadData];
+//
+//                    //                NSString * ttt=[self.content_data valueForKey:@"title"] ;
+//
+//                    weakself.navigationItem.title =  [weakself.content_data_download valueForKey:@"title"] ;
+//                }
+//                else
+//                {
+//                    [weakself download_failed];
+//                    [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
+//
+//                }
+//
+//
+//            });
+//        });
     }
     else if(self.url_type== URL_LOCAL )
     {
@@ -1319,23 +1360,21 @@
         
         self.params[@"refresh_trigger"]=trigger;
         __weak typeof(self) weakself = self;
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-            
-            
-            
-            NSDictionary* refresh_params=[weakself get_refresh_param];
-            
-            NSArray* changed_key=[refresh_params allKeys];
-            for(int i=0;i<changed_key.count;i++)
-            {
-                NSString* obj_str=[NSString stringWithFormat:@"%@",[refresh_params valueForKey:(NSString*)changed_key[i]]];
-                [weakself.params setObject:obj_str forKey:(NSString*)changed_key[i]];
-            }
-            
-            NSDictionary* editor_json = [weakself request_Editor:weakself.request_url params:weakself.params];
+        
+        
+        NSDictionary* refresh_params=[self get_refresh_param];
+        
+        NSArray* changed_key=[refresh_params allKeys];
+        for(int i=0;i<changed_key.count;i++)
+        {
+            NSString* obj_str=[NSString stringWithFormat:@"%@",[refresh_params valueForKey:(NSString*)changed_key[i]]];
+            [self.params setObject:obj_str forKey:(NSString*)changed_key[i]];
+        }
+        
+        [RANetwork request_editor:self.request_url params:self.params completionHandler:^(NSMutableDictionary *result) {
+            NSMutableDictionary* editor_json = result;
             DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
-
-            dispatch_async(dispatch_get_main_queue(), ^{
+            
                 [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
                 
                 
@@ -1360,8 +1399,52 @@
                 
                 
                 
-            });
-        });
+            
+        }];
+        
+//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//
+//
+//
+//            NSDictionary* refresh_params=[weakself get_refresh_param];
+//
+//            NSArray* changed_key=[refresh_params allKeys];
+//            for(int i=0;i<changed_key.count;i++)
+//            {
+//                NSString* obj_str=[NSString stringWithFormat:@"%@",[refresh_params valueForKey:(NSString*)changed_key[i]]];
+//                [weakself.params setObject:obj_str forKey:(NSString*)changed_key[i]];
+//            }
+//
+//            NSDictionary* editor_json = [weakself request_Editor:weakself.request_url params:weakself.params];
+//            DebugLog(@"data string: %@",[RAConvertor dict2string:editor_json] );
+//
+//            dispatch_async(dispatch_get_main_queue(), ^{
+//                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+//
+//
+//                if([[editor_json valueForKey:@"result"] intValue]==2)
+//                {
+//
+//                    weakself.content_data_download = [weakself CopyDirty:weakself.content_data_download to:[editor_json mutableCopy]];//[editor_json mutableCopy];
+//
+//                    weakself.content_data_control = [weakself translate_json:weakself.content_data_download changed: weakself.changed_data];
+//
+//
+//                    [weakself download_success];
+//                    [weakself.editorTable reloadData];
+//
+//                }
+//                else
+//                {
+//                    [weakself download_failed];
+//                    [weakself alertMessage:[editor_json valueForKey:@"err_msg"]];
+//                }
+//
+//
+//
+//
+//            });
+//        });
     }
     else
     {
@@ -6243,11 +6326,11 @@
 
 
 
-#pragma mark Request Editor
--(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
-{
-    return [RANetwork request_Editor:request_url params:params];
-}
+//#pragma mark Request Editor
+//-(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
+//{
+//    return [RANetwork request_Editor:request_url params:params];
+//}
 #pragma mark - Responding to keyboard events
 
 

+ 1 - 30
RedAnt ERP Mobile/common/Functions/contact/ContactAdvanceSearchViewController.m

@@ -51,37 +51,8 @@
   //  searchButton.tintColor = UIColorFromRGB(0x996633);
     self.navigationItem.rightBarButtonItem = searchButton;
     
-    
-//    if (self.data_init==nil) {
-//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-//            
-//            NSDictionary* editor_json = [iSalesNetwork request_CustomerInfo:self.contactId];
-//            
-//            dispatch_async(dispatch_get_main_queue(), ^{
-//                
-//                
-//                
-//                if([[editor_json valueForKey:@"result"] intValue]==2)
-//                {
-//                    self.data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
-//                    
-//                    [self fillData];
-//                    
-//                    
-//                }
-//                else
-//                {
-//                    [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Info Failed." controller:self] ;
-//                }
-//                
-//                
-//            });
-//        });
-//    }
-//    else
-//    {
+
         [self fillData];
- //   }
     
     
     // Do any additional setup after loading the view.

+ 361 - 219
RedAnt ERP Mobile/common/Functions/contact/ContactListViewController.m

@@ -84,101 +84,101 @@
     
     
     
-////    UILabel* titleLabel= [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 100
-//                                                                   
-//                                                                   , 44)];
-//    titleLabel.text=@"Contacts";
-//    //  titleLabel.backgroundColor =[UIColor yellowColor];
-//    titleLabel.textAlignment=NSTextAlignmentCenter;
-//    //    [titleLabel sizeToFit];
-//    
-//    //将搜索条放在一个UIView上
-//  //  UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1768, 44)];
-//    
-//    
-//  
-//    
-//    searchView.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleWidth;
-//
-//    titleLabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
-//    titleLabel.center=searchView.center;
-//    
-//    
-//    
-//    self.searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(searchView.frame.size.width-200.0f-8.0f,0.0f,200.0f,44.0f)];
-//    self.searchBar.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
-//    self.searchBar.delegate = self;
-//    [self.searchBar setPlaceholder:@"name/address"];
-//    //searchBar.barTintColor=[UIColor clearColor];
-//    self.searchBar.searchBarStyle=UISearchBarStyleMinimal;
-//    [searchView addSubview:titleLabel];
-//    [searchView addSubview:self.searchBar];
-//    
-//    self.navigationItem.titleView = searchView;
+    ////    UILabel* titleLabel= [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 100
+    //
+    //                                                                   , 44)];
+    //    titleLabel.text=@"Contacts";
+    //    //  titleLabel.backgroundColor =[UIColor yellowColor];
+    //    titleLabel.textAlignment=NSTextAlignmentCenter;
+    //    //    [titleLabel sizeToFit];
+    //
+    //    //将搜索条放在一个UIView上
+    //  //  UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 1768, 44)];
+    //
+    //
+    //
+    //
+    //    searchView.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleWidth;
+    //
+    //    titleLabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
+    //    titleLabel.center=searchView.center;
+    //
+    //
+    //
+    //    self.searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(searchView.frame.size.width-200.0f-8.0f,0.0f,200.0f,44.0f)];
+    //    self.searchBar.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;
+    //    self.searchBar.delegate = self;
+    //    [self.searchBar setPlaceholder:@"name/address"];
+    //    //searchBar.barTintColor=[UIColor clearColor];
+    //    self.searchBar.searchBarStyle=UISearchBarStyleMinimal;
+    //    [searchView addSubview:titleLabel];
+    //    [searchView addSubview:self.searchBar];
+    //
+    //    self.navigationItem.titleView = searchView;
     
-//    NSMutableArray * items = [[NSMutableArray alloc]init];
-//    
-//    
-//    UIBarButtonItem *Btnback = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
-//    
-//    Btnback = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
-//                                               style:UIBarButtonItemStylePlain
-//                                              target:self
-//                                              action:@selector(onBack:)];
-//    
-//    
-//    UIBarButtonItem *btnAS = nil;
-//    btnAS =[[UIBarButtonItem alloc] initWithTitle:@"Advanced search"
-//                                                style:UIBarButtonItemStylePlain
-//                                               target:self
-//                                               action:@selector(onASearch:)];
-//    
-//    
-//    
-//    
-//    //savebtn setBackgroundImage:(nullable UIImage *) forState:<#(UIControlState)#> style:<#(UIBarButtonItemStyle)#> barMetrics:<#(UIBarMetrics)#>
-//    //[savebtn setImage:[UIImage imageNamed:@"save"] ];
-//    
-//    
-//    /*
-//     UIBarMetricsDefault,
-//     UIBarMetricsCompact,
-//     UIBarMetricsDefaultPrompt = 101, // Applicable only in bars with the prompt property, such as UINavigationBar and UISearchBar
-//     UIBarMetricsCompactPrompt
-//     
-//     */
-//    // [savebtn setBackgroundImage:[UIImage imageNamed:@"save"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
-//    //        UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
-//    //        item1.title = @"item1";
-//    ////        item1.image = [UIImage imageNamed:@"rect_setting"];
-//    //        UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
-//    ////        item2.image = [UIImage imageNamed:@"rect_about"];
-//    //        item2.title = @"item2";
-//    
-//    
-//    UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
-//    fixedItem.width = 20.0f;
-//    
-////    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-////    
-////    if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
-//    
-//        [items addObject:Btnback];
-//        
-//        [items addObject:fixedItem];
-//    
-//    [items addObject:btnAS];
-//    //        [items addObject:item2];
-//    self.navigationItem.leftBarButtonItems=items;
+    //    NSMutableArray * items = [[NSMutableArray alloc]init];
+    //
+    //
+    //    UIBarButtonItem *Btnback = nil;//[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"", nil) style:UIBarButtonItemStylePlain target:self action:@selector(onSaveClick:)];
+    //
+    //    Btnback = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
+    //                                               style:UIBarButtonItemStylePlain
+    //                                              target:self
+    //                                              action:@selector(onBack:)];
+    //
+    //
+    //    UIBarButtonItem *btnAS = nil;
+    //    btnAS =[[UIBarButtonItem alloc] initWithTitle:@"Advanced search"
+    //                                                style:UIBarButtonItemStylePlain
+    //                                               target:self
+    //                                               action:@selector(onASearch:)];
+    //
+    //
+    //
+    //
+    //    //savebtn setBackgroundImage:(nullable UIImage *) forState:<#(UIControlState)#> style:<#(UIBarButtonItemStyle)#> barMetrics:<#(UIBarMetrics)#>
+    //    //[savebtn setImage:[UIImage imageNamed:@"save"] ];
+    //
+    //
+    //    /*
+    //     UIBarMetricsDefault,
+    //     UIBarMetricsCompact,
+    //     UIBarMetricsDefaultPrompt = 101, // Applicable only in bars with the prompt property, such as UINavigationBar and UISearchBar
+    //     UIBarMetricsCompactPrompt
+    //
+    //     */
+    //    // [savebtn setBackgroundImage:[UIImage imageNamed:@"save"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
+    //    //        UIBarButtonItem *item1 = [[UIBarButtonItem alloc] init];
+    //    //        item1.title = @"item1";
+    //    ////        item1.image = [UIImage imageNamed:@"rect_setting"];
+    //    //        UIBarButtonItem *item2 = [[UIBarButtonItem alloc] init];
+    //    ////        item2.image = [UIImage imageNamed:@"rect_about"];
+    //    //        item2.title = @"item2";
+    //
+    //
+    //    UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
+    //    fixedItem.width = 20.0f;
+    //
+    ////    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    ////
+    ////    if(appDelegate.user_type ==USER_ROLE_EMPLOYEE)
+    //
+    //        [items addObject:Btnback];
+    //
+    //        [items addObject:fixedItem];
+    //
+    //    [items addObject:btnAS];
+    //    //        [items addObject:item2];
+    //    self.navigationItem.leftBarButtonItems=items;
     
     
-        self.offset = 0;
-        [self.content_data removeAllObjects];
+    self.offset = 0;
+    [self.content_data removeAllObjects];
     NSLog(@"%s removeAllObjects",__func__);
     //    [self loadpage];
-
     
-
+    
+    
 }
 -(void)manually_refresh
 {
@@ -189,8 +189,8 @@
         return;
     }
     reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
-     if ([self respondsToSelector:@selector(ReloadData)])
-    [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
+    if ([self respondsToSelector:@selector(ReloadData)])
+        [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
     
 }
 
@@ -211,7 +211,7 @@
     [self loadpage];
     
     //   [self loadpage];
-
+    
 }
 - (void)didReceiveMemoryWarning {
     [super didReceiveMemoryWarning];
@@ -221,10 +221,10 @@
 -(void) viewWillAppear:(BOOL)animated
 {
     [super viewWillAppear:animated];
-//        [[self navigationController] setNavigationBarHidden:NO animated:NO];
-//    self.offset = 0;
-//    [self.content_data removeAllObjects];
-//    [self loadpage];
+    //        [[self navigationController] setNavigationBarHidden:NO animated:NO];
+    //    self.offset = 0;
+    //    [self.content_data removeAllObjects];
+    //    [self loadpage];
     
     [[self navigationController] setNavigationBarHidden:!self.showNavibar animated:NO];
 }
@@ -258,42 +258,40 @@
     if (self.dataOperationQueue.operationCount > 1) {
         return;
     }
-        dispatch_async(dispatch_get_main_queue(), ^{
-    if(self.isrefreshing)
-        return;
-    
-self.label_net_err.hidden=true;
+    dispatch_async(dispatch_get_main_queue(), ^{
+        if(self.isrefreshing)
+            return;
         
-        self.isrefreshing=true;
-    if(self.offset==0)
-    {
-        self.table.hidden = true;
-    //    [self.params setValue:[NSString stringWithFormat:@"%ld",self.offset] forKey:@"offset"];
-    self.mum.center = self.view.center;
-
+        self.label_net_err.hidden=true;
         
-        self.mum.hidden = false;
-        [self.mum startAnimating];
-    }
-    //    self.btnrefresh.enabled = false;
-    //
-    //    NSTimeInterval animationDuration = 0.30f;
-    //    [UIView beginAnimations:@"ResizeView" context:nil];
-    //    [UIView setAnimationDuration:animationDuration];
-    //    self.prepageButton.enabled=false;
-    //    self.nextpageButton.enabled=false;
-    //    self.mum.hidden = false;
-    //    self.grid.hidden = true;
-    //    self.mum.hidden = false;
-    //    self.tableview.hidden = true;
-    
-    //    [UIView commitAnimations];
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        self.isrefreshing=true;
+        if(self.offset==0)
+        {
+            self.table.hidden = true;
+            //    [self.params setValue:[NSString stringWithFormat:@"%ld",self.offset] forKey:@"offset"];
+            self.mum.center = self.view.center;
+            
+            
+            self.mum.hidden = false;
+            [self.mum startAnimating];
+        }
+        //    self.btnrefresh.enabled = false;
+        //
+        //    NSTimeInterval animationDuration = 0.30f;
+        //    [UIView beginAnimations:@"ResizeView" context:nil];
+        //    [UIView setAnimationDuration:animationDuration];
+        //    self.prepageButton.enabled=false;
+        //    self.nextpageButton.enabled=false;
+        //    self.mum.hidden = false;
+        //    self.grid.hidden = true;
+        //    self.mum.hidden = false;
+        //    self.tableview.hidden = true;
         
+        //    [UIView commitAnimations];
         
-        NSMutableDictionary* content=nil;
-        content=[[RANetwork request_ContactList:self.offset limit : self.limit keywords:self.keywords type:self.contact_type adv_search:self.adv_search] mutableCopy];
-        dispatch_async(dispatch_get_main_queue(), ^{
+        [RANetwork request_contactlist:self.offset limit:self.limit keywords:self.keywords type:self.contact_type adv_search:self.adv_search completionHandler:^(NSMutableDictionary *result) {
+            NSMutableDictionary* content=result;
+            
             
             [self.mum stopAnimating];
             self.isrefreshing=false;
@@ -346,16 +344,85 @@ self.label_net_err.hidden=true;
             {
                 [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Contact List" controller:self] ;
             }
-           
             
-   
+            
+            
             
             
             self.isrefreshing=false;
             
+            
+        }];
+        
+        return;
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            
+            
+            NSMutableDictionary* content=nil;
+            content=[[RANetwork request_ContactList:self.offset limit : self.limit keywords:self.keywords type:self.contact_type adv_search:self.adv_search] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                
+                [self.mum stopAnimating];
+                self.isrefreshing=false;
+                if (self.dataOperationQueue.operationCount > 1) {
+                    return ;
+                }
+                
+                
+                if([[content valueForKey:@"result"] intValue]==2)
+                {
+                    self.table.hidden =false;
+                    int count = [[content valueForKey:@"count" ] intValue] ;
+                    
+                    self.offset += count;
+                    for(int i=0;i<count;i++)
+                    {
+                        
+                        NSDictionary* objmsg = [content objectForKey:[NSString stringWithFormat:@"item_%d",i]];
+                        [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.table reloadData ];
+                    NSLog(@"%s reloadData",__FUNCTION__);
+                    
+                }
+                else if([[content valueForKey:@"result"] intValue]==RESULT_NET_ERROR &&self.offset==0)
+                {
+                    self.label_net_err.hidden=false;
+                    self.table.hidden = true;
+                }
+                else
+                {
+                    [RAUtils message_alert:[content valueForKey:@"err_msg"] title:@"Loading Contact List" controller:self] ;
+                }
+                
+                
+                
+                
+                
+                self.isrefreshing=false;
+                
+            });
         });
     });
-        });
 }
 
 -(void) loadpage {
@@ -383,10 +450,10 @@ self.label_net_err.hidden=true;
 - (IBAction)onBack:(UIBarButtonItem *)sender {
     if(self.onCancel)
         self.onCancel();
-        [self.navigationController popViewControllerAnimated:(false)];
+    [self.navigationController popViewControllerAnimated:(false)];
 }
 - (IBAction)onASearch:(UIBarButtonItem *)sender {
-
+    
     
     
     ContactAdvanceSearchViewController * vc = [[ContactAdvanceSearchViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
@@ -398,31 +465,31 @@ self.label_net_err.hidden=true;
     
     
     NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
-     vc.params = params;
+    vc.params = params;
     
     vc.data_init = self.adv_search;
     
-   // vc.update_order = true;
+    // vc.update_order = true;
     
-   // vc.contactId=contactid;
+    // vc.contactId=contactid;
     //  vc.delegate = self;
     
     vc.returnValue = ^(NSMutableDictionary* value){
-       
         
         
-
+        
+        
         
         self.adv_search = value;
         
         self.keywords=nil;
         self.offset = 0;
         [self.content_data removeAllObjects];
-       NSLog(@"%s removeAllObjects",__func__);
+        NSLog(@"%s removeAllObjects",__func__);
         [self loadpage];
         
-//        appDelegate.contact_id=[value valueForKey:@"customer_cid"];
-//        appDelegate.customerInfo = value;
+        //        appDelegate.contact_id=[value valueForKey:@"customer_cid"];
+        //        appDelegate.customerInfo = value;
     };
     
     
@@ -431,9 +498,9 @@ self.label_net_err.hidden=true;
 - (IBAction)onNewCustomerClick:(id)sender {
     
     
-        NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
+    NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
+    
     
-
     
     CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
     cuseditVC.bnewcustomer=true;
@@ -448,17 +515,17 @@ self.label_net_err.hidden=true;
     //    {
     //    orderinfoVC.have_tail = true
     //    }
-     [[self navigationController] setNavigationBarHidden:NO animated:NO];
+    [[self navigationController] setNavigationBarHidden:NO animated:NO];
     [self.navigationController pushViewController:cuseditVC animated:false];
     
-
+    
 }
 - (IBAction)resetContactId:(id)sender {
     
     AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
     appDelegate.contact_id=nil;
     appDelegate.customerInfo = nil;
-//     appDelegate.contact_name =nil;
+    //     appDelegate.contact_name =nil;
     
     if(self.onReset)
         self.onReset();
@@ -507,12 +574,87 @@ self.label_net_err.hidden=true;
     DebugLog(@"indexPath is = %i",indexPath.row);
     
     
-        NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
+    NSString* contactid=[self.content_data[indexPath.row] valueForKey:@"contact_id"] ;
     
     
     
     UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Getting Contact information"];
     
+    [RANetwork request_contactinfo:contactid completionHandler:^(NSMutableDictionary *result) {
+        NSMutableDictionary* editor_json = result;
+        
+            
+            [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+            
+            if([[editor_json valueForKey:@"result"] intValue]==2)
+            {
+                __block NSMutableDictionary* data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
+                
+                //---------------- construct customer_contact----------------------
+                NSString* customer_first_name = [data_init valueForKey:@"customer_first_name"];
+                if(customer_first_name==nil)
+                    customer_first_name=@"";
+                
+                NSString* customer_last_name= [data_init valueForKey:@"customer_last_name"];
+                if(customer_last_name==nil)
+                    customer_last_name=@"";
+                NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
+                customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+                [data_init setValue:customer_contact forKey:@"customer_contact"];
+                
+                data_init[@"is_subaction"]=self.is_subaction;
+                data_init[@"subaction_tag"]= self.subaction_tag;
+                [self.navigationController popToRootViewControllerAnimated:false];
+                
+                
+                [self.table reloadData];
+                NSLog(@"%s reloadData",__FUNCTION__);
+                if(self.returnValue)
+                    self.returnValue(data_init,self.from);
+                
+                //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                //                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                //                    NSDictionary* editor_json = [iSalesNetwork update_OrderCustomer:appDelegate.order_code customerinfo:data_init];
+                //
+                //                    dispatch_async(dispatch_get_main_queue(), ^{
+                //
+                //
+                //                        if([[editor_json valueForKey:@"result"] intValue]==2)
+                //                        {
+                //
+                ////                            [self.navigationController popViewControllerAnimated:false];
+                ////                            if(self.returnValue)
+                ////                            {
+                ////
+                ////                                self.returnValue(data_init);
+                ////                            }
+                //
+                //
+                //
+                //                        }
+                //                        else
+                //                        {
+                //                            [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Update Order Customer Infomation" controller:self] ;
+                //                        }
+                //
+                //
+                //
+                //                    });
+                //                });
+                
+            }
+            else
+            {
+                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
+                //                self.btn_assign.enabled=false;
+            }
+            
+            
+        
+    }];
+    
+    return ;
+    
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         
         NSDictionary* editor_json = [RANetwork request_CustomerInfo:contactid];
@@ -547,48 +689,48 @@ self.label_net_err.hidden=true;
                 if(self.returnValue)
                     self.returnValue(data_init,self.from);
                 
-//                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-//                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
-//                    NSDictionary* editor_json = [iSalesNetwork update_OrderCustomer:appDelegate.order_code customerinfo:data_init];
-//                    
-//                    dispatch_async(dispatch_get_main_queue(), ^{
-//                        
-//                        
-//                        if([[editor_json valueForKey:@"result"] intValue]==2)
-//                        {
-//                            
-////                            [self.navigationController popViewControllerAnimated:false];
-////                            if(self.returnValue)
-////                            {
-////                                
-////                                self.returnValue(data_init);
-////                            }
-//                            
-//                            
-//                            
-//                        }
-//                        else
-//                        {
-//                            [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Update Order Customer Infomation" controller:self] ;
-//                        }
-//                        
-//                        
-//                        
-//                    });
-//                });
+                //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                //                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                //                    NSDictionary* editor_json = [iSalesNetwork update_OrderCustomer:appDelegate.order_code customerinfo:data_init];
+                //
+                //                    dispatch_async(dispatch_get_main_queue(), ^{
+                //
+                //
+                //                        if([[editor_json valueForKey:@"result"] intValue]==2)
+                //                        {
+                //
+                ////                            [self.navigationController popViewControllerAnimated:false];
+                ////                            if(self.returnValue)
+                ////                            {
+                ////
+                ////                                self.returnValue(data_init);
+                ////                            }
+                //
+                //
+                //
+                //                        }
+                //                        else
+                //                        {
+                //                            [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Update Order Customer Infomation" controller:self] ;
+                //                        }
+                //
+                //
+                //
+                //                    });
+                //                });
                 
             }
             else
             {
                 [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
-//                self.btn_assign.enabled=false;
+                //                self.btn_assign.enabled=false;
             }
             
             
         });
     });
-
-
+    
+    
     
 }
 #pragma mark - Table view data source
@@ -596,7 +738,7 @@ self.label_net_err.hidden=true;
 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
 {
     
-
+    
     if(indexPath.row==self.content_data.count)
         return 44;
     
@@ -605,7 +747,7 @@ self.label_net_err.hidden=true;
     
     float width = tableView.frame.size.width;
     
-//    40+15+8
+    //    40+15+8
     width-=63;
     CGSize constraintkey = CGSizeMake(width-2*LABEL_MARGIN, 10.0f);//key label width is 40% cell width;
     //            CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
@@ -725,7 +867,7 @@ self.label_net_err.hidden=true;
 {
     //    if(tableView==self.itemListTable)
     //    {
-//    DebugLog(@"row %ld",(long)indexPath.row);
+    //    DebugLog(@"row %ld",(long)indexPath.row);
     if(indexPath.row==self.content_data.count)
     {
         UITableViewCell *moreCell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"mores"];
@@ -747,7 +889,7 @@ self.label_net_err.hidden=true;
     }
     else
     {
-// UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ContactListCell"];
+        // UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ContactListCell"];
         
         AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
         NSString *CellIdentifier = @"ContactListTableViewCell";
@@ -759,18 +901,18 @@ self.label_net_err.hidden=true;
         
         cell.btn_assign.hidden = !(self.assig_icon&&(appDelegate.contact_id.length==0));
         
-  /*      NSString* name= [self.content_data[indexPath.row] valueForKey:@"name"];
-        NSString* address= [self.content_data[indexPath.row] valueForKey:@"address"];
-        cell.detailTextLabel.text=address;
-        cell.textLabel.text=name;
-        
-        //cell.sep
-//        [UIColor rg]*/
+        /*      NSString* name= [self.content_data[indexPath.row] valueForKey:@"name"];
+         NSString* address= [self.content_data[indexPath.row] valueForKey:@"address"];
+         cell.detailTextLabel.text=address;
+         cell.textLabel.text=name;
+         
+         //cell.sep
+         //        [UIColor rg]*/
         cell.backgroundColor = [UIColor whiteColor];
-//        cell.separator.backgroundColor = [UIColor grayColor];
+        //        cell.separator.backgroundColor = [UIColor grayColor];
         return cell;
     }
-   
+    
 }
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
@@ -783,8 +925,8 @@ self.label_net_err.hidden=true;
     
     
     bool editable =[[self.content_data[indexPath.row] valueForKey:@"can_update"]boolValue] ;
-   
-
+    
+    
     
     CustomerInfoViewController * vc=[[CustomerInfoViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
     
@@ -793,10 +935,10 @@ self.label_net_err.hidden=true;
     vc.request_url=LOCAL_URL_CUSTOMER_INFO_EDITOR;
     
     vc.update_order = self.update_order;
-            AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
     if(self.ui_type==CONTACT_LIST)
     {
-
+        
         vc.edit_icon = self.edit_icon&&editable&&appDelegate.can_update_contact_info;
         vc.assig_icon = self.assig_icon&&(appDelegate.contact_id.length==0);
         vc.reset_icon = self.reset_icon&&(appDelegate.contact_id.length!=0);
@@ -807,30 +949,30 @@ self.label_net_err.hidden=true;
         vc.assig_icon = self.assig_icon;
         vc.reset_icon = self.reset_icon;
     }
-
     
-//    NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
-//    //            NSString * string = [checked componentsJoinedByString:@","];
-//    //            [params setValue:string forKey:@"cart2Checkbox"];
-//    
-//    
-//    
-//    
-//    addressVC.params = params;
+    
+    //    NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
+    //    //            NSString * string = [checked componentsJoinedByString:@","];
+    //    //            [params setValue:string forKey:@"cart2Checkbox"];
+    //
+    //
+    //
+    //
+    //    addressVC.params = params;
     vc.contactId=contactid;
-//    vc.delegate = self;
+    //    vc.delegate = self;
     
     vc.from = indexPath;
     //            orderinfoVC.params = params;
     vc.returnValue = ^(NSMutableDictionary* value){
         
-
+        
         
         
         value[@"is_subaction"]=self.is_subaction;
         value[@"subaction_tag"]= self.subaction_tag;
         [self.navigationController popViewControllerAnimated:false];
-
+        
         
         if(self.returnValue)
             self.returnValue(value,self.from);
@@ -839,22 +981,22 @@ self.label_net_err.hidden=true;
     
     [self.navigationController pushViewController:vc animated:true];
     
-
+    
 }
 /*
-#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 - 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 - searchBar delegate;
 - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
 {
-
+    
     self.keywords=searchBar.text;
     self.offset = 0;
     [self.content_data removeAllObjects];
@@ -877,7 +1019,7 @@ self.label_net_err.hidden=true;
         NSLog(@"%s removeAllObjects",__func__);
         self.adv_search=nil;
         [self loadpage];
-//        [self loadpage];
+        //        [self loadpage];
     }
     else
         self.reset = false;

+ 25 - 0
RedAnt ERP Mobile/common/Functions/contact/CustomerInfoViewController.m

@@ -388,6 +388,31 @@
 {
     UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Loading Contact information"];
     
+    
+    [RANetwork request_contactinfo:self.contactId completionHandler:^(NSMutableDictionary *result) {
+        NSMutableDictionary* editor_json = result;
+        
+            
+            [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+            
+            if([[editor_json valueForKey:@"result"] intValue]==2)
+            {
+                self.data_init = [[editor_json objectForKey:@"customerInfo" ] mutableCopy];
+                
+                [self fillData];
+                self.btn_assign.enabled=true;
+                
+            }
+            else
+            {
+                [RAUtils message_alert:[editor_json valueForKey:@"err_msg"] title:@"Loading Contact Information" controller:self] ;
+                self.btn_assign.enabled=false;
+            }
+            
+            
+        
+    }];
+    return;
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         
         NSDictionary* editor_json = [RANetwork request_CustomerInfo:self.contactId];

+ 196 - 0
RedAnt ERP Mobile/common/Functions/sidemenu/LoginViewController.m

@@ -244,6 +244,202 @@
     
     self.btnLogin.enabled = false;
     UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait..." title:@"Sign in"];
+    
+    [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
+        int ret=[result[@"result"] intValue];
+        
+        [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];
+                
+                
+                BOOL condition = offline_dirty && offline_user_exist>0;
+                
+#ifdef OFFLINE_MODE
+                condition = condition && !appDelegate.offline_mode;
+#endif
+                if(condition)
+                {
+                    
+                    UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Detected new offline data" message:@"Do you want to sync with server?" preferredStyle:UIAlertControllerStyleAlert];
+                    //block代码块取代了delegate
+                    
+                    
+                    UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Yes(Recommended)" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+                        
+                        
+                        
+                        
+                        UIApplication * app = [UIApplication sharedApplication];
+                        AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+                        //UIViewController* active_vc = appDelegate.active_controller;
+                        OfflineSettingViewController * offlineVC =[ [UIStoryboard storyboardWithName:@"OLM" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflineSettingViewController"];
+                        //    loginvc.delegate = self;
+                        //    loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
+                        //       appDelegate.active_controller = gunVC;
+                        //        gunVC.onDismissVC = ^(){
+                        //            appDelegate.active_controller = active_vc;
+                        //        };
+                        UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:offlineVC] ;
+                        
+                        
+                        
+                        
+                        
+                        //    [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
+                        
+                        navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
+                        [appDelegate.main_vc presentViewController:navi animated:YES completion:^{
+                            
+                            
+                            MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
+                            
+                            [main_vc checklogin:true];
+                            //        navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
+                            
+                            DebugLog(@"about present.........");
+                            
+                            //   self.btop = false;
+                            //  <#code#>
+                        }];
+                        
+                        
+                        
+                        
+                    }];
+                    
+                    UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
+                        
+                        if(self.returnValue)
+                            self.returnValue(true);
+                        [[NSNotificationCenter defaultCenter] postNotificationName:LoginOK_HandleUrgencyFile_Notification object:nil];
+                        
+                    }];
+                    
+                    [alertControl addAction:actionTwo];
+                    [alertControl addAction:alertthree];
+                    
+                    
+                    
+                    [appDelegate.main_vc presentViewController:alertControl animated:YES completion:nil];
+                    
+                    
+                    
+                    
+                }
+                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"];
+            
+            
+            
+        }
+        
+        
+        
+    }];
+    return;
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         
         

+ 89 - 0
RedAnt ERP Mobile/common/Functions/sidemenu/UserListViewController.m

@@ -153,6 +153,95 @@
                 
 //                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
                 
+                [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
+                    int ret=[result[@"result"]intValue];
+                    
+                    
+                    [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+                    
+                    if(ret==RESULT_TRUE)
+                    {
+                        AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                        
+                        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                        [defaults removeObjectForKey:@"user"];
+                        [defaults removeObjectForKey:@"password"];
+                        if(true)
+                        {
+                            NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
+                            NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
+                            
+                            [defaults setValue:encryptu forKey:@"user"];
+                            [defaults setValue:encryptp forKey:@"password"];
+                            
+                        }
+                        [defaults synchronize];
+                        
+                        MainViewController* main_vc=(MainViewController*)appDelegate.main_vc;
+                        if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
+                        {
+                            [main_vc checklogin:false];
+                        }
+                        else
+                        {
+                            [main_vc checklogin:false];
+                        }
+                        
+                        [self dismissViewControllerAnimated:true completion:^{
+                            if(self.returnValue)
+                                self.returnValue(true);
+                        }];
+                        
+                    } // 登陆成功
+                    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;
+                            default:
+                                break;
+                        }
+                        
+                        
+                        UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Switch User" message:msg preferredStyle:UIAlertControllerStyleAlert];
+                        //block代码块取代了delegate
+                        UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
+                            
+                            [self dismissViewControllerAnimated:true completion:^{
+                                if(self.returnValue)
+                                    self.returnValue(false);
+                            }];
+                            
+                        }];
+                        
+                        
+                        [alertControl addAction:actionOne];
+                        
+                        [self presentViewController:alertControl animated:YES completion:nil];
+                        
+                    } // 登陆失败
+                    
+                    
+                }];
+                
                 
                 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
 

+ 39 - 0
RedAnt ERP Mobile/common/Functions/watchlist/WatchListViewController.m

@@ -535,6 +535,45 @@
     
     reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
     
+        [RANetwork request_wishlist:self.sortIndex completionHandler:^(NSMutableDictionary *result) {
+            NSMutableDictionary* cart_json =result;
+            
+                
+                [self.mum stopAnimating];
+                self.isrefreshing=false;
+                if (self.dataOperationQueue.operationCount > 1) {
+                    return ;
+                }
+                
+                int result_code=[[cart_json valueForKey:@"result"] intValue];
+                self.content_data = [cart_json mutableCopy];
+                [self.itemListTable reloadData];
+                self.print_url = [cart_json objectForKey:@"wishlist_print_url"];
+                
+                if(result_code==2||result_code==1||result_code==0)
+                {
+                    self.itemListTable.hidden=false;
+                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
+                    appDelegate.wish_count =[[self.content_data valueForKey:@"count"] intValue];
+                }
+                else
+                    if(result_code==RESULT_NET_ERROR)
+                    {
+                        self.label_net_err.hidden=false;
+                        self.itemListTable.hidden=true;
+                    }
+                else
+                {
+                    [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Wish list" controller:self] ;
+                }
+                
+                self.isrefreshing=false;
+                
+            
+        }];
+        
+        return;
+        
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         
         NSDictionary* cart_json = [RANetwork request_WatchList:self.sortIndex];

+ 8 - 0
RedAnt ERP Mobile/common/data_provider/RANetwork.h

@@ -196,4 +196,12 @@ extern NSString *const ScreenCodeOfflineSync;
 +(void)request_modeldetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName completionHandler:(resultHandler)result;
 
 +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result;
++(void)request_login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result;
++(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result;
+
++(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result;
+
++(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result;
++(void)request_wishlist:(int)sort completionHandler:(resultHandler)result;
+
 @end

+ 345 - 3
RedAnt ERP Mobile/common/data_provider/RANetwork.m

@@ -5382,12 +5382,12 @@ repeat:
     if(jsobj)
     {
         
-        __block AppDelegate *appDelegate = nil;
+        AppDelegate *appDelegate = nil;
         
-        dispatch_sync(dispatch_get_main_queue(), ^{
+
             //some UI methods ej
             appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-        });
+    
         int result = [[jsobj valueForKey:@"result"] intValue];
         
         if (result<0)
@@ -5547,5 +5547,347 @@ repeat:
     
     return RESULT_USERAUTH_ERROR;
 }
++(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result
+{
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    
+    if(upparams!=nil)
+        params = [upparams mutableCopy];
+ AppDelegate *appDelegate = nil;
+    
+
+        //some UI methods ej
+        appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.user forKey:@"user"];
+    
+    if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
+        [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
+    else
+        [params setValue:appDelegate.contact_id forKey:@"contactId"];
+    
+    if(appDelegate.password!=nil)
+        [params setValue:appDelegate.password forKey:@"password"];
+    
+    [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
+    [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
+    [params setValue:contact_type forKey:@"contactType"];
+    [params setValue:keywords forKey:@"keyword"];
+    
+    [params setObject:ScreenCodeAccount forKey:kScreenName];
+    if (keywords) {
+        [params setObject:@"Search" forKey:kAction];
+    }
+    if (upparams) {
+        [params setObject:@"Advance Search" forKey:kAction];
+    }
+    
+    NSString* url=nil;
+    if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
+        url=URL_SHIPTO_LIST;
+    else
+        url=URL_CONTACT_LIST;
+    
+    
+    
+    if(appDelegate.offline_mode)
+    {
+                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_contactlist:params] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                result(json);
+            });
+        });
+        
+        return;
+
+    }
+    [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
+    
+    
+//
+//    if(appDelegate.offline_mode)
+//        return [OLDataProvider offline_contactlist:params];
+//
+//    if(![self IsNetworkAvailable])
+//        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//    NSData* json=[self get_json:url parameters:params];
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+}
+
++(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result
+{
+    
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+     AppDelegate *appDelegate = nil;
+    
+    
+        appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+    
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.user forKey:@"user"];
+    //    if(appDelegate.contact_id!=nil)
+    
+    if(appDelegate.password!=nil)
+        [params setValue:appDelegate.password forKey:@"password"];
+    [params setValue:contactid forKey:@"contactId"];
+    
+    [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
+    
+    
+    if(appDelegate.offline_mode)
+    {
+                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_contactinfo:params] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                result(json);
+            });
+        });
+        
+        return;
+
+    }
+    [self request_interface:URL_CUSTOMER_INFO parameters:params err_record_url:nil completionHandler:result retry:0];
+    
+    
+    
+//    if(appDelegate.offline_mode)
+//        return [OLDataProvider offline_contactinfo:params];
+//    if(![self IsNetworkAvailable])
+//        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//    NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+//
+}
++(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
+{
+    //    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+     AppDelegate *appDelegate = nil;
+    
+        appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.user forKey:@"user"];
+    
+    
+    //    if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
+    //        [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
+    //    else
+    
+    if(appDelegate.contact_id!=nil)
+        [params setValue:appDelegate.contact_id forKey:@"contactId"];
+    if(appDelegate.password!=nil)
+        [params setValue:appDelegate.password forKey:@"password"];
+    
+    if(appDelegate.order_code!=nil)
+        [params setValue:appDelegate.order_code forKey:@"orderCode"];
+    //    [params setValue:sourceid forKey:@"sourceid"];
+    //    [params setValue:editor forKey:@"editor"];
+    DebugLog(@"request editor url:%@",request_url);
+    
+    
+    if([request_url isEqualToString:URL_NEW_CUSTOMER])
+    {
+        [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
+    }
+    else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
+    {
+        [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
+    }
+    else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
+    {
+        [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
+    }
+    else if([request_url isEqualToString:URL_CARTDELIVERY])
+    {
+        [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
+    }
+    else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
+    {
+        [params setObject:ScreenCodeNewAddress forKey:kScreenName];
+    }
+    else if ([request_url isEqualToString:URL_DM_PARAMS]){
+        [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
+    }
+    
+    
+    if(appDelegate.offline_mode)
+    {
+        
+                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                    
+                    NSData* json = nil;
+            if([request_url isEqualToString:URL_NEW_CUSTOMER])
+            {
+                json= [OLDataProvider offline_createContact:params];
+            }
+            else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
+            {
+                json= [OLDataProvider offline_editContact:params];
+            }
+            else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
+            {
+                json= [OLDataProvider offline_contactAdvancedSearch:params];
+            }
+            else if([request_url isEqualToString:URL_CARTDELIVERY])
+            {
+                json= [OLDataProvider offline_placeorder:params];
+            }
+            else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
+            {
+                json= [OLDataProvider offline_addreditor:params];
+            }
+            else if ([request_url isEqualToString:URL_DM_PARAMS]){
+                json = [OLDataProvider offline_createTearSheet:params];
+            }
+            
+
+            dispatch_async(dispatch_get_main_queue(), ^{
+                
+                if(json==nil)
+                    result( [[OLDataProvider offline_notimpl] mutableCopy]);
+                else
+                    result([[RAConvertor data2dict:json] mutableCopy]);
+            });
+        });
+        
+        return;
+        
+        
+    }
+    else
+    {
+        
+        
+        if([request_url isEqualToString:URL_CARTDELIVERY])
+        {
+
+            
+            NSString * uuid= [[NSUUID UUID] UUIDString];
+            params[@"resultSerial"]=uuid;
+            __block bool bbreak = false;
+            for(int i=0;i<150;i++)
+            {
+                //           NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
+                //            result_params[@"resultSerial"]=uuid;
+                //json=[self get_json:request_url parameters:params];
+                if(bbreak)
+                    break;
+                
+                [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
+                    if(resulti!=nil)
+                    {
+                        
+                        
+                        if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
+                        {
+                            result(resulti);
+                            bbreak=true;
+                        }
+                    }
+                    
+                } retry:0];
+                
+//                [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
+                
+                sleep(2);
+            }
+        }
+        else
+            [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
+    }
+//    if(json!=nil)
+//    {
+//        NSError *error=nil;
+//        NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//        return jsobj;
+//    }
+//    else
+//        return nil;
+}
+
++(void)request_wishlist:(int)sort completionHandler:(resultHandler)result
+{
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+    AppDelegate *appDelegate = nil;
+    
+
+        appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
+
+    if(appDelegate.user!=nil)
+        [params setValue:appDelegate.user forKey:@"user"];
+    if(appDelegate.contact_id!=nil)
+        [params setValue:appDelegate.contact_id forKey:@"contactId"];
+    if(appDelegate.password!=nil)
+        [params setValue:appDelegate.password forKey:@"password"];
+    
+    [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
+    [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
+    
+    [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
+    
+    [params setObject:ScreenCodeWishList forKey:kScreenName];
+    
+    
+    
+    if(appDelegate.offline_mode)
+    {
+                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_wishlist:params] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                result(json);
+            });
+        });
+        
+        return;
+
+    }
+    [self request_interface:URL_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
+        appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
+        //    appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
+        
+        [appDelegate update_count_mark];;
+        result(resulti);
+    }  retry:0];
+    
+    
+    
+//    if(appDelegate.offline_mode)
+//    {
+//        return [OLDataProvider offline_wishlist:params];
+//    }
+//    if(![self IsNetworkAvailable])
+//        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//    NSData* json=[self get_json:URL_WATCHLIST parameters:params];
+//    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.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
+//        appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
+//        //    appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
+//
+//        [appDelegate update_count_mark];
+//    }
+//    return jsobj;
+}
 
 @end