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

前两篇介绍了主页面和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 = getIntent();
34         staff_id = intent.getIntExtra("extra_data", 1);
35         staff = LitePal.find(Staff.class, staff_id);
36         textView_name.setText("员工编号: " + staff.getId() + "     " + "姓名: " + staff.getName());
37
38         button_add.setOnClickListener(new View.OnClickListener() {
39             @Override
40             public void onClick(View view) {
41                 Intent intent1 = new Intent(Staff_homepage.this, staff_input.class);
42                 startActivity(intent1);
43             }
44         });
45
46         button_return.setOnClickListener(new View.OnClickListener() {
47             @Override
48             public void onClick(View view) {
49                 Intent intent = new Intent(Staff_homepage.this, MainActivity.class);
50                 startActivity(intent);
51             }
52         });
53
54         for (int i = 0; i < totalbooks.size(); ++i) {
55             booknames.add("名称:" + totalbooks.get(i).getName() + "  " + "作者:" + totalbooks.get(i).getWriter() + "  " + "数量:" + totalbooks.get(i).getAmount());
56         }
57         ArrayAdapter<String> adapter = new ArrayAdapter<String>(Staff_homepage.this, android.R.layout.simple_list_item_1, booknames);
58         ListView listView = (ListView) findViewById(R.id.staff_home_list_id);
59         listView.setAdapter(adapter);
60     }
61 }

Staff_homepage

运行是界面如图:

                     

关于职员的功能介绍完毕,下一篇来讲述图书馆app的新书上架、借阅排行、黑名单、图书馆介绍、图书馆新闻模块。

原文地址:https://www.cnblogs.com/Gzxjt/p/9648833.html

时间: 2024-08-26 14:14:55

基于Android平台的图书管理系统的制作(3)的相关文章

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

上一篇讲解了制作图书管理系统的初衷与要求,和app首页的代码. 下面来介绍图书管理系统的服务对象:学生 学生类的设计: 个人信息:账号.密码.姓名.学号.邮箱.年龄. 借阅信息:借阅总数(不超过十本).借阅书籍的ID(数组).借阅书籍的日期(数组). 源码在此: 1 package com.example.administrator.library1; 2 3 import org.litepal.LitePal; 4 import org.litepal.crud.DataSupport; 5

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

讲解完学生.职员.书籍这些基础层之后,我们可以来了解一些应用层的活动. 新书上架.借阅排行.黑名单.图书馆介绍.图书馆新闻. 新书上架是查询数据库里的Book表,将最近注册的五本书的基本信息(若图书馆所有书籍少于5,则所有)通过listview展示出来. 源代码贴出: 1 package com.example.administrator.library1; 2 3 import android.content.Intent; 4 import android.support.v7.app.Ap

基于Android平台的会议室管理系统具体设计说明书

会议室管理系统具体设计说明书 第一部分  引言 1.编写目的 本说明对会议室管理系统项目的各模块.页面.脚本分别进行了实现层面上的要求和说明. 软件开发小组的产品实现成员应该阅读和參考本说明进行代码的编写.測试. 1.2 背景 说明: A.软件系统的名称:会议室管理系统 B. 任务提出者:内蒙古大学计算机学院 开发人员:魏晓蕾 本项目将实现基于Android平台的会议室管理系统的原型部分,而且在该原型的基础上进行功能的扩展和需求的界定,终于完毕的版本号将在全国范围内推广使用. 提供会议室管理功能

基于Android平台的汽车租赁平台项目的数据库设计心得

我们团队的项目是基于Android平台的汽车租赁平台,其分为手机客户端与web后台管理系统,用以满足租车公司的业务需求,故数据库设计对于本项目显得尤为重要,我们团队数据库设计最开始用的是最原始的方式:Word手动输入,但随后随着数据库课程以及实验的学习,我们最后使用的PowerDesigner设计的数据库并生成了SQL文件,导入数据库完成的数据库最终设计与搭建,我们团队于第8周完成了数据库的搭建. 数据库设计中,数据库要严格与项目需求相联系,同时保证数据库数据完整.正确.安全以及数据处理的高效与

基于Android平台的i-jetty网站智能农业监控系统

基于android平台i-jetty网站的智能农业监控系统 摘要:传统的监控系统,一般是基于PC的有线通信传输,其有很多不足之处,如功耗较高.布线成本高.难度大,适应性差,可扩展性不强,增加新的通信线路需要再次布线施工,而且维护起来也比较麻烦,一旦线路出问题,需要繁琐的检查.而嵌入式Web监控系统是基于物联网技术,其无线通信技术具有成本低廉.适应性强.扩展性强.信息安全.使用维护简单等优点. 智能农业中,种植大棚是通过大棚内安装温湿度以及光照传感器,来对农作物的环境参数进行实时采集,由Web监控

基于Android 平台简易即时通讯的研究与设计[转]

摘要:论文简单介绍Android 平台的特性,主要阐述了基于Android 平台简易即时通讯(IM)的作用和功能以及实现方法.(复杂的通讯如引入视频音频等可以考虑AnyChat SDK~)关键词:Android 平台:即时通讯 (本文中图表点击附件即可见) 1 Android 平台简介Android 是Google 公司于2007年11月5日推出的手机操作系统,经过2年多的发展,Android平台在智能移动领域占有不小的份额,由Google为首的40 多家移动通信领域的领军企业组成开放手机联盟(

cocos2dx-2.X前后台切换分析,基于android平台

摘自网上的android生命周期图: cocos2dx-2.X前后台切换分析,基于android平台: 1.从后台进入前台 项目的activity一般继承自Cocos2dxActivity,看过activity生命周期的 都知道onCreate,onResume等方法,这些函数是activity生命周期中 最重要的函数,具体什么时候调用,可以查看相关资料. //刚进入游戏和游戏从后台回到前台会调用 @Override protected void onResume() { super.onRes

基于Android平台简易即时通讯的研究与设计

1 Android平台简介 Android是Google公司于2007年11月5日推出的手机操作系统,经过2年多的发展,Android平台在智能移动领域占有不小的份额,由Google为首的40多家移动通信领域的领军企业组成开放手机联盟(OHA).Google与运营商.设备制造商.开发商和其他第三方结成深层次的合作伙伴关系,希望通过建立标准化.开放式的移动电话软件平台,在移动产业内形成一个开放式的生态系统.正因如此,Android正在被越来越多的开发者和使用者所接受.近日,Google发言人Ant

基于Android平台开发的手电筒Light

基于Android平台开发的手电筒Light 1.     需求分析: 在现代社会中,手机的功能越来越完善,手电筒就是这些功能中必不可少的一种.当行走在漆黑的道路上,当你在黑暗狭小的地方寻找物品,当你在家中停电之时,如果你的手机拥有了手电筒的功能,那将为你带来莫大的方便.当然,它的用处不仅仅只是这样,有了这样一个方便携带的手电筒,在许多时候都是大有益处,因此,开发出了手电筒这一应用程序. 2.     开发环境: 1. JDK Ver: jdk-7u4-windows-x64.exe 2. My