19 March 2012
Knowledge of ActionScript will help you make the most of this article.
Intermediate
Easy Library is a complete library management system built using Adobe AIR.
Though it is certainly possible to develop this type of application in various languages and for a variety of deployment platforms, using AIR can reduce the effort needed to deliver a complete system with full database connectivity and a rich user interface.
Easy Library can be used by library staff to manage library operations, including issuing (loaning) books, returning books, checking issue history, querying books due for return, and more. This application can be used in companies or college libraries for managing books and the transactions common to library operations.
A working version of the application and its source code are included in the sample files for this article. Throughout the article I refer to the specific methods within the source code that implement the main features of the application.
Easy Library users are managed via an XML file named Users.xml. This file defines all users, as well as their passwords and access levels.
Users.xml
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user name="Rajesh Kumar" username="rajesh" password="adobe" role="administrator" />
<user name="Temp User" username="tempuser" password="adobe" role="user" />
</users>
To gain access to Easy Library, users must first authenticate via the login screen (see Figure 1).
After login, the user is directed to the dashboard view, which shows all the overdue issued books (see Figure 2).
This functionality for the dashboard view is supported by three key methods:
protected function LogIn_clickHandler(event:MouseEvent):void{
... //authenticate the user and directs the user to dashboard.
}
private function dashboard_handlerCount():void{
..//launches the dashboard with required data
}
protected function populateDashboardCountGrid(event:SQLEvent):void{
..//populate the dashboard with not available books whose returned date has already passed.
}
To issue a book, the user will need to complete the following steps:
protected function bookCodeName_enterHandler(event:FlexEvent):void{
..//fetches the book details and populates the field
}
The book is immediately added to the list of issued books (see Figure 4). This is handled by issueBookEntry:
private function issueBookEntry(event:MouseEvent):void{
...//issue the book to the employee, insert a new entry in the table, and set the book’s availability as false.
}
If the user made a mistake while issuing the book, he or she may click the red X in the last column to delete the entry and create it again. Check deleteBookTransaction in the source code to see how this is done:
public function deleteBookTransaction(event:MouseEvent):void{
..//delete the entry if a mistake was made and user wants to reissue
}
To add a book, an administrator must complete the following steps:
The addBookEntry method is responsible for adding the book to the database:
protected function addBookEntry(event:MouseEvent):void{
..//Adds the new book on purchase.
}
When a book is returned, the librarian can follow these steps to check it back in:
This is handled by the returnBook_clickHandler event handler:
private function returnBook_clickHandler(event):void{
..//when a book is returned and the book is now available for issue
}
To update an issued entry, the user can:
This functionality is handled by the following two methods:
protected function search_clickHandler(event:MouseEvent):void{
...//search for the entry
}
public function updateTransaction(event:MouseEvent):void{
...//updates the entry if any changes is made after searching.
}
To see all issued books (which are not available for issue), click the All Issued Books tab.To see all books in the database click the Display All Books tab. This feature is implemented by the following method:
private function getAllBookResult():void{
...//fetch all the books from database
}
You can also submit a custom query using the Your Query tab. To see the code, explore the query_clickHandler method:
protected function query_clickHandler(event:MouseEvent):void{
..//executes the query directly
}
When issuing your queries, keep in mind the book issue table is named libraryTableNew and the book repository table is named bookTable.
Easy Library uses a SQLite database, and connects using the code below:
public function openDatabaseConnection():void{
// create new sqlConnection
sqlConnection = new SQLConnection();
sqlConnection.addEventListener(SQLEvent.OPEN, onDatabaseOpen);// get currently dir
var dbFile:File = File.applicationStorageDirectory.resolvePath("library.db");
// open database,If the file doesn't exist yet, it will be created
sqlConnection.openAsync(dbFile);
}
// connect and init database/table
private function onDatabaseOpen(event:SQLEvent):void
{
try
{
var sqlStat:SQLStatement;
sqlStat = new SQLStatement();
sqlStat.sqlConnection = sqlConnection;;
var sql:String = "CREATE TABLE IF NOT EXISTS "+dbTableName+"(" +
…………….
"status TEXT"+
")";
sqlStat.text = sql;
sqlStat.addEventListener(SQLEvent.RESULT, statResult);
sqlStat.addEventListener(SQLErrorEvent.ERROR, statFault);sqlStat.execute();
}
catch (error:SQLError)
{
Alert.show(error.details, "Error");
}
}
In its initial version,Easy Library uses a local database (SQLite), but it can be integrated with an external database to use more extensive library data. Other input devicessuch as a barcode readeror access card can also be used with the application to reduce manual steps. I encourage you to explore the source code for the application to better understand how all the methods work.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.