4.30(小组作业十日冲刺第六天)

完成存入日志后自动保存时间,以及在主页面中显示已存入的日志

所花时间:4h

代码行量:865行

package com.example.memosystem.bean;

public class Record {

private String id;
private String title;
private String con;
private String uid;
private String tim;
//alt install

@Override
public String toString() {
return "Record{" +
"id='" + id + '\'' +
", title='" + title + '\'' +
", con='" + con + '\'' +
", uid='" + uid + '\'' +
", tim='" + tim + '\'' +
'}';
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getCon() {
return con;
}

public void setCon(String con) {
this.con = con;
}

public String getUid() {
return uid;
}

public void setUid(String uid) {
this.uid = uid;
}

public String getTim() {
return tim;
}

public void setTim(String tim) {
this.tim = tim;
}

public Record() {
}

public Record(String id, String title, String con, String uid, String tim) {
this.id = id;
this.title = title;
this.con = con;
this.uid = uid;
this.tim = tim;
}
}
package com.example.memosystem.dao;

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

import com.example.memosystem.bean.Record;
import com.example.memosystem.dao.impl.AdminDaoImpl;
import com.example.memosystem.util.DBUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AdminDao implements AdminDaoImpl {

SQLiteDatabase db= DBUtil.db;
@Override
public int registerAdmin(String ...da) {
try {
db.execSQL("INSERT INTO d_admin VALUES(?,?,?,?,?,?)",da);
return 1;
}catch (Exception e){
return -1;
}

}

@Override
public int loginAdmin(String... da) {

int a=0;
Cursor res = db.rawQuery("select * from d_admin where s_id=? and s_pwd=?", da);
if(res.moveToNext()){
a++;
}
return a;




}

/**
* 修改密码 账号 密码
* @param da
* @return
*/
@Override
public int changePassword(String... da) {

ContentValues values=new ContentValues();
values.put("s_pwd", da[1]);

String das[]={da[0]};
try{
return db.update("d_admin",values,"s_id=?",das);
}catch (Exception e){
return -1;
}


}

public int changeMes(String ...da){
ContentValues values=new ContentValues();
values.put("s_name", da[1]);
values.put("s_sex", da[2]);
values.put("s_phone", da[3]);
values.put("s_age", da[4]);
String das[]={da[0]};
try{
return db.update("d_admin",values,"s_id=?",das);
}catch (Exception e){
return -1;
}
}


public Map<String,String> showAccountMes(String account){

Map<String,String> map=new HashMap<>();
String da[]={account};
Cursor result = db.rawQuery("select s_name,s_sex,s_phone,s_age from d_admin where s_id=?", da);
while(result.moveToNext()){
//姓名

//姓名
//手机号
//年纪
String name = result.getString(0);
String sex= result.getString(1);
String phone= result.getString(2);
String age= result.getString(3);


map.put("name",name);
map.put("sex",sex);
map.put("phone",phone);
map.put("age",age);
}
return map;
}

/**
* 删除信息
* @param da
* @return
*/
@Override
public int delRecord(String... da) {
try {
db.execSQL("delete from d_record where s_id=? and s_uid=?",da);
return 1;
}catch (Exception e){
return -1;
}


}


public int saveRecord(String ...da){//id 标题 内容 用户ID 时间
try {
db.execSQL("INSERT INTO d_record VALUES(?,?,?,?,?)",da);
return 1;
}catch (Exception e){

String daa[]={da[1],da[2],da[4],da[0],da[3]};
try {
db.execSQL("update d_record set s_title=? ,s_con=?,s_time=? where s_id=? and s_uid=?",daa);
return 1;
}catch (Exception ee){
e.printStackTrace();
ee.printStackTrace();
return -1;
}
}
}

public List<Record> showRecord(String id){
String da[]={id};
List<Record> re=new ArrayList<>();//存储所有备忘录的
Cursor res = db.rawQuery("select * from d_record where s_uid=?",da);
while(res.moveToNext()){
Record record=new Record(res.getString(0),res.getString(1),res.getString(2),res.getString(3),res.getString(4));
re.add(record);
}

return re;

}
}
 
posted @ 2024-04-30 21:39  不如喝点  阅读(1)  评论(0编辑  收藏  举报