commit
7857e30487
@ -0,0 +1,33 @@
|
|||||||
|
package com.showme.database.DatabaseHelper;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
|
||||||
|
public class CourseSQLHelper extends SQLiteOpenHelper {
|
||||||
|
private static final String db_name = "course";//自定义的数据库名;
|
||||||
|
private static final int version = 2;//版本号
|
||||||
|
|
||||||
|
public CourseSQLHelper(Context context) {
|
||||||
|
super(context, db_name, null, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(SQLiteDatabase db) {
|
||||||
|
db.execSQL("create table courses(" +
|
||||||
|
"id integer primary key autoincrement," +
|
||||||
|
"course_name text," +
|
||||||
|
"teacher text," +
|
||||||
|
"class_room text," +
|
||||||
|
"day integer," +
|
||||||
|
"class_start integer," +
|
||||||
|
"class_end integer," +
|
||||||
|
"weeks text)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||||
|
db.execSQL("drop table if exists schedules");
|
||||||
|
onCreate(db);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.showme.database.utils;
|
||||||
|
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
|
import com.showme.database.MySQLiteDatabase;
|
||||||
|
|
||||||
|
public class CourseSQLUtils {
|
||||||
|
private static SQLiteDatabase courseSQL = MySQLiteDatabase.courseSQL;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.showme.database.utils;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
|
import com.showme.database.MySQLiteDatabase;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ScheduleSQLUtils {
|
||||||
|
private static SQLiteDatabase database = MySQLiteDatabase.scheduleSQL;
|
||||||
|
|
||||||
|
public static List<String> queryByDate(String date) {
|
||||||
|
//columns为null 查询所有列
|
||||||
|
List<String> res = new ArrayList<>();
|
||||||
|
String aScheduleName;
|
||||||
|
Cursor cursor = database.query("schedules",null,"time=?",new String[]{date},null,null,null);
|
||||||
|
if(cursor.moveToFirst()){
|
||||||
|
int scheduleCount = 0;
|
||||||
|
do{
|
||||||
|
aScheduleName = cursor.getString(cursor.getColumnIndex("scheduleName"));
|
||||||
|
String aStartTime = cursor.getString(cursor.getColumnIndex("startTime"));
|
||||||
|
Integer ifStartTime = cursor.getInt(cursor.getColumnIndex("ifStartTime"));
|
||||||
|
String aEndTime = cursor.getString(cursor.getColumnIndex("endTime"));
|
||||||
|
Integer ifEndTime = cursor.getInt(cursor.getColumnIndex("ifEndTime"));
|
||||||
|
String scheduleText = aScheduleName;
|
||||||
|
|
||||||
|
if(ifStartTime == 1){
|
||||||
|
scheduleText += "($时间:"+aStartTime;
|
||||||
|
|
||||||
|
if(ifEndTime ==1){
|
||||||
|
scheduleText += "\n"+aEndTime;
|
||||||
|
} else {
|
||||||
|
scheduleText += "\n24:00";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
scheduleText += "($时间: 00:00\n24:00";
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduleCount++;
|
||||||
|
res.add(scheduleText);
|
||||||
|
}while (cursor.moveToNext());
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String extractScheduleName(String scheduleText) {
|
||||||
|
int index = scheduleText.indexOf("($时间:");
|
||||||
|
if (index != -1) {
|
||||||
|
return scheduleText.substring(0, index);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String extractScheduleTime(String scheduleText) {
|
||||||
|
int index = scheduleText.indexOf("($时间:");
|
||||||
|
if (index != -1) {
|
||||||
|
return scheduleText.substring(index+5);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isScheduleMarked(String date) {
|
||||||
|
Cursor cursor = database.query("schedules",null,"time=?",new String[]{date},null,null,null);
|
||||||
|
return cursor.moveToFirst();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue