1. 程式人生 > >基於Android平臺的圖書管理系統的制作(1)

基於Android平臺的圖書管理系統的制作(1)

teacher stat load over sta ews 來講 androi 管理系

在學習了郭神的第一行代碼前半段之後,想通過一次實踐來完成對已學知識的鞏固。於是碼下了這個圖書管理系統客戶端。 IDE Android studio,語言 JAVA、XML; 在剛開始設計的時候對於這個程序的設定是: 1.支持學生、教師、工作人員三種不同身份的客戶。 2.學生、老師各自註冊賬號,並用賬號登錄。 3.學生、老師能夠查詢、借閱、歸還圖書,逾期沒有歸還圖書的客戶將被列入黑名單。 4.含有圖書館的介紹與新聞通知板塊。 5.管理人員能夠添加書籍。 6.含有新書上架和借閱排行榜兩個list。 7.所有信息從服務器上訪問得到,支持不同客戶端共享相同數據 在經過了一段時間的磨蹭之後,終於將圖書管理系統基本完成: 但和最開始的設定有了一些偏差:由於教師和學生的不同之處僅僅是借閱書籍的最大數量不同,因此將教師這一身份舍去。在寫客戶端向服務器(Windows下建了一個微型服務器)通信的時候遇到了很大的困難,長時間的碼代碼、編譯、通過、服務器無反應之後,暫時放棄了連接服務器這一功能,將所有用戶與書籍的數據儲存在了Android系統自帶的數據庫中。這樣使得過程難度降低了很多,但是無法實現不同客戶端訪問的數據統一化,也就是從聯網退化至了單機。 但是學習仍在路上,以後有時間當將這些不足得以改善。 下面來講解圖書管理系統的制作過程。 主頁面: 技術分享圖片
技術分享圖片 新手上路,界面很low》》》》》》 技術分享圖片
 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:gravity="center" 8 android:orientation="vertical" 9 tools:context=".MainActivity"> 10 11 <ImageView 12 android:id="@+id/image_view_id" 13 android:layout_width="match_parent" 14 android:layout_height="0dp" 15 android:layout_weight
="6" 16 android:src="@drawable/img_1" /> 17 18 <TextView 19 android:layout_width="match_parent" 20 android:layout_height="0dp" 21 android:gravity="center" 22 android:textSize="30sp" 23 android:layout_weight="2" 24 android:text="歡迎使用圖書館安卓客戶端" /> 25 26 <LinearLayout 27 android:layout_width="match_parent" 28 android:layout_height="0dp" 29 android:layout_weight="4" 30 android:orientation="horizontal"> 31 32 <Button 33 android:id="@+id/introduce_id" 34 android:layout_width="0dp" 35 android:layout_height="match_parent" 36 android:layout_weight="1" 37 android:textSize="21sp" 38 android:text="圖書館介紹" /> 39 40 <Button 41 android:id="@+id/news_id" 42 android:layout_width="0dp" 43 android:layout_height="match_parent" 44 android:layout_weight="1" 45 android:textSize="21sp" 46 android:text="圖書館新聞通知" /> 47 </LinearLayout> 48 49 <LinearLayout 50 android:layout_width="match_parent" 51 android:layout_height="0dp" 52 android:layout_weight="4" 53 android:orientation="horizontal"> 54 55 <Button 56 android:id="@+id/newBook_id" 57 android:layout_width="0dp" 58 android:layout_height="match_parent" 59 android:layout_weight="1" 60 android:textSize="21sp" 61 android:text="新書上架" /> 62 63 <Button 64 android:id="@+id/ranking_id" 65 android:layout_width="0dp" 66 android:layout_height="match_parent" 67 android:layout_weight="1" 68 android:textSize="21sp" 69 android:text="借閱排行榜" /> 70 </LinearLayout> 71 72 <LinearLayout 73 android:layout_width="match_parent" 74 android:layout_height="0dp" 75 android:layout_weight="4"> 76 77 <Button 78 android:id="@+id/registerStudent_id" 79 android:layout_width="0dp" 80 android:layout_height="match_parent" 81 android:layout_weight="1" 82 android:textSize="21sp" 83 android:text="學生註冊" /> 84 <Button 85 android:id="@+id/blacklist_id" 86 android:layout_width="0dp" 87 android:layout_height="match_parent" 88 android:layout_weight="1" 89 android:textSize="21sp" 90 android:text="黑名單" /> 91 </LinearLayout> 92 </LinearLayout>
activity_main

下面是主程序的代碼:

技術分享圖片
  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.Menu;
  7 import android.view.MenuItem;
  8 import android.view.View;
  9 import android.widget.Button;
 10 import android.widget.Toast;
 11 
 12 import org.litepal.LitePal;
 13 /*------
 14    郭誌---18年暑假
 15  */
 16 
 17 public class MainActivity extends AppCompatActivity {
 18 
 19     private Button button_introduce,button_information,button_ranking,button_newBooks,button_register_student,button_blacklist;
 20     @Override
 21     public boolean onCreateOptionsMenu(Menu menu) {
 22         getMenuInflater().inflate(R.menu.main,menu);
 23         return true;
 24     }
 25 
 26     @Override
 27     public boolean onOptionsItemSelected(MenuItem item) {
 28         switch (item.getItemId())
 29         {
 30             case R.id.student_id:
 31                 Intent intent_student=new Intent(MainActivity.this,Login_student.class);
 32                 startActivity(intent_student);
 33                 break;
 34             /*case R.id.teacher_id:
 35                 Intent intent_teacher=new Intent(MainActivity.this,Login_teacher.class);
 36                 startActivity(intent_teacher);
 37                 break;*/
 38             case R.id.staff_id:
 39                 Intent intent_staff=new Intent(MainActivity.this,Login_staff.class);
 40                 startActivity(intent_staff);
 41                 break;
 42         }
 43         return true;
 44     }
 45 
 46     @Override
 47     protected void onCreate(Bundle savedInstanceState) {
 48         super.onCreate(savedInstanceState);
 49         setContentView(R.layout.activity_main);
 50         button_introduce=findViewById(R.id.introduce_id);
 51         button_register_student=findViewById(R.id.registerStudent_id);
 52         button_blacklist=findViewById(R.id.blacklist_id);
 53         button_information=findViewById(R.id.news_id);
 54         button_ranking=findViewById(R.id.ranking_id);
 55         button_newBooks=findViewById(R.id.newBook_id);
 56 
 57         button_introduce.setOnClickListener(new View.OnClickListener() {
 58             @Override
 59             public void onClick(View view) {
 60                 Intent intent=new Intent(MainActivity.this,Introduction.class);
 61                 startActivity(intent);
 62                 finish();
 63             }
 64         });
 65         button_register_student.setOnClickListener(new View.OnClickListener() {
 66             @Override
 67             public void onClick(View view) {
 68                 Intent intent=new Intent(MainActivity.this,Register_student.class);
 69                 startActivity(intent);
 70                 finish();
 71             }
 72         });
 73         button_blacklist.setOnClickListener(new View.OnClickListener() {
 74             @Override
 75             public void onClick(View view) {
 76                 Intent intent=new Intent(MainActivity.this,Blacklist.class);
 77                 startActivity(intent);
 78                 finish();
 79             }
 80         });
 81         button_information.setOnClickListener(new View.OnClickListener() {
 82             @Override
 83             public void onClick(View view) {
 84                 Intent intent=new Intent(MainActivity.this,News.class);
 85                 startActivity(intent);
 86                 finish();
 87             }
 88         });
 89         button_ranking.setOnClickListener(new View.OnClickListener() {
 90             @Override
 91             public void onClick(View view) {
 92                 Intent intent=new Intent(MainActivity.this,Ranking.class);
 93                 startActivity(intent);
 94                 finish();
 95             }
 96         });
 97         button_newBooks.setOnClickListener(new View.OnClickListener() {
 98             @Override
 99             public void onClick(View view) {
100                 Intent intent=new Intent(MainActivity.this,New_Books.class);
101                 startActivity(intent);
102                 finish();
103             }
104         });
105 
106     }
107 }
MainActivity.java

下一篇,我將來講述學生的註冊、登錄、借還書功能的實現。

(先附上整個項目的源碼地址:https://github.com/Guozhi-explore/androidlibrary)

基於Android平臺的圖書管理系統的制作(1)