Skip to content

Commit

Permalink
hzuapps#5 hzuapps#178 第五次作业
Browse files Browse the repository at this point in the history
  • Loading branch information
mamingjian committed Jun 18, 2017
1 parent 77bc2fb commit 03469b5
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.hzuapps.androidlabs.net1414080903109;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
* Created by Administrator on 2017/5/31.
*/

/*SQLHelper*/
public class Net1414080903109OpenHelper extends SQLiteOpenHelper {


public Net1414080903109OpenHelper(Context context) {
super(context,"day", null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {

db.execSQL("create table day(name varchar(20),occur varchar(20));");

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package edu.hzuapps.androidlabs.net1414080903109;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.ArrayList;
import java.util.List;

/**
* Created by Administrator on 2017/5/31.
*/

public class Net1414080903109Presenter {

private SQLiteOpenHelper helper;
private static Net1414080903109Presenter presenter;

private Net1414080903109Presenter(Context context){
if (helper==null){
helper=new Net1414080903109OpenHelper(context);
}
}

public static Net1414080903109Presenter getInstance(Context context){
if (presenter==null){
presenter=new Net1414080903109Presenter(context);
}
return presenter;
}

/*添加节日*/
public void add(Net1414080903109DayBean day){
SQLiteDatabase db=helper.getWritableDatabase();
ContentValues values=new ContentValues();
values.put("name",day.getName());
values.put("occur",day.getOccur());
db.insert("day",null,values);
db.close();
}
/*查找所有节日*/
public List<Net1414080903109DayBean> list(){
List<Net1414080903109DayBean> list=new ArrayList<>();
SQLiteDatabase db=helper.getReadableDatabase();
Cursor cursor=db.query("day",null,null,null,null,null,null);
while (cursor.moveToNext()){
Net1414080903109DayBean day=new Net1414080903109DayBean();
day.setName(cursor.getColumnName(cursor.getColumnIndex("name")));
day.setOccur(cursor.getColumnName(cursor.getColumnIndex("occur")));
list.add(day);
}
cursor.close();
db.close();
return list;
}

/*删除节日*/
public void delete(String name){
SQLiteDatabase db=helper.getWritableDatabase();
db.delete("day","name=?",new String[]{name});
db.close();
}


}

0 comments on commit 03469b5

Please sign in to comment.