Commit 2178e112 authored by Soo Hyun Kim's avatar Soo Hyun Kim
Browse files

0711 PostMoney에 임시로 db 불러옴

parent 57b56ce4
import React, { useState } from 'react'; import React, { useState } from 'react';
import { View, Text, StyleSheet, Button } from 'react-native'; import { View, Text, StyleSheet, Button } from 'react-native';
import { DEBUG, enablePromise, openDatabase } from 'react-native-sqlite-storage';
import InputBox from './components/InputBox'; import InputBox from './components/InputBox';
import ButtonsForm from './components/ButtonsForm'; import ButtonsForm from './components/ButtonsForm';
import SelectForm from './components/SelectForm'; import SelectForm from './components/SelectForm';
import StyledButton from './components/StyledButton'; import StyledButton from './components/StyledButton';
DEBUG(true);
enablePromise(true);
const db = openDatabase({
name: 'MyMoney',
location: 'default',
createFromLocation: '~MyMoney.db', // android/src/main/assets/TestDB.db 파일을 위치 시킴
});
const INIT_ASSET_TYPE = [ const INIT_ASSET_TYPE = [
{ {
asset_id: '1', asset_id: '1',
...@@ -37,6 +47,7 @@ const INIT_CATEGORIES = [ ...@@ -37,6 +47,7 @@ const INIT_CATEGORIES = [
const PostMoney = () => { const PostMoney = () => {
const [selectedIndex, setSelectedIndex] = useState(0) const [selectedIndex, setSelectedIndex] = useState(0)
const [date, setDate] = useState('2021-07-09')
const [contents, setContents] = useState('') const [contents, setContents] = useState('')
const [price, setPrice] = useState(0) const [price, setPrice] = useState(0)
const [asset_type, setAsset_type] = useState(INIT_ASSET_TYPE) const [asset_type, setAsset_type] = useState(INIT_ASSET_TYPE)
...@@ -46,6 +57,24 @@ const PostMoney = () => { ...@@ -46,6 +57,24 @@ const PostMoney = () => {
console.log('입력 데이터 : ', selectedIndex, contents, price, selected_asset_type, selected_cat) console.log('입력 데이터 : ', selectedIndex, contents, price, selected_asset_type, selected_cat)
const insertData = async () => {
try {
if (selectedIndex === 0) {type = '수입'}
else if (selectedIndex === 1) {type = '지출'}
else {type = '이동'}
(await db).transaction((tx) => {
console.log("데이터 삽입하기");
tx.executeSql('INSERT INTO Money (type, date, contents, price, asset_type, category) VALUES (?,?);',
[expense, income],
() => { console.log("삽입 성공"); },
(error) => console.log(error))
})
} catch (error) {
console.log('error in insert data', error)
}
}
return ( return (
<View> <View>
<View> <View>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment