瀏覽代碼

新增ERP Mobile portfolio model 数据访问接口,并修改相关调用。
新增ERP Mobile portfolio pdf 数据访问接口,并修改相关调用。
新增ERP Mobile order 列表数据访问接口,并修改相关调用。

Ray Zhang 6 年之前
父節點
當前提交
067719040c

+ 94 - 46
RedAnt ERP Mobile/common/Functions/MainViewController.m

@@ -660,54 +660,102 @@
     if(appDelegate.bLogin)
     {
         UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Sign out"];
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-            
-            NSDictionary* return_json = [RANetwork logout];
+        
+        [RANetwork request_logout:^(NSMutableDictionary *result) {
+            NSMutableDictionary* return_json =result;
             
-            dispatch_async(dispatch_get_main_queue(), ^{
-                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-                
-                
-                if([[return_json valueForKey:@"result"] intValue]==2)
-                {
-//                    [self hideMenu];
-//                    [self switchToHome:nil];
-                    [appDelegate Logout];
-                    [self checklogin :false];
-                    if(showlogin)
-                    {
-                    LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
-                    loginvc.returnValue = ^(bool blogin){
-                        
-                        [self checklogin :true];
-                        
-                    };
-                    
-                    UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
-                    
-                    
-                    
-                    
-                    
-                    
-                    navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
-                    [self presentViewController:navi animated:YES completion:^{
-                        
-                        DebugLog(@"login present.........");
+                            [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+                            
+                            
+                            if([[return_json valueForKey:@"result"] intValue]==2)
+                            {
+            //                    [self hideMenu];
+            //                    [self switchToHome:nil];
+                                [appDelegate Logout];
+                                [self checklogin :false];
+                                if(showlogin)
+                                {
+                                LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
+                                loginvc.returnValue = ^(bool blogin){
+                                    
+                                    [self checklogin :true];
+                                    
+                                };
+                                
+                                UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
+                                
+                                
+                                
+                                
+                                
+                                
+                                navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
+                                [self presentViewController:navi animated:YES completion:^{
+                                    
+                                    DebugLog(@"login present.........");
+                                    
+                                }];
+                                }
+                            }
+                            else
+                            {
+                                [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
+                            }
+                            
+                            
+                            
+                            
                         
-                    }];
-                    }
-                }
-                else
-                {
-                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
-                }
-                
-                
-                
-                
-            });
-        });
+        }];
+        
+//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//            
+//            NSDictionary* return_json = [RANetwork logout];
+//            
+//            dispatch_async(dispatch_get_main_queue(), ^{
+//                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+//                
+//                
+//                if([[return_json valueForKey:@"result"] intValue]==2)
+//                {
+////                    [self hideMenu];
+////                    [self switchToHome:nil];
+//                    [appDelegate Logout];
+//                    [self checklogin :false];
+//                    if(showlogin)
+//                    {
+//                    LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
+//                    loginvc.returnValue = ^(bool blogin){
+//                        
+//                        [self checklogin :true];
+//                        
+//                    };
+//                    
+//                    UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
+//                    
+//                    
+//                    
+//                    
+//                    
+//                    
+//                    navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
+//                    [self presentViewController:navi animated:YES completion:^{
+//                        
+//                        DebugLog(@"login present.........");
+//                        
+//                    }];
+//                    }
+//                }
+//                else
+//                {
+//                    [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
+//                }
+//                
+//                
+//                
+//                
+//            });
+//        });
     }
     else
     {

+ 187 - 81
RedAnt ERP Mobile/common/Functions/offline/OfflineSettingViewController.m

@@ -440,61 +440,117 @@
         if(appDelegate.bLogin)
         {
             UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Sign out"];
-            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            
+            [RANetwork request_logout:^(NSMutableDictionary *result) {
+                NSMutableDictionary* return_json=result ;
                 
-                NSDictionary* return_json = [RANetwork logout];
+                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
                 
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+                
+                if([[return_json valueForKey:@"result"] intValue]==2)
+                {
                     
+                    [appDelegate Logout];
+                    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                    [defaults removeObjectForKey:@"EnableOfflineMode"];
+                    [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
                     
-                    if([[return_json valueForKey:@"result"] intValue]==2)
-                    {
-
-                        [appDelegate Logout];
-                        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-                        [defaults removeObjectForKey:@"EnableOfflineMode"];
-                        [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
-                        
-                        [defaults synchronize];
+                    [defaults synchronize];
 #ifdef OFFLINE_MODE
-                        appDelegate.offline_mode =self.switch_offline.isOn;
+                    appDelegate.offline_mode =self.switch_offline.isOn;
 #endif
-
+                    
 #ifdef RA_NOTIFICATION
-                        
-                        [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                    
+                    [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
 #else
-                        [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
-                        [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
-                        
-                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-                        [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
-                        [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
-                        
-//                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-                        
-                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-                        [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
-//                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-                        
-                        
-#endif
-                        
-
-                        
-                        [((MainViewController*)appDelegate.main_vc) switchToHome];
-                    }
-                    else
-                    {
-                       // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
-                    }
+                    [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
+                    [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
                     
+                    [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+                    [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
+                    [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+                    
+                    //                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+                    
+                    [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+                    [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
+                    //                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+                    
+                    
+#endif
                     
                     
                     
-                });
-            });
+                    [((MainViewController*)appDelegate.main_vc) switchToHome];
+                }
+                else
+                {
+                    // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
+                }
+                
+                
+                
+                
+                
+            }];
+            
+            
+//            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//
+//                NSDictionary* return_json = [RANetwork logout];
+//
+//                dispatch_async(dispatch_get_main_queue(), ^{
+//                    [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+//
+//
+//                    if([[return_json valueForKey:@"result"] intValue]==2)
+//                    {
+//
+//                        [appDelegate Logout];
+//                        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+//                        [defaults removeObjectForKey:@"EnableOfflineMode"];
+//                        [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
+//
+//                        [defaults synchronize];
+//#ifdef OFFLINE_MODE
+//                        appDelegate.offline_mode =self.switch_offline.isOn;
+//#endif
+//
+//#ifdef RA_NOTIFICATION
+//
+//                        [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+//#else
+//                        [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
+//                        [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
+//
+//                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+//                        [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
+//                        [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+//
+////                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+//
+//                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+//                        [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
+////                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+//
+//
+//#endif
+//
+//
+//
+//                        [((MainViewController*)appDelegate.main_vc) switchToHome];
+//                    }
+//                    else
+//                    {
+//                       // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
+//                    }
+//
+//
+//
+//
+//                });
+//            });
         }
         else
         {
@@ -536,57 +592,107 @@
             if(appDelegate.bLogin)
             {
                 UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Sign out"];
-                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+                [RANetwork request_logout:^(NSMutableDictionary *result) {
+                    NSMutableDictionary* return_json = result;
+                    
+                    [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
                     
-                    NSDictionary* return_json = [RANetwork logout];
                     
-                    dispatch_async(dispatch_get_main_queue(), ^{
-                        [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+                    if([[return_json valueForKey:@"result"] intValue]==2)
+                    {
                         
+                        [appDelegate Logout];
                         
-                        if([[return_json valueForKey:@"result"] intValue]==2)
-                        {
-                            
-                            [appDelegate Logout];
-                            
-                            NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
-                            [defaults removeObjectForKey:@"EnableOfflineMode"];
-                            [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
-                            
-                            [defaults synchronize];
+                        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                        [defaults removeObjectForKey:@"EnableOfflineMode"];
+                        [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
+                        
+                        [defaults synchronize];
 #ifdef OFFLINE_MODE
-                            appDelegate.offline_mode =self.switch_offline.isOn;
+                        appDelegate.offline_mode =self.switch_offline.isOn;
 #endif
-
+                        
 #ifdef RA_NOTIFICATION
-                            [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+                        [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
 #else
-                            [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
-                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-                            [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
-                            [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
-                            [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
-//                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
-                            [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
-                            [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
-//                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+                        [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
+                        [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+                        [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
+                        [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+                        [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
+                        //                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+                        [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+                        [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
+                        //                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
 #endif
-                            
-
-                            
-                            
-                            [((MainViewController*)appDelegate.main_vc) switchToHome];
-                        }
-                        else
-                        {
-                            // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
-                        }
                         
                         
                         
                         
-                    });
-                });
+                        [((MainViewController*)appDelegate.main_vc) switchToHome];
+                    }
+                    else
+                    {
+                        // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
+                    }
+                    
+                    
+                    
+                    
+                    
+                }];
+                
+//                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//
+//                    NSDictionary* return_json = [RANetwork logout];
+//
+//                    dispatch_async(dispatch_get_main_queue(), ^{
+//                        [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+//
+//
+//                        if([[return_json valueForKey:@"result"] intValue]==2)
+//                        {
+//
+//                            [appDelegate Logout];
+//
+//                            NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+//                            [defaults removeObjectForKey:@"EnableOfflineMode"];
+//                            [defaults setBool:self.switch_offline.isOn forKey:@"EnableOfflineMode"];
+//
+//                            [defaults synchronize];
+//#ifdef OFFLINE_MODE
+//                            appDelegate.offline_mode =self.switch_offline.isOn;
+//#endif
+//
+//#ifdef RA_NOTIFICATION
+//                            [ActiveViewController Notify:@"PortfolioViewController,WatchListViewController,CategoryViewController,PDFListViewController,CartViewController,OrderListViewController,ContactListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
+//#else
+//                            [((MainViewController*)appDelegate.main_vc) reloadPortfolio:true immediately:false];
+//                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+//                            [((MainViewController*)appDelegate.main_vc) reloadDocuments:true immediately:false];
+//                            [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
+//                            [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
+////                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+//                            [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
+//                            [((MainViewController*)appDelegate.main_vc) reloadContact:true immediately:false];
+////                            [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:false];
+//#endif
+//
+//
+//
+//
+//                            [((MainViewController*)appDelegate.main_vc) switchToHome];
+//                        }
+//                        else
+//                        {
+//                            // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Sign Out" controller:self] ;
+//                        }
+//
+//
+//
+//
+//                    });
+//                });
             }
         }
         else

+ 93 - 21
RedAnt ERP Mobile/common/Functions/order/OrderListViewController.m

@@ -540,27 +540,25 @@
         
         NSString * str_status = [arr_status componentsJoinedByString:@","];
     
-    BOOL isMerged = NO;
-    __block AppDelegate *appDelegate = nil;
+    
+     
+    
     
     dispatch_sync(dispatch_get_main_queue(), ^{
-        //some UI methods ej
+        BOOL isMerged = NO;
+        AppDelegate *appDelegate = nil;
         appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
-    });
-    if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
-        if (self.orderType == 0) {
-            isMerged = NO;
-        } else {
-            isMerged = YES;
+        if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
+            if (self.orderType == 0) {
+                isMerged = NO;
+            } else {
+                isMerged = YES;
+            }
         }
-    }
-    
-    
-        NSMutableDictionary* content=nil;
-        content=[[RANetwork request_OrderList:self.offset limit : self.limit keywords:self.keywords status:str_status customer:self.customer_id is_merged:isMerged] mutableCopy];
-    
         
-        dispatch_sync(dispatch_get_main_queue(), ^{
+        [RANetwork request_orderlist:self.offset limit:self.limit keywords:self.keywords status:str_status customer:self.customer_id is_merged:isMerged completionHandler:^(NSMutableDictionary *result) {
+            NSMutableDictionary* content=result;
+            
             
             
             
@@ -571,9 +569,9 @@
             if (self.dataOperationQueue.operationCount > 1) { // 队列后面还有操作
                 return ;
             }
-            int result=[[content valueForKey:@"result"] intValue];
+            int result_code=[[content valueForKey:@"result"] intValue];
             
-            if(result==2||result==0)
+            if(result_code==2||result_code==0)
             {
                 
                 
@@ -610,7 +608,7 @@
                 self.reset_result=false;
                 [self.table_order reloadData ];
             }
-            else if(result==RESULT_NET_ERROR &&self.offset==0)
+            else if(result_code==RESULT_NET_ERROR &&self.offset==0)
             {
                 self.label_net_err.hidden=false;
                 self.table_order.hidden = true;
@@ -620,11 +618,85 @@
                 [RAUtils message_alert:[content valueForKey:@"err_msg"]  title:@"Loading Order List" controller:self] ;
             }
             
-    
             
             
-        });
+            
+            
+            
+        }];
         
+    });
+    
+//
+//        NSMutableDictionary* content=nil;
+//        content=[[RANetwork request_OrderList:self.offset limit : self.limit keywords:self.keywords status:str_status customer:self.customer_id is_merged:isMerged] 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)
+//            {
+//
+//
+//                int count = [[content valueForKey:@"count" ] intValue] ;
+//
+//
+//                self.time_zone = [content valueForKey:@"time_zone" ];
+//                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_order.hidden = false;
+//                self.reset_result=false;
+//                [self.table_order reloadData ];
+//            }
+//            else if(result==RESULT_NET_ERROR &&self.offset==0)
+//            {
+//                self.label_net_err.hidden=false;
+//                self.table_order.hidden = true;
+//            }
+//            else
+//            {
+//                [RAUtils message_alert:[content valueForKey:@"err_msg"]  title:@"Loading Order List" controller:self] ;
+//            }
+//
+//
+//
+//
+//        });
+//
         
 //    });
 }

+ 60 - 0
RedAnt ERP Mobile/common/Functions/portfolio/PortfolioListViewController.m

@@ -167,6 +167,66 @@
         
         self.mum.hidden = false;
         [self.mum startAnimating];
+        
+        
+        [RANetwork request_portfoliopdf:self.offset limit:self.limit keywords:self.keywords completionHandler:^(NSMutableDictionary *result) {
+           NSMutableDictionary* content= result;
+            [self.mum stopAnimating];
+                      
+                      int result_code=[[content valueForKey:@"result"] intValue];
+                      
+                      if(result_code==2||result_code==0)
+                      {
+                          self.table.hidden =false;
+                          
+                          int count = [[content valueForKey:@"count" ] intValue] ;
+                          
+                          
+                         // self.time_zone = [content valueForKey:@"time_zone" ];
+                          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]];
+                              DebugLog(@"content_data: %@",self.content_data);
+                          }
+                          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 ];
+                      }
+                      else if(result_code==RESULT_NET_ERROR)
+                      {
+                          self.label_net_err.hidden=false;
+                          self.table.hidden=true;
+                      }
+                      else
+                      {
+                          [RAUtils message_alert:[content valueForKey:@"err_msg"]  title:@"Loading Portfilio List" controller:self] ;
+                      }
+                      
+                      
+                     
+                      self.isrefreshing=false;
+        }];
+        
+        return;
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         
         

+ 63 - 30
RedAnt ERP Mobile/common/Functions/portfolio/PortfolioViewController.m

@@ -2012,42 +2012,75 @@ commitEditingStyle:(UITableViewCellEditingStyle)editingStyle  forRowAtIndexPath:
         
         reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
         
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        [RANetwork request_portfolio:self.sortIndex completionHandler:^(NSMutableDictionary *result) {
+            NSMutableDictionary* cart_json =result;
+            [self.mum stopAnimating];
             
-            NSDictionary* cart_json = [RANetwork request_Portfolio:self.sortIndex];
+            int result_code=[[cart_json valueForKey:@"result"] intValue];
             
-            dispatch_async(dispatch_get_main_queue(), ^{
-                [self.mum stopAnimating];
-                
-                int result=[[cart_json valueForKey:@"result"] intValue];
+            if(result_code==2||result_code==1||result_code==0)
+            {
+                self.itemListTable.hidden=false;
+                self.content_data = [cart_json mutableCopy];
+                [self.itemListTable reloadData];
                 
-                if(result==2||result==1||result==0)
+                [self initCheckedCount];
+                [self.btnselect setTitle: @"Deselect all"];
+                UIApplication * app = [UIApplication sharedApplication];
+                AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+                appDelegate.port_count =[[self.content_data valueForKey:@"count"] intValue];
+            }
+            else
+                if(result_code==RESULT_NET_ERROR)
                 {
-                    self.itemListTable.hidden=false;
-                    self.content_data = [cart_json mutableCopy];
-                    [self.itemListTable reloadData];
-                    
-                    [self initCheckedCount];
-                    [self.btnselect setTitle: @"Deselect all"];
-                    UIApplication * app = [UIApplication sharedApplication];
-                    AppDelegate *appDelegate = (AppDelegate *)[app delegate];
-                    appDelegate.port_count =[[self.content_data valueForKey:@"count"] intValue];
+                    self.label_net_err.hidden=false;
+                    self.itemListTable.hidden=true;
                 }
                 else
-                    if(result==RESULT_NET_ERROR)
-                    {
-                        self.label_net_err.hidden=false;
-                        self.itemListTable.hidden=true;
-                    }
-                    else
-                    {
-                        [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Portfolio" controller:self] ;
-                    }
-                
-                self.isrefreshing=false;
-                
-            });
-        });
+                {
+                    [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Portfolio" controller:self] ;
+                }
+            
+            self.isrefreshing=false;
+        }];
+        
+//        return;
+//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//
+//            NSDictionary* cart_json = [RANetwork request_Portfolio:self.sortIndex];
+//
+//            dispatch_async(dispatch_get_main_queue(), ^{
+//                [self.mum stopAnimating];
+//
+//                int result=[[cart_json valueForKey:@"result"] intValue];
+//
+//                if(result==2||result==1||result==0)
+//                {
+//                    self.itemListTable.hidden=false;
+//                    self.content_data = [cart_json mutableCopy];
+//                    [self.itemListTable reloadData];
+//
+//                    [self initCheckedCount];
+//                    [self.btnselect setTitle: @"Deselect all"];
+//                    UIApplication * app = [UIApplication sharedApplication];
+//                    AppDelegate *appDelegate = (AppDelegate *)[app delegate];
+//                    appDelegate.port_count =[[self.content_data valueForKey:@"count"] intValue];
+//                }
+//                else
+//                    if(result==RESULT_NET_ERROR)
+//                    {
+//                        self.label_net_err.hidden=false;
+//                        self.itemListTable.hidden=true;
+//                    }
+//                    else
+//                    {
+//                        [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Portfolio" controller:self] ;
+//                    }
+//
+//                self.isrefreshing=false;
+//
+//            });
+//        });
     });
     
     

+ 432 - 207
RedAnt ERP Mobile/common/Functions/sidemenu/UserListViewController.m

@@ -111,233 +111,458 @@
         }
         
         UIAlertView * waitalert = [RAUtils waiting_alert:@"Please wait" title:@"Switch user"];
-        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+        
+        [RANetwork request_logout:^(NSMutableDictionary *result) {
             
-            [RANetwork logout];
             
-            dispatch_async(dispatch_get_main_queue(), ^{
-                
-                
-                appDelegate.cart_count = 0;
-                appDelegate.wish_count =0;
-                appDelegate.port_count =0;
-                
-                [appDelegate update_count_mark];
-                
-                
-                appDelegate.can_show_price =false;
-                appDelegate.can_see_price =false;
-                appDelegate.can_create_portfolio =false;
-                appDelegate.can_create_order =false;
-                
-                
-                appDelegate.can_cancel_order =false;
-                appDelegate.can_set_cart_price =false;
-                appDelegate.can_delete_order =false;
-                appDelegate.can_submit_order =false;
-                appDelegate.can_set_tearsheet_price =false;
-                appDelegate.can_update_contact_info = false;
-                
-                appDelegate.save_order_logout = false;
-                appDelegate.submit_order_logout = false;
-                appDelegate.alert_sold_in_quantities = false;
-                
-                appDelegate.ipad_perm =nil ;
-                appDelegate.user_type = USER_ROLE_UNKNOWN;
-                appDelegate.OrderFilter= nil;
-                [appDelegate SetSo:nil];
-                [appDelegate set_main_button_panel];
+            
+            appDelegate.cart_count = 0;
+            appDelegate.wish_count =0;
+            appDelegate.port_count =0;
+            
+            [appDelegate update_count_mark];
+            
+            
+            appDelegate.can_show_price =false;
+            appDelegate.can_see_price =false;
+            appDelegate.can_create_portfolio =false;
+            appDelegate.can_create_order =false;
+            
+            
+            appDelegate.can_cancel_order =false;
+            appDelegate.can_set_cart_price =false;
+            appDelegate.can_delete_order =false;
+            appDelegate.can_submit_order =false;
+            appDelegate.can_set_tearsheet_price =false;
+            appDelegate.can_update_contact_info = false;
+            
+            appDelegate.save_order_logout = false;
+            appDelegate.submit_order_logout = false;
+            appDelegate.alert_sold_in_quantities = false;
+            
+            appDelegate.ipad_perm =nil ;
+            appDelegate.user_type = USER_ROLE_UNKNOWN;
+            appDelegate.OrderFilter= nil;
+            [appDelegate SetSo:nil];
+            [appDelegate set_main_button_panel];
+            
+            [appDelegate Logout];
+            [appDelegate checkLogin:NO];
+            
+            //                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+            
+            [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
+                int ret=[result[@"result"]intValue];
                 
-                [appDelegate Logout];
-                [appDelegate checkLogin:NO];
                 
-//                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
+                [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
                 
-                [RANetwork request_login:user password:password completionHandler:^(NSMutableDictionary *result) {
-                    int ret=[result[@"result"]intValue];
-                    
+                if(ret==RESULT_TRUE)
+                {
+                    AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
                     
-                    [waitalert dismissWithClickedButtonIndex:0 animated:FALSE];
-                    
-                    if(ret==RESULT_TRUE)
+                    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+                    [defaults removeObjectForKey:@"user"];
+                    [defaults removeObjectForKey:@"password"];
+                    if(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];
+                        NSString* encryptu=[AESCrypt encrypt:appDelegate.user password:@"usai"];
+                        NSString* encryptp=[AESCrypt encrypt:appDelegate.password password:@"usai"] ;
                         
-                        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);
-                        }];
+                        [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
                     {
-                        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) {
+                        [main_vc checklogin:false];
+                    }
+                    
+                    [self dismissViewControllerAnimated:true completion:^{
+                        if(self.returnValue)
+                            self.returnValue(true);
+                    }];
+                    
+                } // 登陆成功
+                else
+                {
+                    NSString* msg=nil;
+                    
+                    switch (ret) {
                             
-                            [self dismissViewControllerAnimated:true completion:^{
-                                if(self.returnValue)
-                                    self.returnValue(false);
-                            }];
+                        case RESULT_NET_NOTAVAILABLE:
+                            msg = MSG_NET_NOTAVAILABLE;
+                            break;
                             
-                        }];
-                        
-                        
-                        [alertControl addAction:actionOne];
+                            
+                        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 presentViewController:alertControl animated:YES completion:nil];
+                        [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), ^{
-
-                    int ret=[RANetwork  Authorize:user password:password];
-
-                    dispatch_async(dispatch_get_main_queue(), ^{
-                        
-                        [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];
-
-                        } // 登陆失败
-
-                    }); // update login ui
-
-                }); // attemp login
-
-            }); // update logout ui
+            }];
             
-        }); // logout
+            
+            //                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            //
+            //                    int ret=[RANetwork  Authorize:user password:password];
+            //
+            //                    dispatch_async(dispatch_get_main_queue(), ^{
+            //
+            //                        [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];
+            //
+            //                        } // 登陆失败
+            //
+            //                    }); // update login ui
+            //
+            //                }); // attemp login
+            
+            
+        }];
+        
+//        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+//
+//            [RANetwork logout];
+//
+//            dispatch_async(dispatch_get_main_queue(), ^{
+//
+//
+//                appDelegate.cart_count = 0;
+//                appDelegate.wish_count =0;
+//                appDelegate.port_count =0;
+//
+//                [appDelegate update_count_mark];
+//
+//
+//                appDelegate.can_show_price =false;
+//                appDelegate.can_see_price =false;
+//                appDelegate.can_create_portfolio =false;
+//                appDelegate.can_create_order =false;
+//
+//
+//                appDelegate.can_cancel_order =false;
+//                appDelegate.can_set_cart_price =false;
+//                appDelegate.can_delete_order =false;
+//                appDelegate.can_submit_order =false;
+//                appDelegate.can_set_tearsheet_price =false;
+//                appDelegate.can_update_contact_info = false;
+//
+//                appDelegate.save_order_logout = false;
+//                appDelegate.submit_order_logout = false;
+//                appDelegate.alert_sold_in_quantities = false;
+//
+//                appDelegate.ipad_perm =nil ;
+//                appDelegate.user_type = USER_ROLE_UNKNOWN;
+//                appDelegate.OrderFilter= nil;
+//                [appDelegate SetSo:nil];
+//                [appDelegate set_main_button_panel];
+//
+//                [appDelegate Logout];
+//                [appDelegate checkLogin:NO];
+//
+////                [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), ^{
+////
+////                    int ret=[RANetwork  Authorize:user password:password];
+////
+////                    dispatch_async(dispatch_get_main_queue(), ^{
+////
+////                        [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];
+////
+////                        } // 登陆失败
+////
+////                    }); // update login ui
+////
+////                }); // attemp login
+//
+//            }); // update logout ui
+//
+//        }); // logout
     }
     
     

+ 4 - 1
RedAnt ERP Mobile/common/data_provider/RANetwork.h

@@ -203,5 +203,8 @@ extern NSString *const ScreenCodeOfflineSync;
 
 +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result;
 +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result;
-
++(void)request_portfolio:(int)sort completionHandler:(resultHandler)result;
++(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result;
++(void)request_orderlist:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged completionHandler:(resultHandler)result;
++(void)request_logout:(resultHandler)result;
 @end

+ 354 - 0
RedAnt ERP Mobile/common/data_provider/RANetwork.m

@@ -5889,5 +5889,359 @@ repeat:
 //    }
 //    return jsobj;
 }
++(void)request_portfolio:(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:ScreenCodePortfolio forKey:kScreenName];
+    
+    
+    if(appDelegate.offline_mode)
+    {
+                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_portfolioList:params] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                if ([json[@"result"] intValue]==2)
+                {
+                appDelegate.port_count =[[json valueForKey:@"count"] intValue];
+                
+                [appDelegate update_count_mark];
+                }
+                result(json);
+            });
+        });
+        
+        return;
+
+    }
+    [self request_interface:URL_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
+        
+        if ([resulti[@"result"] intValue]==2)
+        {
+        appDelegate.port_count =[[resulti valueForKey:@"count"] intValue];
+        
+        [appDelegate update_count_mark];
+        }
+        result(resulti);
+    } retry:0];
+    
+    
+//    NSData* json = nil;
+//    if(appDelegate.offline_mode)
+//    {
+//        json = [OLDataProvider offline_portfolioList:params];
+//    } else {
+//        if(![self IsNetworkAvailable])
+//            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//        json = [self get_json:URL_PORTFOLIO 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:@"count"] intValue];
+//
+//        [appDelegate update_count_mark];
+//    }
+//    return jsobj;
+}
+
++(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords 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",price_template]  forKey:@"price_template"];
+    //    [params setValue:[NSString stringWithFormat:@"%d",customid]  forKey:@"custom_id"];
+    //    [params setValue:[NSString stringWithFormat:@"%@",category]  forKey:@"category"];
+    //    [params setValue:[NSString stringWithFormat:@"%d",sort_by]  forKey:@"sort_by"];
+    //    [params setValue:filter forKey:@"filter"];
+    [params setValue:keywords forKey:@"keyWord"];
+    
+    [params setValue:[NSString stringWithFormat:@"%d",limit]  forKey:@"limit"];
+    [params setValue:[NSString stringWithFormat:@"%d",offset]  forKey:@"offset"];
 
+    [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
+    if (keywords) {
+        [params setObject:@"Search" forKey:kAction];
+    }
+    
+    
+    if(appDelegate.offline_mode)
+    {
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_pdfList:params] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                result(json);
+            });
+        });
+        
+        return;
+    }
+    
+    
+    [self request_interface:URL_DM_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
+    
+    return;
+    
+//    NSData* json = nil;
+//    if(appDelegate.offline_mode)
+//    {
+//        json = [OLDataProvider offline_pdfList:params];
+//    } else {
+//        if(![self IsNetworkAvailable])
+//            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//        json=[self get_json:URL_DM_LIST parameters:params];
+//    }
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+    
+}
++(void)request_orderlist:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged completionHandler:(resultHandler)result
+{
+    
+    
+    
+    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
+     AppDelegate *appDelegate = nil;
+    
+
+        //some UI methods ej
+        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",offset ] forKey:@"offset"];
+    [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
+    [params setValue:keywords forKey:@"keyWord"];
+    [params setValue:customer forKey:@"customer_filter"];
+    [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
+    
+    [params setValue:status_code forKey:@"orderStatus"];
+    
+    [params setObject:ScreenCodeOrderList forKey:kScreenName];
+    if (keywords) {
+        [params setObject:@"Search" forKey:kAction];
+    }
+  
+    
+    if(appDelegate.offline_mode)
+    {
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_orderlist:params] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                result(json);
+            });
+        });
+        
+        return;
+    }
+    
+    
+    [self request_interface:URL_ORDER_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
+    
+//    NSData* json=nil;
+//    if(appDelegate.offline_mode)
+//    {
+//        json= [OLDataProvider offline_orderlist:params];
+//    }
+//    else
+//    {
+//        if(![self IsNetworkAvailable])
+//            return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//
+//        json=[self get_json:URL_ORDER_LIST parameters:params];
+//    }
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    return jsobj;
+}
+
+
++(void)request_logout:(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.password!=nil)
+        [params setValue:appDelegate.password forKey:@"password"];
+    
+    
+    
+    if(appDelegate.offline_mode)
+    {
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            NSMutableDictionary* json = [[OLDataProvider offline_logout:params] mutableCopy];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                result(json);
+            });
+        });
+        
+        return;
+    }
+    
+    
+    [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
+        NSMutableDictionary* jsobj=resulti;
+         int result_code = [[jsobj valueForKey:@"result"] intValue];
+            
+            if (result_code==2)
+            {
+                
+                appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
+                appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
+                appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
+                
+                [appDelegate update_count_mark];
+                
+                
+                appDelegate.can_show_price =false;
+                appDelegate.can_see_price =false;
+                appDelegate.can_create_portfolio =false;
+                appDelegate.can_create_order =false;
+                
+                
+                appDelegate.can_cancel_order =false;
+                appDelegate.can_set_cart_price =false;
+                appDelegate.can_delete_order =false;
+                appDelegate.can_submit_order =false;
+                appDelegate.can_set_tearsheet_price =false;
+                appDelegate.can_update_contact_info = false;
+                
+                appDelegate.save_order_logout = false;
+                appDelegate.submit_order_logout = false;
+                appDelegate.alert_sold_in_quantities = false;
+                
+                appDelegate.ipad_perm =nil ;
+                appDelegate.user_type = USER_ROLE_UNKNOWN;
+                appDelegate.OrderFilter= nil;
+                [appDelegate SetSo:nil];
+                [appDelegate set_main_button_panel];
+        #ifdef RA_NOTIFICATION
+                [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
+        #endif
+            }
+        result(resulti);
+    } retry:0];
+//
+//    if(appDelegate.offline_mode)
+//    {
+//        return [OLDataProvider offline_logout:params];
+//    }
+//    if(![self IsNetworkAvailable])
+//    {
+//        DebugLog(@"NET ERR");
+//
+//        return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
+//        //        return nil;
+//    }
+//    NSData* json=[self get_json:URL_LOGOUT parameters:params];
+//    //if(json==nil)
+//
+//
+//    if(json==nil)
+//        return nil;
+//    NSError *error=nil;
+//    NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
+//    int result = [[jsobj valueForKey:@"result"] intValue];
+//
+//    if (result==2)
+//    {
+//
+//        appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
+//        appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
+//        appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
+//
+//        [appDelegate update_count_mark];
+//
+//
+//        appDelegate.can_show_price =false;
+//        appDelegate.can_see_price =false;
+//        appDelegate.can_create_portfolio =false;
+//        appDelegate.can_create_order =false;
+//
+//
+//        appDelegate.can_cancel_order =false;
+//        appDelegate.can_set_cart_price =false;
+//        appDelegate.can_delete_order =false;
+//        appDelegate.can_submit_order =false;
+//        appDelegate.can_set_tearsheet_price =false;
+//        appDelegate.can_update_contact_info = false;
+//
+//        appDelegate.save_order_logout = false;
+//        appDelegate.submit_order_logout = false;
+//        appDelegate.alert_sold_in_quantities = false;
+//
+//        appDelegate.ipad_perm =nil ;
+//        appDelegate.user_type = USER_ROLE_UNKNOWN;
+//        appDelegate.OrderFilter= nil;
+//        [appDelegate SetSo:nil];
+//        [appDelegate set_main_button_panel];
+//#ifdef RA_NOTIFICATION
+//        [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
+//#endif
+//    }
+//    return jsobj;
+}
 @end