iOS-数据库-FMDB-第三方-插入数据列表-
//
// ViewController.m
// UI18_FMDB
//
// Created by YIem on 16/3/4.
// 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 greenColor]; 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 *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]; UIButton *insertMoreB = [UIButton buttonWithType:UIButtonTypeSystem]; insertMoreB.frame = CGRectMake(130, 570, 200, 100); [insertMoreB setTitle:@"(队列)数据" forState:UIControlStateNormal]; [insertMoreB addTarget:self action:@selector(insertMoreAction) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:insertMoreB];
}
// 插入队列数据
(void)insertMoreAction
{
for (NSInteger i = 0; i < 100; i++) {Student *stu = [[Student alloc] init]; stu.name = @"YIem"; stu.sex = @"m"; stu.age = 21; [[DataBaseHandle shareDataBase] insertMoreStudent:stu];
}
}
// 查询分类
(void)selectAction
{
NSMutableArray *arr = [[DataBaseHandle shareDataBase] selectStuWithSex:@"男"];
NSMutableArray *stuArr = [NSMutableArray arrayWithArray:arr];
for (Student *stu in stuArr) {NSLog(@"%@ %@ %ld", stu.name, stu.sex, stu.age);
}
}
// 删除数据
(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:4];
}
// 插入数据
(void)insertAction
{Student *stu = [[Student alloc] init]; stu.name = @"卞一"; stu.sex = @"男"; stu.age = 21; [[DataBaseHandle shareDataBase] insertDataWithStu:stu];
}
// 删除表单
(void)dropTableAction
{[[DataBaseHandle shareDataBase] deleteTable];
}
// 创建表单
(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