02每日打卡APP
2023.6.10
第一阶段目标:
1、用户注册:用户注册信息包括用户ID(学号)、用户名(姓名),手机号码,用户单位(班级),用户班级四项基本信息,用户第一次注册后,用户姓名不用每次输入 。
2、每日总结打卡:内容包括:日期、每日关键字、每日总结、坚持天数(自动计数,显示上次天数)、连续最长天数。
3、每日提醒记事本:设置每日事件闹钟,可以提醒用户每日必做事件。
4、当天数据存储到本地数据库,其余数据存储到远程服务器上。
第二阶段目标:
1、汇总统计:教师可以查询统计所有同学的每日打卡记录。
2、每日总结查询:可以按照关键字、每日总结查询。
3、自动从数据库中生成所有人的每日总结记录,包括序号、班级、学号、姓名、发表总次数。
package com.example.newone;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class good extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_good);
}
}
package com.example.newone;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.clock.db.DatabaseHelper;
import java.util.ArrayList;
public class Login extends AppCompatActivity {
private DatabaseHelper mSQLite;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Button btn_login = findViewById(R.id.login);
Button btn_register = findViewById(R.id.register);
EditText ed_name = findViewById(R.id.userName);
EditText ed_password = findViewById(R.id.userpassword);
btn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = ed_name.getText().toString().trim();
String password = ed_password.getText().toString().trim();
ArrayList<User> data = mSQLite.getAllDATA();
boolean flag = false;
for(int i = 0; i < data.size(); i++){
User userdata = data.get(i);
if(name.equals(userdata.getName())&&password.equals(userdata.getPassword())){
flag = true;
break;
}else{
flag = false;
}
}
if(!TextUtils.isEmpty(name)&&!TextUtils.isEmpty(password)){
if(flag){
Intent intent1 = new Intent(Login.this, MainActivity.class);
startActivity(intent1);
finish();
Toast.makeText(Login.this, "登录成功", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(Login.this, "用户名或密码不正确", Toast.LENGTH_SHORT).show();
}
}
else{
Toast.makeText(Login.this, "用户名与密码不能为空", Toast.LENGTH_SHORT).show();
}
}
});
btn_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent2 = new Intent(Login.this, Register.class);
startActivity(intent2);
finish();
}
});
mSQLite = new DatabaseHelper(Login.this);
}
}
package com.example.newone;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
//import com.example.newone.javabean.User;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button login, register, update;
private EditText name, password;
private MYsqliteopenhelper mYsqliteopenhelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mYsqliteopenhelper = new MYsqliteopenhelper(this);
find();
}
private void find() {
login = findViewById(R.id.login);
register = findViewById(R.id.register);
name = findViewById(R.id.edname);
password = findViewById(R.id.edpassword);
update = findViewById(R.id.update2);
login.setOnClickListener(this);
register.setOnClickListener(this);
update.setOnClickListener(this);
}
@Override
public void onClick(View view) {
int id = view.getId();
switch (id) {
case R.id.login:
String s = name.getText().toString();
String s1 = password.getText().toString();
boolean login = mYsqliteopenhelper.login(s, s1);
if (login) {
Toast.makeText(this, "登录成功!", Toast.LENGTH_SHORT).show();
Intent i = new Intent(this, good.class);
startActivity(i);
} else {
Toast.makeText(this, "登录失败!", Toast.LENGTH_SHORT).show();
}
break;
case R.id.register:
Intent i1 = new Intent(this, com.example.newone.register.class);
startActivity(i1);
break;
case R.id.update2:
Intent i2 =new Intent(this,update_test.class);
startActivity(i2);
}
}
}
package com.example.newone;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
//import com.example.logindemo.javabean.User;
public class MYsqliteopenhelper extends SQLiteOpenHelper {
private static final String DB_NAME="MYsqlite.db";
private static final String create_users="create table users(name varchar(32),password varchar(32))";
public MYsqliteopenhelper(@Nullable Context context) {
super(context, DB_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL(create_users);
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
public long register(User u){
SQLiteDatabase db = getWritableDatabase();
ContentValues cv =new ContentValues();
cv.put("name",u.getName());
cv.put("password",u.getPassword());
long users = db.insert("users", null, cv);
return users;
}
public boolean login(String name,String password){
SQLiteDatabase db1 = getWritableDatabase();
boolean result =false;
Cursor users = db1.query("users", null, "name like ?", new String[]{name}, null, null, null);
if (users !=null){
while (users.moveToNext()){
String password1 = users.getString(1);
result=password1.equals(password);
return result;
}
}
return false;
}
public int update(String name,String NEWpassword,String password){
SQLiteDatabase db2 = getWritableDatabase();
ContentValues cv1=new ContentValues();
boolean login = login(name, password);
if (login){
cv1.put("name",name);
cv1.put("password",NEWpassword);
}else {
int o=-1;
return o;
}
int i = db2.update("users", cv1, "name= ?", new String[]{name});
return i;
}
}
package com.example.newone;
import static com.example.clock.R.id.userNames;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.clock.db.DatabaseHelper;
import java.util.ArrayList;
public class Register extends AppCompatActivity {
private DatabaseHelper mSQLite;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
//找到各个控件
Button btn_ready = findViewById(R.id.reday);
Button btn_back = findViewById(R.id.back);
EditText ed_name = findViewById(R.id.userName);
EditText ed_password = findViewById(R.id.userpassword);
EditText ed_name1 = findViewById(R.id.userNames);
EditText ed_tel= findViewById(R.id.usertel);
EditText ed_class = findViewById(R.id.userclass);
//注册监听事件
btn_ready.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//获取输入的用户名和密码
String name = ed_name.getText().toString().trim();
String password = ed_password.getText().toString().trim();
String name1 =ed_name1.getText().toString().trim();
String tel = ed_tel.getText().toString().trim();
String classs=ed_class.getText().toString().trim();
//获取数据库数据,判断用户名是否已存在
ArrayList<User> data = mSQLite.getAllDATA();
boolean flag = false;
for(int i = 0; i < data.size(); i++){
User userdata = data.get(i);
if(name.equals(userdata.getName())){
flag = true;
break;
}else{
flag = false;
}
}
//判断用户名和密码是否为空
if(!TextUtils.isEmpty(name)&&!TextUtils.isEmpty(password)){
if(!flag){
mSQLite.insert(name, password,name1,tel,classs);
Intent intent1 = new Intent(Register.this, Login.class);
startActivity(intent1);
finish();
Toast.makeText(Register.this, "注册成功", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(Register.this, "用户名已被注册", Toast.LENGTH_SHORT).show();
}
}
else{
Toast.makeText(Register.this, "用户名与密码不能为空", Toast.LENGTH_SHORT).show();
}
}
});
//监听返回按钮
btn_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent2 = new Intent(Register.this, Login.class);
startActivity(intent2);
finish();
}
});
mSQLite = new DatabaseHelper(Register.this);
}
}
package com.example.newone;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class update_test extends AppCompatActivity {
private EditText name,password,repassword;
private Button update;
private MYsqliteopenhelper mYsqliteopenhelper2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_test);
mYsqliteopenhelper2 =new MYsqliteopenhelper(this);
find();
}
private void find() {
name =findViewById(R.id.etname2);
password =findViewById(R.id.edpassword2);
repassword =findViewById(R.id.repassword1);
}
public void xiugai(View view) {
String s = name.getText().toString();
String s1 = password.getText().toString();
String s2 = repassword.getText().toString();
int update = mYsqliteopenhelper2.update(s, s2, s1);
if (update !=-1){
Toast.makeText(this, "密码修改成功!", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(this, "密码修改失败!", Toast.LENGTH_SHORT).show();
}
}
}
package com.example.newone;
public class User {
private String name;
private String password;
public User() {
}
public User(String name, String password) {
this.name = name;
this.password = password;
}
/**
* 获取
* @return name
*/
public String getName() {
return name;
}
/**
* 设置
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取
* @return password
*/
public String getPassword() {
return password;
}
/**
* 设置
* @param password
*/
public void setPassword(String password) {
this.password = password;
}
public String toString() {
return "User{name = " + name + ", password = " + password + "}";
}
}
标签:02,name,APP,public,import,打卡,password,android,String From: https://www.cnblogs.com/ZRGUGUGU818/p/17472111.html