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
e14353c4
Commit
e14353c4
authored
Jul 23, 2021
by
Soo Hyun Kim
Browse files
0723 db 변경사항
parent
a12bc2cf
Changes
6
Hide whitespace changes
Inline
Side-by-side
MoneyDB.js
deleted
100644 → 0
View file @
a12bc2cf
import
{
DEBUG
,
enablePromise
,
openDatabase
}
from
'
react-native-sqlite-storage
'
;
DEBUG
(
true
);
enablePromise
(
true
);
const
db
=
openDatabase
({
name
:
'
MyMoney
'
,
location
:
'
default
'
,
createFromLocation
:
'
~MyMoney.db
'
,
// android/src/main/assets/TestDB.db 파일을 위치 시킴
});
const
QueryFunc
=
async
(
Query
)
=>
{
(
await
db
).
transaction
(
Query
)
};
const
moneyApi
=
{
QueryFunc
,
}
export
default
moneyApi
\ No newline at end of file
PostMoney.js
View file @
e14353c4
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
React
,
{
useState
,
useEffect
}
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
'
;
import
DatePicker
from
'
./components/DatePicker
'
;
import
DatePicker
from
'
./components/DatePicker
'
;
import
moneyApi
from
'
./MoneyDB
'
;
import
moneyApi
from
'
./db/postMoney.api
'
;
DEBUG
(
true
);
enablePromise
(
true
);
const
db
=
openDatabase
({
name
:
'
MyMoney
'
,
location
:
'
default
'
,
createFromLocation
:
'
~MyMoney.db
'
,
// android/src/main/assets/TestDB.db 파일을 위치 시킴
});
const
getDate
=
()
=>
{
const
getDate
=
()
=>
{
var
date
=
new
Date
();
var
date
=
new
Date
();
...
@@ -73,17 +62,13 @@ const PostMoney = () => {
...
@@ -73,17 +62,13 @@ const PostMoney = () => {
const
insertData
=
async
()
=>
{
const
insertData
=
async
()
=>
{
try
{
try
{
let
type
=
''
let
type
=
''
if
(
selectedIndex
===
0
)
{
type
=
'
수입
'
}
if
(
selectedIndex
===
0
)
{
type
=
'
수입
'
}
else
if
(
selectedIndex
===
1
)
{
type
=
'
지출
'
}
else
if
(
selectedIndex
===
1
)
{
type
=
'
지출
'
}
else
{
type
=
'
이동
'
}
else
{
type
=
'
이동
'
}
(
await
db
).
transaction
((
tx
)
=>
{
const
result
=
await
moneyApi
.
insertMoney
([
type
,
date
,
contents
,
price
,
selected_asset_type
,
selected_cat
,
selected_subcat
])
console
.
log
(
"
데이터 삽입하기
"
);
console
.
log
(
result
)
tx
.
executeSql
(
'
INSERT INTO Money (type, date, contents, price, asset_type, category, subcategory) VALUES (?,?,?,?,?,?,?);
'
,
[
type
,
date
,
contents
,
price
,
selected_asset_type
,
selected_cat
,
selected_subcat
],
()
=>
{
console
.
log
(
"
삽입 성공
"
);
},
(
error
)
=>
console
.
log
(
error
))
})
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
'
error in insert data
'
,
error
)
console
.
log
(
'
error in insert data
'
,
error
)
}
}
...
@@ -91,42 +76,24 @@ const PostMoney = () => {
...
@@ -91,42 +76,24 @@ const PostMoney = () => {
const
loadCat
=
async
()
=>
{
const
loadCat
=
async
()
=>
{
try
{
try
{
await
moneyApi
.
QueryFunc
(
async
(
tx
)
=>
{
const
catArray
=
await
moneyApi
.
selectCategories
()
console
.
log
(
"
카테고리 부르기
"
);
console
.
log
(
'
catload
'
,
catArray
)
const
[
txn
,
results
]
=
await
tx
.
executeSql
(
'
SELECT * FROM categories
'
);
setCategories
(
catArray
);
console
.
log
(
'
item length
'
,
results
.
rows
.
length
);
const
temp
=
[];
for
(
let
i
=
0
;
i
<
results
.
rows
.
length
;
i
++
)
{
const
tempId
=
results
.
rows
.
item
(
i
).
category_id
;
const
tempName
=
results
.
rows
.
item
(
i
).
category_name
;
temp
.
push
({
id
:
tempId
,
value
:
tempName
});
}
setCategories
(
temp
);
})
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
'
error in load
d
at
a
( postMoney.js )
'
,
error
)
console
.
log
(
'
error in load
c
at
egories
( postMoney.js )
'
,
error
)
}
}
}
}
const
loadAssetType
=
async
()
=>
{
const
loadAssetType
=
async
()
=>
{
try
{
try
{
(
await
db
).
transaction
(
async
(
tx
)
=>
{
const
assetsTypeArray
=
await
moneyApi
.
selectAssetsType
()
console
.
log
(
"
자산 유형 부르기
"
);
setAsset_type
(
assetsTypeArray
);
const
[
txn
,
results
]
=
await
tx
.
executeSql
(
'
SELECT * FROM assets_type
'
);
console
.
log
(
'
item length
'
,
results
.
rows
.
length
);
const
temp
=
[];
for
(
let
i
=
0
;
i
<
results
.
rows
.
length
;
i
++
)
{
const
tempId
=
results
.
rows
.
item
(
i
).
assets_id
;
const
tempName
=
results
.
rows
.
item
(
i
).
assets_name
;
temp
.
push
({
id
:
tempId
,
value
:
tempName
});
}
setAsset_type
(
temp
);
})
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
'
error in
insert data
'
,
error
)
console
.
log
(
'
error in
load assets type ( postMoney.js )
'
,
error
)
}
}
}
}
useEffect
(()
=>
{
useEffect
(()
=>
{
loadCat
()
loadCat
()
loadAssetType
()
loadAssetType
()
...
...
components/Notification.js
View file @
e14353c4
import
React
,
{
useEffect
,
useRef
}
from
'
react
'
;
import
React
,
{
useEffect
,
useRef
}
from
'
react
'
;
import
{
Animated
,
Text
,
View
,
StyleSheet
}
from
'
react-native
'
;
import
{
Animated
,
Text
,
View
,
StyleSheet
}
from
'
react-native
'
;
const
Notification
=
(
props
)
=>
{
const
Notification
Box
=
(
props
)
=>
{
const
opacity
=
useRef
(
new
Animated
.
Value
(
0
)).
current
;
const
opacity
=
useRef
(
new
Animated
.
Value
(
0
)).
current
;
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
props
.
notification
!==
''
)
{
Animated
.
sequence
([
Animated
.
sequence
([
Animated
.
timing
(
opacity
,
{
Animated
.
timing
(
opacity
,
{
toValue
:
1
,
toValue
:
1
,
duration
:
500
,
duration
:
500
,
useNativeDriver
:
true
,
useNativeDriver
:
true
,
}),
}),
Animated
.
delay
(
2500
),
Animated
.
delay
(
2500
),
Animated
.
timing
(
opacity
,
{
Animated
.
timing
(
opacity
,
{
toValue
:
0
,
toValue
:
0
,
duration
:
500
,
duration
:
500
,
useNativeDriver
:
true
,
useNativeDriver
:
true
,
}),
}),
]).
start
(()
=>
{
]).
start
(()
=>
{
props
.
onHide
();
props
.
setNotification
(
''
);
})
})
},
[])
}
},
[
props
.
notification
])
return
(
<
Animated
.
View
style
=
{[
{
opacity
:
opacity
},
{
transform
:
[{
translateY
:
opacity
.
interpolate
({
inputRange
:
[
0
,
1
],
outputRange
:
[
-
20
,
0
],
})
}],
},
style
.
msgBox
]}
>
<
Text
style
=
{
style
.
textStyle
}
>
{
props
.
message
}
<
/Text
>
<
/Animated.View
>
);
};
const
Notification
=
(
props
)
=>
{
return
(
return
(
<
View
style
=
{{
<
View
style
=
{{
position
:
'
absolute
'
,
position
:
'
absolute
'
,
...
@@ -31,29 +54,21 @@ const Notification = (props) => {
...
@@ -31,29 +54,21 @@ const Notification = (props) => {
left
:
0
,
left
:
0
,
right
:
0
,
right
:
0
,
}}
>
}}
>
<
Animated
.
View
{
console
.
log
(
props
.
notification
)}
style
=
{[
{
props
.
notification
.
map
((
notificationMsg
)
=>
(
{
<
NotificationBox
opacity
:
opacity
key
=
{
notificationMsg
}
},
message
=
{
notificationMsg
}
{
onHide
=
{()
=>
{
transform
:
[{
props
.
setNotification
((
prev
)
=>
translateY
:
opacity
.
interpolate
({
prev
.
filter
((
currentNotification
)
=>
currentNotification
!==
notificationMsg
)
inputRange
:
[
0
,
1
],
)
outputRange
:
[
-
20
,
0
],
}}
})
/
>
}],
))}
},
<
/View
>
style
.
msgBox
)
]}
}
>
<
Text
style
=
{
style
.
textStyle
}
>
{
props
.
notification
}
<
/Text
>
<
/Animated.View
>
<
/View
>
);
};
const
style
=
StyleSheet
.
create
({
const
style
=
StyleSheet
.
create
({
msgBox
:
{
msgBox
:
{
...
...
components/SelectForm.js
View file @
e14353c4
...
@@ -17,11 +17,11 @@ const SelectForm = (props) => {
...
@@ -17,11 +17,11 @@ const SelectForm = (props) => {
const
[
subOptionShow
,
setSubOptionShow
]
=
useState
(
false
)
const
[
subOptionShow
,
setSubOptionShow
]
=
useState
(
false
)
const
[
modalOpen
,
setModalOpen
]
=
useState
(
false
)
const
[
modalOpen
,
setModalOpen
]
=
useState
(
false
)
const
[
notification
,
setNotification
]
=
useState
(
''
)
const
[
notification
,
setNotification
]
=
useState
(
[]
)
const
onPressSelectBox
=
()
=>
{
setModalOpen
(
true
)
}
const
onPressSelectBox
=
()
=>
{
setModalOpen
(
true
)
}
const
modalClose
=
()
=>
{
setModalOpen
(
false
)
}
const
modalClose
=
()
=>
{
setModalOpen
(
false
)
;
setNotification
([])
}
const
onPressOption
=
(
item
)
=>
{
const
onPressOption
=
(
item
)
=>
{
if
(
subOption
!==
undefined
)
{
if
(
subOption
!==
undefined
)
{
...
@@ -51,13 +51,12 @@ const SelectForm = (props) => {
...
@@ -51,13 +51,12 @@ const SelectForm = (props) => {
return
true
;
return
true
;
})
})
if
(
newOption
.
length
===
0
)
{
if
(
newOption
.
length
===
0
)
{
setNotification
(
`
${
item
.
value
}
의 세부 카테고리가 존재하지 않습니다.`
)
setNotification
(
(
prev
)
=>
[...
prev
,
`
${
item
.
value
}
의 세부 카테고리가 존재하지 않습니다.`
]
)
}
else
{
}
else
{
setSubOption
(
newOption
)
setSubOption
(
newOption
)
setSubOptionShow
(
true
)
setSubOptionShow
(
true
)
}
}
}
}
const
renderOptionItem
=
({
item
})
=>
(
const
renderOptionItem
=
({
item
})
=>
(
<
TouchableOpacity
onPress
=
{()
=>
onPressOption
(
item
)}
style
=
{
style
.
option
}
>
<
TouchableOpacity
onPress
=
{()
=>
onPressOption
(
item
)}
style
=
{
style
.
option
}
>
<
Text
style
=
{
style
.
optionText
}
>
<
Text
style
=
{
style
.
optionText
}
>
...
...
db/MoneyDB.js
0 → 100644
View file @
e14353c4
import
{
DEBUG
,
enablePromise
,
openDatabase
}
from
'
react-native-sqlite-storage
'
;
DEBUG
(
true
);
enablePromise
(
true
);
const
getDb
=
async
()
=>
{
return
await
openDatabase
({
name
:
'
MyMoney
'
,
location
:
'
default
'
,
createFromLocation
:
'
~MyMoney.db
'
,
})
}
export
default
getDb
\ No newline at end of file
db/postMoney.api.js
0 → 100644
View file @
e14353c4
import
{
DEBUG
,
enablePromise
}
from
'
react-native-sqlite-storage
'
;
import
getDb
from
'
./MoneyDB
'
DEBUG
(
true
);
enablePromise
(
true
);
const
insertMoney
=
async
(
moneyData
)
=>
{
const
db
=
await
getDb
();
return
new
Promise
((
resolve
,
reject
)
=>
{
db
.
transaction
((
tx
)
=>
{
console
.
log
(
"
데이터 삽입하기
"
);
tx
.
executeSql
(
'
INSERT INTO Money (type, date, contents, price, asset_type, category, subcategory) VALUES (?,?,?,?,?,?,?);
'
,
moneyData
,
(
error
)
=>
console
.
log
(
error
))
resolve
(
'
데이터 삽입 완료
'
);
})
})
};
const
selectCategories
=
async
()
=>
{
const
db
=
await
getDb
();
return
new
Promise
((
resolve
,
reject
)
=>
{
db
.
transaction
(
async
(
tx
)
=>
{
console
.
log
(
"
카테고리 부르기
"
);
const
[
txn
,
results
]
=
await
tx
.
executeSql
(
'
SELECT * FROM categories
'
);
console
.
log
(
'
item length
'
,
results
.
rows
.
length
);
const
temp
=
[];
for
(
let
i
=
0
;
i
<
results
.
rows
.
length
;
i
++
)
{
const
tempId
=
results
.
rows
.
item
(
i
).
category_id
;
const
tempName
=
results
.
rows
.
item
(
i
).
category_name
;
temp
.
push
({
id
:
tempId
,
value
:
tempName
});
}
console
.
log
(
temp
)
resolve
(
temp
);
})
})
}
const
selectAssetsType
=
async
()
=>
{
const
db
=
await
getDb
();
return
new
Promise
((
resolve
,
reject
)
=>
{
db
.
transaction
(
async
(
tx
)
=>
{
console
.
log
(
"
자산 유형 부르기
"
);
const
[
txn
,
results
]
=
await
tx
.
executeSql
(
'
SELECT * FROM assets_type
'
);
console
.
log
(
'
item length
'
,
results
.
rows
.
length
);
const
temp
=
[];
for
(
let
i
=
0
;
i
<
results
.
rows
.
length
;
i
++
)
{
const
tempId
=
results
.
rows
.
item
(
i
).
assets_id
;
const
tempName
=
results
.
rows
.
item
(
i
).
assets_name
;
temp
.
push
({
id
:
tempId
,
value
:
tempName
});
}
console
.
log
(
temp
)
resolve
(
temp
);
})
})
}
const
moneyApi
=
{
insertMoney
,
selectCategories
,
selectAssetsType
,
}
export
default
moneyApi
;
\ No newline at end of file
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