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

Posted 潜力无限*start

tags:

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

前两篇介绍了主页面和Student,这一篇来讲Book类和工作人员。

Book是图书管理系统的核心,查书,借书,还书,增加书都与Book类息息相关。Book类的设计很简单:包含信息:名称、作者、页数、价钱、出版日期、数量、在架数量。

Book类的代码:

 1 package com.example.administrator.library1;
 2 
 3 import org.litepal.annotation.Column;
 4 import org.litepal.crud.LitePalSupport;
 5 
 6 public class Book extends LitePalSupport{
 7     int id;
 8     private String name;
 9     private String writer,page,price,time;
10     private int amount,in_shelf;
11     public Book(String name,String writer,String page,String price,String time,int amount)
12     {
13         this.name=name;
14         this.writer=writer;
15         this.page=page;
16         this.price=price;
17         this.time=time;
18         this.amount=amount;
19         in_shelf=amount;
20     }
21     public void setAmount(int amount) {
22         this.amount = amount;
23     }
24     public int getAmount() {
25         return amount;
26     }
27     public void setIn_shelf(int in_shelf) {
28         this.in_shelf = in_shelf;
29     }
30     public int getIn_shelf() {
31         return in_shelf;
32     }
33     public void setId(int id) {
34         this.id = id;
35     }
36     public int getId() {
37         return id;
38     }
39     public void setName(String name) {
40         this.name = name;
41     }
42     public void setPrice(String price) {
43         this.price = price;
44     }
45     public void setPage(String page) {
46         this.page = page;
47     }
48     public void setTime(String time) {
49         this.time = time;
50     }
51     public void setWriter(String writer) {
52         this.writer = writer;
53     }
54     public String getName() {
55         return name;
56     }
57     public String getPage() {
58         return page;
59     }
60     public String getPrice() {
61         return price;
62     }
63     public String getTime() {
64         return time;
65     }
66     public String getWriter() {
67         return writer;
68     }
69 
70 }
Book

Staff的类也很简单,包含职员的一些个人信息。

 1 package com.example.administrator.library1;
 2 
 3 import org.litepal.LitePal;
 4 import org.litepal.crud.LitePalSupport;
 5 
 6 public class Staff extends LitePalSupport {
 7     private int id;
 8     private String account,password,name,staff_number,mail_box;
 9     int age;
10     public Staff(String account,String password,String name,String staff_number,String mail_box,int age)
11     {
12         this.account=account;
13         this.age=age;
14         this.staff_number=staff_number;
15         this.mail_box=mail_box;
16         this.password=password;
17         this.name=name;
18     }
19 
20     public int getId() {
21         return id;
22     }
23     public String getName() {
24         return name;
25     }
26     public String getPassword() {
27         return password;
28     }
29     public int getAge() {
30         return age;
31     }
32     public String getStaff_number() {
33         return staff_number;
34     }
35     public String getMail_box() {
36         return mail_box;
37     }
38     public String getAccount() {
39         return account;
40     }
41     public void setName(String name) {
42         this.name = name;
43     }
44     public void setId(int id) {
45         this.id = id;
46     }
47     public void setPassword(String password) {
48         this.password = password;
49     }
50     public void setAge(int age) {
51         this.age = age;
52     }
53     public void setAccount(String account) {
54         this.account = account;
55     }
56     public void setMail_box(String mail_box) {
57         this.mail_box = mail_box;
58     }
59     public void setStaff_number(String staff_number) {
60         this.staff_number = staff_number;
61     }
62 }
Staff

职员的登录界面,大致与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.CheckBox;
 9 import android.widget.EditText;
10 import android.widget.Toast;
11 
12 import org.litepal.LitePal;
13 
14 import java.util.List;
15 
16 public class Login_staff extends AppCompatActivity {
17 
18     private EditText staff_editAccount,staff_editPassword;
19     private CheckBox staff_checkBox;
20     private Button staff_button_commit;
21     @Override
22     protected void onCreate(Bundle savedInstanceState) {
23         super.onCreate(savedInstanceState);
24         setContentView(R.layout.activity_login_staff);
25         staff_editAccount=findViewById(R.id.accountStaff_id);
26         staff_editPassword=findViewById(R.id.passwordStaff_id);
27         staff_checkBox=findViewById(R.id.rememberPassStaff_id);
28         staff_button_commit=findViewById(R.id.commitStaff_id);
29         Simple simple=LitePal.find(Simple.class,3);
30         staff_editAccount.setText(simple.getAccount());
31         staff_editPassword.setText(simple.getPassword());
32 
33         staff_button_commit.setOnClickListener(new View.OnClickListener() {
34             @Override
35             public void onClick(View view) {                  //在这里之前已经出错
36                 List<Staff> staffs_account = LitePal.findAll(Staff.class);
37                 boolean is_account_available = false;
38                 String st_account = staff_editAccount.getText().toString();
39                 String st_password = staff_editPassword.getText().toString();
40                 for (int i = 0; i < staffs_account.size(); ++i) {
41                     if (st_account.equals(staffs_account.get(i).getAccount())) {  //get(i)这里的查询是从0开始的,即是get(0)查询的是id为1的员工
42                         is_account_available = true;
43                         if (st_password.equals(staffs_account.get(i).getPassword())) {
44                             if(staff_checkBox.isChecked())
45                             {
46                                 Simple simple= LitePal.find(Simple.class,3);
47                                 simple.setAccount(staff_editAccount.getText().toString());
48                                 simple.setPassword(staff_editPassword.getText().toString());
49                                 simple.save();
50                             }
51                             else
52                             {
53                                 Simple simple1=LitePal.find(Simple.class,3);
54                                 simple1.setAccount("");
55                                 simple1.setPassword("");
56                                 simple1.save();
57                             }
58                             Intent intent = new Intent(Login_staff.this, Staff_homepage.class);
59                             intent.putExtra("extra_data", i+1);
60                             startActivity(intent);
61                             finish();
62                         } else {
63                             Toast.makeText(Login_staff.this, "密码错误", Toast.LENGTH_SHORT).show();
64                             break;                           //记住密码还没有用上
65                         }
66                     }
67                 }
68                 if (is_account_available == false) {
69                     Toast.makeText(Login_staff.this, "账号不存在", Toast.LENGTH_SHORT).show();
70                 }
71             }
72         });
73     }
74 }
Login_Staff
 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     android:orientation="vertical"
 5     xmlns:tools="http://schemas.android.com/tools"
 6     android:layout_width="match_parent"
 7     android:layout_height="match_parent"
 8     tools:context=".Login_student">
 9 
10     <ImageView
11         android:layout_width="match_parent"
12         android:layout_height="211dp"
13         android:src="@drawable/img_login" />
14     <LinearLayout
15         android:layout_width="match_parent"
16         android:layout_height="wrap_content"
17         android:layout_marginTop="20dp"
18         android:layout_marginLeft="20dp"
19         android:layout_marginRight="20dp"
20         android:orientation="horizontal">
21         <TextView
22             android:layout_width="0dp"
23             android:layout_height="match_parent"
24             android:layout_weight="1"
25             android:textSize="21sp"
26             android:text="账号: "/>
27         <EditText
28             android:id="@+id/accountStaff_id"
29             android:layout_width="0dp"
30             android:layout_height="match_parent"
31             android:layout_weight="5"
32             android:hint="type here"/>
33     </LinearLayout>
34     <LinearLayout
35         android:orientation="horizontal"
36         android:layout_width="match_parent"
37         android:layout_marginLeft="20dp"
38         android:layout_marginRight="20dp"
39         android:layout_height="wrap_content">
40         <TextView
41             android:layout_width="0dp"
42             android:layout_height="match_parent"
43             android:layout_weight="1"
44             android:textSize="21sp"
45             android:text="密码 :"/>
46         <EditText
47             android:id="@+id/passwordStaff_id"
48             android:layout_width="0dp"
49             android:layout_height="match_parent"
50             android:layout_weight="5"
51             android:hint="type here"/>
52     </LinearLayout>
53     <LinearLayout
54         android:layout_marginLeft="20dp"
55         android:layout_marginRight="20dp"
56         android:layout_width="match_parent"
57         android:layout_height="wrap_content">
58         <CheckBox
59             android:id="@+id/rememberPassStaff_id"
60             android:layout_width="wrap_content"
61             android:layout_height="wrap_content"
62             android:checked="true"/>
63         <TextView
64             android:layout_width="wrap_content"
65             android:layout_height="wrap_content"
66             android:textSize="18sp"
67             android:text="记住密码"/>
68     </LinearLayout>
69     <Button
70         android:id="@+id/commitStaff_id"
71         android:layout_width="150dp"
72         android:layout_height="wrap_content"
73         android:layout_gravity="center"
74         android:textSize="20sp"
75         android:text="登录"/>
76 </LinearLayout>
Staff_login_xml

下面讲述staff职员的个人主页,中间有两个Button,分别是添加书籍和返回。

点击添加书籍会进入另一个界面填写新入库的书籍信息,提交后将返回职员的主页。

由于进入填写信息的界面再次返回职员主页后,此时想要返回MainActivity需要点击三下手机自带的返回键,于是在职员主页中添加了一个返回按钮。

下面使用了listview,展示当前图书馆所有书籍的名称、作者与各本书的数量。

代码贴出来如下:

 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:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     android:orientation="vertical"
 8     tools:context=".Staff_homepage">
 9     <ImageView
10         android:layout_width="match_parent"
11         android:layout_height="wrap_content"
12         android:src="@drawable/img_login"/>
13     <TextView
14         android:id="@+id/sta_home_infor_id"
15         android:layout_width="match_parent"
16         android:layout_height="wrap_content"
17         android:layout_gravity="center"
18         android:gravity="center"
19         android:textSize="20sp"/>
20     <Button
21         android:id="@+id/sta_input_book_id"
22         android:layout_width="match_parent"
23         android:layout_height="wrap_content"
24         android:text="增加书籍"/>
25     <Button
26         android:id="@+id/sta_return_id"
27         android:layout_width="match_parent"
28         android:layout_height="wrap_content"
29         android:text="返回主菜单"/>
30     <ListView
31         android:id="@+id/staff_home_list_id"
32         android:layout_width="match_parent"
33         android:layout_height="wrap_content">
34     </ListView>
35 </LinearLayout>
Staff_homepage_xml
 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.ArrayAdapter;
 8 import android.widget.Button;
 9 import android.widget.ListView;
10 import android.widget.TextView;
11 
12 import org.litepal.LitePal;
13 
14 import java.util.ArrayList;
15 import java.util.List;
16 
17 public class Staff_homepage extends AppCompatActivity {
18     private int staff_id;
19     Staff staff;
20     private TextView textView_name;
21     private Button button_add,button_return;
22     private List<Book> totalbooks=new ArrayList<>();
23     private List<String> booknames=new ArrayList<>();
24     @Override
25     protected void onCreate(Bundle savedInstanceState) {
26         super.onCreate(savedInstanceState);
27         setContentView(R.layout.activity_staff_homepage);
28         textView_name = (TextView) findViewById(R.id.sta_home_infor_id);
29         button_add = (Button) findViewById(R.id.sta_input_book_id);
30         button_return = (Button) findViewById(R.id.sta_return_id);
31         totalbooks = LitePal.findAll(Book.class);
32 
33         final Intent intent =基于Android平台的图书管理系统的制作

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

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

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

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

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