- Auto format code:
Ctrl
+Shift
+Alt
+L
- Show only a few Columns:
Ctrl
+Shift
+Right arrow
- Show only a few Rows :
Ctrl
+Shift
+Down arrow
- Table of Contents:
Insert
->Table of Contents and Index
->Table of Contents, Index or Bibliography
package vn.edu.hust.student.quangnd.devofappformobiledevices.dao; | |
import android.content.ContentValues; | |
import android.content.Context; | |
import android.database.Cursor; | |
import android.database.sqlite.SQLiteDatabase; | |
import android.database.sqlite.SQLiteOpenHelper; | |
import android.util.Log; | |
import vn.edu.hust.student.quangnd.devofappformobiledevices.objects.User; |
public class LoginActivity extends AppCompatActivity { | |
private static final String TAG = "User Login"; | |
private Button loginButton; | |
private EditText userName; | |
private EditText password; | |
public static final String USER_NAME = "name"; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { |
public class HomeActivity extends AppCompatActivity { | |
public static final String BD_STUDENT_ID = "st_id"; | |
public static final String BD_NAME = "st_name"; | |
public static final String BD_DATE = "st_date"; | |
public static final String BD_CLASS = "st_class"; | |
public static final String BD_PROGRAM = "st_program"; | |
public static final String BD_TRAINING_SYSTEM = "st_training_system"; | |
public static final String BD_STATE = "st_state"; | |
public static final String BD_YEAR = "st_year"; |
public Student getStudentById(String studentId) { | |
SQLiteDatabase db = this.getReadableDatabase(); | |
// Define a projection that specifies which columns from the database | |
// you will actually use after this query. | |
String[] columns = { | |
STUDENT_ID, | |
NAME, | |
DATE_OF_BIRTH, | |
STUDENT_CLASS, |
public int updateStudent(Student student) { | |
SQLiteDatabase db = this.getWritableDatabase(); | |
// New value for one column | |
ContentValues values = new ContentValues(); | |
values.put(NAME, student.getName()); | |
values.put(DATE_OF_BIRTH, student.getDateOfBirth()); | |
values.put(EMAIL, student.getEmail()); | |
// Which row to update, based on the title |
public int deleteStudent(String studentId) { | |
SQLiteDatabase db = this.getWritableDatabase(); | |
// Define 'where' part of query. | |
String selection = STUDENT_ID + " LIKE ?"; | |
// Specify arguments in placeholder order. | |
String[] selectionArgs = {studentId}; | |
// Issue SQL statement. | |
int deletedStudentRows = db.delete(STUDENT_TABLE, selection, selectionArgs); | |
db.close(); | |
return deletedStudentRows; |
private String createUserTable = "CREATE TABLE IF NOT EXISTS " + USER_TABLE + " (" + | |
USER_NAME + " TEXT PRIMARY KEY," + | |
PASSWORD + " TEXT," + | |
ROLE + " TEXT)"; | |
private String createStudentTable = "CREATE TABLE IF NOT EXISTS " + STUDENT_TABLE + " (" + | |
STUDENT_ID + " TEXT PRIMARY KEY," + | |
NAME + " TEXT," + | |
DATE_OF_BIRTH + " TEXT," + | |
STUDENT_CLASS + " TEXT," + |
BEGIN | |
IF((SELECT COUNT(overlap1.class_id) | |
FROM class overlap1, class overlap2 | |
WHERE (overlap2.start_time BETWEEN overlap1.start_time AND overlap1.end_time | |
OR overlap2.end_time BETWEEN overlap1.start_time AND overlap1.end_time) | |
AND overlap1.class_id <> overlap2.class_id | |
AND overlap1.day = overlap2.day | |
AND overlap1.room = overlap2.room) > 0) THEN | |
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Phòng học đã bị trùng với lớp khác!'; | |
END IF; |
BEGIN | |
IF((SELECT COUNT(overlap1.class_id) | |
FROM class overlap1, class overlap2 | |
WHERE (overlap2.start_time BETWEEN overlap1.start_time AND overlap1.end_time | |
OR overlap2.end_time BETWEEN overlap1.start_time AND overlap1.end_time) | |
AND overlap1.class_id <> overlap2.class_id | |
AND overlap1.day = overlap2.day | |
AND overlap1.room = overlap2.room) > 0) THEN | |
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Phòng học vừa update đã bị trùng!'; |