222wan

导航

个人作业——打卡app中

delete界面

 

`package com.example.conect_sqlite;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.example.conect_sqlite.util.ToastUtil;

public class delete extends AppCompatActivity {
private EditText etname ,etuid;
private MySQLiteOpenHelper mMySQLiteOpenHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_delete);
  etname=findViewById(R.id.et_name);
  etuid=findViewById(R.id.et_uid);
  mMySQLiteOpenHelper=new MySQLiteOpenHelper(this);

}

public void deleteDate(View view) {
   String name= etname.getText().toString().trim();
    String uid= etuid.getText().toString().trim();
    //从数据库中删除
    int row=mMySQLiteOpenHelper.deletefromdb(name,uid);
    if(row>0){
        ToastUtil.toastLong(this,"删除成功!"+row+"条数据");
    }else{
        ToastUtil.toastLong(this,"删除失败!没有找到符合条件的数据");
    }

}

}updata界面用于修改数据package com.example.conect_sqlite;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.example.conect_sqlite.bean.student;

import java.text.SimpleDateFormat;
import java.util.Date;

public class updata extends AppCompatActivity {
private EditText etname,etthing,etdate;
private MySQLiteOpenHelper mMySQLiteOpenHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_updata2);

    etname =findViewById(R.id.et_name);
    etthing=findViewById(R.id.et_thing);
    etdate=findViewById(R.id.et_date);

    mMySQLiteOpenHelper =new MySQLiteOpenHelper(this);
}

public void updata(View view) {
    Intent intent=null;
    intent=this.getIntent();
    String password=intent.getStringExtra("password");//从上一个页面或取账号数据
    String name= etname.getText().toString().trim();
    String thing= etthing.getText().toString().trim();
    String date= etdate.getText().toString().trim();
    student student1=new student();
    student1.setPassword(password);
    student1.setName(name);
    student1.setThing(thing);
    student1.setDate(date);
    student1.setDaytime(getCurrentTimeFormat());
    long rowId=mMySQLiteOpenHelper.updata(student1);
    if(rowId>0){
        Toast.makeText(this,"修改成功!",Toast.LENGTH_SHORT).show();

    }else {
        Toast.makeText(this,"修改失败!",Toast.LENGTH_SHORT).show();
    }


}
private String getCurrentTimeFormat(){//创建我们的实时获取时间。
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat( "yyy年MM月dd HH:mm:ss");
    Date date = new Date();
    return   simpleDateFormat.format(date);

}

}
list界面查询界面package com.example.conect_sqlite;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.conect_sqlite.bean.student;
import com.example.conect_sqlite.util.ToastUtil;

import java.util.List;

public class list extends AppCompatActivity {
private EditText etname;
private TextView tvresult;
private MySQLiteOpenHelper mMySQLiteOpenHelper;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    etname=findViewById(R.id.et_name);
    tvresult=findViewById(R.id.tv_result);
    mMySQLiteOpenHelper=new MySQLiteOpenHelper(this);
}

public void search(View view) {
    String name= etname.getText().toString().trim();
    if(TextUtils.isEmpty(name)){
        ToastUtil.toastLong(this,"请输入查询信息");
    }

else {
//从数据库中查询
List studentList = mMySQLiteOpenHelper.searchfromdb(name);
String result = "";
for (student stu : studentList) {
result += "账号:" + stu.getUid() + ". 名字:" + stu.getName() + ", 事件:" + stu.getThing() + ", 打卡日期:" + stu.getDaytime() + ",提醒时间" + stu.getDate() + "\n";

        }
        tvresult.setText(result);
       /* if(result==null){不好使
            ToastUtil.toastLong(this,"未查询到相关数据!");
        }*/
    }

}

}

`

posted on 2023-03-19 22:10  角落的蘑菇  阅读(9)  评论(0编辑  收藏  举报