Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
package com.example.login; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; public class MainActivity extends ActionBarActivity { String DATABASE_NAME="login.sqlite"; String DATABASE_PATH="/databases/"; SQLiteDatabase database=null; //lấy đường dẫn cho database private String path_data(){ return getApplicationInfo().dataDir + DATABASE_PATH + DATABASE_NAME; } //hàm kết nối với database private void connectData(){ File dbfile=getDatabasePath(DATABASE_NAME); if(!dbfile.exists()){ try{ CopyDatafromassets(); Toast.makeText(this,"Sao chép CSDL vào hệ thống thành công!",Toast.LENGTH_LONG).show(); }catch (Exception e){ Toast.makeText(this, e.toString(),Toast.LENGTH_LONG).show(); } } } //hàm sao chép dữ liệu từ assets đến database của phần mềm private void CopyDatafromassets() { try{ InputStream myinput=getAssets().open(DATABASE_NAME); String outfilename= path_data(); File f=new File(getApplicationInfo().dataDir + DATABASE_PATH); if(!f.exists()){ f.mkdir(); } OutputStream myoutput=new FileOutputStream(outfilename); byte[] buffer= new byte[1024]; int length; while((length=myinput.read(buffer))>0){ myoutput.write(buffer,0,length); } myoutput.flush(); myoutput.close(); myinput.close(); }catch (Exception e){ Log.e("Lỗi sao chép", e.toString()); } } int i=0; TextView username; TextView password; Button login; Button registration; @Override // tạo thuộc tính protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); connectData(); // kết nối dữ liệu connectView(); // ánh xạ clickbtnlogin(); // đăng nhập clickbtnRegistration(); // đăng ký } private void clickbtnRegistration() { registration.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, Registration.class); startActivity(intent); } }); } private void kiemtrataikhoan(String tentaikhoan, String pass) { database=openOrCreateDatabase(DATABASE_NAME,MODE_PRIVATE,null); Cursor cursor =database.rawQuery("SELECT * FROM taikhoan WHERE tentaikhoan=? AND matkhau=?",new String[]{tentaikhoan,pass}); while (cursor.moveToNext()){ i=cursor.getInt(0); } cursor.close(); } private void clickbtnlogin() { login.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { i=0; kiemtrataikhoan(username.getText().toString(),password.getText().toString()); if(i==0){ Toast.makeText(MainActivity.this,"Tài khoản không đúng",Toast.LENGTH_LONG).show(); } else if(i==1){ Intent intent= new Intent(MainActivity.this,Admin.class); startActivity(intent); } else{ Intent intent= new Intent(MainActivity.this,Thongtin.class); intent.putExtra("idlogin",i); startActivity(intent); } } }); } private void connectView() { username = (TextView) findViewById(R.id.username); password = (TextView) findViewById(R.id.password); login = (Button) findViewById(R.id.btn_login); registration = (Button) findViewById(R.id.btn_registration); } }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत