Commit 4e3a96be authored by Choi Ga Young's avatar Choi Ga Young
Browse files

DB연결중

parent e96aa4df
import React, { useState } from 'react';
import { StyleSheet, Text, View, FlatList, TouchableOpacity, Modal, Alert, TouchableWithoutFeedback, Keyboard } from 'react-native';
import TodoItem from './components/todoItem';
import TodoItem from './components/TodoItem';
import InfoForm from './screens/InfoForm';
import Ionicons from 'react-native-vector-icons/Ionicons';
import InfoDetails from './screens/InfoDetails'
import ButtonsForm from './components/ButtonsForm';
import { TabView } from 'react-native-elements';
......
import React, { useState } from 'react';
import { StyleSheet, Text, View, FlatList, TouchableOpacity, Modal, TouchableWithoutFeedback, Keyboard } from 'react-native';
import TodoItem from './components/todoItem';
import TodoItem from './components/TodoItem';
import Ionicons from 'react-native-vector-icons/Ionicons';
import { NavigationContainer } from '@react-navigation/native';
import MemoDetails from './screens/MemoDetails';
......
import React from 'react';
import React, { useEffect } from 'react';
import Calendar from './components/Calendar';
import calApi from './db/calendarInfo.api';
const Montly = ({ navigation }) => {
const getData = async () => {
try {
const totalM = await calApi.getFullData()
console.log('db res', totalM)
} catch (error) {
console.log('error in getData', error)
}
}
useEffect(() => {
getData()
}, [])
return (
<Calendar navigation={navigation} />
<Calendar navigation={navigation} MData={totalM} />
)
}
......
......@@ -38,7 +38,7 @@ const INIT_Data = [
},
];
function Calendar({ navigation }) {
function Calendar({ navigation, MData }) {
const date = new Date();
const [year, setYear] = useState(date.getFullYear());
const [month, setMonth] = useState(date.getMonth());
......@@ -71,9 +71,9 @@ function Calendar({ navigation }) {
}
//DB 데이터와 날짜 비교
for (let i = 0; i < INIT_Data.length; i++) {
const str = INIT_Data[i].date
DBDates.push({ date: new Date(Number(str.slice(0, 4)), Number(str.slice(5, 7)) - 1, Number(str.slice(8, 10))), type: INIT_Data[i].type })
for (let i = 0; i < MData.length; i++) {
const str = MData[i].date
DBDates.push({ date: new Date(Number(str.slice(0, 4)), Number(str.slice(5, 7)) - 1, Number(str.slice(8, 10))), type: MData[i].type })
}
for (let i = 0; i < Dates.length; i++) {
......@@ -99,7 +99,7 @@ function Calendar({ navigation }) {
color = '#a9a9a9'
}
return (
<DateItem dateitem={item} textColor={{ color }} onPress={() => navigation.navigate('DetailInfo',item.date)} flatListHeight={flatListHeight / (Dates.length / 7)} />
<DateItem dateitem={item} textColor={{ color }} onPress={() => navigation.navigate('DetailInfo', item.date)} flatListHeight={flatListHeight / (Dates.length / 7)} />
)
}
const prevBtn = () => {
......
import { DEBUG, enablePromise } from 'react-native-sqlite-storage';
import getDb from './moneyDB'
DEBUG(true);
enablePromise(true);
const getFullData = async () => {
const db = await getDb();
return new Promise((res, rej) => {
db.transaction(async (tx) => {
console.log('월간 데이터');
const [txn, results] = await tx.executeSql('SELECT * FROM money WHERE date BETWEEN "2021-07-01" AND "2021-07-31"');
const temp = [];
for (let i = 0; i < results.rows.length; i++) {
console.log('item check', results.rows.item(i));
if (results.rows.item(i).type == '수입') {
temp.push({ date: results.rows.item(i).date, type: { 'input': results.rows.item(i).price } })
}
if (results.rows.item(i).type == '지출') {
temp.push({ date: results.rows.item(i).date, type: { 'output': results.rows.item(i).price } })
}
}
console.log('temp1', temp)
temp.sort(function (a, b) {
return a.date < b.date ? -1 : a.date > b.date ? 1 : 0;
})
const temp2 = [temp[0]]
for (let i = 1; i < temp.length; i++) {
if (temp[i].date === temp[i-1].date) {
let lastObj = temp2.pop()
let newObj = lastObj.type
for (const key in temp[i].type) {
let data = 0
if (newObj.hasOwnProperty(key)) {
console.log('둘이 더할거임', temp[i].date, newObj[key], ' + ', temp[i].type[key], data)
data = newObj[key] + temp[i].type[key]
newObj[key] = data
} else {
newObj[key] = temp[i].type[key]
}
console.log('TETETET', temp[i].date, newObj)
}
temp2.push({ date: temp[i].date, type: newObj})
} else {
temp2.push(temp[i])
}
}
console.log('temp2', temp2)
res(temp2);
})
})
}
const calApi = {
getFullData
}
export default calApi;
\ No newline at end of file
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