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
5a3649e7
Commit
5a3649e7
authored
5 years ago
by
Tharun kumar
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
47e7c4ec
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
Userlogin.java
+159
-0
159 additions, 0 deletions
Userlogin.java
with
159 additions
and
0 deletions
Userlogin.java
0 → 100644
+
159
−
0
View file @
5a3649e7
package
com.example.fund_restart
;
import
androidx.appcompat.app.AlertDialog
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.cardview.widget.CardView
;
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.TextView
;
import
android.widget.Toast
;
public
class
Userlogin
extends
AppCompatActivity
implements
View
.
OnClickListener
{
EditText
register_name1
,
register_email1
,
register_password1
;
CardView
btnAdd2
,
btnViewshow
;
SQLiteDatabase
db
;
Button
delete_data
,
data_search
;
String
regex
=
"^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$"
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_userlogin
);
register_name1
=
(
EditText
)
findViewById
(
R
.
id
.
register_name1
);
register_email1
=
(
EditText
)
findViewById
(
R
.
id
.
register_email1
);
register_password1
=
(
EditText
)
findViewById
(
R
.
id
.
register_password1
);
delete_data
=
findViewById
(
R
.
id
.
data_delete
);
data_search
=
findViewById
(
R
.
id
.
data_search
);
btnViewshow
=
findViewById
(
R
.
id
.
btnshow
);
db
=
openOrCreateDatabase
(
"StudentDB"
,
Context
.
MODE_PRIVATE
,
null
);
db
.
execSQL
(
"CREATE TABLE IF NOT EXISTS student(name VARCHAR,email VARCHAR,password VARCHAR);"
);
btnAdd2
=
findViewById
(
R
.
id
.
btnAdd2
);
btnAdd2
.
setOnClickListener
(
this
);
btnViewshow
.
setOnClickListener
(
this
);
}
@Override
public
void
onClick
(
View
view
)
{
if
(
view
==
delete_data
)
{
// Checking empty roll number
if
(
register_email1
.
getText
().
toString
().
trim
().
length
()
==
0
)
{
showMessage
(
"Error"
,
"Please enter Rollno"
);
return
;
}
// Searching roll number
Cursor
c
=
db
.
rawQuery
(
"SELECT * FROM student WHERE email='"
+
register_email1
.
getText
()
+
"'"
,
null
);
if
(
c
.
moveToFirst
())
{
// Deleting record if found
showMessage
(
"Success"
,
"Record Deleted"
);
db
.
execSQL
(
"DELETE FROM student WHERE email='"
+
register_email1
.
getText
()
+
"'"
);
}
else
{
showMessage
(
"Error"
,
"Invalid email"
);
}
clearText
();
}
// Modifying a record
// Viewing a record
if
(
view
==
data_search
)
{
// Checking empty roll number
if
(
register_email1
.
getText
().
toString
().
trim
().
length
()
==
0
)
{
showMessage
(
"Error"
,
"Please enter Rollno"
);
return
;
}
// Searching roll number
Cursor
c
=
db
.
rawQuery
(
"SELECT * FROM student WHERE email='"
+
register_email1
.
getText
()
+
"'"
,
null
);
if
(
c
.
moveToFirst
())
{
// Displaying record if found
register_password1
.
setText
(
c
.
getString
(
1
));
}
else
{
showMessage
(
"Error"
,
"Invalid Rollno"
);
clearText
();
}
}
if
(
view
==
btnAdd2
)
{
// Checking empty fields
if
(
register_name1
.
getText
().
toString
().
trim
().
length
()
==
0
||
register_email1
.
getText
().
toString
().
trim
().
length
()
==
0
||
register_password1
.
getText
().
toString
().
trim
().
length
()
==
0
)
{
showMessage
(
"Error"
,
"Please enter all values"
);
return
;
}
if
(
register_email1
.
getText
().
toString
().
matches
(
regex
))
{
Cursor
x
=
db
.
rawQuery
(
"SELECT COUNT (email) FROM student WHERE email='"
+
register_email1
.
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_name1
.
getText
()
+
"','"
+
register_email1
.
getText
()
+
"','"
+
register_password1
.
getText
()
+
"');"
);
Toast
.
makeText
(
getApplicationContext
(),
"Success....Account CREATED!!!!!"
,
Toast
.
LENGTH_SHORT
).
show
();
clearText
();
}
else
{
showMessage
(
"email already exists"
,
"pls try a different one "
);
register_email1
.
setText
(
""
);
}
}
else
{
Toast
.
makeText
(
getApplicationContext
(),
"Password doesn't match..."
,
Toast
.
LENGTH_LONG
).
show
();
register_password1
.
setText
(
""
);
}
}
else
{
showMessage
(
"Error"
,
"enter correct email "
);
}
}
clearText
();
// Deleting a record
// Viewing all records
if
(
view
==
btnViewshow
)
{
// 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_name1
.
setText
(
""
);
register_email1
.
setText
(
""
);
register_password1
.
setText
(
""
);
register_name1
.
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