Skip to content

Commit

Permalink
More code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NSExceptional committed Aug 6, 2019
1 parent 2a9ef1f commit 62d8526
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ - (IBAction)actionSelected {
handler: ^(UIAlertAction *action) {
FLEXSQLCommandExecutionViewController* controller = [FLEXSQLCommandExecutionViewController new];
controller.dbManager = dbManager;
controller.isSelectionType = false;
controller.isSelect = NO;

[self.navigationController pushViewController:controller animated: true];
}
Expand All @@ -88,7 +88,7 @@ - (IBAction)actionSelected {
handler: ^(UIAlertAction *action) {
FLEXSQLCommandExecutionViewController* controller = [FLEXSQLCommandExecutionViewController new];
controller.dbManager = dbManager;
controller.isSelectionType = true;
controller.isSelect = YES;

[self.navigationController pushViewController:controller animated: true];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
#import "FLEXSQLiteDatabaseManager.h"

@interface FLEXSQLCommandExecutionViewController: UIViewController
@property (nonatomic) BOOL isSelectionType;
@property (nonatomic) BOOL isSelect;
@property (nonatomic) FLEXSQLiteDatabaseManager *dbManager;
@end
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ @interface FLEXSQLCommandExecutionViewController ()
@end

@implementation FLEXSQLCommandExecutionViewController
@synthesize isSelectionType, dbManager, textView, submitButton, statusLabel;

- (void)viewDidLoad {
[super viewDidLoad];

self.navigationItem.title = isSelectionType ? @"Select with SQL" : @"Execute SQL";
self.navigationItem.title = self.isSelect ? @"Select with SQL" : @"Execute SQL";
[self.view addObserver:self forKeyPath:@"frame" options:0 context:NULL];

[self addOtherUIElementsAndPositionThem];
Expand All @@ -37,32 +36,32 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
}

- (void)addOtherUIElementsAndPositionThem {
if(textView == nil) {
textView = [UITextView new];
textView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0];
textView.textColor = [UIColor blackColor];
if (!self.textView) {
self.textView = [UITextView new];
self.textView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0];
self.textView.textColor = [UIColor blackColor];

[self.view addSubview:textView];
[self.view addSubview:self.textView];
}

if(submitButton == nil) {
submitButton = [UIButton new];
if (!self.submitButton) {
self.submitButton = [UIButton new];

[submitButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[submitButton setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:1.0]];
[self.submitButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[self.submitButton setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:1.0]];

[submitButton setTitle:@"Submit" forState:UIControlStateNormal];
[submitButton addTarget:self action:@selector(submitPressed) forControlEvents:UIControlEventTouchUpInside];
[self.submitButton setTitle:@"Submit" forState:UIControlStateNormal];
[self.submitButton addTarget:self action:@selector(submitPressed) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:submitButton];
[self.view addSubview:self.submitButton];
}

if(statusLabel == nil) {
statusLabel = [UILabel new];
if (!self.statusLabel) {
self.statusLabel = [UILabel new];

statusLabel.textAlignment = NSTextAlignmentCenter;
statusLabel.textColor = [UIColor blackColor];
[self.view addSubview:statusLabel];
self.statusLabel.textAlignment = NSTextAlignmentCenter;
self.statusLabel.textColor = [UIColor blackColor];
[self.view addSubview:self.statusLabel];
}

self.view.backgroundColor = [UIColor whiteColor];
Expand All @@ -74,19 +73,20 @@ - (void)addOtherUIElementsAndPositionThem {
CGFloat statusLabelHeight = 70;
CGFloat textViewHeight = self.view.frame.size.height - startingY - submitButtonHeight - statusLabelHeight - sideMargin * 4;

textView.frame = CGRectMake(sideMargin, startingY + sideMargin, width, textViewHeight);
statusLabel.frame = CGRectMake(sideMargin, textView.frame.origin.y + textViewHeight + sideMargin, width, statusLabelHeight);
submitButton.frame = CGRectMake(sideMargin, statusLabel.frame.origin.y + statusLabelHeight + sideMargin, width, submitButtonHeight);
self.textView.frame = CGRectMake(sideMargin, startingY + sideMargin, width, textViewHeight);
self.statusLabel.frame = CGRectMake(sideMargin, self.textView.frame.origin.y + textViewHeight + sideMargin, width, statusLabelHeight);
self.submitButton.frame = CGRectMake(sideMargin, self.statusLabel.frame.origin.y + statusLabelHeight + sideMargin, width, submitButtonHeight);
}

- (void)submitPressed {
NSString* text = textView.text == nil ? @"" : textView.text;
- (void)submitPressed
{
NSString *text = self.textView.text == nil ? @"" : self.textView.text;

if (isSelectionType) {
if (self.isSelect) {
NSString *errorString;
NSArray<NSDictionary<NSString *, id> *> *responce = [dbManager executeSelectionQuery:text error:&errorString];
NSArray<NSDictionary<NSString *, id> *> *response = [self.dbManager executeSelectionQuery:text error:&errorString];

if (responce == nil) {
if (!response) {
[self presentOnErrorAlert:errorString];
return;
}
Expand All @@ -103,31 +103,32 @@ - (void)submitPressed {

FLEXTableContentViewController *contentViewController = [FLEXTableContentViewController new];

contentViewController.contentsArray = responce;
contentViewController.columnsArray = [tables copy];
contentViewController.contentsArray = response;
contentViewController.columnsArray = tables;

contentViewController.title = @"Executed sql";
contentViewController.title = @"Executed SQL";

[self.navigationController pushViewController:contentViewController animated:YES];
} else {
NSString* errorMessage = [self.dbManager executeNonSelectQuery:text];

statusLabel.text = errorMessage == nil ? @"SUCCESS" : errorMessage;
NSString *errorMessage = [self.dbManager executeNonSelectQuery:text];
self.statusLabel.text = errorMessage ?: @"SUCCESS";
}
}


- (void)presentOnErrorAlert: (NSString *)message
- (void)presentOnErrorAlert:(NSString *)message
{
UIAlertController *alert = [UIAlertController
alertControllerWithTitle:@"SQL Execution error !!!"
message:message
preferredStyle:UIAlertControllerStyleAlert];
alertControllerWithTitle:@"SQL Execution error !!!"
message:message
preferredStyle:UIAlertControllerStyleAlert
];

UIAlertAction *okButton = [UIAlertAction
actionWithTitle:@"Ok"
style:UIAlertActionStyleDestructive
handler:nil];
actionWithTitle:@"Ok"
style:UIAlertActionStyleDestructive
handler:nil
];

[alert addAction:okButton];
[self presentViewController:alert animated:YES completion:nil];
Expand Down

0 comments on commit 62d8526

Please sign in to comment.