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

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

Book类的代码:

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

Book

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

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

Staff

职员的登录界面,大致与Student的登录界面相同这里只将代码贴出:

  1. 1 package com.example.administrator.library1;
  2. 2
  3. 3 import android.content.Intent;
  4. 4 import android.support.v7.app.AppCompatActivity;
  5. 5 import android.os.Bundle;
  6. 6 import android.view.View;
  7. 7 import android.widget.Button;
  8. 8 import android.widget.CheckBox;
  9. 9 import android.widget.EditText;
  10. 10 import android.widget.Toast;
  11. 11
  12. 12 import org.litepal.LitePal;
  13. 13
  14. 14 import java.util.List;
  15. 15
  16. 16 public class Login_staff extends AppCompatActivity {
  17. 17
  18. 18 private EditText staff_editAccount,staff_editPassword;
  19. 19 private CheckBox staff_checkBox;
  20. 20 private Button staff_button_commit;
  21. 21 @Override
  22. 22 protected void onCreate(Bundle savedInstanceState) {
  23. 23 super.onCreate(savedInstanceState);
  24. 24 setContentView(R.layout.activity_login_staff);
  25. 25 staff_editAccount=findViewById(R.id.accountStaff_id);
  26. 26 staff_editPassword=findViewById(R.id.passwordStaff_id);
  27. 27 staff_checkBox=findViewById(R.id.rememberPassStaff_id);
  28. 28 staff_button_commit=findViewById(R.id.commitStaff_id);
  29. 29 Simple simple=LitePal.find(Simple.class,3);
  30. 30 staff_editAccount.setText(simple.getAccount());
  31. 31 staff_editPassword.setText(simple.getPassword());
  32. 32
  33. 33 staff_button_commit.setOnClickListener(new View.OnClickListener() {
  34. 34 @Override
  35. 35 public void onClick(View view) { //在这里之前已经出错
  36. 36 List<Staff> staffs_account = LitePal.findAll(Staff.class);
  37. 37 boolean is_account_available = false;
  38. 38 String st_account = staff_editAccount.getText().toString();
  39. 39 String st_password = staff_editPassword.getText().toString();
  40. 40 for (int i = 0; i < staffs_account.size(); ++i) {
  41. 41 if (st_account.equals(staffs_account.get(i).getAccount())) { //get(i)这里的查询是从0开始的,即是get(0)查询的是id为1的员工
  42. 42 is_account_available = true;
  43. 43 if (st_password.equals(staffs_account.get(i).getPassword())) {
  44. 44 if(staff_checkBox.isChecked())
  45. 45 {
  46. 46 Simple simple= LitePal.find(Simple.class,3);
  47. 47 simple.setAccount(staff_editAccount.getText().toString());
  48. 48 simple.setPassword(staff_editPassword.getText().toString());
  49. 49 simple.save();
  50. 50 }
  51. 51 else
  52. 52 {
  53. 53 Simple simple1=LitePal.find(Simple.class,3);
  54. 54 simple1.setAccount("");
  55. 55 simple1.setPassword("");
  56. 56 simple1.save();
  57. 57 }
  58. 58 Intent intent = new Intent(Login_staff.this, Staff_homepage.class);
  59. 59 intent.putExtra("extra_data", i+1);
  60. 60 startActivity(intent);
  61. 61 finish();
  62. 62 } else {
  63. 63 Toast.makeText(Login_staff.this, "密码错误", Toast.LENGTH_SHORT).show();
  64. 64 break; //记住密码还没有用上
  65. 65 }
  66. 66 }
  67. 67 }
  68. 68 if (is_account_available == false) {
  69. 69 Toast.makeText(Login_staff.this, "账号不存在", Toast.LENGTH_SHORT).show();
  70. 70 }
  71. 71 }
  72. 72 });
  73. 73 }
  74. 74 }

Login_Staff

  1. 1 <?xml version="1.0" encoding="utf-8"?>
  2. 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. 3 xmlns:app="http://schemas.android.com/apk/res-auto"
  4. 4 android:orientation="vertical"
  5. 5 xmlns:tools="http://schemas.android.com/tools"
  6. 6 android:layout_width="match_parent"
  7. 7 android:layout_height="match_parent"
  8. 8 tools:context=".Login_student">
  9. 9
  10. 10 <ImageView
  11. 11 android:layout_width="match_parent"
  12. 12 android:layout_height="211dp"
  13. 13 android:src="@drawable/img_login" />
  14. 14 <LinearLayout
  15. 15 android:layout_width="match_parent"
  16. 16 android:layout_height="wrap_content"
  17. 17 android:layout_marginTop="20dp"
  18. 18 android:layout_marginLeft="20dp"
  19. 19 android:layout_marginRight="20dp"
  20. 20 android:orientation="horizontal">
  21. 21 <TextView
  22. 22 android:layout_width="0dp"
  23. 23 android:layout_height="match_parent"
  24. 24 android:layout_weight="1"
  25. 25 android:textSize="21sp"
  26. 26 android:text="账号: "/>
  27. 27 <EditText
  28. 28 android:id="@+id/accountStaff_id"
  29. 29 android:layout_width="0dp"
  30. 30 android:layout_height="match_parent"
  31. 31 android:layout_weight="5"
  32. 32 android:hint="type here"/>
  33. 33 </LinearLayout>
  34. 34 <LinearLayout
  35. 35 android:orientation="horizontal"
  36. 36 android:layout_width="match_parent"
  37. 37 android:layout_marginLeft="20dp"
  38. 38 android:layout_marginRight="20dp"
  39. 39 android:layout_height="wrap_content">
  40. 40 <TextView
  41. 41 android:layout_width="0dp"
  42. 42 android:layout_height="match_parent"
  43. 43 android:layout_weight="1"
  44. 44 android:textSize="21sp"
  45. 45 android:text="密码 :"/>
  46. 46 <EditText
  47. 47 android:id="@+id/passwordStaff_id"
  48. 48 android:layout_width="0dp"
  49. 49 android:layout_height="match_parent"
  50. 50 android:layout_weight="5"
  51. 51 android:hint="type here"/>
  52. 52 </LinearLayout>
  53. 53 <LinearLayout
  54. 54 android:layout_marginLeft="20dp"
  55. 55 android:layout_marginRight="20dp"
  56. 56 android:layout_width="match_parent"
  57. 57 android:layout_height="wrap_content">
  58. 58 <CheckBox
  59. 59 android:id="@+id/rememberPassStaff_id"
  60. 60 android:layout_width="wrap_content"
  61. 61 android:layout_height="wrap_content"
  62. 62 android:checked="true"/>
  63. 63 <TextView
  64. 64 android:layout_width="wrap_content"
  65. 65 android:layout_height="wrap_content"
  66. 66 android:textSize="18sp"
  67. 67 android:text="记住密码"/>
  68. 68 </LinearLayout>
  69. 69 <Button
  70. 70 android:id="@+id/commitStaff_id"
  71. 71 android:layout_width="150dp"
  72. 72 android:layout_height="wrap_content"
  73. 73 android:layout_gravity="center"
  74. 74 android:textSize="20sp"
  75. 75 android:text="登录"/>
  76. 76 </LinearLayout>

Staff_login_xml

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

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

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

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

代码贴出来如下:

  1. 1 <?xml version="1.0" encoding="utf-8"?>
  2. 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. 3 xmlns:app="http://schemas.android.com/apk/res-auto"
  4. 4 xmlns:tools="http://schemas.android.com/tools"
  5. 5 android:layout_width="match_parent"
  6. 6 android:layout_height="match_parent"
  7. 7 android:orientation="vertical"
  8. 8 tools:context=".Staff_homepage">
  9. 9 <ImageView
  10. 10 android:layout_width="match_parent"
  11. 11 android:layout_height="wrap_content"
  12. 12 android:src="@drawable/img_login"/>
  13. 13 <TextView
  14. 14 android:id="@+id/sta_home_infor_id"
  15. 15 android:layout_width="match_parent"
  16. 16 android:layout_height="wrap_content"
  17. 17 android:layout_gravity="center"
  18. 18 android:gravity="center"
  19. 19 android:textSize="20sp"/>
  20. 20 <Button
  21. 21 android:id="@+id/sta_input_book_id"
  22. 22 android:layout_width="match_parent"
  23. 23 android:layout_height="wrap_content"
  24. 24 android:text="增加书籍"/>
  25. 25 <Button
  26. 26 android:id="@+id/sta_return_id"
  27. 27 android:layout_width="match_parent"
  28. 28 android:layout_height="wrap_content"
  29. 29 android:text="返回主菜单"/>
  30. 30 <ListView
  31. 31 android:id="@+id/staff_home_list_id"
  32. 32 android:layout_width="match_parent"
  33. 33 android:layout_height="wrap_content">
  34. 34 </ListView>
  35. 35 </LinearLayout>

Staff_homepage_xml

  1. 1 package com.example.administrator.library1;
  2. 2
  3. 3 import android.content.Intent;
  4. 4 import android.support.v7.app.AppCompatActivity;
  5. 5 import android.os.Bundle;
  6. 6 import android.view.View;
  7. 7 import android.widget.ArrayAdapter;
  8. 8 import android.widget.Button;
  9. 9 import android.widget.ListView;
  10. 10 import android.widget.TextView;
  11. 11
  12. 12 import org.litepal.LitePal;
  13. 13
  14. 14 import java.util.ArrayList;
  15. 15 import java.util.List;
  16. 16
  17. 17 public class Staff_homepage extends AppCompatActivity {
  18. 18 private int staff_id;
  19. 19 Staff staff;
  20. 20 private TextView textView_name;
  21. 21 private Button button_add,button_return;
  22. 22 private List<Book> totalbooks=new ArrayList<>();
  23. 23 private List<String> booknames=new ArrayList<>();
  24. 24 @Override
  25. 25 protected void onCreate(Bundle savedInstanceState) {
  26. 26 super.onCreate(savedInstanceState);
  27. 27 setContentView(R.layout.activity_staff_homepage);
  28. 28 textView_name = (TextView) findViewById(R.id.sta_home_infor_id);
  29. 29 button_add = (Button) findViewById(R.id.sta_input_book_id);
  30. 30 button_return = (Button) findViewById(R.id.sta_return_id);
  31. 31 totalbooks = LitePal.findAll(Book.class);
  32. 32
  33. 33 final Intent intent = getIntent();
  34. 34 staff_id = intent.getIntExtra("extra_data", 1);
  35. 35 staff = LitePal.find(Staff.class, staff_id);
  36. 36 textView_name.setText("员工编号: " + staff.getId() + " " + "姓名: " + staff.getName());
  37. 37
  38. 38 button_add.setOnClickListener(new View.OnClickListener() {
  39. 39 @Override
  40. 40 public void onClick(View view) {
  41. 41 Intent intent1 = new Intent(Staff_homepage.this, staff_input.class);
  42. 42 startActivity(intent1);
  43. 43 }
  44. 44 });
  45. 45
  46. 46 button_return.setOnClickListener(new View.OnClickListener() {
  47. 47 @Override
  48. 48 public void onClick(View view) {
  49. 49 Intent intent = new Intent(Staff_homepage.this, MainActivity.class);
  50. 50 startActivity(intent);
  51. 51 }
  52. 52 });
  53. 53
  54. 54 for (int i = 0; i < totalbooks.size(); ++i) {
  55. 55 booknames.add("名称:" + totalbooks.get(i).getName() + " " + "作者:" + totalbooks.get(i).getWriter() + " " + "数量:" + totalbooks.get(i).getAmount());
  56. 56 }
  57. 57 ArrayAdapter<String> adapter = new ArrayAdapter<String>(Staff_homepage.this, android.R.layout.simple_list_item_1, booknames);
  58. 58 ListView listView = (ListView) findViewById(R.id.staff_home_list_id);
  59. 59 listView.setAdapter(adapter);
  60. 60 }
  61. 61 }

Staff_homepage

运行是界面如图:

                     

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

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

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

    在学习了郭神的第一行代码前半段之后,想通过一次实践来完成对已学知识的巩固.于是码下了这个图书管理系统客户端. IDE Android studio,语言 JAVA.XML: 在刚开始设计的时候对于这个 ...

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

    上一篇讲解了制作图书管理系统的初衷与要求,和app首页的代码. 下面来介绍图书管理系统的服务对象:学生 学生类的设计: 个人信息:账号.密码.姓名.学号.邮箱.年龄. 借阅信息:借阅总数(不超过十本) ...

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

    讲解完学生.职员.书籍这些基础层之后,我们可以来了解一些应用层的活动. 新书上架.借阅排行.黑名单.图书馆介绍.图书馆新闻. 新书上架是查询数据库里的Book表,将最近注册的五本书的基本信息(若图书馆 ...

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

    会议室管理系统具体设计说明书 第一部分  引言 1.编写目的 本说明对会议室管理系统项目的各模块.页面.脚本分别进行了实现层面上的要求和说明. 软件开发小组的产品实现成员应该阅读和參考本说明进行代码的 ...

  5. 基于android平台的斗地主AI

    本软件是基于android平台的斗地主AI,我们在源代码的基础之上,旨在改进AI的算法,使玩家具有更丰富的体验感,让NPC可以更为智能. (一)玩法解析: (1)发牌和叫牌:一副扑克54张,先为每个人 ...

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

    摘要:论文简单介绍Android 平台的特性,主要阐述了基于Android 平台简易即时通讯(IM)的作用和功能以及实现方法.(复杂的通讯如引入视频音频等可以考虑AnyChat SDK~)关键词:An ...

  7. 基于Android平台的简易人脸检测库

    代码地址如下:http://www.demodashi.com/demo/12135.html ViseFace 简易人脸检测库,不依赖三方库,可快速接入人脸检测功能. 项目依赖:compile 'c ...

  8. 基于ANDROID平台,U3D对蓝牙手柄键值的获取

    对于ANDROID平台,物理蓝牙手柄已被封装,上层应用不可见,也就是说对于上层应用,不区分蓝牙手柄还是其它手柄: 完成蓝牙手柄和ANDROID手机的蓝牙连接后,即可以UNITY3D中获取其键值: 在U ...

  9. 结对编程--基于android平台的黄金点游戏

    游戏内容: 阿超的课都是下午两点钟,这时班上不少的同学都昏昏欲睡,为了让大家兴奋起来,阿超让同学玩一个叫“黄金点”的游戏: N个同学(N通常大于10),每人写一个0~100之间的有理数 (不包括0或1 ...

随机推荐

  1. Win64 驱动内核编程-26.强制结束进程

    强制结束进程 依然已经走到驱动这一层了,那么通常结束掉一个进程不是什么难的事情.同时因为win64 位的各种保护,导致大家慢慢的已经不敢HOOK了,当然这指的是产品.作为学习和破解的话当然可以尝试各种 ...

  2. 前端基础问题:CSS居中的几种方式

    水平居中 (1)内联元素: text-align: center; 利用 text-align: center :可以实现在块级元素内部的内联元素水平居中. 如果一行中有多个块级元素,可以通过设置块级 ...

  3. JVM垃圾回收器总结

    常见七种垃圾回收器以及使用的垃圾回收算法总结:

  4. Java版的扫雷游戏源码

    package com.xz.sl; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; i ...

  5. MySQL慢日志全解析

    前言: 慢日志在日常数据库运维中经常会用到,我们可以通过查看慢日志来获得效率较差的 SQL ,然后可以进行 SQL 优化.本篇文章我们一起来学习下慢日志相关知识. 1.慢日志简介 慢日志全称为慢查询日 ...

  6. BUAA软件工程热身作业

    写在前面 项目 内容 所属课程 2020春季计算机学院软件工程(罗杰 任健) (北航) 作业要求 热身作业(阅读) 课程目标 培养软件开发能力 本作业对实现目标的具体作用 深入认识自己,总结过往并展望 ...

  7. 5Spring动态代理开发小结

    5Spring动态代理开发小结 1.为什么要有动态代理? 好处 1.利于程序维护 2.利于原始类功能的增强 3.得益于JDK或者CGlib等动态代理技术使得程序扩展性很强 为什么说使得程序扩展性很强? ...

  8. n/a或N/A是英语“不适用”(Not applicable)

    n/a或N/A是英语"不适用"(Not applicable)等类似单词的缩写,常可在各种表格中看到. N/A比较多用在填写表格的时候,表示"本栏目(对我)不适用&quo ...

  9. 本文介绍使用windows系统自带的远程桌面mstsc连接Centos 7.x远程桌面的基本方法。

    本文介绍使用windows系统自带的远程桌面mstsc连接Centos 7.x远程桌面的基本方法. 一.前言 我希望用windows远程访问centos图形界面.xmanager连接centos远程桌 ...

  10. Linux 部署 iSCSI 服务端

    Linux 部署 iSCSI 服务端 服务端实验环境 iSCSI-server :RHEL8 IP:192.168.121.10 一.服务端安装 target 服务和 targetcli 命令行工具 ...