基于Android平台的图书管理系统的制作

Posted 潜力无限*start

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于Android平台的图书管理系统的制作相关的知识,希望对你有一定的参考价值。

上一篇讲解了制作图书管理系统的初衷与要求,和app首页的代码。

下面来介绍图书管理系统的服务对象:学生

学生类的设计:

个人信息:账号、密码、姓名、学号、邮箱、年龄。

借阅信息:借阅总数(不超过十本)、借阅书籍的ID(数组)、借阅书籍的日期(数组)。

源码在此:

  1 package com.example.administrator.library1;
  2 
  3 import org.litepal.LitePal;
  4 import org.litepal.crud.DataSupport;
  5 import org.litepal.crud.LitePalSupport;
  6 
  7 import java.util.ArrayList;
  8 import java.util.List;
  9 
 10 public class Student extends LitePalSupport{
 11     private int id;
 12     private String account,name,password,student_ID,mailBox;
 13     private int age,bookAmount;
 14     private int bookList[]=new int[10];
 15     private int bookyear[]=new int[10];
 16     private int bookday[]=new int[10];
 17 
 18     public Student(String account, String password, String name, String student_ID, String mailBox, int age)
 19     {
 20         this.account=account;
 21         this.password=password;
 22         this.name=name;
 23         this.student_ID=student_ID;
 24         this.mailBox=mailBox;
 25         this.age=age;
 26         bookAmount=0;
 27         for(int i=0;i<10;++i)
 28         {
 29             bookList[i]=0;
 30             bookyear[i]=0;
 31             bookday[i]=0;
 32         }
 33     }
 34     public int getId() {
 35         return id;
 36     }
 37     public void setId(int id) {
 38         this.id = id;
 39     }
 40     public void setName(String name) {
 41         this.name = name;
 42     }
 43     public void setAccount(String account) {
 44         this.account = account;
 45     }
 46     public void setAge(int age) {
 47         this.age = age;
 48     }
 49     public void setPassword(String password) {
 50         this.password = password;
 51     }
 52     public void setMailBox(String mailBox) {
 53         this.mailBox = mailBox;
 54     }
 55     public void setStudent_ID(String student_ID) {
 56         this.student_ID = student_ID;
 57     }
 58     public String getName() {
 59         return name;
 60     }
 61     public int getAge() {
 62         return age;
 63     }
 64     public String getAccount() {
 65         return account;
 66     }
 67     public String getPassword() {
 68         return password;
 69     }
 70     public String getStudent_ID() {
 71         return student_ID;
 72     }
 73     public String getMailBox() {
 74         return mailBox;
 75     }
 76     public void setBookList(int[] bookList) {
 77         this.bookList = bookList;
 78     }
 79     public void setBookList(int number,int book_id)
 80     {
 81         this.bookList[number]=book_id;
 82     }
 83     public int[] getBookList() {
 84         return bookList;
 85     }
 86     public int getBookAmount() {
 87         return bookAmount;
 88     }
 89     public void setBookAmount(int bookAmount) {
 90         this.bookAmount = bookAmount;
 91     }
 92     public int getBookList(int number)
 93     {
 94         return bookList[number];
 95     }
 96     public int getBookyear(int number){return bookyear[number];}
 97     public int getBookday(int number){return bookday[number];}
 98     public void setBookyear(int number,int year){this.bookyear[number]=year;}
 99     public void setBookday(int number,int day){this.bookday[number]=day;}
100 
101 }
Student

学生的注册:

注册有个人信息的填写:账号、密码(重复输入)、学号、姓名、邮箱、年龄。

代码如下:

主逻辑:

 1 package com.example.administrator.library1;
 2 
 3 import android.content.Intent;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.os.Bundle;
 6 import android.view.View;
 7 import android.widget.Button;
 8 import android.widget.EditText;
 9 import android.widget.Toast;
10 
11 import org.litepal.LitePal;
12 
13 import java.util.List;
14 
15 public class Register_student extends AppCompatActivity {
16     private EditText editAccount,editPassword1,editPassword2,editName,editMailbox,editAge,editStudentID;
17     private Button button_commit;
18     @Override
19     protected void onCreate(Bundle savedInstanceState) {
20         super.onCreate(savedInstanceState);
21         setContentView(R.layout.activity_register_student);
22         editAccount=findViewById(R.id.reg_st_acc_id);
23         editPassword1=findViewById(R.id.reg_st_pass1_id);
24         editPassword2=findViewById(R.id.reg_st_pass2_id);
25         editName=findViewById(R.id.reg_st_name_id);
26         editAge=findViewById(R.id.reg_st_age_id);
27         editMailbox=findViewById(R.id.reg_st_mail_id);
28         editStudentID=findViewById(R.id.reg_st_ID_id);
29         button_commit=findViewById(R.id.reg_st_commit_id);
30         button_commit.setOnClickListener(new View.OnClickListener() {
31             @Override
32             public void onClick(View view) {
33                 if(editAccount.getText().toString().equals("")||editPassword1.getText().toString().equals("")||editPassword2.getText().toString().equals("")||editName.getText().toString().equals("")||editAge.getText().toString().equals("")||editMailbox.getText().toString().equals("")||editStudentID.getText().toString().equals(""))
34                 {
35                     Toast.makeText(Register_student.this,"注册信息不能为空",Toast.LENGTH_SHORT);
36                 }
37                 else
38                 {
39                     if(editAccount.getText().toString().length()>=6&&editAccount.getText().toString().length()<=12)
40                     {
41                         List<Student> students_account= LitePal.findAll(Student.class);
42                         boolean differ=true;
43                         for(int i=0;i<students_account.size();++i)
44                         {
45                             if(editAccount.getText().toString().equals(students_account.get(i).getAccount()))
46                             {
47                                 Toast.makeText(Register_student.this,"账号已存在",Toast.LENGTH_SHORT).show();
48                                 differ=false;
49                             }
50                         }
51                         if(differ==true)
52                         {
53                             if(editPassword2.getText().toString().equals(editPassword1.getText().toString()))
54                             {
55                                 int reg_age=Integer.parseInt(editAge.getText().toString());
56                                 Student student=new Student(editAccount.getText().toString(),editPassword1.getText().toString(),editName.getText().toString(),editStudentID.getText().toString(),editMailbox.getText().toString(),reg_age);
57                                 student.save();
58                                 Intent intent=new Intent(Register_student.this,MainActivity.class);
59                                 startActivity(intent);
60                                 //Toast.makeText(Register_student.this,"注册成功",Toast.LENGTH_SHORT).show();
61                             }
62                             else
63                             {
64                                 Toast.makeText(Register_student.this,"两次密码不相同",Toast.LENGTH_SHORT).show();
65                             }
66                         }
67                     }
68                     else
69                     {
70                         Toast.makeText(Register_student.this,"账号大小需要在6-12位数之间",Toast.LENGTH_SHORT).show();
71                     }
72                 }
73 
74             }
75         });
76     }
77 
78     @Override
79     protected void onPause() {
80         Intent intent=new Intent(Register_student.this,MainActivity.class);
81         startActivity(intent);
82         super.onPause();
83     }
84 }
Student_Register

界面:

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     xmlns:app="http://schemas.android.com/apk/res-auto"
  4     xmlns:tools="http://schemas.android.com/tools"
  5     android:orientation="vertical"
  6     android:layout_width="match_parent"
  7     android:layout_height="match_parent"
  8     tools:context=".Register_student">
  9     <LinearLayout
 10         android:layout_marginTop="20dp"
 11         android:orientation="horizontal"
 12         android:layout_width="match_parent"
 13         android:layout_height="wrap_content">
 14         <TextView
 15             android:layout_width="0dp"
 16             android:layout_height="match_parent"
 17             android:layout_weight="1"
 18             android:text="账号 :"
 19             android:textSize="21sp"/>
 20         <EditText
 21             android:id="@+id/reg_st_acc_id"
 22             android:layout_width="0dp"
 23             android:layout_height="match_parent"
 24             android:inputType="number"
 25             android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890*/@#$%^"
 26             android:layout_weight="3"/>
 27     </LinearLayout>
 28     <LinearLayout
 29         android:orientation="horizontal"
 30         android:layout_width="match_parent"
 31         android:layout_height="wrap_content">
 32         <TextView
 33             android:layout_width="0dp"
 34             android:layout_height="match_parent"
 35             android:layout_weight="1"
 36             android:text="输入密码"
 37             android:textSize="18sp"/>
 38         <EditText
 39             android:id="@+id/reg_st_pass1_id"
 40             android:layout_width="0dp"
 41             android:layout_height="match_parent"
 42             android:inputType="textPassword"
 43             android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890*/@#$%^"
 44             android:layout_weight="3"/>
 45     </LinearLayout>
 46     <LinearLayout
 47         android:orientation="horizontal"
 48         android:layout_width="match_parent"
 49         android:layout_height="wrap_content">
 50         <TextView
 51             android:layout_width="0dp"
 52             android:layout_height="match_parent"
 53             android:layout_weight="1"
 54             android:text="再输入密码"
 55             android:textSize="18sp"/>
 56         <EditText
 57             android:id="@+id/reg_st_pass2_id"
 58             android:layout_width="0dp"
 59             android:layout_height="match_parent"
 60             android:inputType="textPassword"
 61             android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890*/@#$%^"
 62             android:layout_weight="3"/>
 63     </LinearLayout>
 64     <LinearLayout
 65         android:orientation="horizontal"
 66         android:layout_width="match_parent"
 67         android:layout_height="wrap_content">
 68         <TextView
 69             android:layout_width="0dp"
 70             android:layout_height="match_parent"
 71             android:layout_weight="1"
 72             android:text="姓名 :"
 73             android:textSize="21sp"/>
 74         <EditText
 75             android:id="@+id/reg_st_name_id"
 76             android:layout_width="0dp"
 77             android:layout_height="match_parent"
 78             android:layout_weight="3"/>
 79     </LinearLayout>
 80     <LinearLayout
 81         android:orientation="horizontal"
 82         android:layout_width="match_parent"
 83         android:layout_height="wrap_content">
 84         <TextView
 85             android:layout_width="0dp"
 86             android:layout_height="match_parent"
 87             android:layout_weight="1"
 88             android:text="学号 :"
 89             android:textSize="21sp"/>
 90         <EditText
 91             android:id="@+id/reg_st_ID_id"
 92             android:inputType="number"
 93             android:digits="1234567890"
 94             android:layout_width="0dp"
 95             android:layout_height="match_parent"
 96             android:layout_weight="3"/>
 97     </LinearLayout>
 98     <LinearLayout
 99         android:orientation="horizontal"
100         android:layout_width="match_parent"
101         android:layout_height="wrap_content">
102         <TextView
103             android:layout_width="0dp"
104             android:layout_height="match_parent"
105             android:layout_weight="1"
106             android:text="邮箱 :"
107             android:textSize="21sp"/>
108         <EditText
109             android:id="@+id/reg_st_mail_id"
110             android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@."
111             android:layout_width="0dp"
112             android:inputType="number"
113             android:layout_height="match_parent"
114             android:layout_weight="3"/>
115     </LinearLayout>
116     <LinearLayout
117         android:orientation="horizontal"
118         android:layout_width="match_parent"
119         android:layout_height="wrap_content">
120         <TextView
121             android:layout_width="0dp"
122             android:layout_height="match_parent"
123             android:layout_weight="1"
124             android:text="年龄 :"
125             android:textSize="21sp"/>
126         <EditText
127             android:id="@+id/reg_st_age_id"
128             android:layout_width="0dp"
129             android:layout_height="match_parent"
130             android:layout_weight="3"
131             android:inputType="number"/>
132     </LinearLayout>
133     <Button
134         android:id="@+id/reg_st_commit_id"
135         android:layout_width="150dp"
136         android:layout_height="wrap_content"
137         android:textSize="24sp"
138         android:layout_gravity="center"
139         android:gravity="center"
140         android:text="注册提交"/>
141 </LinearLayout>
Studnet_register_xml

界面很丑,截图如下:

注册成功之后,将会使用开源项目Litepal将Edittext里的内容储存至本地数据库。Intent将活动带回MainActivity。

学生的登录:

使用账号密码登录,记住密码自动开启,并将账号和密码通过Simple类储存至Library数据库Simple表的第一列,登录开始时,会自动先访问Simple表ID为1的simple获得数据,登陆成功后进入Student homepage。

逻辑代码:

 1 package com.example.administrator.library1;
 2 
 3 import android.content.Intent;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.os.Bundle;
 6 import android.util.Log;
 7 import android.view.View;
 8 import android.widget.Button;
 9 import android.widget.CheckBox;
10 import android.widget.EditText;
11 import android.widget.Toast;
12 
13 import org.litepal.LitePal;
14 import org.litepal.crud.LitePalSupport;
15 
16 import java.util.List;
17 
18 public class Login_student extends AppCompatActivity {
19 
20     private EditText editAccount,editPassword;
21     private CheckBox checkBox;
22     private Button button_commit;
23     @Override
24     protected void onCreate(Bundle savedInstanceState) {
25         super.onCreate(savedInstanceState);
26         setContentView(R.layout.activity_login_student);
27         editAccount=findViewById(R.id.accountStudent_id);
28         editPassword=findViewById(R.id.passwordStudent_id);
29         checkBox=findViewById(R.id.rememberPassStudent_id);
30         button_commit=findViewById(R.id.commitStudent_id);
31 
32         //自动登录功能
33         final Simple simple=LitePal.find(Simple.class,1);
34         editAccount.setText(simple.getAccount());
35         editPassword.setText(simple.getPassword());
36 
37         button_commit.setOnClickListener(new View.OnClickListener() {
38             @Override
39             public void onClick(View view) {                  //在这里之前已经出错
40                 List<Student> students_account= LitePal.findAll(Student.class);
41                 boolean is_account_available=false;
42                 String st_account,st_password;
43                 st_account=editAccount.getText().toString();
44                 st_password=editPassword.getText().toString();
45                 for(int i=0;i<students_account.size();++i)
46                 {
47                     if(st_account.equals(students_account.get(i).getAccount()))
48                     {
49                         is_account_available=true;
50                         if(st_password.equals(students_account.get(i).getPassword()))
51                         {
52                             if(checkBox.isChecked())
53                             {
54                                 Simple simple= LitePal.find(Simple.class,1);
55                                 simple.setAccount(editAccount.getText().toString());
56                                 simple.setPassword(editPassword.getText().toString());
57                                 simple.save();
基于Android平台的图书管理系统的制作

基于Android平台的图书管理系统的制作

基于Android高校图书馆推荐书目系统

基于Android图书馆借阅系统app毕业设计

java计算机毕业设计基于安卓Android的图书零售管理系统APP-图书销售app-图书商城

我的Android进阶之旅关于Android平台获取文件的mime类型:为啥不传小写后缀名就获取不到mimeType?为啥android 4.4系统获取不到webp格式的mimeType呢?(代码片段