Shinobi reload bug (1)


#1

i cannot find any part of my code that tells the other column to behave differently but it seems the shinobi reload is the affecting it.

please help me troubleshoot this.

//
    // OrderVerification.m
    // TMS
    //
    // Created by Ariel Marlon Javier on 4/10/13.
    // Copyright (c) 2013 Procuro. All rights reserved.
    //

    #import "OrderVerification.h"
    #import <QuartzCore/QuartzCore.h>
    #import "GlobalFunctions.h"
    #import "GlobalObjects.h"
    #import "JSONKit.h"
    #import "SingleTemp.h"
    #import "OrderDetailProduct.h"
    #import "ProductGroupDataSource.h"
    #import "PIMMGlobals.h"
    #import "OrderGroup.h"
    #import "NumericCell.h"
    #import "QtyReceivedCell.h"
    @interface OrderVerification ()

    @end

    @implementation OrderVerification
    CGRect _realBounds;
    @synthesize btnReasonCodeChiller, btnReasonCodeDry, btnReasonCodeFreezer, btnStatusChiller, btnStatusDry, btnStatusFreezer, btnTempChiller, btnTempDry,btnTempFreezer;
    @synthesize txtQtyReceviedChiller, txtQtyReceviedDry, txtQtyReceviedFreezer, txtReasonCodeChiller, txtReasonCodeDry, txtReasonCodeFreezer, txtTempChiller, txtTempDry, txtTempFreezer;
    @synthesize lblQtyOrderedChiller, lblQtyOrderedDry, lblQtyOrderedFreezer, lblQtyShippedChiller, lblQtyShippedDry, lblQtyShippedFreezer, lblShortPlusChiller,
    lblShortPlusDry, lblShortPlusFreezer;
    @synthesize keypad;
    @synthesize rcpop;
    @synthesize rc;
    @synthesize delivery;
    @synthesize src;
    @synthesize btnClose, btnCheck;
    @synthesize tmskeypad;
    NSString *reasonValue;
    @synthesize pop;
    NSString *src;

    NSArray *_data;
    NSArray *_sortedData;

    UIImage *btnTempImage;
    UIImage *btnReasonImage;
    UIImage *btnStatusImage;

    NSInteger rowQtyRcvd;
    NSString *groupNameOld;

    SDataGridCoord *_editingCell;

    //
    //_editingCell

    NSInteger rowRcvd;
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
  
    -(void)dismissKeypad:(NSString *)value
    {
        
        
        // Get the cell that we were editing.
        SDataGridTextCell *cell = (SDataGridTextCell*)[_shinobiDataGrid visibleCellAtCoordinate:_editingCell];
        // Find its contents
        
        OrderGroup *group=_sortedData[cell.coordinate.row.sectionIndex];
        
        OrderDetailProduct *order=group.groups[cell.coordinate.row.rowIndex];
        
        if ([_editingCell.column.title isEqualToString:@"Qty Rcvd"]) {
            cell.textField.text=value;
            order.QuantityReceived=value;
            
            [_shinobiDataGrid reload];
        }
        
     
        _editingCell = nil;
        [self.pop dismissPopoverAnimated:YES];
    }
    - (BOOL)shinobiDataGrid:(ShinobiDataGrid *)grid shouldBeginEditingCellAtCoordinate:(const SDataGridCoord *)coordinate {
        _editingCell = (SDataGridCoord *)coordinate;
        
        // Get the cell that was tapped.
        SDataGridCell *cell = (SDataGridCell*)[grid visibleCellAtCoordinate:_editingCell];
        
        
        // Get the frame of the tapped cell
        // CGRect cellFrame = cell.frame;
        if ([_editingCell.column.title isEqualToString:@"Qty Rcvd"]) {
            if (self.pop) {
                [self.pop dismissPopoverAnimated:YES];
            }
            UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
            Keypad *controller = [storyBoard instantiateViewControllerWithIdentifier:@"Keypad"];
            controller.delegate=self;
            UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:controller];
            popover.delegate = self;
            popover.popoverContentSize = CGSizeMake(250,300);
            
            self.pop=popover;
            
            [popover presentPopoverFromRect:cell.bounds inView:cell permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
            
            
        }
        if ([_editingCell.column.title isEqualToString:@"Reason Code"]) {
            if (self.pop) {
                [self.pop dismissPopoverAnimated:YES];
            }
            UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
            ReasonCode *controller = [storyBoard instantiateViewControllerWithIdentifier:@"ReasonCode"];
            controller.delegate=self;
            
            UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:controller];
            popover.delegate = self;
            popover.popoverContentSize = CGSizeMake(300,400);
            
            self.pop=popover;
            [popover presentPopoverFromRect:cell.bounds inView:cell permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

            
            
        }
        
        
        
        
        return NO;
        
    }


    -(NSUInteger)shinobiDataGrid:(ShinobiDataGrid *)grid numberOfRowsInSection:(int)sectionIndex
    {
        OrderGroup *group=(OrderGroup *)_sortedData[sectionIndex];
        return group.groups.count;
    }



    - (void)shinobiDataGrid:(ShinobiDataGrid *)grid didReorderRow:(SDataGridRow *)rowSwitched withRow:(SDataGridRow *)rowSwitchedWith
    {
        // clone the sorted data into a mutable array
        NSMutableArray* sortedData = [[NSMutableArray alloc] initWithArray:_sortedData];
        
        // perform the switch
        [sortedData exchangeObjectAtIndex:rowSwitched.rowIndex withObjectAtIndex:rowSwitchedWith.rowIndex];
        
        // copy back to the sorted data property
        _sortedData = [[NSArray alloc] initWithArray:sortedData];
    }



    ///ReasonCode
    -(void)dismissPop:(NSString *)value
    {
        
        SDataGridTextCell *cell = (SDataGridTextCell*)[_shinobiDataGrid visibleCellAtCoordinate:_editingCell];
        // Find its contents
      
        OrderGroup *group=_sortedData[cell.coordinate.row.sectionIndex];
        
        OrderDetailProduct *order=group.groups[cell.coordinate.row.rowIndex];
        NSLog(@"popup value %@", value);
        if ([_editingCell.column.title isEqualToString:@"Reason Code"]) {
            cell.textField.text=value;
            order.ReasonCode=value;
            
            [_shinobiDataGrid reload];
        }

        _editingCell = nil;
        [self.pop dismissPopoverAnimated:YES];

    }


    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        _realBounds = self.view.bounds;
        [self renderOrderDetail];
        
        rowRcvd=0;
        rowQtyRcvd=0;
        btnTempImage=[UIImage imageNamed:@"temp_icon20.png"];
        //btnStatusImage=[UIImage imageNamed:@"d_Green_Check_Mark.png"];
        btnStatusImage=[UIImage imageNamed:@"d_Blank_Circle.png"];
        globDelReason=@"delivery";
        groupNameOld=nil;
        
        //SDataGridRow *row=(SDataGridRow *)
        
    }
    - (void)shinobiDataGrid:(ShinobiDataGrid *)grid prepareCellForDisplay:(SDataGridCell *)cell
    {

        SDataGridTextCell* textCell= (SDataGridTextCell*)cell;
        textCell.textField.text=@"";
        
        OrderGroup *group=_sortedData[cell.coordinate.row.sectionIndex];
        
        
        OrderDetailProduct *order=group.groups[cell.coordinate.row.rowIndex];
        
        
            
            
        // determine which column this cell belongs to
        if ([cell.coordinate.column.title isEqualToString:@"Location"])
        {
            textCell.textField.text = order.Location;
        }
        if ([cell.coordinate.column.title isEqualToString:@"Item No"])
        {
            textCell.textField.text = order.ItemNo;
        }
        if ([cell.coordinate.column.title isEqualToString:@"Product"])
        {
            textCell.textField.text=order.ProducDescription;
            
        }
        if ([cell.coordinate.column.title isEqualToString:@"Temp"])
        {
            textCell.textField.text=order.Temp;
            
        }
        if ([cell.coordinate.column.title isEqualToString:@"Unit"])
        {
            textCell.textField.text =order.Unit;
            
        }
        if ([cell.coordinate.column.title isEqualToString:@"Qty Ordered"])
        {
            textCell.textField.text =[NSString stringWithFormat:@"%@",order.QuantityOrdered];
            
        }
        if ([cell.coordinate.column.title isEqualToString:@"Qty Shipped"])
        {
            textCell.textField.text =[NSString stringWithFormat:@"%@", order.QuanityShipped];
            
        }
        if ([cell.coordinate.column.title isEqualToString:@"Weight"])
        {
            NSNumberFormatter *formatter=[NSNumberFormatter new];
            [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
            float weightFloat=[[NSString stringWithFormat:@"%@",order.Weight]floatValue];
            
            NSString *weightFormatted=[formatter stringFromNumber:[NSNumber numberWithFloat:weightFloat]];
            textCell.textField.text =weightFormatted;
            
        }
        if ([cell.coordinate.column.title isEqualToString:@"Qty Rcvd"])
            
        {
            textCell.textField.borderStyle=UITextBorderStyleRoundedRect;
            textCell.textField.text=[NSString stringWithFormat:@"%@",order.QuantityReceived];
            
        }
        if ([cell.coordinate.column.title isEqualToString:@"Reason Code"])
        {
            NSString *strQR=[NSString stringWithFormat:@"%@",order.QuantityReceived];
            NSString *strQO=[NSString stringWithFormat:@"%@",order.QuantityOrdered];
            // btnReason=[UIButton buttonWithType:UIButtonTypeCustom];
            
            
            if (![strQR isEqualToString:strQO]) {
                
                textCell.textField.borderStyle=UITextBorderStyleRoundedRect;
                textCell.textField.backgroundColor=[UIColor orangeColor];
                textCell.textField.textColor=[UIColor whiteColor];
                  
            }
            else
            {
                textCell.textField.borderStyle=UITextBorderStyleRoundedRect;
                textCell.textField.backgroundColor=[UIColor clearColor];
            }
            
            textCell.textField.text=order.ReasonCode;
            
        }
        if ([cell.coordinate.column.title isEqualToString:@"Short/Plus"])
        {
            NSNumber *shipped=order.QuantityOrdered;
            NSNumber *received=order.QuantityReceived;
            NSNumber *result=@([shipped doubleValue]-[received doubleValue]);
            textCell.textField.text=[result stringValue];
          
            
        }
        if ([cell.coordinate.column.title isEqualToString:@"Status"])
        {
            textCell.textField.text=order.Status;
             
            
        }
        
    }



    -(void)renderOrderDetail
    {
        _shinobiDataGrid=[[ShinobiDataGrid alloc]initWithFrame:CGRectMake(15, 122, 970, 499)];
        SDataGridTheme *verticalLinesTheme =[SDataGridiOS7Theme new];
        
        
        verticalLinesTheme.hideVerticalGridlines = NO;
        [_shinobiDataGrid applyTheme:verticalLinesTheme];
        
        // Set the default font size.
        UIFont *font = [UIFont fontWithName:@"Helvetica" size:10.5f];
        UIFont *fontSelected = [UIFont fontWithName:@"Helvetica" size:11.0f];
        UIFont *fontSection=[UIFont fontWithName:@"Helvetica-Bold" size:11.0f];
        
        // Set the padding for the cell.
        UIEdgeInsets padding = UIEdgeInsetsMake(5, 5, 5, 5);
        
        // Create an alternating row style.
        SDataGridCellStyle* alternatingRowStyle = [[SDataGridCellStyle alloc] init];
        alternatingRowStyle.font = font;
        alternatingRowStyle.contentInset = padding;
        alternatingRowStyle.backgroundColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
        
        // Create the selected row style.
        SDataGridCellStyle* selectedRowStyle = [[SDataGridCellStyle alloc] init];
        selectedRowStyle.font = fontSelected;
        
        selectedRowStyle.contentInset = padding;
        selectedRowStyle.backgroundColor = [UIColor colorWithWhite:.9f alpha:1.0f];
        
        selectedRowStyle.textColor = [UIColor orangeColor];
        
        
        // Create the header style.
        // Style the headers to have a dark background, and white text.
        SDataGridCellStyle* headerStyle = [[SDataGridCellStyle alloc] init];
        headerStyle.font = fontSection;
        headerStyle.contentInset = padding;
        
        headerStyle.backgroundColor = [UIColor colorWithWhite:0.6f alpha:1.0f];
        headerStyle.textColor = [UIColor whiteColor];
        
        //[deliveryEquipment.layer setCornerRadius:10.f]
        [_shinobiDataGrid.layer setCornerRadius:4.f];
        // Set the row heights.
        _shinobiDataGrid.defaultHeaderRowHeight = @35;
        _shinobiDataGrid.defaultRowHeight = @35;
        
        // Set the cell styles.
        _shinobiDataGrid.defaultCellStyleForHeaderRow = headerStyle;
        _shinobiDataGrid.defaultCellStyleForSelectedRows = selectedRowStyle;
        _shinobiDataGrid.defaultCellStyleForAlternateRows = alternatingRowStyle;
        
        _shinobiDataGrid.defaultSectionHeaderStyle.font=fontSection;
        
        // _shinobiDataGrid.singleTapEventMask = SDataGridEventSelect;
        _shinobiDataGrid.singleTapEventMask = SDataGridEventEdit;
        
        
        // Create the style for the cell.
        SDataGridCellStyle* cellStyle;
        
        // Create the columns.
        SDataGridColumn* column;
        
        // *************************************
        // Location column
        // *************************************
        column = [[SDataGridColumn alloc] initWithTitle:@"Location"];
        column.editable = NO;
        column.width = @63;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        // *************************************
        // Location column
        // *************************************
        column = [[SDataGridColumn alloc] initWithTitle:@"Item No"];
        column.editable = NO;
        column.width = @60;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        // *************************************
        // Location column
        // *************************************
        column = [[SDataGridColumn alloc] initWithTitle:@"Product"];
        column.editable = NO;
        column.width = @175;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        
        column = [[SDataGridColumn alloc] initWithTitle:@"Temp"];
        column.editable = YES;
        column.width = @70;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        // *************************************
        // Location column
        // *************************************
        column = [[SDataGridColumn alloc] initWithTitle:@"Unit"];
        column.editable = NO;
        column.width = @70;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        // *************************************
        // Location column
        // *************************************
        column = [[SDataGridColumn alloc] initWithTitle:@"Qty Ordered"];
        column.editable = YES;
        column.width = @85;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        // *************************************
        // Location column
        // *************************************
        column = [[SDataGridColumn alloc] initWithTitle:@"Qty Shipped"];
        column.editable = NO;
        column.width = @83;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        // *************************************
        // Location column
        // *************************************
        column = [[SDataGridColumn alloc] initWithTitle:@"Weight"];
        column.editable = NO;
        column.width = @80;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        // *************************************
        // Location column
        // *************************************
        column = [[SDataGridColumn alloc] initWithTitle:@"Qty Rcvd"];
        column.editable = YES;
        column.width = @55;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        // column.cellType=[QtyReceivedCell class];
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        // *************************************
        // Location column
        // *************************************
        column = [[SDataGridColumn alloc] initWithTitle:@"Reason Code"];
        column.editable = YES;
        column.width = @86;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        // *************************************
        // Location column
        // *************************************
        column = [[SDataGridColumn alloc] initWithTitle:@"Short/Plus"];
        column.editable = NO;
        column.width = @70;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        // *************************************
        // Location STATUS
        // *************************************
        column = [[SDataGridColumn alloc] initWithTitle:@"Status"];
        column.editable = NO;
        column.width = @60;
        column.headerCellStyle.contentInset = padding;
        column.headerCellStyle.textAlignment = NSTextAlignmentCenter;
        
        cellStyle = [[SDataGridCellStyle alloc] init];
        cellStyle.font = font;
        cellStyle.contentInset = padding;
        cellStyle.textAlignment = NSTextAlignmentCenter;
        column.cellStyle = cellStyle;
        [_shinobiDataGrid addColumn:column];
        
        _shinobiDataGrid.canReorderRows=NO;
        
        
        _shinobiDataGrid.delegate = self;
        
        
        // add to the view
        
        //
        _data=[self createGroupProduct];
        _sortedData=[PIMMGlobals sortArray:_data sortBy:@"groupName"];
        _shinobiDataGrid.dataSource=self;
        //_sortedData = [NSArray arrayWithArray:_data];
        
        
        [self.view addSubview:_shinobiDataGrid];
        
    }
    -(NSUInteger )numberOfSectionsInShinobiDataGrid:(ShinobiDataGrid *)grid
    {
        return _sortedData.count;
    }
    -(NSString *)shinobiDataGrid:(ShinobiDataGrid *)grid titleForHeaderInSection:(NSInteger)section
    {
        OrderGroup *group=(OrderGroup *)_sortedData[section];
        
        return group.groupName;
    }
    -(NSArray *)createGroupProduct
    {
        NSMutableArray *groupProducts=[[NSMutableArray alloc]init];
        _data=[ProductGroupDataSource getOrderDetail:globDeliveryDictionary];
        
        NSMutableSet *products=[[NSMutableSet alloc]init];
        for (OrderDetailProduct *product in _data) {
            [products addObject:product.GroupName];
        }
        
        //create the groups
        
        for (NSString *groupName in products) {
            
            OrderGroup *ordergroup=[[OrderGroup alloc]init];
            ordergroup.groupName=groupName;
            
            NSPredicate *predicate=[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
                OrderDetailProduct *product=(OrderDetailProduct *)evaluatedObject;
                return [product.GroupName isEqualToString:groupName];
            }];
            ordergroup.groups=[_data filteredArrayUsingPredicate:predicate];
            [groupProducts addObject:ordergroup];
        }
        return groupProducts;
        
    }

    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    -(void)viewWillAppear:(BOOL)animated
    {
        self.view.superview.bounds = _realBounds;
    }

    -(IBAction)btnClose:(id)sender
    {
        
        
        
        
        [self dismissViewControllerAnimated:YES completion:nil];
    }

    -(IBAction)btnExit:(id)sender
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    -(IBAction)btnCheck:(id)sender
    {
        
    }



    @end