Archive

Posts Tagged ‘library’

Library System with Excel -P4

November 24, 2020 Leave a comment


Learning :Excel formulas and VBA Cods
Subject: To Develop a Library System with Excel

In last post we wrote all the codes needed to Manage the Authors.

In this part we will do all the coding needed to enter New Books and Edit or Delete anyone we select, in Classifications and Authors we were dealing with one attribute, but here with Books Manage form we have several pieces of information to collect from the user such as [Book Title, Book Author, Book Classification, Publish date, Notes, Book Language ]. So first let’s design the form..

1. Open the Books sheet
2. Change the color of the range(B6:E24)
3. In Cell B6 write “Select a Book to Edit or Delete”, Color and format it as you want.

4. In Cell H6 write “Books Form”, Color and format it as you want.

5. Color and format the Range (B6:L26) as you want.
6. Create three rectangular shapes as New, Delete, and Save buttons.
7. Create another three small rectangular shapes write “+” inside them.
5. We need to create a ListBox name it “books_ListBox 4”.
6. Arrange everything as in the image.


Now move to the “setting” sheet and write the following: B4:Books, B5:current_book, C5:1, B6:mode, C6: edit.

Then in the “Data” Sheet starting from A1 write the following:
A1:Books Data, B1:BookTitle, C1:book_author, D1:class, E1:Published, F1:Note, G1:lang
A2:ID, B2:Title, C2:Author, D2:Class, E2:Published, F2:Note, G2:language

CODING:

To copy the list of the Books we have into the books_ListBox 4 we create:
1.1 From the Menu go to Formulas and click on Name Manager.
1.2 From the pop-up screen click on New, then write books_list in Name, and =OFFSET(Data!$B$3,,,COUNTA(Data!$B:$B)) in Refers to.

2.1. Select books_ListBox 4 on the Books sheet.
2.2. Right-click the mouse, and select FormatControl.
2.3. Goto Control Tab, and in Input range write: books_list, and in Cell link write Setting!$C$5 then press OK.

Now the listBox will contain the Books we have in the Books table in Data Sheet. (If we have any Data there)
3. Data Validation: We need to create Data Validation-list in the cells K12: for Authors list, K14: for Classifications list and K18: for Language list.
1. Select K12, from Data-menu click on Data-validation, select List then in the source type this: =OFFSET(Data!$K$3,,,COUNTA(Data!$K:$K))
2. Select K14, from Data-menu click on Data-validation, select List then in the source type this: =OFFSET(Data!$P$3,,,COUNTA(Data!$P:$P))
3. Select K18, from Data-menu click on Data-validation, select List then in the source type this: =OFFSET(Data!$M$3,,,COUNTA(Data!$M:$M))

book_new_Click() In this function we will Clear all cells [k8, k10,k12,k14,k16,k18, K20] also the note_TextBox1 and will change the cell C6 in Setting Sheet to “new”. Here is the code..

Sub book_new_Click()

‘ Clear all cells.
Sheets(“Books”).Range(“K8”).Value = “” ‘ID/number
Sheets(“Books”).Range(“K10”).Value = “” ‘Title
Sheets(“Books”).Range(“K12”).Value = “” ‘Author name
Sheets(“Books”).Range(“K14”).Value = “” ‘classification
Sheets(“Books”).Range(“K16”).Value = “” ‘published date
Sheets(“Books”).Range(“K18”).Value = “” ‘language
Sheets(“Books”).Range(“K20”).Value = “” ‘note
Sheets(“Books”).note_TextBox1 = “”

‘ change book mode to “new”
Sheets(“setting”).Range(“c6”).Value = “new”

Sheets(“Books”).Range(“K8”).Select

End Sub

now in the Books sheet select the button “New” we create and assign the “book_new_Click” macro to it.

book_save_Click() The Save function will have tow parts, if the user click on New then we will have:

Sheets(“setting”).Range(“C6”).Value = “new” in this case we will copy all the Book Data from Range(“K8”),Range(“K10”),Range(“K12”),Range(“K14”),Range(“K16”),Range(“K18”) and the value of the note_TextBox1 to the Data sheet under Boos Table, then will empty all the range in the book form, also will pop-up a MsgBox ” One New Book has been Added.”.

if Sheets(“setting”).Range(“C6”).Value = “edit” in this case we will get the current selected book location by selected_book = Sheets(“setting”).Range(“C5”).Value + 2 then re-copy the book data from the form to the Book Table in the Data Sheet and pop-up MsgBox ” One Book Data has been Updated.”.

In Books form we have also three + buttons next to Author, Classification and Language cells, if the user did not find say the Author in the list then he/she can add new one by clicking on the +

Edit Book Data: The user can select any Book from the Book List on the left-hand list then it’s Data will show-up in the form, the user then can change any of the Book-Data and press on Save.

book_delete_Click() The user will select the Book to de deleted then click on “Delete” button, a massage will pop-up to make sure that Book will be DELETED, if the user confirm the cation (press OK) we will run this line of code:

‘To get the book row number.
selected_book = Sheets(“setting”).Range(“C5”).Value + 2
‘To delete the book row
Sheets(“data”).Range(“A” & selected_book & “:G” & selected_book).Delete Shift:=xlUp

Pressing the (+) button: We have three (+) buttons in this form to add New Authors, Classifications, and Languages if not exist in the list; for example, if the user couldn’t find the Author of the Book (he/she want to enter to the system) pressing the (+) will pop-up a dialog box to Enter New Author and the same for classification and Language. Here is the code..

Sub book_form_new_author()

Sheets(“Books”).Range(“K12”).Value = “”
new_author_name = InputBox(“Enter a New Author Name and Click OK:”, “:: New Author :: “)

‘if we add new author then save it.
If new_author_name > “” Then
‘ Get next empty row
next_row = Sheets(“Data”).Range(“K” & Rows.Count).End(xlUp).Offset(1).Row
Sheets(“Data”).Range(“K” & next_row) = new_author_name
Sheets(“Books”).Range(“K12”).Value = new_author_name ‘Author name
Sheets(“setting”).Range(“F6”).Value = “still”

‘ To Sort the Authors list
next_row = Sheets(“Data”).Range(“K” & Rows.Count).End(xlUp).Offset(1).Row
Sheets(“Data”).Range(“K3:K” & next_row – 1).SortSpecial SortMethod:=xlPinYin

End If
Sheets(“Books”).Range(“K12”).Select

End Sub


End of Part-4

Recap this part:
1. We Create the Books header Tabke.
2. We Create a form to collect the Books from the user.
3. We Create the Books ListBox.
4. We wrote the VBA code to Save, Delete, and Create New Book also to retrieve the Books information into Books ListBox.
5. We let the user to Enter New Author, classification, Language into the system through a dialog box.


:: Library System with Excel ::

Part 1 Part 2 Part 3 Part 4 Part 5



To Download EXCEL (.xlsm) files Click-Here




Follow me on Twitter..




By: Ali Radwani




Library System with Excel -P3

November 17, 2020 1 comment


Learning :Excel formulas and VBA Cods
Subject: To Develop a Library System with Excel

In last post we wrote all the codes needed to Manage the Classifications.

In this part we will do all the coding needed to enter the Authors and Edit or Delete anyone we select, so first we will go to the “setting” sheet and will write the following: E5:current_author, F5:1, E6:mode, F6: edit as in the image.


Now in the “Data” sheets, we create a table with “Author Name” header on range K2, then enter any Autor name such as “Albert” as in the image.



Now, we move to “Authors” Sheet and do the following:
1. In Cell B6 write “Select an Author to Edit or Delete”, Color and format it as you want.
2. In Cell H6 write “Authors Form”, Color and format it as you want.

3. Color and format the Range (B6:E19) and the Range (H6:K13) as you want.
4. Create three rectangular shapes as New, Delete, and Save buttons.
5. We need to create a ListBox name it “authors_ListBox1”.
6. Arrange everything as in the image.


CODING:
To copy the list of the Authors we have into the ListBox:
1.1 From the Menu goto Formulas and click on Name Manager

1.2 From the pop-up screen click on New, then write author_list in Name, and =OFFSET(Data!$K$3,,,COUNTA(Data!$K:$K)) in Refers to [as in image]

2.1. Select the ListBox in the Authors sheet.
2.2. Right-click the mouse, and select FormatControl.
2.3. Goto Control Tab, and in Input range write: author_list, and in Cell link write Setting!$F$5 then press OK.

Now the listBox will contain the Authors we have in the Author list in Data Sheep. … [SEE THE IMAGE]


ListBox Code:
Now we will write a three lines of code to take action when we select any things in this box, so select the ListBox, click right-mouse-button, select “Assinge Macro, then the VBA application will start and write the foloing code:

Sub authors_ListBox1_Change()

selected_author = Sheets(“Setting”).Range(“F5”).Value + 2
Sheets(“authors”).Range(“j9”).Value = Sheets(“data”).Range(“K” & selected_author)
Sheets(“Setting”).Range(“F6”).Value = “edit”

End Sub



Buttons Codes:
1. While in Authors sheet, select the rectangular shape named “New”, click right-mouse-button, select “Assinge Macro, then the VBA application will start and we will write this code:

Sub author_new_Click()
Sheets(“authors”).Range(“J9”).ClearContents
Sheets(“Setting”).Range(“F6”).Value = “new”
Sheets(“Authors”).Range(“J9”).Select
End Sub


2. While the VBA application is on, we will write all the codes we need for Edit and Delete buttons and then will assign the macros:
author_delete_Click

Sub author_delete_Click()

If Not Sheets(“setting”).Range(“F5”).Value Then
MsgBox “Nothing selected to be Deleted..”
Exit Sub
End If

answer = MsgBox(“Are you sure you want to DELETE this Author?.”, vbQuestion + vbYesNo)
If answer = vbYes Then
current_select = Sheets(“setting”).Range(“F5”).Value + 2
Sheets(“Data”).Range(“K” & current_select).ClearContents

next_row = Sheets(“Data”).Range(“K” & Rows.Count).End(xlUp).Offset(1).Row
Sheets(“Data”).Range(“K3:K” & next_row – 1).SortSpecial SortMethod:=xlPinYin
authors_ListBox1_Change

MsgBox “One Author has been Deleted..”
Else
MsgBox “OK, Nothing will be changed.”
End If
End Sub



author_save_Click

Sub author_save_Click()

If Sheets(“authors”).Range(“J9”).Value = Empty Then
MsgBox “There is no Author Name to Save.”
Exit Sub

End If

If Sheets(“Setting”).Range(“F6”).Value = “new” Then

‘ Get next empty row
next_row = Sheets(“Data”).Range(“K” & Rows.Count).End(xlUp).Offset(1).Row

‘ copy the new classification to the data-table
Sheets(“authors”).Range(“j9”) = StrConv(Sheets(“authors”).Range(“J9”), vbProperCase)
Sheets(“Data”).Range(“K” & next_row).Value = Sheets(“Authors”).Range(“J9”)

‘ Empty the form
Sheets(“Authors”).Range(“J9″).ClearContents
MsgBox ” One New Author Name Saved.”

‘ To Sort the classifications
next_row = Sheets(“Data”).Range(“K” & Rows.Count).End(xlUp).Offset(1).Row
Sheets(“Data”).Range(“K3:K” & next_row – 1).SortSpecial SortMethod:=xlPinYin
authors_ListBox1_Change
Exit Sub

End If

If Sheets(“setting”).Range(“F6”).Value = “edit” Then

selected_author = Sheets(“Setting”).Range(“F5”).Value + 2
Sheets(“authors”).Range(“J9”) = StrConv(Sheets(“authors”).Range(“J9”), vbProperCase)
Sheets(“data”).Range(“K” & selected_author) = Sheets(“authors”).Range(“J9″).Value
MsgBox ” One Author Name Changed.”

‘ Sort the Authors Name
next_row = Sheets(“Data”).Range(“K” & Rows.Count).End(xlUp).Offset(1).Row
Sheets(“Data”).Range(“K3:K” & next_row).SortSpecial SortMethod:=xlPinYin
authors_ListBox1_Change
Exit Sub
End If

End Sub



In the Save code we re-sort the data in the ListBox. Here is a part of the code we use to do so:
‘ Sort the Authors Name
next_row = Sheets(“Data”).Range(“K” & Rows.Count).End(xlUp).Offset(1).Row
Sheets(“Data”).Range(“K3:K” & next_row).SortSpecial SortMethod:=xlPinYin
authors_ListBox1_Change


New we can assign the macros we just creates to the buttons we have (Delete and Save).

End of Part-3

Recap this part:
1. We Create an Author list.
2. We Create a form to collect the Author from the user.
3. We Create the Author ListBox.
4. We wrote the VBA code to Save, Delete, and Create New Author also to retrieve the Author into Author ListBox.


:: Library System with Excel ::

Part 1 Part 2 Part 3 Part 4 Part 5



To Download EXCEL (.xlsm) files Click-Here




Follow me on Twitter..




By: Ali Radwani




Library System with Excel -P1

November 11, 2020 2 comments


Learning :Excel formulas and VBA Cods
Subject: To Develop a Library System with Excel

Someone asked if we can do the Library Management system using Excel, so in the coming several posts we will try to develop an Excel File to store our Books. So I will stop the CRM Project and will work on Library System, we will use MS-EXCEL and VBA code to create a simple spreadsheet looking after our Books.

To start, do the following:
1. We will create an empty Excel file and call it “my Library System” and save it as “Excel Macro-Enabled Workbook.xlsm”
2. Create 7 Tabs(Sheets), name them as:
Menu, Books, Authors, Classifications, Data, Setting, Summary

In this post (Part-1), we will work on the Menu sheet, I will not concern about the themes and colors or fonts all this is back to each user to do formating as needed. So let’s begin with creating four buttons using the insert – shapes Rectangle: Rounded Corners.

We need to create four Rectangle: Rounded Corners, align them as you want and use any theme color, then give each a Captions as in the coming image..

Now, select the Books Button and with Right-Mouse-button select “Assign Macro” and from the new Assign Macro pop-up screen click on New.

This will launch the VBA Application with an open window to write our code, here is the code that if the user clicks on ‘SAY’: Books-Button the Books Sheet will be selected. In coming image, you will find the codes for all buttons we have in the Menu.

Also, we create a code to take us back to the Menu sheets and we call the button MENU, we will add this Button to all sheets we have.


    Recap this part:

  • 1. We Create an Excel file.
  • 2. We Create 7 Sheets and named them.
  • 3. We Create Buttons for the Menu Sheet.
  • 4. We Create the Home Button.
  • 5. We wrote the VBA code so we /the user can navigate thrugh the system.



:: Library System with Excel ::

Part 1 Part 2 Part 3 Part 4



To Download EXCEL (.xlsm) files Click-Here




Follow me on Twitter..




By: Ali Radwani




Python: Library Managment System -P2

June 16, 2020 5 comments


Learning : Python, DataBase, SQlite
Subject: Create Simple Library Managment System

The Data: In the Part-1 we Talk about the Entities that we will create and about the Data we will collect (Fields). So here we are writing them again and we will add classification for each book :
Books Entity: Book Name, Book Author, Date of publish, Edition Number, Book classification number.
Author Entity : Author name, Author Nationality, email, SMA (social media account).
From the Author information we can see that we need to define a new Entity to hold the SMA.
SMA Entity: SMA Name, SMA Link.
Class Entity: class Name.
Here is each entity and field :
book:

  • b_id integer PK
  • b_name text,
  • b_a_id integer,
  • b_isbn text,
  • b_dop text,
  • b_ed integer

author:

  • a_id integer PK
  • a_name text
  • a_email text

sma:

  • sma_id integer PK,
  • a_id integer,
  • sma_name text,
  • sma_link text

class:

  • class_id integer PK
  • class_name text
  • Now we will write the code to create the Database and set a connection

    # create the Database and set a connection

    import sqlite3, os

    # Create the data-base & name it as LMS.
    db_conn = sqlite3.connect ("LMS.db")

    # set the connection.
    c = db_conn.cursor()

    Now we will create the tables..

    # Function to create the tables

    def create_tables_() :
    # to create tables.
    sql_books = "CREATE TABLE if not exists books (b_id INTEGER PRIMARY KEY AUTOINCREMENT, b_name text, b_a_id integer,b_isbn text, b_dop text, b_ed integer)"

    sql_author = "CREATE TABLE if not exists author (a_id INTEGER PRIMARY KEY AUTOINCREMENT ,a_ name text, a_email text )"

    sql_class = "CREATE TABLE if not exists classifi_list (class_id INTEGER PRIMARY KEY AUTOINCREMENT, class_name text )"



    sql_b_class = "CREATE TABLE if not exists b_class (b_class_id INTEGER PRIMARY KEY AUTOINCREMENT, b_id integer, class_id integer )"

    sql_sma = "CREATE TABLE if not exists sma (sma_id INTEGER PRIMARY KEY AUTOINCREMENT, a_id integer,sma_name text, sma_link text)"


    c.execute(sql_books)
    db_conn.commit()

    c.execute(sql_author)
    db_conn.commit()

    c.execute(sql_class)
    db_conn.commit()


    c.execute(sql_b_class)
    db_conn.commit()

    c.execute(sql_sma)
    db_conn.commit()

    input('\n .. LMS Tables created.. Press any key .. ')

    After creating the tables, and to make sure that AUTOINCREMENT of Primary key will run we need to have a number in each PK field, to do that we will add a 0 (Zero) record to each table. Here is the code to do it ..

    #Function to Insert the Zero Record

    #Function to Insert the Zero Record.
    def insert_record_0():

    c.execute ("INSERT INTO books (b_id) VALUES(:b_id)",{"b_id":0})
    c.execute ("INSERT INTO authors (a_id) VALUES(:a_id)",{"a_id":0})
    c.execute ("INSERT INTO classifi_list (class_id) VALUES(:class_id)",{"class_id":0})

    c.execute ("INSERT INTO b_class (class_id) VALUES(:class_id)",{"class_id":0})
    c.execute ("INSERT INTO sma (sma_id) VALUES(:sma_id)",{"sma_id":0})

    db_conn.commit()

    input('\n ...Dummy records been Inserted .... Press any key .. ')

    The above functions create_tables_() and insert_record_0() will be run only one time to create the tables, and insert record number ZERO. During the programming and coding we may need to delete the DataBase and re-created again, in that case we run the both functions again.

    Create the Menus
    As we side, each Entities will have three Main Functions [Add, Edit, delete ad search]. Let’s start with Main Menu.

    Main Menu Code
    Main Menu Run-Time
    Book Menu, Code
    Book Menu, Run-Time
    Author Menu, Code
    Author Menu, Run-Time
    Classification Menu, Code
    Classification Menu, Run-Time
    Search Menu, Code Search Menu, Run-Time

    What’s Coming In coming post, we will write the Functions to Manage the Authors and Classifications.

    [ NOTE ]
    1. I am using Galaxy Tab and QPython3 App.
    2. All the above codes are available in the download section/page under the project name.
    3. During the progress of the project, we may need to Add, Edit or delete any Tables, Fields, Menus or Functions that we had already finished.

    :: Library Managment System ::


    Part 1 Part 2

    To Download my Python code (.py) files Click-Here


Follow me on Twitter..


By: Ali Radwani