| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527 |
- //
- // ResultViewController.m
- // Apex Mobile
- //
- // Created by Ray on 14-3-4.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "GridResultViewController.h"
- #import "TabBarController.h"
- @interface GridResultViewController ()
- -(void) getHeader: (NSMutableArray*)header_name header_aname:(NSMutableArray*)header_aname;
- -(void) loadpage;
- -(NSArray*) getActions;
- @end
- @implementation GridResultViewController
- -(void) loadpage
- {
-
- [self.params setValue:[NSString stringWithFormat:@"%ld",self.offset] forKey:@"offset"];
- self.mum.center = self.view.center;
-
- 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;
-
- [UIView commitAnimations];
-
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- // PageData* pageData=nil;
- if(self.recordCount<0)
- self.recordCount=[RANetwork get_recordcount: self.params ];
- if(self.recordCount>0)
- {
- self.pageData=[RANetwork get_pagedata:self.params];
- // self.pageData=[RANetwork]
- }
-
- dispatch_async(dispatch_get_main_queue(), ^{
- NSTimeInterval animationDuration = 0.30f;
- [UIView beginAnimations:@"ResizeView" context:nil];
- [UIView setAnimationDuration:animationDuration];
-
- if(self.recordCount>=0)
- {
- if(self.recordCount<2000)
- self.countView.title = [NSString stringWithFormat:@"%ld records",self.recordCount];
- else
- self.countView.title = @"2000+ records";
- }
- else
- {
- self.countView.title = @"Net error!";
- }
- if(self.offset<self.pageData.get_count||self.offset==0)
- self.prepageButton.enabled=false;
- else
- self.prepageButton.enabled=true;
- if(self.offset+self.pageData.get_count>=self.recordCount)
- self.nextpageButton.enabled=false;
- else
- self.nextpageButton.enabled=true;
- [self.grid initgrid :self.pageData];
-
- // CGPoint p = self.grid.frame.origin;
-
-
- self.mum.hidden = true;
- self.grid.hidden = false;
- [UIView commitAnimations];
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- bool autologin =[defaults boolForKey:@"autologin"];
- if(!autologin)
- {
- TabBarController * viewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginTabBar"];
- [self presentViewController:viewController animated:YES completion:^{
-
- }];
- }
-
- });
- });
- }
- - (void) showDetail:(UIMenuItem*) sender
- {
- DebugLog(@"show detail id = %@",self.detail_id);
- NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithDictionary:self.params copyItems:true];
-
-
- [params setValue:self.detail_id forKey:@"id"];
-
-
- DetailTabBarController *detailViewController=[[DetailTabBarController alloc] init:self.function_name actions:self.actions params:params];
-
-
- // DetailTabBarController *detailViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailTabBarController"];
- // detailViewController.function_name = self.function_name;
- // detailViewController.actions = self.actions;
- // detailViewController.params =params;
- [self.navigationController pushViewController:detailViewController animated:YES];
-
- }
- - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
- {
- if (action == @selector(showDetail:))
- return YES;//显示
- else
- return NO;//不显示
- }
- -(void)menuItemSelected:(NSIndexPath *)indexPath
- {
- NSLog(@"%ld",indexPath.item);
- [pulldownMenu animateDropDown];
- if(indexPath.item==0)
- {
- CustomizeFieldViewController *ViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CustomizeFieldViewController"];
- ViewController.function_name = self.function_name;
- ViewController.behavior =BEHAVIOR_RESULT;
- self.dirty=true;
- // ViewController.dirty = self.dirty;
-
- [self.navigationController pushViewController:ViewController animated:YES];
- }
- else
- {
-
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_create_tag", nil) message:NSLocalizedString(@"alert_msg_savehint", nil) preferredStyle:UIAlertControllerStyleAlert];
-
- __block UITextField *inputTextField;
- [alertVC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
- inputTextField = textField;
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
-
- UIAlertAction *saveAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"save", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- UITextField * txt= inputTextField;
- NSString* name = txt.text;
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.params
- options:0
- error:nil];
- NSString* param = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- NSString* user = appDelegate.user;
-
- sqlite3 *db =[ApexMobileDB get_db];
-
- [ApexMobileDB execSql: [NSString stringWithFormat: @"insert into history(params,name,module_name,user) values('%@','%@','%@','%@')",param,name,self.function_name,user] db:db];
-
- sqlite3_close(db);
-
- }];
-
- [alertVC addAction:cancelAction];
- [alertVC addAction:saveAction];
-
- [self presentViewController:alertVC animated:YES completion:nil];
-
- }
- }
- -(void)pullDownAnimated:(BOOL)open
- {
- if (open)
- {
- NSLog(@"Pull down menu open!");
- }
- else
- {
- NSLog(@"Pull down menu closed!");
- }
- }
- - (IBAction)onCustomize:(UIBarButtonItem *)sender {
-
-
-
- // CGRect ff = self.navigationController.navigationBar.frame;
- // : CGPointMake(0.0f,self.navigationController.navigationBar.frame.size.height)
-
- [pulldownMenu animateDropDown:CGPointMake(0.0f,self.navigationController.navigationBar.frame.size.height)];
- // CustomizeFieldViewController *ViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CustomizeFieldViewController"];
- // ViewController.function_name = self.function_name;
- // ViewController.behavior =BEHAVIOR_RESULT;
- // self.dirty=true;
- // // ViewController.dirty = self.dirty;
- //
- // [self.navigationController pushViewController:ViewController animated:YES];
- }
- - (BOOL)canBecomeFirstResponder{
- return YES;
- }
- - (void) Tap:(UIView*)view url:(NSString*) url
- {
- WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
- ViewController.url = url;
- // ViewController. = self.function_name;
- // ViewController.behavior =BEHAVIOR_SEARCH;
-
- [self.navigationController pushViewController:ViewController animated:YES];
- }
- - (void) LongPress:(UIView*)view _id:(NSString*) _id
- {
- DebugLog(@"!!!!!!!!!!!!!!!!!");
- self.actions = [self getActions];
-
- if(self.actions.count<1)
- return;
- self.detail_id = _id;
- UIMenuItem *detail = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"menuitem_showdetail", nil) action:@selector(showDetail:)];
- // [detail setValue:_id forKey:@"_id"];
-
- UIMenuController *menu = [UIMenuController sharedMenuController];
-
- [menu setMenuItems:[NSArray arrayWithObjects:detail, nil]];
-
- [menu setTargetRect:view.frame inView:view.superview];
- [menu setMenuVisible:YES animated:YES];
-
-
-
- }
- - (IBAction)onPrePageClick:(UIButton *)sender {
- self.offset -=self.prepageCount;
- [self loadpage];
- }
- - (IBAction)onNextPageClick:(UIButton *)sender {
- self.offset +=self.pageData.get_count;
- self.prepageCount=self.pageData.get_count;
- [self loadpage];
- }
- -(NSArray*) getActions
- {
- DebugLog(@"getActions");
-
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-
-
- NSMutableArray* actions = [[NSMutableArray alloc]init];
- sqlite3 *db =[ApexMobileDB get_db];
- NSString *quary = [NSString stringWithFormat:@"select name from actions_info where function_name='%@' and user='%@'order by priority",self.function_name, appDelegate.user];
-
-
-
- sqlite3_stmt *stmt;
-
- if (sqlite3_prepare_v2(db, [quary UTF8String], -1, &stmt, nil) == SQLITE_OK) {
- DebugLog(@"sql:%@",quary);
- DebugLog(@"=======================show tabs===================");
- while (sqlite3_step(stmt)==SQLITE_ROW)
- {
-
- NSString *name = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(stmt, 0)];
- [actions addObject:name];
- DebugLog(@"action name: %@",name);
- }
- DebugLog(@"=======================show tabs===================");
- sqlite3_finalize(stmt);
- }
- //用完了一定记得关闭,释放内存
- sqlite3_close(db);
- return actions;
- }
- -(void) getHeader: (NSMutableArray*)header_name header_aname:(NSMutableArray*)header_aname
- {
- // NSMutableDictionary* header = [[NSMutableDictionary alloc] init];
- // [header setValue:@"aaa" forKey:@"bbb"];
- DebugLog(@"initHeader");
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
-
- sqlite3 *db =[ApexMobileDB get_db];
- NSString *quary = [NSString stringWithFormat:@"select aname,name from fields_info where function_name='%@' and user='%@' and behavior=%d and show=1 order by priority,aname",self.function_name, appDelegate.user,BEHAVIOR_RESULT];
-
-
-
- sqlite3_stmt *stmt;
-
- if (sqlite3_prepare_v2(db, [quary UTF8String], -1, &stmt, nil) == SQLITE_OK) {
- DebugLog(@"sql:%@",quary);
- DebugLog(@"=======================show fields===================");
- while (sqlite3_step(stmt)==SQLITE_ROW)
- {
- NSString *aname = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(stmt, 0)];
- NSString *name = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(stmt, 1)];
- // [header setValue:aname forKey:name];
- [header_name addObject:name];
- [header_aname addObject:aname];
- DebugLog(@"%@",aname);
-
- }
- DebugLog(@"=======================show fields===================");
- sqlite3_finalize(stmt);
- }
- //用完了一定记得关闭,释放内存
- sqlite3_close(db);
- // return header;
- }
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // self.pageData=[[PageData alloc] init];
-
-
- }
- return self;
- }
- //- (BOOL)shouldAutorotate
- //{
- // return YES;
- //}
- //
- //- (NSUInteger)supportedInterfaceOrientations
- //{
- // return UIInterfaceOrientationMaskLandscapeRight;
- //}
- //
- //- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
- //{
- // return UIInterfaceOrientationLandscapeRight;
- //}
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
-
-
-
-
-
- NSString* title=@"";
- if([self.function_name isEqualToString:@"Ocean Booking"])
- title = @"Booking Result";
- else if([self.function_name isEqualToString:@"Ocean B/L info."])
- title = @"B/L info. Result";
- else if([self.function_name isEqualToString:@"Container detail"])
- title = @"Container Result";
- else if([self.function_name isEqualToString:@"Download Document"])
- title = @"Document Result";
- self.navigationItem.title = title;
- // UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
- // backButton.title = @"Back";
- //
- // self.navigationItem.backBarButtonItem = backButton;
-
- // self.navigationController.view.frame.size.height;
-
- // NSMutableArray * items = [[NSMutableArray alloc]init];
- // 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";
- // [items addObject:item1];
- // [items addObject:item2];
- // self.navigationItem.rightBarButtonItems=items;
- // self.navigationItem.backBarButtonItem = backButton;
-
-
- self.dirty = @"true";
-
- if([self.function_name isEqualToString:@"Download Document"])
- self.fullrow_select =false;
- else
- self.fullrow_select=true;
-
-
-
- pulldownMenu = [[PulldownMenu alloc] initWithView:self.view];
- [self.view addSubview:pulldownMenu];
-
- [pulldownMenu insertButton:NSLocalizedString(@"menuitem_setting", nil)];
- [pulldownMenu insertButton:NSLocalizedString(@"menuitem_savesearch", nil)];
-
-
- pulldownMenu.delegate = self;
- // self.navigationItem.rightBarButtonItems
-
- [pulldownMenu loadMenu];
-
-
-
-
-
- UIRefreshControl *ref = [[UIRefreshControl alloc]init];
- ref.tag = 200 ;
- ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"drag to refresh"];
- ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- // ref.hidden = true;
- [ref addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
- [self.grid addSubview:ref];
-
- }
- -(void)changeCell
- {
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
- [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
- DebugLog(@"refresh!!!!!!!!");
-
- }
- -(void)ReloadData
- {
-
- // Count ++ ;
- // [mytabelview reloadData];
- [self loadpage];
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-
- [reF endRefreshing];
-
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- DebugLog(@"viewWillAppear");
-
-
-
-
- if(self.dirty ==true)
- {
- self.prepageCount=0;
- self.recordCount = -1;
- self.offset = 0;
- NSMutableArray* header_name =[[NSMutableArray alloc]init];
- NSMutableArray* header_aname =[[NSMutableArray alloc]init];
- [self getHeader:header_name header_aname:header_aname];
- // self.header = [self getHeader:header_name];
- // self.grid.header = self.header;
- self.grid.fullrowselect = self.fullrow_select;
- self.grid.griddelegate = self;
- self.grid.header_name=header_name;
- self.grid.header_aname=header_aname;
- [self.params setValue:self.function_name forKey:@"module_name"];
- NSString* fields =@"";
- for(int i=0;i<header_name.count;i++)
- {
- fields=[fields stringByAppendingFormat:@"%@,",header_name[i]];
-
- }
- fields=[fields substringToIndex: fields.length-1];
-
- [self.params setValue:fields forKey:@"columns"];
-
- [self loadpage];
- self.dirty = false;
- // [pulldownMenu loadMenu:self.grid.frame.origin];
- }
-
-
- }
- //-(NSUInteger)supportedInterfaceOrientations
- //{
- // DebugLog(@"myViewController::supportedInterfaceOrientations");
- // return UIInterfaceOrientationMaskLandscape;
- // // return [[self topViewController] supportedInterfaceOrientations];
- //}
- //- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
- //{
- // DebugLog(@"myViewController::preferredInterfaceOrientationForPresentation");
- // return UIInterfaceOrientationLandscapeRight;
- //}
- //-(BOOL)shouldAutorotate
- //{
- // DebugLog(@"myViewController::shouldAutorotate");
- // return YES;
- //}
- //
- //- (void)viewWillAppear:(BOOL)animated
- //{
- //// [self presentViewController:[[UIViewController alloc]init] animated:NO completion:^
- //// {
- //// DebugLog(@"dismiss viewcontroller");
- //// [self dismissViewControllerAnimated:NO completion:nil];
- //// }];
- //
- //
- //// [self presentViewController:nil animated:NO completion:nil];
- //
- // // [self presentViewController];
- //
- //}
- // - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- // {
- // return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
- // }
- // - (NSUInteger)supportedInterfaceOrientations
- // {
- // // return UIInterfaceOrientationMaskLandscapeLeft;
- // return UIInterfaceOrientationMaskLandscapeRight;
- // }
- // - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
- // return UIInterfaceOrientationLandscapeRight;
- // // return UIInterfaceOrientationPortrait;
- // }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|