Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
Helping_hand-419-423-604
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tharun kumar
Helping_hand-419-423-604
Commits
47e7c4ec
Commit
47e7c4ec
authored
5 years ago
by
Tharun kumar
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
d3001ca0
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Register.java
+117
-0
117 additions, 0 deletions
Register.java
with
117 additions
and
0 deletions
Register.java
0 → 100644
+
117
−
0
View file @
47e7c4ec
package
com.example.fund_restart
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.content.Context
;
import
android.database.Cursor
;
import
android.database.sqlite.SQLiteDatabase
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.Toast
;
import
androidx.appcompat.app.AlertDialog
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.cardview.widget.CardView
;
public
class
Register
extends
AppCompatActivity
implements
View
.
OnClickListener
{
EditText
register_name
,
register_email
,
register_password
;
Button
btnAdd
,
btnViewAll
;
SQLiteDatabase
db
;
CardView
btnAd
;
String
regex
=
"^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$"
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_register
);
register_name
=
(
EditText
)
findViewById
(
R
.
id
.
register_name
);
register_email
=
(
EditText
)
findViewById
(
R
.
id
.
register_email
);
register_password
=
(
EditText
)
findViewById
(
R
.
id
.
register_password
);
db
=
openOrCreateDatabase
(
"StudentDB"
,
Context
.
MODE_PRIVATE
,
null
);
db
.
execSQL
(
"CREATE TABLE IF NOT EXISTS student(name VARCHAR,email VARCHAR,password VARCHAR);"
);
btnAd
=
findViewById
(
R
.
id
.
btnAdd
);
btnAd
.
setOnClickListener
(
this
);
}
@Override
public
void
onClick
(
View
view
)
{
// Adding a record
if
(
view
==
btnAd
)
{
// Checking empty fields
if
(
register_name
.
getText
().
toString
().
trim
().
length
()
==
0
||
register_email
.
getText
().
toString
().
trim
().
length
()
==
0
||
register_password
.
getText
().
toString
().
trim
().
length
()
==
0
)
{
showMessage
(
"Error"
,
"Please enter all values"
);
return
;
}
if
(
register_email
.
getText
().
toString
().
matches
(
regex
))
{
Cursor
x
=
db
.
rawQuery
(
"SELECT COUNT (email) FROM student WHERE email='"
+
register_email
.
getText
()
+
"'"
,
null
);
if
(
x
.
moveToFirst
())
{
if
(
x
.
getInt
(
0
)
==
0
)
{
Toast
.
makeText
(
getApplicationContext
(),
"Pls wait patiently...while creating your account"
,
Toast
.
LENGTH_LONG
).
show
();
db
.
execSQL
(
"INSERT INTO student VALUES('"
+
register_name
.
getText
()
+
"','"
+
register_email
.
getText
()
+
"','"
+
register_password
.
getText
()
+
"');"
);
Toast
.
makeText
(
getApplicationContext
(),
"Success....Account CREATED!!!!!"
,
Toast
.
LENGTH_SHORT
).
show
();
clearText
();
}
else
{
showMessage
(
"email already exists"
,
"pls try a different one "
);
register_email
.
setText
(
""
);
}
}
else
{
Toast
.
makeText
(
getApplicationContext
(),
"Password doesn't match..."
,
Toast
.
LENGTH_LONG
).
show
();
register_password
.
setText
(
""
);
}
}
else
{
showMessage
(
"Error"
,
"enter correct email "
);
}
}
clearText
();
// Deleting a record
// Viewing all records
if
(
view
==
btnViewAll
)
{
// Retrieving all records
Cursor
c
=
db
.
rawQuery
(
"SELECT * FROM student"
,
null
);
// Checking if no records found
if
(
c
.
getCount
()
==
0
)
{
showMessage
(
"Error"
,
"No records found"
);
return
;
}
// Appending records to a string buffer
StringBuffer
buffer
=
new
StringBuffer
();
while
(
c
.
moveToNext
())
{
buffer
.
append
(
"Name: "
+
c
.
getString
(
0
)
+
"\n"
);
buffer
.
append
(
"Email: "
+
c
.
getString
(
1
)
+
"\n"
);
buffer
.
append
(
"Password: "
+
c
.
getString
(
2
)
+
"\n\n"
);
}
// Displaying all records
showMessage
(
"Student Details"
,
buffer
.
toString
());
}
// Displaying info
}
public
void
showMessage
(
String
title
,
String
message
){
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
builder
.
setCancelable
(
true
);
builder
.
setTitle
(
title
);
builder
.
setMessage
(
message
);
builder
.
show
();
}
public
void
clearText
(){
register_name
.
setText
(
""
);
register_email
.
setText
(
""
);
register_password
.
setText
(
""
);
register_name
.
requestFocus
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment