Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
rich-maker
Commits
2178e112
Commit
2178e112
authored
Jul 11, 2021
by
Soo Hyun Kim
Browse files
0711 PostMoney에 임시로 db 불러옴
parent
57b56ce4
Changes
1
Show whitespace changes
Inline
Side-by-side
PostMoney.js
View file @
2178e112
import
React
,
{
useState
}
from
'
react
'
;
import
{
View
,
Text
,
StyleSheet
,
Button
}
from
'
react-native
'
;
import
{
DEBUG
,
enablePromise
,
openDatabase
}
from
'
react-native-sqlite-storage
'
;
import
InputBox
from
'
./components/InputBox
'
;
import
ButtonsForm
from
'
./components/ButtonsForm
'
;
import
SelectForm
from
'
./components/SelectForm
'
;
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
=
[
{
asset_id
:
'
1
'
,
...
...
@@ -37,6 +47,7 @@ const INIT_CATEGORIES = [
const
PostMoney
=
()
=>
{
const
[
selectedIndex
,
setSelectedIndex
]
=
useState
(
0
)
const
[
date
,
setDate
]
=
useState
(
'
2021-07-09
'
)
const
[
contents
,
setContents
]
=
useState
(
''
)
const
[
price
,
setPrice
]
=
useState
(
0
)
const
[
asset_type
,
setAsset_type
]
=
useState
(
INIT_ASSET_TYPE
)
...
...
@@ -46,6 +57,24 @@ const PostMoney = () => {
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
(
<
View
>
<
View
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment