package com.example.a80205050.myapplication.Dao; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import java.util.ArrayList; import java.util.List; import com.example.a80205050.myapplication.Modle.Tb_flag; /** * Created by 80205050 on 2017/10/30. */ public class FlagDao { private DBOpenHelper helper; private SQLiteDatabase db; public FlagDao(Context context) { helper=new DBOpenHelper(context); } /** * 添加便签的信息 * @param tb_flag */ public void add(Tb_flag tb_flag){ db=helper.getWritableDatabase(); db.execSQL("insert into tb_flag (_id, flag) values(?,?)", new Object[]{tb_flag.get_id(),tb_flag.getFlag()}); } /** * 更新便签的信息 * @param tb_flag */ public void updata(Tb_flag tb_flag){ db=helper.getWritableDatabase(); db.execSQL("update tb_flag set flag=? where _id=?",new Object[]{ tb_flag.getFlag(),tb_flag.get_id() }); } /** * 查找便签的信息 * @param id * @return */ public Tb_flag find(int id){ db=helper.getWritableDatabase(); Cursor cursor=db.rawQuery("select _id flag from tb_flag where _id=?",new String[]{String.valueOf(id)}); if(cursor.moveToNext()){ return new Tb_flag(cursor.getInt(cursor.getColumnIndex("_id")), cursor.getString(cursor.getColumnIndex("flag"))); } return null; } /** * 删除便签的信息 * @param ids */ public void delete(Integer... ids){ if(ids.length>0){ StringBuilder sb=new StringBuilder(); for(int i=0;i<ids.length;i++){ sb.append('?').append(','); } sb.deleteCharAt(sb.length()-1); db=helper.getWritableDatabase(); db.execSQL("delete from tb_flag where _id in ("+sb+")",(Object[])ids); } } /** * 获取便签的信息 * @param start 开始的位置 * @param count 每页的显示数量 * @return */ public List<Tb_flag> getScrollData(int start,int count){ List<Tb_flag> listTb_flags=new ArrayList<Tb_flag>(); db=helper.getWritableDatabase(); Cursor cursor=db.rawQuery("select * from tb_flag limit ?,?",new String[]{String.valueOf(start),String.valueOf(count)}); while (cursor.moveToNext()){ listTb_flags.add(new Tb_flag(cursor.getInt(cursor.getColumnIndex("_id")), cursor.getString(cursor.getColumnIndex("flag")))); } return listTb_flags; } /** * 返回总的记录数 * @return */ public long getCount(){ db=helper.getWritableDatabase(); Cursor cursor=db.rawQuery("select count(_id) from tb_flag",null); if(cursor.moveToNext()){ return cursor.getLong(0); } return 0; } /** * 获取便签的最大编号 * @return */ public int getMaxId(){ db=helper.getWritableDatabase(); Cursor cursor=db.rawQuery("select max(_id) from tb_flag",null); while (cursor.moveToLast()){ return cursor.getInt(0); } return 0;//默认返回0 } }

1393782939 LV1
2024年12月17日
yao123456999 LV1
2024年7月11日
heweimin LV13
2024年4月15日
代码wuyu LV2
2023年11月25日
dingruiasdad LV3
2023年4月10日
懒耗子 LV3
2023年2月25日
222RRR LV1
2022年12月12日
787194770 LV10
2022年10月19日
zhuimengren LV4
2022年5月30日
GZW012345 LV8
2022年5月29日

1393782939 LV1
2024年12月17日
652654393 LV5
2024年11月18日
yao123456999 LV1
2024年7月11日
anjuw521 LV1
2024年7月10日
咩咩咩咩咩 LV2
2024年6月17日
1941549176 LV4
2024年6月4日
lilitu LV6
2024年5月30日
pangzhihui LV14
2024年5月28日
求学的熊猫 LV11
2024年5月12日
13543528515 LV8
2024年4月29日