栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

安卓大作业Library System

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

安卓大作业Library System

一、JAVA文件

1.Announcement_Page.java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Announcement_Pgae extends AppCompatActivity {

    private Button button_return;
    private Button button_confirm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.announcement_page);

        button_return = findViewById(R.id.button_return);
        button_confirm = findViewById(R.id.button_confirm);


        button_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_return = new Intent(getApplicationContext(), MainActivity.class);
                startActivity((intent_return));
            }
        });


        button_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_return = new Intent(getApplicationContext(), MainActivity.class);
                startActivity((intent_return));
            }
        });



    }
}

2.Borrow_books_Page.java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

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

public class Borrow_books_Page extends AppCompatActivity {

    private Button button_return;
    private Spinner spinner;
    private String search_pattern;
    private EditText editText_search;
    private Button button_search;
    private ListView listView;
    private SQLiteDatabase database;
    private List> mData;
    private String user;
    private String name;
    private SharedPreferences sp;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.borrow_books_page);

        button_return = findViewById(R.id.button_return);
        spinner = findViewById(R.id.spinner);
        editText_search = findViewById(R.id.editText_search);
        button_search = findViewById(R.id.button_search);
        listView = findViewById(R.id.listView);

        Database_user database_user= new Database_user(Borrow_books_Page.this);
        database = database_user.getWritableDatabase();

        sp = getSharedPreferences("LibrarySystem", Context.MODE_PRIVATE);
        SharedPreferences.Editor  editor = sp.edit();
        user = sp.getString("user","");
        name = sp.getString("name","");

        button_return.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent intent_return = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(intent_return);
            }
        });

        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView adapterView, View view, int i, long l) {
                search_pattern = adapterView.getItemAtPosition(i).toString();
            }

            @Override
            public void onNothingSelected(AdapterView adapterView) {
            }
        });



        button_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                mData = getData();
                MyAdapter adapter = new MyAdapter(getApplicationContext());
                listView.setAdapter(adapter);
//                Booklist = new ArrayList<>();
//                String sql = "select * from books where 书名 like ?";
//                if(search_pattern.equals("责任者")){
//                    sql = "select * from books where 责任者 like ?";
//                }
//                else if(search_pattern.equals("出版信息")){
//                    sql = "select * from books where 出版信息 like ?";
//                }
//                Cursor cursor = database.rawQuery(sql,new String[]{'%'+EditText_search.getText().toString()+'%'});
//                while(cursor.moveToNext()){
//                    Map map = new HashMap<>();
//                    int book_name_ColumnIndex = cursor.getColumnIndex("书名");
//                    String book_name_searched = cursor.getString(book_name_ColumnIndex);
//                    int book_author_ColumnIndex = cursor.getColumnIndex("责任者");
//                    String book_author_searched = cursor.getString(book_author_ColumnIndex);
//                    int book_publisher_ColumnIndex = cursor.getColumnIndex("出版信息");
//                    String book_publisher_searched = cursor.getString(book_publisher_ColumnIndex);
//                    int book_count_ColumnIndex = cursor.getColumnIndex("借阅册次");
//                    String book_count_searched = cursor.getString(book_count_ColumnIndex);
//                    int book_state_ColumnIndex = cursor.getColumnIndex("是否借出");
//                    String book_state_searched = cursor.getString(book_state_ColumnIndex);
//                    map.put("book_name",book_name_searched);
//                    map.put("book_author",book_author_searched);
//                    map.put("book_publisher",book_publisher_searched);
//                    map.put("book_count","借阅册次:"+book_count_ColumnIndex);
//                    map.put("book_state","是否借出:"+book_state_searched);
//                    Booklist.add(map);
//                }
//                adapter= new SimpleAdapter(getApplicationContext(),Booklist,R.layout.simpleadapter_books,new String[]{"book_name","book_author","book_publisher","book_count","book_state"},new int[]{R.id.textView_book_name,R.id.textView_book_author,R.id.textView_book_publisher,R.id.textView_book_count,R.id.textView_book_state});

            }
        });








    }

    public class MyAdapter extends BaseAdapter{
        private LayoutInflater mInflater;

        public MyAdapter(Context context) {
            this.mInflater = LayoutInflater.from((Context) context);
        }

        @Override
        public int getCount() {

            return mData.size();
        }

        @Override
        public Object getItem(int i) {

            return null;
        }

        @Override
        public long getItemId(int i) {

            return 0;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;

            if (convertView == null) {

                holder=new ViewHolder();

                //可以理解为从vlist获取view 之后把view返回给ListView

                convertView = mInflater.inflate(R.layout.adapter_books, null);
                holder.book_name = (TextView)convertView.findViewById(R.id.textView_book_name);
                holder.book_author = (TextView)convertView.findViewById(R.id.textView_book_author);
                holder.book_publisher = (TextView) convertView.findViewById(R.id.textView_book_publisher);
                holder.book_count = (TextView)convertView.findViewById(R.id.textView_book_count);
                holder.book_state = (TextView)convertView.findViewById(R.id.textView_book_state);
                holder.button_borrow = (Button)convertView.findViewById(R.id.button_borrow);
                convertView.setTag(holder);
            }else {
                holder = (ViewHolder)convertView.getTag();
            }

            holder.book_name.setText((String)mData.get(position).get("book_name"));
            holder.book_author.setText((String)mData.get(position).get("book_author"));
            holder.book_publisher.setText((String)mData.get(position).get("book_publisher"));
            holder.book_count.setText("借阅册次:" + (String)mData.get(position).get("book_count"));
            holder.book_state.setText("是否借出:" + (String)mData.get(position).get("book_state"));
            holder.button_borrow.setTag(position);

            //给Button添加单击事件 添加Button之后ListView将失去焦点 需要的直接把Button的焦点去掉
            ViewHolder finalHolder = holder;
            holder.button_borrow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mData.get(position).get("book_state").toString().equals("是")) {
                        Toast.makeText(Borrow_books_Page.this, "已被借出,请重新选择", Toast.LENGTH_SHORT).show();
                    } else {
                        String sql = "select * from borrow_books where 学号=? and 是否归还=?";
                        Cursor cursor = database.rawQuery(sql, new String[]{user,"否"});
                        if (cursor.getCount() == 3) {
                            Toast.makeText(Borrow_books_Page.this, "已借三本书,请归还后再借", Toast.LENGTH_SHORT).show();
                        } else {
                            Calendar calendar = Calendar.getInstance();
                            int year = calendar.get(Calendar.YEAR);
                            int month = calendar.get(Calendar.MONTH) + 1;
                            int day = calendar.get(Calendar.DAY_OF_MONTH);
                            ContentValues values = new ContentValues();
                            values.put("学号",user);
                            values.put("姓名",name);
                            values.put("书名", mData.get(position).get("book_name").toString());
                            values.put("借书日期",Integer.toString(year)+"-"+Integer.toString(month)+"-"+Integer.toString(day));
                            values.put("是否归还", "否");
                            values.put("还书日期","未归还");
                            values.put("是否逾期", "否");
                            database.insert("borrow_books", null, values);
                            String stl1 = "update books set 是否借出=?,借出人学号=?,借出人姓名=? where 书名=?";
                            database.execSQL(stl1, new Object[]{"是", user, name, mData.get(position).get("book_name").toString()});
                            String stl2 = "select * from user where 学号=?";
                            Cursor cursor1 = database.rawQuery(stl2,new String[]{user});
                            cursor1.moveToFirst();
                            int countColumnIndex = cursor1.getColumnIndex("借书次数");
                            int count = cursor1.getInt(countColumnIndex) + 1;
                            String stl3 = "update user set 借书次数=? where 学号=?";
                            database.execSQL(stl3,new Object[]{count,user});
                            String stl4 = "select * from books where 书名=?";
                            Cursor cursor2 = database.rawQuery(stl4,new String[]{mData.get(position).get("book_name").toString()});
                            cursor2.moveToFirst();
                            int book_countColumnIndex = cursor2.getColumnIndex("借阅册次");
                            int book_count = cursor2.getInt(book_countColumnIndex) + 1;
                            String stl5="update books set 借阅册次=? where 书名=?";
                            database.execSQL(stl5,new Object[]{book_count,mData.get(position).get("book_name").toString()});
                            Toast.makeText(Borrow_books_Page.this, "借书成功", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            });

            //holder.viewBtn.setOnClickListener(MyListener(position));

            return convertView;
        }


    }

    private List> getData() {
        List> list = new ArrayList>();
        String sql = "select * from books where 书名 like ?";
        if(search_pattern.equals("责任者")){
            sql = "select * from books where 责任者 like ?";
        }
        else if(search_pattern.equals("出版信息")){
            sql = "select * from books where 出版信息 like ?";
        }
        Cursor cursor = database.rawQuery(sql,new String[]{'%'+editText_search.getText().toString()+'%'});
        while(cursor.moveToNext()){
            Map map = new HashMap<>();
            int book_name_ColumnIndex = cursor.getColumnIndex("书名");
            String book_name_searched = cursor.getString(book_name_ColumnIndex);
            int book_author_ColumnIndex = cursor.getColumnIndex("责任者");
            String book_author_searched = cursor.getString(book_author_ColumnIndex);
            int book_publisher_ColumnIndex = cursor.getColumnIndex("出版信息");
            String book_publisher_searched = cursor.getString(book_publisher_ColumnIndex);
            int book_count_ColumnIndex = cursor.getColumnIndex("借阅册次");
            String book_count_searched = cursor.getString(book_count_ColumnIndex);
            int book_state_ColumnIndex = cursor.getColumnIndex("是否借出");
            String book_state_searched = cursor.getString(book_state_ColumnIndex);
            map.put("book_name",book_name_searched);
            map.put("book_author",book_author_searched);
            map.put("book_publisher",book_publisher_searched);
            map.put("book_count",book_count_searched);
            map.put("book_state",book_state_searched);
            list.add(map);
        }
        return list;
    }

    public final class ViewHolder{
        TextView book_name;
        TextView book_author;
        TextView book_publisher;
        TextView book_count;
        TextView book_state;
        Button button_borrow;
    }
}

3.Database_user.java

package com.example.myapplication;

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;

public class Database_user extends SQLiteOpenHelper {
    public Database_user(@Nullable Context context) {
        super(context, "user.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
//        String sql="CREATE TABLE [user](n" +
//                "  [学号] varchar(50) UNIQUE, n" +
//                "  [姓名] varchar(50), n" +
//                "  [密码] varchar(50), n" +
//                "  [学习次数] INT, n" +
//                "  [借书次数] INT)";
//        sqLiteDatabase.execSQL(sql);
//        String sql1="CREATE TABLE [study](n" +
//                "  [学号] varchar(50), n" +
//                "  [姓名] varchar(50), n" +
//                "  [年] varchar(20), n" +
//                "  [月] varchar(20), n" +
//                "  [日] varchar(20), n" +
//                "  [时刻] varchar(20))";
//        sqLiteDatabase.execSQL(sql1);
//        String sql2="CREATE TABLE [borrow_books](n" +
//                "  [学号] varchar(50), n" +
//                "  [姓名] varchar(50), n" +
//                "  [书名] varchar(100), n" +
//                "  [借书日期] VARCHAr(20), n" +
//                "  [是否归还] varchar(20), n" +
//                "  [还书日期] VARCHAr(20), n" +
//                "  [是否逾期] varchar(20))";
//        sqLiteDatabase.execSQL(sql2);
//        String sql3="CREATE TABLE [books](n" +
//                "  [书名] VARCHAr(100) UNIQUE, n" +
//                "  [责任者] VARCHAr(100), n" +
//                "  [出版信息] VARCHAr(100), n" +
//                "  [借阅册次] INT, n" +
//                "  [是否借出] VARCHAr(20), n" +
//                "  [借出人学号] VARCHAr(50), n" +
//                "  [借出人姓名] VARCHAr(50))";
//        sqLiteDatabase.execSQL(sql3);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }

}

4.Login_Page.java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class Login_Page extends AppCompatActivity {
    private Button button_sign_in;
    private Button button_register;
    private EditText editText_user;
    private EditText editText_password;
    private SQLiteDatabase database;
    private SharedPreferences sp;
    private CheckBox checkbox_remember_user;
    private CheckBox checkbox_remember_password;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_page);

        Database_user database_user= new Database_user(Login_Page.this);
        database = database_user.getWritableDatabase();

        button_sign_in = findViewById(R.id.button_sign_in);
        button_register = findViewById(R.id.button_register);
        editText_user = findViewById(R.id.editText_user);
        editText_password = findViewById(R.id.editText_password);
        checkbox_remember_user = findViewById(R.id.checkBox_remember_user);
        checkbox_remember_password = findViewById(R.id.checkBox_remember_password);


        sp = getSharedPreferences("LibrarySystem", Context.MODE_PRIVATE);
        SharedPreferences.Editor  editor = sp.edit();


        if(sp.getBoolean("remember_user_selected",true)){
            editText_user.setText(sp.getString("user_saved",""));
            checkbox_remember_user.setChecked(true);
        }

        if(sp.getBoolean("remember_password_selected",true)){
            editText_password.setText(sp.getString("password_saved",""));
            checkbox_remember_password.setChecked(true);
        }

            button_sign_in.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String sql="select * from user where 学号=?";
                Cursor cursor = database.rawQuery(sql,new String[]{editText_user.getText().toString()});
                if(cursor.getCount()==0){
                    Toast.makeText(getApplicationContext(), "学号尚未注册", Toast.LENGTH_SHORT).show();
                    editText_user.setText("");
                }else{
                    cursor.moveToFirst();
                    int passwordColumnIndex = cursor.getColumnIndex("密码");
                    String password_saved = cursor.getString(passwordColumnIndex);
                    if(password_saved.equals(editText_password.getText().toString())){
                        int nameColumnIndex = cursor.getColumnIndex("姓名");
                        String name = cursor.getString(nameColumnIndex);

                        editor.putString("name",name);
                        editor.putString("user",editText_user.getText().toString());
                        if(checkbox_remember_user.isChecked()){
                            editor.putString("user_saved",editText_user.getText().toString());
                            editor.putBoolean("remember_user_selected",true);
                        }else{
                            editor.putBoolean("remember_user_selected",false);
                        }
                        if(checkbox_remember_password.isChecked()){
                            editor.putString("password_saved",editText_password.getText().toString());
                            editor.putBoolean("remember_password_selected",true);
                        }else{
                            editor.putBoolean("remember_password_selected",false);
                        }
                        editor.commit();
                        Intent intent_sign_in = new Intent(getApplicationContext(), MainActivity.class);
                        startActivity(intent_sign_in);
                    }else{
                        Toast.makeText(getApplicationContext(), "密码错误", Toast.LENGTH_SHORT).show();
                        editText_password.setText("");
                    }
                }

            }
        });

        button_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_register = new Intent(getApplicationContext(), Register_Page.class);
                startActivity(intent_register);
            }
        });



    }
}

5.MainAcitivity.java

package com.example.myapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class MainActivity extends AppCompatActivity {
    private TextView textView_current_time2;
    private TextView textView_hello;
    private TextView textView_name;
    private TextView textView_hello2;
    private Button button_return;
    private String timeString;
    private String hello;
    private String hello2;
    private Button button_study;
    private Button button_borrow;
    private Button button_record;
    private Button button_return_book;
    private Button button_announcement;
    private Button button_modify_password;
    private String name;
    private SharedPreferences sp;

    Handler handler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if(msg.what==0x00){
                String time = (String) msg.obj;
                textView_current_time2.setText(time);
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView_current_time2 = findViewById(R.id.textView_current_time2);
        textView_hello = findViewById(R.id.textView_hello);
        textView_name = findViewById(R.id.textView_name);
        textView_hello2 = findViewById(R.id.textView_hello2);
        button_return = findViewById(R.id.button_return);
        button_study = findViewById(R.id.button_study);
        button_borrow = findViewById(R.id.button_borrow);
        button_record = findViewById(R.id.button_record);
        button_return_book = findViewById(R.id.button_return_book);
        button_announcement = findViewById(R.id.button_announcement);
        button_modify_password = findViewById(R.id.button_modify_password);

        sp = getSharedPreferences("LibrarySystem", Context.MODE_PRIVATE);
        SharedPreferences.Editor  editor = sp.edit();
        name = sp.getString("name","");

        button_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_return = new Intent(getApplicationContext(), Login_Page.class);
                startActivity(intent_return);
            }
        });

        button_study.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_announcement = new Intent(getApplicationContext(), Study_Page.class);
                startActivity((intent_announcement));
            }
        });

        button_borrow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_borrow = new Intent(getApplicationContext(), Borrow_books_Page.class);
                startActivity((intent_borrow));
            }
        });

        button_modify_password.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_modify_password = new Intent(getApplicationContext(), Modify_password_Pgae.class);
                startActivity(intent_modify_password);
            }
        });

        button_return_book.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_return_book = new Intent(getApplicationContext(), Return_books_Page.class);
                startActivity(intent_return_book);
            }
        });

        button_record.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_record= new Intent(getApplicationContext(), Rank_Page.class);
                startActivity(intent_record);
            }
        });


        button_announcement.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_announcement = new Intent(getApplicationContext(), Announcement_Pgae.class);
                startActivity(intent_announcement);
            }
        });


        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        if(hour>=6 && hour<12){
            hello = "早上好,";
            hello2 = ",早晨朝气蓬勃!";
        }else if(hour>=12 && hour<18)
        {
            hello = "下午好,";
            hello2 = ",下午继续坚持!";
        }else if(hour>=18 && hour<24){
            hello = "晚上好,";
            hello2 = ",夜晚孜孜不倦!";
        }else{
            hello = "深夜好,";
            hello2 = ",深夜早点休息!";
        }
        textView_hello.setText(hello);
        textView_name.setText(name);
        textView_hello2.setText(hello2);

            new Thread(){
                @Override
                public void run() {
                    super.run();
                    while(true){
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        timeString = simpleDateFormat.format(System.currentTimeMillis());
                        Message message = new Message();
                        message.what = 0x00;
                        message.obj = timeString;
                        handler.sendMessage(message);
                        try {
                            sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
            };

        }.start();
    }
}

6.Modify_[assword_Page.java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Modify_password_Pgae extends AppCompatActivity {
    private Button button_return;
    private EditText editText_password_old;
    private EditText editText_password_new;
    private EditText editText_password_new_again;
    private Button button_confirm;
    private SQLiteDatabase database;
    private String user;
    private SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.modify_password_page);

        button_return = findViewById(R.id.button_return);
        editText_password_old = findViewById(R.id.editText_password_old);
        editText_password_new = findViewById(R.id.editText_password_new);
        editText_password_new_again = findViewById(R.id.editText_password_new_again);
        button_confirm = findViewById(R.id.button_confirm);

        Database_user database_user= new Database_user(Modify_password_Pgae.this);
        database = database_user.getWritableDatabase();

        sp = getSharedPreferences("LibrarySystem", Context.MODE_PRIVATE);
        SharedPreferences.Editor  editor = sp.edit();
        user = sp.getString("user","");

        button_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_return = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(intent_return);
            }
        });


        button_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if(editText_password_old.getText().toString().equals("") || editText_password_new.getText().toString().equals("") || editText_password_new_again.getText().toString().equals("")){
                    Toast.makeText(Modify_password_Pgae.this, "请输入密码信息", Toast.LENGTH_SHORT).show();
                }else{
                    String sql = "select * from user where 学号=?";
                    Cursor cursor = database.rawQuery(sql,new String[]{user});
                    cursor.moveToFirst();
                    int passwordColumnIndex = cursor.getColumnIndex("密码");
                    if(editText_password_old.getText().toString().equals(cursor.getString(passwordColumnIndex))){
                        if(editText_password_new.getText().toString().equals(editText_password_new_again.getText().toString())){
                            String sql1 = "update user set 密码=? where 学号=?";
                            database.execSQL(sql1,new Object[]{editText_password_new.getText().toString(),user});
                            Toast.makeText(Modify_password_Pgae.this, "修改成功", Toast.LENGTH_SHORT).show();
                            Intent intent_return = new Intent(getApplicationContext(), Login_Page.class);
                            startActivity(intent_return);
                        }else{
                            Toast.makeText(Modify_password_Pgae.this, "新密码不一致", Toast.LENGTH_SHORT).show();
                            editText_password_new.setText("");
                            editText_password_new_again.setText("");
                        }
                    }else{
                        Toast.makeText(Modify_password_Pgae.this, "原密码错误", Toast.LENGTH_SHORT).show();
                        editText_password_old.setText("");
                    }
                }
            }
        });

    }
}

7.Rank_Page.java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

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

public class Rank_Page extends AppCompatActivity {

    private Button button_return;
    private ListView listView_borrow;
    private ListView listView_study;
    private SQLiteDatabase database;
    private List> mData_borrow;
    private List> mData_study;
    private String user;
    private SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rank_page);

        button_return = findViewById(R.id.button_return);
        listView_borrow = findViewById(R.id.listView_borrow);
        listView_study = findViewById(R.id.listView_study);

        Database_user database_user= new Database_user(Rank_Page.this);
        database = database_user.getWritableDatabase();

        sp = getSharedPreferences("LibrarySystem", Context.MODE_PRIVATE);
        SharedPreferences.Editor  editor = sp.edit();
        user = sp.getString("user","");

        button_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_return= new Intent(getApplicationContext(), MainActivity.class);
                startActivity(intent_return);
            }
        });

        mData_borrow = getData_borrow();
        MyAdapter_borrow adapter_borrow = new MyAdapter_borrow(getApplicationContext());
        listView_borrow.setAdapter(adapter_borrow);

        mData_study = getData_study();
        MyAdapter_study adapter_study = new MyAdapter_study(getApplicationContext());
        listView_study.setAdapter(adapter_study);


    }



    public class MyAdapter_borrow extends BaseAdapter {
        private LayoutInflater mInflater;

        public MyAdapter_borrow(Context context) {
            this.mInflater = LayoutInflater.from((Context) context);
        }

        @Override
        public int getCount() {
            return mData_borrow.size();
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder_rank holder = null;

            if (convertView == null) {

                holder=new ViewHolder_rank();

                //可以理解为从vlist获取view 之后把view返回给ListView

                convertView = mInflater.inflate(R.layout.adapter_rank, null);
                holder.user = (TextView)convertView.findViewById(R.id.textView_user);
                holder.name = (TextView)convertView.findViewById(R.id.textView_name);
                holder.rank = (TextView)convertView.findViewById(R.id.textView_rank);
                holder.times = (TextView)convertView.findViewById(R.id.textView_times);
                convertView.setTag(holder);
            }else {
                holder = (ViewHolder_rank)convertView.getTag();
            }

            holder.user.setText("学号:" + (String)mData_borrow.get(position).get("rank_user"));
            holder.name.setText("姓名:" + (String)mData_borrow.get(position).get("rank_name"));
            holder.rank.setText((String)mData_borrow.get(position).get("rank_rank"));
            holder.times.setText("借书次数:" + (String)mData_borrow.get(position).get("rank_borrow_times"));


            ViewHolder_rank finalHolder = holder;


            //holder.viewBtn.setOnClickListener(MyListener(position));

            return convertView;
        }


    }


    public class MyAdapter_study extends BaseAdapter {
        private LayoutInflater mInflater;

        public MyAdapter_study(Context context) {
            this.mInflater = LayoutInflater.from((Context) context);
        }

        @Override
        public int getCount() {
            return mData_study.size();
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder_rank holder = null;

            if (convertView == null) {

                holder=new ViewHolder_rank();

                //可以理解为从vlist获取view 之后把view返回给ListView

                convertView = mInflater.inflate(R.layout.adapter_rank, null);
                holder.user = (TextView)convertView.findViewById(R.id.textView_user);
                holder.name = (TextView)convertView.findViewById(R.id.textView_name);
                holder.rank = (TextView)convertView.findViewById(R.id.textView_rank);
                holder.times = (TextView)convertView.findViewById(R.id.textView_times);
                convertView.setTag(holder);
            }else {
                holder = (ViewHolder_rank)convertView.getTag();
            }

            holder.user.setText("学号:" + (String)mData_study.get(position).get("rank_user"));
            holder.name.setText("姓名:" + (String)mData_study.get(position).get("rank_name"));
            holder.rank.setText((String)mData_study.get(position).get("rank_rank"));
            holder.times.setText("学习次数:" + (String)mData_study.get(position).get("rank_borrow_times"));


            ViewHolder_rank finalHolder = holder;


            //holder.viewBtn.setOnClickListener(MyListener(position));

            return convertView;
        }


    }


    private List> getData_borrow() {
        List> list = new ArrayList>();
        String sql = "select * from user order by 借书次数 desc";
        Cursor cursor = database.rawQuery(sql,new String[]{});
        int count = 0;
        while(cursor.moveToNext()){
            count++;
            if(count > 3) break;

            Map map = new HashMap<>();
            int userColumnIndex = cursor.getColumnIndex("学号");
            String rank_user = cursor.getString(userColumnIndex);
            int nameColumnIndex = cursor.getColumnIndex("姓名");
            String rank_name = cursor.getString(nameColumnIndex);
            int timesColumnIndex = cursor.getColumnIndex("借书次数");
            int rank_borrow_times = cursor.getInt(timesColumnIndex);
            String rank_borrow_times_ = Integer.toString(rank_borrow_times);
            map.put("rank_user",rank_user);
            map.put("rank_name",rank_name);
            map.put("rank_rank","排  名n    "+Integer.toString(count));
            map.put("rank_borrow_times",rank_borrow_times_);
            list.add(map);
        }

        String sql1 = "select * from user order by 借书次数 desc";
        Cursor cursor1 = database.rawQuery(sql1,new String[]{});
        int count_ = 0;
        while(cursor1.moveToNext()) {
            count_++;
            int userColumnIndex = cursor1.getColumnIndex("学号");
            String rank_user = cursor1.getString(userColumnIndex);
            if(rank_user.equals(user)){
                Map map = new HashMap<>();
                int nameColumnIndex = cursor.getColumnIndex("姓名");
                String rank_name = cursor1.getString(nameColumnIndex);
                int timesColumnIndex = cursor1.getColumnIndex("借书次数");
                int rank_borrow_times = cursor1.getInt(timesColumnIndex);
                String rank_borrow_times_ = Integer.toString(rank_borrow_times);
                map.put("rank_user", rank_user);
                map.put("rank_name", rank_name);
                map.put("rank_rank", "我  的n排  名n    "+Integer.toString(count_));
                map.put("rank_borrow_times", rank_borrow_times_);
                list.add(map);
                break;
            }
        }
        return list;
    }


    private List> getData_study() {
        List> list = new ArrayList>();
        String sql = "select * from user order by 学习次数 desc";
        Cursor cursor = database.rawQuery(sql,new String[]{});
        int count = 0;
        while(cursor.moveToNext()){
            count++;
            if(count > 3) break;

            Map map = new HashMap<>();
            int userColumnIndex = cursor.getColumnIndex("学号");
            String rank_user = cursor.getString(userColumnIndex);
            int nameColumnIndex = cursor.getColumnIndex("姓名");
            String rank_name = cursor.getString(nameColumnIndex);
            int timesColumnIndex = cursor.getColumnIndex("学习次数");
            int rank_borrow_times = cursor.getInt(timesColumnIndex);
            String rank_borrow_times_ = Integer.toString(rank_borrow_times);
            map.put("rank_user",rank_user);
            map.put("rank_name",rank_name);
            map.put("rank_rank","排  名n    "+Integer.toString(count));
            map.put("rank_borrow_times",rank_borrow_times_);
            list.add(map);
        }

        String sql1 = "select * from user order by 学习次数 desc";
        Cursor cursor1 = database.rawQuery(sql1,new String[]{});
        int count_ = 0;
        while(cursor1.moveToNext()) {
            count_++;
            int userColumnIndex = cursor1.getColumnIndex("学号");
            String rank_user = cursor1.getString(userColumnIndex);
            if(rank_user.equals(user)){
                Map map = new HashMap<>();
                int nameColumnIndex = cursor.getColumnIndex("姓名");
                String rank_name = cursor1.getString(nameColumnIndex);
                int timesColumnIndex = cursor1.getColumnIndex("学习次数");
                int rank_borrow_times = cursor1.getInt(timesColumnIndex);
                String rank_borrow_times_ = Integer.toString(rank_borrow_times);
                map.put("rank_user", rank_user);
                map.put("rank_name", rank_name);
                map.put("rank_rank", "我  的n排  名n    "+Integer.toString(count_));
                map.put("rank_borrow_times", rank_borrow_times_);
                list.add(map);
                break;
            }
        }
        return list;
    }

    public final class ViewHolder_rank{
        TextView user;
        TextView name;
        TextView times;
        TextView rank;
    }
}

8.Register_Page.java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Register_Page extends AppCompatActivity {
    private SQLiteDatabase database;
    private EditText editText_user;
    private EditText editText_name;
    private EditText editText_password;
    private EditText editText_password_again;
    private Button button_confirm;
    private Button button_return;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register_page);

        editText_user = findViewById(R.id.editText_user);
        editText_name = findViewById(R.id.editText_name);
        editText_password = findViewById(R.id.editText_password);
        editText_password_again = findViewById(R.id.editText_password_again);
        button_confirm = findViewById(R.id.button_confirm);
        button_return = findViewById(R.id.button_return);

        Database_user database_user= new Database_user(Register_Page.this);
        database = database_user.getWritableDatabase();

        button_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(!editText_user.getText().toString().equals("") && !editText_name.getText().toString().equals("") && !editText_password.getText().toString().equals("") && !editText_password_again.getText().toString().equals("")){
                    insert(view);
                }else{
                    Toast.makeText(getApplicationContext(),"请输入完整注册信息",Toast.LENGTH_SHORT).show();
                }
            }
        });

        button_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_return = new Intent(getApplicationContext(), Login_Page.class);
                startActivity(intent_return);
            }
        });

    }

    public void insert(View view){
        String sql = "select * from user where 学号=?";
        Cursor cursor = database.rawQuery(sql,new String[]{editText_user.getText().toString()});
        if(cursor.getCount()==0){
            if(editText_password.getText().toString().equals(editText_password_again.getText().toString())){
                ContentValues values = new ContentValues();
                values.put("学号",editText_user.getText().toString());
                values.put("姓名",editText_name.getText().toString());
                values.put("密码",editText_password.getText().toString());
                values.put("学习次数",0);
                values.put("借书次数",0);
                database.insert("user",null,values);
                Intent intent_return = new Intent(getApplicationContext(), Login_Page.class);
                Toast.makeText(getApplicationContext(),"注册成功",Toast.LENGTH_SHORT).show();
                startActivity(intent_return);
            }else{
                Toast.makeText(getApplicationContext(),"两次密码输入不一致,请重新输入",Toast.LENGTH_SHORT).show();
                editText_password.setText("");
                editText_password_again.setText("");
            }
        }else{
            Toast.makeText(getApplicationContext(),"学号已存在,请重新输入",Toast.LENGTH_SHORT).show();
            editText_user.setText("");
        }
    }
}

9.Return_books_Page.java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

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

public class Return_books_Page extends AppCompatActivity {

    private Button button_return;
    private Button button_refresh;
    private ListView listView_borrow;
    private ListView listView_return;
    private SQLiteDatabase database;
    private List> mData_borrow;
    private List> mData_return;
    private String user;
    private SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.return_books_page);

        button_return = findViewById(R.id.button_return);
        button_refresh = findViewById(R.id.button_refresh);
        Database_user database_user= new Database_user(Return_books_Page.this);
        database = database_user.getWritableDatabase();
        listView_borrow = findViewById(R.id.listView_borrow);
        listView_return = findViewById(R.id.listView_return);

        sp = getSharedPreferences("LibrarySystem", Context.MODE_PRIVATE);
        SharedPreferences.Editor  editor = sp.edit();
        user = sp.getString("user","");

        mData_borrow = getData_borrow();
        MyAdapter_borrow adapter_borrow = new MyAdapter_borrow(getApplicationContext());
        listView_borrow.setAdapter(adapter_borrow);

        mData_return = getData_return();
        MyAdapter_return adapter_return = new MyAdapter_return(getApplicationContext());
        listView_return.setAdapter(adapter_return);


        button_return.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent intent_return = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(intent_return);
            }
        });


        button_refresh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mData_borrow = getData_borrow();
                MyAdapter_borrow adapter_borrow = new MyAdapter_borrow(getApplicationContext());
               listView_borrow.setAdapter(adapter_borrow);

                mData_return = getData_return();
                MyAdapter_return adapter_return = new MyAdapter_return(getApplicationContext());
                listView_return.setAdapter(adapter_return);
            }
        });

    }


    public class MyAdapter_return extends BaseAdapter {
        private LayoutInflater mInflater;

        public MyAdapter_return(Context context) {
            this.mInflater = LayoutInflater.from((Context) context);
        }

        @Override
        public int getCount() {
            return mData_return.size();
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder_return holder = null;

            if (convertView == null) {

                holder=new ViewHolder_return();

                //可以理解为从vlist获取view 之后把view返回给ListView

                convertView = mInflater.inflate(R.layout.adapter_books_return, null);
                holder.book_name = (TextView)convertView.findViewById(R.id.textView_book_name);
                holder.book_borrow_time = (TextView)convertView.findViewById(R.id.textView_book_borrow_time);
                holder.book_return_time = (TextView)convertView.findViewById(R.id.textView_book_return_time);
                holder.book_state = (TextView)convertView.findViewById(R.id.textView_book_state);
                convertView.setTag(holder);
            }else {
                holder = (ViewHolder_return)convertView.getTag();
            }

            holder.book_name.setText((String)mData_return.get(position).get("book_name"));
            holder.book_borrow_time.setText("借出日期:" + (String)mData_return.get(position).get("book_borrow_time"));
            holder.book_return_time.setText("归还日期:" + (String)mData_return.get(position).get("book_return_time"));
            holder.book_state.setText("是否逾期:" + (String)mData_return.get(position).get("book_state"));

            ViewHolder_return finalHolder = holder;


            //holder.viewBtn.setOnClickListener(MyListener(position));

            return convertView;
        }


    }


    public class MyAdapter_borrow extends BaseAdapter {
        private LayoutInflater mInflater;

        public MyAdapter_borrow(Context context) {
            this.mInflater = LayoutInflater.from((Context) context);
        }

        @Override
        public int getCount() {

            return mData_borrow.size();
        }

        @Override
        public Object getItem(int i) {

            return null;
        }

        @Override
        public long getItemId(int i) {

            return 0;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder_borrow holder = null;

            if (convertView == null) {

                holder = new ViewHolder_borrow();

                //可以理解为从vlist获取view 之后把view返回给ListView

                convertView = mInflater.inflate(R.layout.adapter_books_borrow, null);
                holder.book_name = (TextView) convertView.findViewById(R.id.textView_book_name);
                holder.book_borrow_time = (TextView) convertView.findViewById(R.id.textView_book_borrow_time);
                holder.book_state = (TextView) convertView.findViewById(R.id.textView_book_state);
                holder.button_return = (Button) convertView.findViewById(R.id.button_return);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder_borrow) convertView.getTag();
            }

            holder.book_name.setText((String) mData_borrow.get(position).get("book_name"));
            holder.book_borrow_time.setText("借出日期:" + (String) mData_borrow.get(position).get("book_borrow_time"));
            holder.book_state.setText("是否逾期:" + (String) mData_borrow.get(position).get("book_state"));
            holder.button_return.setTag(position);

            //给Button添加单击事件 添加Button之后ListView将失去焦点 需要的直接把Button的焦点去掉
            ViewHolder_borrow finalHolder = holder;
            holder.button_return.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String book_name = (String) mData_borrow.get(position).get("book_name");
                    Calendar calendar = Calendar.getInstance();
                    int year = calendar.get(Calendar.YEAR);
                    int month = calendar.get(Calendar.MONTH) + 1;
                    int day = calendar.get(Calendar.DAY_OF_MONTH);
                    String book_return_time = Integer.toString(year) + "-" +Integer.toString(month) + "-" + Integer.toString(day);
                    String sql = "update borrow_books set 是否归还=?,还书日期=? where 学号=? and 书名=?";
                    database.execSQL(sql,new Object[]{"是",book_return_time,user,(String)mData_borrow.get(position).get("book_name")});
                    String sql1 = "update books set 是否借出=?,借出人学号=?,借出人姓名=? where 书名=?";
                    database.execSQL(sql1,new Object[]{"否","无","无",(String)mData_borrow.get(position).get("book_name")});
                    Toast.makeText(Return_books_Page.this, "还书成功", Toast.LENGTH_SHORT).show();
                }
            });

            //holder.viewBtn.setOnClickListener(MyListener(position));

            return convertView;
        }
    }


        private List> getData_return() {
        List> list = new ArrayList>();
        String sql = "select * from borrow_books where 学号=? and 是否归还=?";
        Cursor cursor = database.rawQuery(sql,new String[]{user,"是"});
        while(cursor.moveToNext()){
            Map map = new HashMap<>();
            int book_name_ColumnIndex = cursor.getColumnIndex("书名");
            String book_name_searched = cursor.getString(book_name_ColumnIndex);
            int book_borrow_time_ColumnIndex = cursor.getColumnIndex("借书日期");
            String book_borrow_time_searched = cursor.getString(book_borrow_time_ColumnIndex);
            int book_return_time_ColumnIndex = cursor.getColumnIndex("还书日期");
            String book_return_time_searched = cursor.getString(book_return_time_ColumnIndex);
            int book_state_ColumnIndex = cursor.getColumnIndex("是否逾期");
            String book_state_searched = cursor.getString(book_state_ColumnIndex);
            map.put("book_name",book_name_searched);
            map.put("book_borrow_time",book_borrow_time_searched);
            map.put("book_return_time",book_return_time_searched);
            map.put("book_state",book_state_searched);
            list.add(map);
        }
        return list;
    }

    private List> getData_borrow() {
        List> list = new ArrayList>();
        String sql = "select * from borrow_books where 学号=? and 是否归还=?";
        Cursor cursor = database.rawQuery(sql,new String[]{user,"否"});
        while(cursor.moveToNext()){
            Map map = new HashMap<>();
            int book_name_ColumnIndex = cursor.getColumnIndex("书名");
            String book_name_searched = cursor.getString(book_name_ColumnIndex);
            int book_borrow_time_ColumnIndex = cursor.getColumnIndex("借书日期");
            String book_borrow_time_searched = cursor.getString(book_borrow_time_ColumnIndex);

            String[] book_borrow_time = book_borrow_time_searched.split("-");
            int year_picked = Integer.parseInt(book_borrow_time[0]);
            int month_picked = Integer.parseInt(book_borrow_time[1]);
            int day_picked = Integer.parseInt(book_borrow_time[2]);

            Calendar calendar = Calendar.getInstance();
            int year = calendar.get(Calendar.YEAR);
            int month = calendar.get(Calendar.MONTH) + 1;
            int day = calendar.get(Calendar.DAY_OF_MONTH);

            int time_current = (year-1) * 365 + day;
            if(month > 1){
                time_current += 31;
            }
            if(month > 2){
                time_current += 28;
            }
            if(month > 3){
                time_current += 31;
            }
            if(month > 4){
                time_current += 30;
            }
            if(month > 5){
                time_current += 31;
            }
            if(month > 6){
                time_current += 30;
            }
            if(month > 7){
                time_current += 31;
            }
            if(month> 8){
                time_current += 31;
            }
            if(month > 9){
                time_current += 30;
            }
            if(month > 10){
                time_current += 31;
            }
            if(month > 11){
                time_current += 30;
            }

            int time_picked = (year_picked-1) * 365 + day_picked;
            if(month_picked > 1){
                time_picked += 31;
            }
            if(month_picked > 2){
                time_picked += 28;
            }
            if(month_picked > 3){
                time_picked += 31;
            }
            if(month_picked > 4){
                time_picked += 30;
            }
            if(month_picked > 5){
                time_picked += 31;
            }
            if(month_picked > 6){
                time_picked += 30;
            }
            if(month_picked > 7){
                time_picked += 31;
            }
            if(month_picked > 8){
                time_picked += 31;
            }
            if(month_picked > 9){
                time_picked += 30;
            }
            if(month_picked > 10){
                time_picked += 31;
            }
            if(month_picked > 11){
                time_picked += 30;
            }
            String book_state;
            if(time_current > time_picked +30){
                book_state = "是";
            }else{
                book_state = "否";
            }
            map.put("book_name",book_name_searched);
            map.put("book_borrow_time",book_borrow_time_searched);
            map.put("book_state",book_state);
            list.add(map);
        }
        return list;
    }

    public final class ViewHolder_return{
        TextView book_name;
        TextView book_borrow_time;
        TextView book_return_time;
        TextView book_state;
    }
    public final class ViewHolder_borrow{
        TextView book_name;
        TextView book_borrow_time;
        TextView book_state;
        Button button_return;
    }
}

10.Study_Page.java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import java.util.Calendar;

public class Study_Page extends AppCompatActivity {
    private SQLiteDatabase database;
    private DatePicker datePicker;
    private int year_current;
    private int month_current;
    private int day_current;
    private int year_picked;
    private int month_picked;
    private int day_picked;
    private Button button_confirm;
    private Button button_return;
    private RadioGroup radioGroup;
    private RadioButton radioButton;
    private String shike;
    private String user;
    private String name;
    private SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.study_page);

        datePicker = findViewById(R.id.datapicker);
        button_confirm = findViewById(R.id.button_confirm);
        Database_user database_user= new Database_user(Study_Page.this);
        database = database_user.getWritableDatabase();
        radioGroup = findViewById(R.id.RadioGroup);
        button_return = findViewById(R.id.button_return);

        sp = getSharedPreferences("LibrarySystem", Context.MODE_PRIVATE);
        SharedPreferences.Editor  editor = sp.edit();
        user = sp.getString("user","");
        name = sp.getString("name","");

        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        year_current = year;
        month_current = month+1;
        day_current = day;
        datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() {
            @Override
            public void onDateChanged(DatePicker datePicker, int i, int i1, int i2) {
                year_picked = i;
                month_picked = (i1+1);
                day_picked = i2;
            }
        });

        button_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent_return = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(intent_return);
            }
        });


        button_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int time_current = (year_current-1) * 365 + day_current;
                if(month_current > 1){
                    time_current += 31;
                }
                if(month_current > 2){
                    time_current += 28;
                }
                if(month_current > 3){
                    time_current += 31;
                }
                if(month_current > 4){
                    time_current += 30;
                }
                if(month_current > 5){
                    time_current += 31;
                }
                if(month_current > 6){
                    time_current += 30;
                }
                if(month_current > 7){
                    time_current += 31;
                }
                if(month_current > 8){
                    time_current += 31;
                }
                if(month_current > 9){
                    time_current += 30;
                }
                if(month_current > 10){
                    time_current += 31;
                }
                if(month_current > 11){
                    time_current += 30;
                }

                int time_picked = (year_picked-1) * 365 + day_picked;
                if(month_picked > 1){
                    time_picked += 31;
                }
                if(month_picked > 2){
                    time_picked += 28;
                }
                if(month_picked > 3){
                    time_picked += 31;
                }
                if(month_picked > 4){
                    time_picked += 30;
                }
                if(month_picked > 5){
                    time_picked += 31;
                }
                if(month_picked > 6){
                    time_picked += 30;
                }
                if(month_picked > 7){
                    time_picked += 31;
                }
                if(month_picked > 8){
                    time_picked += 31;
                }
                if(month_picked > 9){
                    time_picked += 30;
                }
                if(month_picked > 10){
                    time_picked += 31;
                }
                if(month_picked > 11){
                    time_picked += 30;
                }

                if(time_picked <= time_current || time_picked - time_current > 3){
                    Toast.makeText(Study_Page.this, "请选择三天之内的时间预约自习", Toast.LENGTH_SHORT).show();
                }else{
                    for(int i=0;i10){
                        Toast.makeText(Study_Page.this, "当前日期时间段预约自习人数已满,请重新选择", Toast.LENGTH_SHORT).show();
                    }else{
                        int flag = 1;
                        while(cursor.moveToNext())
                        {
                            int yearColumnIndex = cursor.getColumnIndex("年");
                            String year_saved = cursor.getString(yearColumnIndex);
                            int monthColumnIndex = cursor.getColumnIndex("月");
                            String month_saved = cursor.getString(monthColumnIndex);
                            int dayColumnIndex = cursor.getColumnIndex("日");
                            String day_saved = cursor.getString(dayColumnIndex);
                            int shikeColumnIndex = cursor.getColumnIndex("时刻");
                            String shike_saved = cursor.getString(shikeColumnIndex);
                            int userColumnIndex = cursor.getColumnIndex("学号");
                            String user_saved = cursor.getString(userColumnIndex);
                            if(year_saved.equals(Integer.toString(year_picked)) && month_saved.equals(Integer.toString(month_picked)) && day_saved.equals(Integer.toString(day_picked)) && shike_saved.equals(shike) && user_saved.equals(user)) {
                                Toast.makeText(Study_Page.this, "当前日期时间段已预约过,请重新选择", Toast.LENGTH_SHORT).show();
                                flag = 0;
                                break;
                            }
                        }
                        if(flag == 1){
                            ContentValues values = new ContentValues();
                            values.put("学号", user);
                            values.put("姓名", name);
                            values.put("年", Integer.toString(year_picked));
                            values.put("月", Integer.toString(month_picked));
                            values.put("日", Integer.toString(day_picked));
                            values.put("时刻", shike);
                            database.insert("study",null,values);
                            String sql1 = "select * from user where 学号=?";
                            Cursor cursor2 = database.rawQuery(sql1,new String[]{user});
                            cursor2.moveToFirst();
                            int timesColumnIndex = cursor2.getColumnIndex("学习次数");
                            int times = cursor2.getInt(timesColumnIndex) + 1;
                            String sql2 = "update user set 学习次数=? where 学号=?";
                            database.execSQL(sql2,new Object[]{times,user});
                            Toast.makeText(Study_Page.this, "预约自习成功", Toast.LENGTH_SHORT).show();
                        }
                    }
                }

            }
        });

    }
}

11.Welcome_Page.java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class Welcome_Page extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome_page);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(getApplicationContext(), Login_Page.class);
                startActivity(intent);
                finish();
            }
        },3000);


    }
}

二、layout文件xml

1.activity_main.xml




    

        

2.adapter_books.xml




    

3.adapter_books_borrow.xml




    

4.adapter_books_return.xml






    



    


    


    

5.adapter_rank.xml





    

    

    

    

6.announcement_page.xml




    

    

    

    

    

7.borrow_books_page.xml




    

    

8.login_page.xml







        

        


        

        

        

9.modify_password_page.xml




    

    

10.rank_page.xml





    

    

    

    

    

11.register_page.xml





    

12.return_books_page.xml






    

    

    

    

    

13.study_page.xml




    

        

        
    

    


    

14.welcome_page.xml




    

三、drawable文件xml

1.button_circle_shape.xml



    android:shape="rectangle">
    
    
    
    
    
    
    
    
    
    
    
    
    **设置文字padding**
    
    
    

2.button_full_circle_shape.xml



    
    
    

3.button_rectangle.xml



    android:shape="rectangle">
    
    
    
    


    
    
    
    
    
    
    
    **设置文字padding**
    






    

4.text_background.xml



    android:shape="rectangle">
    

    

5.text_background1.xml



    android:shape="rectangle">
    
    
    

四、values文件xml

1.colors.xml



    #FFBB86FC
    #FF6200EE
    #FF3700B3
    #FF03DAC5
    #FF018786
    #FF000000
    #FFFFFF
    #FFFFF0
    #FFFFE0
    #FFFF00
    #FFFAFA
    #FFFAF0
    #FFFACD
    #FFF8DC
    #FFF5EE
    #FFF0F5
    #FFEFD5
    #FFEBCD
    #FFE4E1
    #FFE4C4
    #FFE4B5
    #FFDEAD
    #FFDAB9
    #FFD700
    #FFC0CB
    #FFB6C1
    #FFA500
    #FFA07A
    #FF8C00
    #FF7F50
    #FF69B4
    #FF6347
    #FF4500
    #FF1493
    #FF00FF
    #FF00FF
    #FF0000
    #FDF5E6
    #FAFAD2
    #FAF0E6
    #FAEBD7
    #FA8072
    #F8F8FF
    #F5FFFA
    #F5F5F5
    #F5F5DC
    #F5DEB3
    #F4A460
    #F0FFFF
    #F0FFF0
    #F0F8FF
    #F0E68C
    #F08080
    #EEE8AA
    #EE82EE
    #E9967A
    #E6E6FA
    #E0FFFF
    #DEB887
    #DDA0DD
    #DCDCDC
    #DC143C
    #DB7093
    #DAA520
    #DA70D6
    #D8BFD8
    #D3D3D3
    #D3D3D3
    #D2B48C
    #D2691E
    #CD853F
    #CD5C5C
    #C71585
    #C0C0C0
    #BDB76B
    #BC8F8F
    #BA55D3
    #B8860B
    #B22222
    #B0E0E6
    #B0C4DE
    #AFEEEE
    #ADFF2F
    #ADD8E6
    #A9A9A9
    #A9A9A9
    #A52A2A
    #A0522D
    #9932CC
    #98FB98
    #9400D3
    #9370DB
    #90EE90
    #8FBC8F
    #8B4513
    #8B008B
    #8B0000
    #8A2BE2
    #87CEFA
    #87CEEB
    #808080
    #808080
    #808000
    #800080
    #800000
    #7FFFD4
    #7FFF00
    #7CFC00
    #7B68EE
    #778899
    #778899
    #708090
    #708090
    #6B8E23
    #6A5ACD
    #696969
    #696969
    #66CDAA
    #6495ED
    #5F9EA0
    #556B2F
    #4B0082
    #48D1CC
    #483D8B
    #4682B4
    #4169E1
    #3CB371
    #32CD32
    #2F4F4F
    #2F4F4F
    #2E8B57
    #228B22
    #20B2AA
    #1E90FF
    #191970
    #00FFFF
    #00FFFF
    #00FF7F
    #00FF00
    #00FA9A
    #00CED1
    #00BFFF
    #008B8B
    #008080
    #008000
    #006400
    #0000FF
    #0000CD
    #00008B
    #000080

2.strings.xml


    My Application

    
        书名
        责任者
        出版信息
    

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/952558.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号