// // WatchListViewController.m // RedAnt ERP Mobile // // Created by Ray on 14-8-1. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved. // #import "WatchListViewController.h" #import "iSalesNetwork.h" #import "ModelItemCell.h" #import "DetailViewController.h" #import "LoginViewController.h" #import "MainViewController.h" #import "TearSheetParamViewController.h" #import "EditModelPriceViewController.h" #import "ContactListViewController.h" #define ALERT_DEL 1025 //#import "PDFViewController.h" @interface WatchListViewController () @end @implementation WatchListViewController -(void) logout { self.content_data = nil; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } -(void) reload_container_getdata:(bool) update_data { [super reload_container_getdata:update_data]; if(update_data) [self reload_data]; else [self.itemListTable reloadData]; } - (IBAction)onAddtoCart:(id)sender { [RAUtils add_to_cart:self selectorholder:self selector:@selector(addtocart)]; return; UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; if(appDelegate.bLogin==false) { LoginViewController * loginvc =[ self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"]; // loginvc.delegate = self; // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种 loginvc.returnValue = ^(bool blogin){ // UIApplication * app = [UIApplication sharedApplication]; // AppDelegate *appDelegate = (AppDelegate *)[app delegate]; if(blogin) { if(appDelegate.user_type==USER_ROLE_EMPLOYEE) { [main_vc checklogin:false]; if(appDelegate.can_create_order) { NSString* msg =@""; if(appDelegate.contact_id.length>0) { msg = [msg stringByAppendingString:@"\n\nCustomer:"]; msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]]; } UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil]; // alert. [alert show]; } else { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil]; // alert. [alert show]; } } else { [main_vc checklogin:true]; } } // self.offset = 0; // [self.content_data removeAllObjects]; // [self loadpage]; // // [[self navigationController] setNavigationBarHidden:YES animated:NO]; }; UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ; // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi]; navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种 [self presentViewController:navi animated:YES completion:^{ // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320); NSLog(@"LoginViewController present........."); // self.btop = false; // <#code#> }]; } else { if(appDelegate.user_type==USER_ROLE_EMPLOYEE&&/*appDelegate.contact_id==nil&&*/appDelegate.order_code==nil) { [main_vc checklogin:false]; if(appDelegate.can_create_order) { NSString* msg =@""; if(appDelegate.contact_id.length>0) { msg = [msg stringByAppendingString:@"\n\nCustomer:"]; msg = [msg stringByAppendingString:appDelegate.customerInfo[@"customer_name"]]; } UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:msg delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil),NSLocalizedString(@"Add to new order", nil), nil]; // alert. [alert show]; } else { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Add to cart", nil) message:NSLocalizedString(@"", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:NSLocalizedString(@"Add to pending order", nil), nil]; // alert. [alert show]; } } else { if(appDelegate.order_code==nil) [ self neworder]; else [self addtocart]; } } } -(void) addtocart { NSMutableArray* checked = [[NSMutableArray alloc] init]; NSMutableArray* checked_iid = [[NSMutableArray alloc] init]; int count = [[self.content_data valueForKey:@"count"] intValue]; for(int i=0;i // }]; // // [self.btnselect setTitle:@"Select all"]; // // //} - (void)viewDidLoad { [super viewDidLoad]; UIRefreshControl *ref = [[UIRefreshControl alloc]init]; ref.tag = 200 ; ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"]; ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7]; // ref.hidden = true; [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged]; [self.itemListTable addSubview:ref]; [[UIToolbar appearance] setBackgroundColor: [UIColor whiteColor]]; self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor; self.label_net_err.layer.borderWidth = 2.0; self.label_net_err.layer.cornerRadius=15; self.label_net_err.layer.masksToBounds=true; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)]; // tap.minimumPressDuration = 0.8; //定义按的时间 [self.label_net_err addGestureRecognizer:tap]; // [self reload_data]; } -(void)manually_refresh { UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200]; if(self.isrefreshing) { [reF endRefreshing]; return; } reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"]; [self performSelector:@selector(reload_data) withObject:nil afterDelay:1]; // DebugLog(@"refresh!!!!!!!!"); } - (IBAction)onSelectClick:(id)sender { // self.total=0; if([self.btnselect.title isEqualToString:@"Select all"]) { int count =[[self.content_data valueForKey:@"count"] intValue]; for(int i=0;i // }]; // // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle]; // // // }]; // editRowAction.backgroundColor = UIColorFromRGB(0xff9933); AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(appDelegate.user_type==USER_ROLE_EMPLOYEE) return @[deleteRowAction]; else return @[deleteRowAction]; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { } #pragma mark - UIAlertViewDelegate // Called when a button is clicked. The view will be automatically dismissed after this call returns - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { UIApplication * app = [UIApplication sharedApplication]; AppDelegate *appDelegate = (AppDelegate *)[app delegate]; // if(alertView.tag==1234) // { // // // availability warring; // // // if(buttonIndex!=alertView.cancelButtonIndex) // { // if(appDelegate.order_code==nil) // { // [self neworder]; // } // else // { // [self addtocart]; // } // } // return; // } // int count=[self.quantity_text.text intValue]; if(alertView.tag==ALERT_DEL) { if(buttonIndex!=alertView.cancelButtonIndex) { [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle]; NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)self.indexPath.row]] mutableCopy]; NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"item_id"] intValue]]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSDictionary* cart_json = [iSalesNetwork watchlist_remove:ids]; dispatch_async(dispatch_get_main_queue(), ^{ if([[cart_json valueForKey:@"result"] intValue]==2) { [self reload_data]; } else { [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ; } }); }); } return; } MainViewController* main_vc=(MainViewController*)appDelegate.main_vc; if(buttonIndex==alertView.cancelButtonIndex) { } else if(buttonIndex==1) { //open exist OrderListViewController* ovc =[ self.storyboard instantiateViewControllerWithIdentifier:@"OrderListViewController"]; ovc.showNavibar = true; ovc.selectOrder = ^(NSMutableDictionary* order_detail){ if(appDelegate.order_code==nil) { [self neworder]; } else { [self addtocart]; [main_vc checklogin:true]; } }; ovc.init_style = OL_OPEN; ovc.onCancel = ^(){ [main_vc checklogin:true]; }; [self.navigationController pushViewController:ovc animated:true]; } else { //create new; if(appDelegate.customerInfo==nil)// select contact if current contact not exist { ContactListViewController* cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ContactListViewController" ]; cvc.showNavibar = true; cvc.contact_type = @"Sales_Order_Customer"; cvc.returnValue = ^(NSMutableDictionary* value,NSIndexPath* source){ appDelegate.contact_id=[value valueForKey:@"customer_cid"]; appDelegate.customerInfo = value; if(appDelegate.order_code==nil) [self neworder]; // [main_vc checklogin:true]; // [self handle_action_return:value indexPath:indexPath action:ACTION_FILL_SECTION]; // // if(self.returnValue) // self.returnValue(value); }; cvc.onCancel = ^(){ [RAUtils message_alert:@"Cannot create order without cursomer infomation." title:@"" controller:self]; }; cvc.onReset = ^(){ [main_vc checklogin:true]; }; [self.navigationController pushViewController:cvc animated:true]; } else { [self neworder]; } } } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end