2024/5/17

package com.example.newunder.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;


import com.example.newunder.R;
import com.example.newunder.bean.SubBean;

import java.util.List;

public class SubAdapter extends ArrayAdapter<SubBean> {

List<SubBean> items;
public SubAdapter(Context context, List<SubBean> items) {
super(context, R.layout.sub_view,items);
this.items = items;
}


@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
if(convertView == null){
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.sub_view,parent,false);
}

ImageView img = convertView.findViewById(R.id.tp);
TextView name = convertView.findViewById(R.id.name);
TextView tran = convertView.findViewById(R.id.tran);

SubBean sub = items.get(position);
if(sub.getTran().equals("1")){
img.setImageResource(R.drawable.sub_transform);
}else{
img.setImageResource(R.drawable.sub_down);
}
name.setText(sub.getName());
tran.setText(" ");

return convertView;
}

}

package com.example.newunder.dao;

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

import com.example.newunder.bean.SubBean;
import com.example.newunder.until.DBUntil;

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

public class SubDao {
public static SQLiteDatabase db = DBUntil.db;

public static List<SubBean> getAllSub(){
List<SubBean> list = new ArrayList<>();
Cursor res = db.rawQuery("select * from d_subline", null);
while(res.moveToNext()){

SubBean subBean = new SubBean(res.getString(0), res.getString(1),res.getString(2));

list.add(subBean);
}
return list;
}
public static void delPeo(String id){
db.execSQL("DELETE FROM d_peo where s_id=?",new String[]{id});
}
public static void delAll() {
db.execSQL("DELETE FROM d_peo"); // 删除所有数据
}

// public static PeoBean getOnePeo(String id){
//
// Cursor res = db.rawQuery("select * from d_peo where s_id=?", new String[]{id});
// PeoBean peoBean = null;
// while(res.moveToNext()){
// peoBean = new PeoBean(res.getString(0), res.getString(1),res.getString(2),res.getString(3),res.getString(4));
//
// }
// return peoBean;
// }
//
// public static PeoBean getOnePeoFromDay(String day){
//
// Cursor res = db.rawQuery("select * from d_peo where s_day=?", new String[]{day});
// PeoBean peoBean = null;
// while(res.moveToNext()){
// peoBean = new PeoBean(res.getString(0), res.getString(1),res.getString(2),res.getString(3),res.getString(4));
// }
// return peoBean;
// }
//
// public static void updatePeo(String ...id) {
// db.execSQL("update d_peo set s_name = ?,s_phone = ?,s_sex = ?,s_remark = ? where s_id = ?",id);
// }
//
// public static void savePeo(String ...id) {
// db.execSQL("INSERT INTO d_peo (s_day,s_time,s_remark,s_username) VALUES(?,?,?,?)",id);
// }
//
//
// public static List<PeoBean> getAllPeo(String username){
// List<PeoBean> list = new ArrayList<>();
// String query = "SELECT * FROM d_peo WHERE s_username = '"+ username +"'";
// Cursor res = db.rawQuery(query, null);
// while(res.moveToNext()){
// PeoBean peoBean = new PeoBean(res.getString(0), res.getString(1), res.getString(2), res.getString(3), res.getString(4));
// list.add(peoBean);
// }
// return list;
// }
}

package com.example.newunder.until;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class DBUntil extends SQLiteOpenHelper {
private static final String DB_NAME = "db.addBook.db";
private Context mContext;
private static final int VERSION = 19;
public static SQLiteDatabase db;
public DBUntil(Context context) {
super(context, DB_NAME, null, VERSION);
mContext = context;
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("drop table if exists d_peo");

db.execSQL("CREATE TABLE d_peo (s_id INTEGER primary key AUTOINCREMENT," +
"s_day varchar(20)," +
"s_time varchar(20)," +
"s_remark varchar(20)," +
"s_username varchar(20))");
db.execSQL("INSERT INTO d_peo (s_day,s_time,s_remark,s_username) VALUES('2024-03-12','13','打胶','20220001')");
db.execSQL("INSERT INTO d_peo (s_day,s_time,s_remark,s_username) VALUES('2024-03-13','13','打胶','20224050')");
db.execSQL("INSERT INTO d_peo (s_day,s_time,s_remark,s_username) VALUES('2024-03-14','15','打胶','20224051')");
db.execSQL("INSERT INTO d_peo (s_day,s_time,s_remark,s_username) VALUES('2024-03-15','13','打胶','20224052')");
db.execSQL("INSERT INTO d_peo (s_day,s_time,s_remark,s_username) VALUES('2024-03-16','13','打胶','20224053')");

db.execSQL("drop table if exists d_weeksum");

db.execSQL("CREATE TABLE d_weeksum (s_id INTEGER primary key AUTOINCREMENT," +
"s_name varchar(20)," +
"s_username varchar(20)," +
"s_weeksum varchar(20)," +
"s_weekrate varchar(20)," +
"s_weekweek varchar(20))");
db.execSQL("INSERT INTO d_weeksum (s_name,s_username,s_weeksum,s_weekrate,s_weekweek) VALUES('20224050','4545','4545','4545','4545')");

db.execSQL("drop table if exists d_subline");

db.execSQL("CREATE TABLE d_subline (s_id INTEGER primary key AUTOINCREMENT," +
"s_name varchar(20)," +
"s_tran varchar(20))");
db.execSQL("INSERT INTO d_subline (s_name,s_tran) VALUES('你能','1号线')");
db.execSQL("INSERT INTO d_subline (s_name,s_tran) VALUES('2','1号线')");
db.execSQL("INSERT INTO d_subline (s_name,s_tran) VALUES('3','1号线')");
db.execSQL("INSERT INTO d_subline (s_name,s_tran) VALUES('4','1号线')");


}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// 在不同版本之间执行不同的更新操作
db.execSQL("drop table if exists d_peo");
db.execSQL("drop table if exists d_weeksum");
db.execSQL("drop table if exists d_subline");
onCreate(db);
}
}
posted @ 2024-05-17 19:23  Hbro  阅读(9)  评论(0)    收藏  举报