iOS-数据库-ViewController.m 调用- 数据库附件(1)
iOS-数据库-ViewController.m 调用- 数据库附件(1)
ViewController.m 调用
//
// ViewController.m
// UI17_数据库
//
// Created by YIem on 16/3/3.
// Copyright © 2016年 YIem. All rights reserved.
//
import "ViewController.h"
import "DataBaseHandle.h"
import "Student.h"
@interface ViewController ()
@end
@implementation ViewController
(void)viewDidLoad {
[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor = [UIColor redColor]; UIButton *openB = [UIButton buttonWithType:UIButtonTypeSystem]; openB.frame = CGRectMake(10, 10, 100, 100); [openB setTitle:@"打开数据库" forState:UIControlStateNormal]; [openB addTarget:self action:@selector(openAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:openB]; UIButton *closeB = [UIButton buttonWithType:UIButtonTypeSystem]; closeB.frame = CGRectMake(130, 10, 100, 100); [closeB setTitle:@"关闭数据库" forState:UIControlStateNormal]; [closeB addTarget:self action:@selector(closeAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:closeB]; UIButton *createTableB = [UIButton buttonWithType:UIButtonTypeSystem]; createTableB.frame = CGRectMake(10, 120, 100, 100); [createTableB setTitle:@"创建表单" forState:UIControlStateNormal]; [createTableB addTarget:self action:@selector(createTableAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:createTableB]; UIButton *dropTableB = [UIButton buttonWithType:UIButtonTypeSystem]; dropTableB.frame = CGRectMake(130, 120, 100, 100); [dropTableB setTitle:@"删除表单" forState:UIControlStateNormal]; [dropTableB addTarget:self action:@selector(dropTableAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:dropTableB]; UIButton *inserTableB = [UIButton buttonWithType:UIButtonTypeSystem]; inserTableB.frame = CGRectMake(10, 250, 100, 100); [inserTableB setTitle:@"插入数据" forState:UIControlStateNormal]; [inserTableB addTarget:self action:@selector(insertAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:inserTableB]; UIButton *updateTableB = [UIButton buttonWithType:UIButtonTypeSystem]; updateTableB.frame = CGRectMake(130, 250, 100, 100); [updateTableB setTitle:@"更新数据" forState:UIControlStateNormal]; [updateTableB addTarget:self action:@selector(updateAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:updateTableB]; UIButton *deletedateTableB = [UIButton buttonWithType:UIButtonTypeSystem]; deletedateTableB.frame = CGRectMake(10, 360, 100, 100); [deletedateTableB setTitle:@"删除数据" forState:UIControlStateNormal]; [deletedateTableB addTarget:self action:@selector(deletedateAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:deletedateTableB]; UIButton *aceTableB = [UIButton buttonWithType:UIButtonTypeSystem]; aceTableB.frame = CGRectMake(10, 470, 100, 100); [aceTableB setTitle:@"查询数据" forState:UIControlStateNormal]; [aceTableB addTarget:self action:@selector(aceAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:aceTableB]; UIButton *selectTableB = [UIButton buttonWithType:UIButtonTypeSystem]; selectTableB.frame = CGRectMake(130, 470, 200, 100); [selectTableB setTitle:@"查询分类数据" forState:UIControlStateNormal]; [selectTableB addTarget:self action:@selector(selectAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:selectTableB];
}
// 查询分类
(void)selectAction
{Student *stu = [[Student alloc] init]; stu.sex = @"m"; NSMutableArray *arr = [[DataBaseHandle shareDataBase] selectStuWithSex:stu.sex]; NSLog(@"%@", arr);
}
// 查询所有
(void)aceAction
{NSMutableArray *arr = [[DataBaseHandle shareDataBase] selectAllStudent];
NSLog(@"%@", arr);
}
// 删除数据
(void)deletedateAction
{[[DataBaseHandle shareDataBase] deleteDataWithNum:2];
}
// 修改数据
(void)updateAction
{Student *stu = [[Student alloc] init]; stu.name = @"YIem"; stu.sex = @"m"; stu.age = 99; [[DataBaseHandle shareDataBase] updateWithStu:stu num:3];
}
// 插入数据
(void)insertAction
{Student *stu = [[Student alloc] init]; stu.name = @"卞一"; stu.sex = @"男"; stu.age = 21; [[DataBaseHandle shareDataBase] insertDataWithStu:stu];
}
// 删除表单
(void)dropTableAction
{[[DataBaseHandle shareDataBase] deleteTabl];
}
// 创建表单
(void)createTableAction
{[[DataBaseHandle shareDataBase] createTable];
}
// 关闭数据库
(void)closeAction
{[[DataBaseHandle shareDataBase] closeDB];
}
// 打开数据库
(void)openAction
{[[DataBaseHandle shareDataBase] openDB];
}
(void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.
}
@end