//
//  PrintBarcodeViewController.m
//  SIIMpaPrinterSample
//

#import "PrintBarcodeViewController.h"
#import "PrinterManager.h"
#import "ValueManager.h"
#import "ValueViewController.h"

@interface PrintBarcodeViewController () <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation PrintBarcodeViewController {
    UIView *_indicatorView;
    ValueViewController *_viewController;
    NSInteger _sectionIndex;
    int _footerSize;
    NSInteger _frameWidth;
}

static NSUInteger const SIZE_OF_SECTION_TITLE_TABLE = 6;
static NSString *const SECTION_TITLE_TABLE[] = {
    BARCODE_TYPE_SECTION,
    BARCODE_DATA_SECTION,
    BARCODE_MODULE_WIDTH_SECTION,
    BARCODE_HEIGHT_SECTION,
    BARCODE_HRI_SETTING_SECTION,
    BARCODE_NW_RATIO_SECTION
};

static NSUInteger const SIZE_OF_BARCODE_TYPE_TABLE = 15;
static NSString *const BARCODE_TYPE_TABLE[] = {
    BARCODE_TYPE_UPC_A,
    BARCODE_TYPE_UPC_E,
    BARCODE_TYPE_JAN13,
    BARCODE_TYPE_JAN8,
    BARCODE_TYPE_CODE39,
    BARCODE_TYPE_ITF,
    BARCODE_TYPE_CODABAR,
    BARCODE_TYPE_CODE128,
    BARCODE_TYPE_CODE93,
    BARCODE_TYPE_JAN13_ADDON2,
    BARCODE_TYPE_JAN13_ADDON5,
    BARCODE_TYPE_GS1_OMNI_DIRECTIONAL,
    BARCODE_TYPE_GS1_TRUNCATED,
    BARCODE_TYPE_GS1_LIMITED,
    BARCODE_TYPE_GS1_EXPANDED
};

static NSUInteger const SIZE_OF_BARCODE_MODULE_WIDTH_TABLE = 5;
static NSString *const BARCODE_MODULE_WIDTH_TABLE[] = {
    BARCODE_MODULE_WIDTH_2,
    BARCODE_MODULE_WIDTH_3,
    BARCODE_MODULE_WIDTH_4,
    BARCODE_MODULE_WIDTH_5,
    BARCODE_MODULE_WIDTH_6
};

static NSUInteger const SIZE_OF_BARCODE_HRI_SETTING_TABLE = 7;
static NSString *const BARCODE_HRI_SETTING_TABLE[] = {
    BARCODE_HRI_SETTING_NONE,
    BARCODE_HRI_SETTING_TOP_FONT_A,
    BARCODE_HRI_SETTING_BOTTOM_FONT_A,
    BARCODE_HRI_SETTING_FONT_A,
    BARCODE_HRI_SETTING_TOP_FONT_B,
    BARCODE_HRI_SETTING_BOTTOM_FONT_B,
    BARCODE_HRI_SETTING_FONT_B
};

static NSUInteger const SIZE_OF_BARCODE_NW_RATIO_TABLE = 3;
static NSString *const BARCODE_NW_RATIO_TABLE[] = {
    BARCODE_NW_RATIO_1TO2,
    BARCODE_NW_RATIO_1TO2_5,
    BARCODE_NW_RATIO_1TO3
};

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _sectionIndex = -1;
    self.tableView.delegate = (id <UITableViewDelegate>)self;
    self.tableView.dataSource = (id <UITableViewDataSource>)self;
    [self initIndicatorView];
    [self setDefaultValue];
}

-(void)viewDidDisappear:(BOOL)animated {
    [self removeKeyboardNotification];
    [super viewDidDisappear:animated];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self addKeyboardNotification];
    [self reloadTableView];
    [self reloadViewSize];
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    //
    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
        [self reloadViewSize];
    } completion:nil];
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return SIZE_OF_SECTION_TITLE_TABLE;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if (section < SIZE_OF_SECTION_TITLE_TABLE) {
        return SECTION_TITLE_TABLE[section];
    } else {
        return @"";
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    cell.textLabel.text = @"";
    cell.textLabel.numberOfLines = 0;
    NSString *sectionTitle = SECTION_TITLE_TABLE[indexPath.section];
    if (([sectionTitle isEqualToString:BARCODE_DATA_SECTION])
        || ([sectionTitle isEqualToString:BARCODE_HEIGHT_SECTION])) {
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 0, _frameWidth - 20, cell.frame.size.height)];
        textField.contentVerticalAlignment= UIControlContentVerticalAlignmentCenter;
        textField.returnKeyType = UIReturnKeyDone;
        textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        textField.tag = indexPath.section;
        textField.clearButtonMode = YES;
        [textField setDelegate:self];
        if ([sectionTitle isEqualToString:BARCODE_DATA_SECTION]) {
            textField.text = [ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_DATA];
        } else if ([sectionTitle isEqualToString:BARCODE_HEIGHT_SECTION]) {
            textField.text = [ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT];
        }
        [cell.contentView addSubview:textField];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
    } else if ([sectionTitle isEqualToString:BARCODE_TYPE_SECTION]) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = [ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_TYPE];
    } else if ([sectionTitle isEqualToString:BARCODE_MODULE_WIDTH_SECTION]) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = [ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH];
    } else if ([sectionTitle isEqualToString:BARCODE_HRI_SETTING_SECTION]) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = [ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING];
    } else if ([sectionTitle isEqualToString:BARCODE_NW_RATIO_SECTION]) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = [ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO];
    }
    return cell;
}

#pragma mark - TextField
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    if (0 <= textField.tag && textField.tag < SIZE_OF_SECTION_TITLE_TABLE) {
        NSString *sectionTitle = SECTION_TITLE_TABLE[textField.tag];
        if ([sectionTitle isEqualToString:BARCODE_DATA_SECTION]) {
            [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:textField.text];
        } else if ([sectionTitle isEqualToString:BARCODE_HEIGHT_SECTION]) {
            BOOL result = YES;
            if ([textField.text integerValue] < 1) {
                textField.text = @"1";
                result = NO;
            } else if ([textField.text integerValue] > 255) {
                textField.text = @"255";
                result = NO;
            }
            [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:textField.text];
            return result;
        }
    }
    return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if (0 <= textField.tag && textField.tag < SIZE_OF_SECTION_TITLE_TABLE) {
        NSString *sectionTitle = SECTION_TITLE_TABLE[textField.tag];
        if ([sectionTitle isEqualToString:BARCODE_HEIGHT_SECTION]) {
            NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:string];
            if ([[NSCharacterSet decimalDigitCharacterSet] isSupersetOfSet:characterSet]) {
                NSMutableString *inputText= [textField.text mutableCopy];
                [inputText replaceCharactersInRange:range withString:string];
                return YES;
            } else {
                return NO;
            }
        } else {
            NSMutableString *inputText= [textField.text mutableCopy];
            [inputText replaceCharactersInRange:range withString:string];
            return YES;
        }
    }
    return YES;
}

#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    if (0 <= indexPath.section && indexPath.section <= SIZE_OF_SECTION_TITLE_TABLE) {
        NSString *sectionTitle = SECTION_TITLE_TABLE[indexPath.section];
        _sectionIndex = indexPath.section;
        if ([sectionTitle isEqualToString:BARCODE_TYPE_SECTION]) {
            UITableViewCell *cell = sender;
            _viewController = [segue destinationViewController];
            NSMutableArray *valueData = [[NSMutableArray alloc] init];
            for (int i = 0; i < SIZE_OF_BARCODE_TYPE_TABLE; i++) {
                [valueData addObject:BARCODE_TYPE_TABLE[i]];
                if ([cell.textLabel.text isEqualToString:BARCODE_TYPE_TABLE[i]]) {
                    _viewController.currentValueIndex = i;
                }
            }
            _viewController.tableData = valueData;
        } else if ([sectionTitle isEqualToString:BARCODE_MODULE_WIDTH_SECTION]) {
            UITableViewCell *cell = sender;
            _viewController = [segue destinationViewController];
            NSMutableArray *valueData = [[NSMutableArray alloc] init];
            for (int i = 0; i < SIZE_OF_BARCODE_MODULE_WIDTH_TABLE; i++) {
                [valueData addObject:BARCODE_MODULE_WIDTH_TABLE[i]];
                if ([cell.textLabel.text isEqualToString:BARCODE_MODULE_WIDTH_TABLE[i]]) {
                    _viewController.currentValueIndex = i;
                }
            }
            _viewController.tableData = valueData;
        } else if ([sectionTitle isEqualToString:BARCODE_HRI_SETTING_SECTION]) {
            UITableViewCell *cell = sender;
            _viewController = [segue destinationViewController];
            NSMutableArray *valueData = [[NSMutableArray alloc] init];
            for (int i = 0; i < SIZE_OF_BARCODE_HRI_SETTING_TABLE; i++) {
                [valueData addObject:BARCODE_HRI_SETTING_TABLE[i]];
                if ([cell.textLabel.text isEqualToString:BARCODE_HRI_SETTING_TABLE[i]]) {
                    _viewController.currentValueIndex = i;
                }
            }
            _viewController.tableData = valueData;
        } else if ([sectionTitle isEqualToString:BARCODE_NW_RATIO_SECTION]) {
            UITableViewCell *cell = sender;
            _viewController = [segue destinationViewController];
            NSMutableArray *valueData = [[NSMutableArray alloc] init];
            for (int i = 0; i < SIZE_OF_BARCODE_NW_RATIO_TABLE; i++) {
                [valueData addObject:BARCODE_NW_RATIO_TABLE[i]];
                if ([cell.textLabel.text isEqualToString:BARCODE_NW_RATIO_TABLE[i]]) {
                    _viewController.currentValueIndex = i;
                }
            }
            _viewController.tableData = valueData;
        }
    }
}

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    if (0 <= indexPath.section && indexPath.section <= SIZE_OF_SECTION_TITLE_TABLE) {
        NSString *sectionTitle = SECTION_TITLE_TABLE[indexPath.section];
        if ([sectionTitle isEqualToString:BARCODE_TYPE_SECTION]) {
            return YES;
        } else if ([sectionTitle isEqualToString:BARCODE_MODULE_WIDTH_SECTION]) {
            return YES;
        } else if ([sectionTitle isEqualToString:BARCODE_HRI_SETTING_SECTION]) {
            return YES;
        } else if ([sectionTitle isEqualToString:BARCODE_NW_RATIO_SECTION]) {
            return YES;
        } else {
            return NO;
        }
    } else {
        return NO;
    }
}

#pragma mark - Button Action
- (IBAction)printButtonOnClicked:(id)sender {
    [self startLoadingView];
    dispatch_async([PrinterManager getDispatchQueue], ^{
        NSInteger type = [ValueManager convertBarcodeTypeStringToInt:[ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_TYPE]];
        NSString *text = [ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_DATA];
        NSInteger width = [ValueManager convertBarcodeModuleWidthStringToInt:[ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH]];
        NSInteger height = [[ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT] integerValue];
        NSInteger hri = [ValueManager convertBarcodeHriSettingStringToInt:[ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING]];
        NSInteger nwRatio = [ValueManager convertBarcodeNwRatioStringToInt:[ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO]];
        BOOL result = [PrinterManager printBarcode:type text:text width:width height:height hri:hri nwRatio:nwRatio];
        [self stopLoadingView];
        if (result == NO) {
            [self showMessageBox:@"" message:[NSString stringWithFormat:@"%@%@", @"Attempt to print Barcode failed.\n ErrorCode : ", [PrinterManager getErrorCodeText]]];
        }
    });
}

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

#pragma mark - Private
- (void)initIndicatorView {
    _indicatorView = [[NSBundle mainBundle] loadNibNamed:@"IndicatorView" owner:self options:nil][0];
    _indicatorView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
    _indicatorView.hidden = YES;
    [self.view addSubview:_indicatorView];
}

- (void)setDefaultValue {
    if ([[ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_TYPE] length] == 0) {
        [[NSUserDefaults standardUserDefaults] setObject:BARCODE_TYPE_UPC_A forKey:KEY_TYPE_BARCODE_TYPE];
        [[NSUserDefaults standardUserDefaults] setObject:@"012345678901" forKey:KEY_TYPE_BARCODE_DATA];
        [[NSUserDefaults standardUserDefaults] setObject:BARCODE_MODULE_WIDTH_3 forKey:KEY_TYPE_BARCODE_MODULE_WIDTH];
        [[NSUserDefaults standardUserDefaults] setObject:@"162" forKey:KEY_TYPE_BARCODE_HEIGHT];
        [[NSUserDefaults standardUserDefaults] setObject:BARCODE_HRI_SETTING_NONE forKey:KEY_TYPE_BARCODE_HRI_SETTING];
        [[NSUserDefaults standardUserDefaults] setObject:BARCODE_NW_RATIO_1TO2_5 forKey:KEY_TYPE_BARCODE_NW_RATIO];
    }
}

- (void)reloadTableView {
    if (0 <= _sectionIndex && _sectionIndex < SIZE_OF_SECTION_TITLE_TABLE) {
        NSString *sectionTitle = SECTION_TITLE_TABLE[_sectionIndex];
        if ([sectionTitle isEqualToString:BARCODE_TYPE_SECTION]) {
            for (int i = 0; i < SIZE_OF_BARCODE_TYPE_TABLE; i++) {
                if (_viewController.currentValueIndex == i) {
                    NSString *newBarcodeType = BARCODE_TYPE_TABLE[i];
                    NSString *currentBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_TYPE];
                    if ([currentBarcodeType isEqualToString:newBarcodeType] == NO) {
                        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_TYPE value:newBarcodeType];
                        [self reloadDefaultValue];
                        break;
                    }
                }
            }
        } else if ([sectionTitle isEqualToString:BARCODE_MODULE_WIDTH_SECTION]) {
            for (int i = 0; i < SIZE_OF_BARCODE_MODULE_WIDTH_TABLE; i++) {
                if (_viewController.currentValueIndex == i) {
                    [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_TABLE[i]];
                }
            }
        } else if ([sectionTitle isEqualToString:BARCODE_HRI_SETTING_SECTION]) {
            for (int i = 0; i < SIZE_OF_BARCODE_HRI_SETTING_TABLE; i++) {
                if (_viewController.currentValueIndex == i) {
                    [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_TABLE[i]];
                }
            }
        } else if ([sectionTitle isEqualToString:BARCODE_NW_RATIO_SECTION]) {
            for (int i = 0; i < SIZE_OF_BARCODE_NW_RATIO_TABLE; i++) {
                if (_viewController.currentValueIndex == i) {
                    [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_TABLE[i]];
                }
            }
        }
    }
    _sectionIndex = -1;
    [self.tableView reloadData];
}

- (void)reloadViewSize {
    _frameWidth = (NSInteger)self.view.bounds.size.width;    
    [self.tableView reloadData];
}

- (void)addKeyboardNotification {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    _footerSize = self.tableView.superview.frame.size.height - self.tableView.frame.size.height;
}

- (void)removeKeyboardNotification {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

- (void)keyboardWillShow:(NSNotification *)aNotification {
    CGRect keyboardRect = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    float keyboardHeight = keyboardRect.size.height;
    self.tableView.frame = CGRectMake(0, 0, self.tableView.frame.size.width, (self.tableView.superview.frame.size.height - keyboardHeight));
}

- (void)keyboardWillHide:(NSNotification *)aNotification {
    self.tableView.frame = CGRectMake(0, 0, self.tableView.frame.size.width, self.tableView.superview.frame.size.height - _footerSize);
}

- (void)startLoadingView {
    dispatch_async(dispatch_get_main_queue(), ^{
        self->_indicatorView.hidden = NO;
    });
}

- (void)stopLoadingView {
    dispatch_async(dispatch_get_main_queue(), ^{
        self->_indicatorView.hidden = YES;
    });
}

- (void)showMessageBox:(NSString *)title message:(NSString *)message {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIAlertController *alertController =  [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
        [alertController addAction:[UIAlertAction actionWithTitle:@"Close" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        }]];
        [self presentViewController:alertController animated:YES completion:nil];
    });
}

- (void)reloadDefaultValue {
    NSString *currentBarcodeType = [ValueManager getCurrentStringValue:KEY_TYPE_BARCODE_TYPE];
    if ([currentBarcodeType isEqualToString:BARCODE_TYPE_UPC_A]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"012345678901"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_UPC_E]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"01200000123"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_JAN13]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"012345678912"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_JAN8]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"0123456"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_CODE39]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"A"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_ITF]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"01"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_CODABAR]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"B+C"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_CODE128]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"{A0123456789"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_CODE93]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"0123456789"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_JAN13_ADDON2]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"49012345678940"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_JAN13_ADDON5]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"49012345678940123"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_GS1_OMNI_DIRECTIONAL]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"4901234567894"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_GS1_TRUNCATED]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"4901234567894"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_GS1_LIMITED]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"0123456789012"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    } else if ([currentBarcodeType isEqualToString:BARCODE_TYPE_GS1_EXPANDED]) {
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_DATA value:@"490{123456789"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_MODULE_WIDTH value:BARCODE_MODULE_WIDTH_3];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HEIGHT value:@"162"];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_HRI_SETTING value:BARCODE_HRI_SETTING_NONE];
        [ValueManager setCurrentStringValue:KEY_TYPE_BARCODE_NW_RATIO value:BARCODE_NW_RATIO_1TO2_5];
    }
}

@end
