-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b87d850
commit 6a145cb
Showing
10 changed files
with
715 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// https://blog.edafait.com | ||
// https://www.edafait.com | ||
|
||
import 'react-native-gesture-handler'; | ||
|
||
import * as React from 'react'; | ||
import { Button, View, Text } from 'react-native'; | ||
|
||
import { NavigationContainer } from '@react-navigation/native'; | ||
import { createStackNavigator } from '@react-navigation/stack'; | ||
|
||
import HomeScreen from './pages/HomeScreen'; | ||
import NewContact from './pages/NewContact'; | ||
import UpdateUser from './pages/UpdateUser'; | ||
import ViewUser from './pages/ViewUser'; | ||
import ViewAllUser from './pages/ViewAllUser'; | ||
import DeleteUser from './pages/DeleteUser'; | ||
|
||
const Stack = createStackNavigator(); | ||
|
||
const App = () => { | ||
return ( | ||
<NavigationContainer> | ||
<Stack.Navigator initialRouteName="HomeScreen"> | ||
<Stack.Screen | ||
name="HomeScreen" | ||
component={HomeScreen} | ||
options={{ | ||
title: 'Home', //Set Header Title | ||
headerStyle: { | ||
backgroundColor: '#221eeb', //Set Header color | ||
}, | ||
headerTintColor: '#fff', //Set Header text color | ||
headerTitleStyle: { | ||
fontWeight: 'bold', //Set Header text style | ||
}, | ||
}} | ||
/> | ||
<Stack.Screen | ||
name="View" | ||
component={ViewUser} | ||
options={{ | ||
title: 'View User', //Set Header Title | ||
headerStyle: { | ||
backgroundColor: '#221eeb', //Set Header color | ||
}, | ||
headerTintColor: '#fff', //Set Header text color | ||
headerTitleStyle: { | ||
fontWeight: 'bold', //Set Header text style | ||
}, | ||
}} | ||
/> | ||
<Stack.Screen | ||
name="ViewAll" | ||
component={ViewAllUser} | ||
options={{ | ||
title: 'View Users', //Set Header Title | ||
headerStyle: { | ||
backgroundColor: '#221eeb', //Set Header color | ||
}, | ||
headerTintColor: '#fff', //Set Header text color | ||
headerTitleStyle: { | ||
fontWeight: 'bold', //Set Header text style | ||
}, | ||
}} | ||
/> | ||
<Stack.Screen | ||
name="Update" | ||
component={UpdateUser} | ||
options={{ | ||
title: 'Update User', //Set Header Title | ||
headerStyle: { | ||
backgroundColor: '#221eeb', //Set Header color | ||
}, | ||
headerTintColor: '#fff', //Set Header text color | ||
headerTitleStyle: { | ||
fontWeight: 'bold', //Set Header text style | ||
}, | ||
}} | ||
/> | ||
<Stack.Screen | ||
name="NewContact" | ||
component={NewContact} | ||
options={{ | ||
title: 'New Contact', //Set Header Title | ||
headerStyle: { | ||
backgroundColor: '#221eeb', //Set Header color | ||
}, | ||
headerTintColor: '#fff', //Set Header text color | ||
headerTitleStyle: { | ||
fontWeight: 'bold', //Set Header text style | ||
}, | ||
}} | ||
/> | ||
<Stack.Screen | ||
name="Delete" | ||
component={DeleteUser} | ||
options={{ | ||
title: 'Delete User', //Set Header Title | ||
headerStyle: { | ||
backgroundColor: '#221eeb', //Set Header color | ||
}, | ||
headerTintColor: '#fff', //Set Header text color | ||
headerTitleStyle: { | ||
fontWeight: 'bold', //Set Header text style | ||
}, | ||
}} | ||
/> | ||
</Stack.Navigator> | ||
</NavigationContainer> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// https://blog.edafait.com | ||
// https://www.edafait.com | ||
|
||
// Screen to delete the user | ||
|
||
import React, { useState } from 'react'; | ||
import { Button, Text, View, Alert, SafeAreaView } from 'react-native'; | ||
import Mytextinput from './components/Mytextinput'; | ||
import Mybutton from './components/Mybutton'; | ||
import { openDatabase } from 'react-native-sqlite-storage'; | ||
|
||
var db = openDatabase({ name: 'UserDatabase.db' }); | ||
|
||
const DeleteUser = ({ navigation }) => { | ||
let [inputUserId, setInputUserId] = useState(''); | ||
|
||
let deleteUser = () => { | ||
db.transaction((tx) => { | ||
tx.executeSql( | ||
'DELETE FROM table_user where user_id=?', | ||
[inputUserId], | ||
(tx, results) => { | ||
console.log('Results', results.rowsAffected); | ||
if (results.rowsAffected > 0) { | ||
Alert.alert( | ||
'Success', | ||
'User deleted successfully', | ||
[ | ||
{ | ||
text: 'Ok', | ||
onPress: () => navigation.navigate('HomeScreen'), | ||
}, | ||
], | ||
{ cancelable: false } | ||
); | ||
} else { | ||
alert('Please insert a valid User Id'); | ||
} | ||
} | ||
); | ||
}); | ||
}; | ||
|
||
return ( | ||
<SafeAreaView style={{ flex: 1 }}> | ||
<View style={{ flex: 1, backgroundColor: 'white' }}> | ||
<View style={{ flex: 1 }}> | ||
<Mytextinput | ||
placeholder="Enter User Id" | ||
onChangeText={(inputUserId) => setInputUserId(inputUserId)} | ||
style={{ padding: 10 }} | ||
/> | ||
<Mybutton title="Delete User" customClick={deleteUser} /> | ||
</View> | ||
<Text style={{ fontSize: 16, textAlign: 'center', color: 'Black' }}> | ||
www.edafait.com | ||
</Text> | ||
</View> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
export default DeleteUser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// https://blog.edafait.com | ||
// https://www.edafait.com | ||
|
||
import React, { useEffect } from 'react'; | ||
import { View, Text, SafeAreaView } from 'react-native'; | ||
import Mybutton from './components/Mybutton'; | ||
import Mytext from './components/Mytext'; | ||
import { openDatabase } from 'react-native-sqlite-storage'; | ||
|
||
var db = openDatabase({ name: 'UserDatabase.db' }); | ||
|
||
const HomeScreen = ({ navigation }) => { | ||
useEffect(() => { | ||
db.transaction(function (txn) { | ||
txn.executeSql( | ||
"SELECT name FROM sqlite_master WHERE type='table' AND name='table_user'", | ||
[], | ||
function (tx, res) { | ||
console.log('item:', res.rows.length); | ||
if (res.rows.length == 0) { | ||
txn.executeSql('DROP TABLE IF EXISTS table_user', []); | ||
txn.executeSql( | ||
'CREATE TABLE IF NOT EXISTS table_user(user_id INTEGER PRIMARY KEY AUTOINCREMENT, user_name VARCHAR(20), user_contact INT(10), user_address VARCHAR(255))', | ||
[] | ||
); | ||
} | ||
} | ||
); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<SafeAreaView style={{ flex: 1 }}> | ||
<View style={{ flex: 1, backgroundColor: 'white' }}> | ||
<View style={{ flex: 1 }}> | ||
<Mytext text="SQLite Example" /> | ||
<Mybutton | ||
title="New Contact" | ||
customClick={() => navigation.navigate('NewContact')} | ||
/> | ||
<Mybutton | ||
title="Update" | ||
customClick={() => navigation.navigate('Update')} | ||
/> | ||
<Mybutton | ||
title="View" | ||
customClick={() => navigation.navigate('View')} | ||
/> | ||
<Mybutton | ||
title="View All" | ||
customClick={() => navigation.navigate('ViewAll')} | ||
/> | ||
<Mybutton | ||
title="Delete" | ||
customClick={() => navigation.navigate('Delete')} | ||
/> | ||
</View> | ||
<Text style={{ fontSize: 16, textAlign: 'center', color: 'Black' }}> | ||
www.edafait.com | ||
</Text> | ||
</View> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
export default HomeScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// https://blog.edafait.com | ||
// https://www.edafait.com | ||
// Screen to ADD the user | ||
|
||
import React, { useState } from 'react'; | ||
import { | ||
View, | ||
ScrollView, | ||
KeyboardAvoidingView, | ||
Alert, | ||
SafeAreaView, | ||
Text, | ||
} from 'react-native'; | ||
import Mytextinput from './components/Mytextinput'; | ||
import Mybutton from './components/Mybutton'; | ||
import { openDatabase } from 'react-native-sqlite-storage'; | ||
|
||
var db = openDatabase({ name: 'UserDatabase.db' }); | ||
|
||
const NewContact = ({ navigation }) => { | ||
let [userName, setUserName] = useState(''); | ||
let [userContact, setUserContact] = useState(''); | ||
let [userAddress, setUserAddress] = useState(''); | ||
|
||
let register_user = () => { | ||
console.log(userName, userContact, userAddress); | ||
|
||
if (!userName) { | ||
alert('Please fill name'); | ||
return; | ||
} | ||
if (!userContact) { | ||
alert('Please fill Contact Number'); | ||
return; | ||
} | ||
if (!userAddress) { | ||
alert('Please fill Address'); | ||
return; | ||
} | ||
|
||
db.transaction(function (tx) { | ||
tx.executeSql( | ||
'INSERT INTO table_user (user_name, user_contact, user_address) VALUES (?,?,?)', | ||
[userName, userContact, userAddress], | ||
(tx, results) => { | ||
console.log('Results', results.rowsAffected); | ||
if (results.rowsAffected > 0) { | ||
Alert.alert( | ||
'Success', | ||
'Add New Contact Successfully', | ||
[ | ||
{ | ||
text: 'Ok', | ||
onPress: () => navigation.navigate('HomeScreen'), | ||
}, | ||
], | ||
{ cancelable: false } | ||
); | ||
} else alert('Add New Contact Failed'); | ||
} | ||
); | ||
}); | ||
}; | ||
|
||
return ( | ||
<SafeAreaView style={{ flex: 1 }}> | ||
<View style={{ flex: 1, backgroundColor: 'white' }}> | ||
<View style={{ flex: 1 }}> | ||
<ScrollView keyboardShouldPersistTaps="handled"> | ||
<KeyboardAvoidingView | ||
behavior="padding" | ||
style={{ flex: 1, justifyContent: 'space-between' }}> | ||
<Mytextinput | ||
placeholder="Enter Name" | ||
onChangeText={(userName) => setUserName(userName)} | ||
style={{ padding: 10 }} | ||
/> | ||
<Mytextinput | ||
placeholder="Enter Contact No" | ||
onChangeText={(userContact) => setUserContact(userContact)} | ||
maxLength={10} | ||
keyboardType="numeric" | ||
style={{ padding: 10 }} | ||
/> | ||
<Mytextinput | ||
placeholder="Enter Address" | ||
onChangeText={(userAddress) => setUserAddress(userName)} | ||
maxLength={225} | ||
numberOfLines={5} | ||
multiline={true} | ||
style={{ textAlignVertical: 'top', padding: 10 }} | ||
/> | ||
<Mybutton title="Submit" customClick={register_user} /> | ||
</KeyboardAvoidingView> | ||
</ScrollView> | ||
</View> | ||
<Text style={{ fontSize: 16, textAlign: 'center', color: 'Black' }}> | ||
www.edafait.com | ||
</Text> | ||
</View> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
export default NewContact; | ||
|
Oops, something went wrong.