forked from hzuapps/android-labs-2017
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77bc2fb
commit 03469b5
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...n/java/edu/hzuapps/androidlabs/homeworks/net1414080903109/Net1414080903109OpenHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...in/java/edu/hzuapps/androidlabs/homeworks/net1414080903109/Net1414080903109Presenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} |