DOTNET : Library Management System Project with Source Code

Previous Project with Source Code :

  1. Stock Management System Project With Source Code
  2. Photo Album Project With Source Code
  3. Reminder Application Project With Source Code
asp.net library management project for beginners
Hi Friends,
In previous project I posted SMS Project (i.e Stock Management System) is a web based application developed by using asp.net and c# coding.Now I come with my New Project Called Library Mgmt System Project is done based on basic term of .NET, its mostly helpful for beginners.
  • LMS is used to create inventory of Book's and accessing the existing database of student's.
  • Book Inventory is used to add New Books Details and edit the book information.
  • Book Assign module is used to maintain studentid, bookid, assigndate, returndate, penality and status.
  • Book Assign Module page is used to assign Book's to Student's through bookid, studentid.
  • Pending Modules is nothing but a tracking the Book's through bookid and studentid.
  • Pending Modules page is help's to find Student Information of taken book, and its also help's to find Book Information of taken Student.

Add | Edit | Delete Book Details


DOTNET : Library Management System Project with Source Code

C# Coding - Add | Edit | Delete Book Details :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["bs"].ConnectionString);
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds;
    string sql_query;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        try
        {
            sql_query = "Insert into BookRecord(bookid, bookname, bookpubname, bookpubyear, bookprice, bookquantity, recorddate) values('" + txt_bookid.Text.Trim() + "','" + txt_bookname.Text.Trim() + "','" + txt_bookpubname.Text.Trim() + "','" + txt_bookpubyear.Text.Trim() + "','" + txt_bookprice.Text.Trim() + "','" + txt_bookqty.Text.Trim() + "','" + DateTime.Today.Date.ToShortDateString() + "')";
            cmd = new SqlCommand(sql_query, con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            lblresult.Text = "Record Inserted Successfully...";
        }
        catch
        {
            con.Close();
        }
    }
    protected void btn_Add_Reset_Click(object sender, EventArgs e)
    {
        ResetTextbox();
    }
    private void ResetTextbox()
    {
        txt_bookid.Text = "";
        txt_bookname.Text = "";
        txt_bookpubname.Text = "";
        txt_bookpubyear.Text = "";
        txt_bookprice.Text = "";
        txt_bookqty.Text = "";        
    }
    private void ResetEditTextbox()
    {
        txt_edit_bookid.Text = "";
        txt_edit_bookid.Style.Add("width", "235px");
        txt_edit_bookid.Style.Add("background", "#ffffff");
        txt_edit_bookid.ReadOnly = false;

        btn_check.Visible = true;
        txt_edit_bookname.Text = "";
        txt_edit_bookpubname.Text = "";
        txt_edit_bookpubdate.Text = "";
        txt_edit_bookprice.Text = "";
        txt_edit_bookqty.Text = "";
    }
    private void ResetDeleteTextbox()
    {
        txt_delete_bookid.Text = "";
    }

    private void DisableReadOnly_EditTextBoxColor()
    {
        txt_edit_bookname.ReadOnly = true;
        txt_edit_bookname.Style.Add("background", "#dddddd");
        txt_edit_bookpubname.ReadOnly = true;
        txt_edit_bookpubname.Style.Add("background", "#dddddd");
        txt_edit_bookpubdate.ReadOnly = true;
        txt_edit_bookpubdate.Style.Add("background", "#dddddd");
        txt_edit_bookprice.ReadOnly = true;
        txt_edit_bookprice.Style.Add("background", "#dddddd");
        txt_edit_bookqty.ReadOnly = true;
        txt_edit_bookqty.Style.Add("background", "#dddddd");
    }
    protected void btn_Add_Cancel_Click(object sender, EventArgs e)
    {
        ResetTextbox();
    }

    // Check Book Detail through BookID
    protected void btn_check_Click(object sender, EventArgs e)
    {
        try
        {
            sql_query = "Select * from BookRecord Where bookid='" + txt_edit_bookid.Text.Trim() + "'";
            da = new SqlDataAdapter(sql_query, con);
            ds = new DataSet();
            da.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                txt_edit_bookid.Text = ds.Tables[0].Rows[0]["bookid"].ToString();
                txt_edit_bookname.Text = ds.Tables[0].Rows[0]["bookname"].ToString();
                txt_edit_bookpubname.Text = ds.Tables[0].Rows[0]["bookpubname"].ToString();
                txt_edit_bookpubdate.Text = ds.Tables[0].Rows[0]["bookpubyear"].ToString();
                txt_edit_bookprice.Text = ds.Tables[0].Rows[0]["bookprice"].ToString();
                txt_edit_bookqty.Text = ds.Tables[0].Rows[0]["bookquantity"].ToString();
                btn_check.Visible = false;
                
                EnableReadOnly_TextBoxColor();

                div_add.Style.Add("display", "none");
                table_Add.Style.Add("display", "none");
                div_edit.Style.Add("display", "block");
                table_Edit.Style.Add("display", "block");
                div_delete.Style.Add("display", "none");
                table_Delete.Style.Add("display", "none");


                txt_edit_bookid.Style.Add("width", "300px");
                txt_edit_bookid.Style.Add("background", "#dddddd");
                txt_edit_bookid.ReadOnly = true;
            }
        }
        catch
        {
            con.Close();
        }
    }

    private void EnableReadOnly_TextBoxColor()
    {
        txt_edit_bookid.ReadOnly = false;
        txt_edit_bookid.Style.Add("background","#ffffff");
        txt_edit_bookname.ReadOnly = false;
        txt_edit_bookname.Style.Add("background","#ffffff");
        txt_edit_bookpubname.ReadOnly = false;
        txt_edit_bookpubname.Style.Add("background","#ffffff");
        txt_edit_bookpubdate.ReadOnly = false;
        txt_edit_bookpubdate.Style.Add("background","#ffffff");
        txt_edit_bookprice.ReadOnly = false;
        txt_edit_bookprice.Style.Add("background","#ffffff");
        txt_edit_bookqty.ReadOnly = false;
        txt_edit_bookqty.Style.Add("background","#ffffff");
    }

    protected void btn_Update_Click(object sender, EventArgs e)
    {
        try
        {
            sql_query = "Update BookRecord set bookname='" + txt_edit_bookname.Text.Trim() + "', bookpubname='" + txt_edit_bookpubname.Text.Trim() + "', bookpubyear='" + txt_edit_bookpubdate.Text.Trim() + "', bookprice='" + txt_edit_bookprice.Text.Trim() + "', bookquantity='" + txt_edit_bookqty.Text.Trim() + "' where bookid='" + txt_edit_bookid.Text.Trim() + "'";
            cmd = new SqlCommand(sql_query, con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            lblresult.Text = "Record Updated Successfully...";
        }
        catch
        {
            con.Close();
        }
    }
    protected void btn_Update_Reset_Click(object sender, EventArgs e)
    {
        ResetEditTextbox();
        DisableReadOnly_EditTextBoxColor();
    }
    protected void btn_Update_Cancel_Click(object sender, EventArgs e)
    {
        ResetEditTextbox();
        DisableReadOnly_EditTextBoxColor();
    }

    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        try
        {
            sql_query = "Delete BookRecord where bookid='" + txt_delete_bookid.Text.Trim() + "'";
            cmd = new SqlCommand(sql_query, con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

            div_add.Style.Add("display", "none");
            table_Add.Style.Add("display", "none");
            div_edit.Style.Add("display", "none");
            table_Edit.Style.Add("display", "none");
            div_delete.Style.Add("display", "block");
            table_Delete.Style.Add("display", "block");

            lblresult.Text = "Record Deleted Successfully...";
        }
        catch
        {
            con.Close();
        }
    }
    protected void btn_Delete_Reset_Click(object sender, EventArgs e)
    {
        ResetDeleteTextbox();
    }
    protected void btn_Delete_Cancel_Click(object sender, EventArgs e)
    {
        ResetDeleteTextbox();
    }
}

Book Assign



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

public partial class BookAssign : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["bs"].ConnectionString);
    SqlCommand cmd = new SqlCommand();
    SqlDataAdapter da;
    DataSet ds;
    string sql_query;

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_Assign_Click(object sender, EventArgs e)
    {
        try
        {
            string returndate = DateTime.Today.AddDays(15).ToShortDateString();
            sql_query = "Insert into Assign (studentid, bookid, assigneddate, returndate, penality, statusid) values ('" + txt_assign_studentid.Text.Trim() + "','" + txt_assign_bookid.Text.Trim() + "','" + txt_assign_bookdate.Text.Trim() + "','" + returndate + "','0','s1')";
            cmd = new SqlCommand(sql_query, con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            lblresult_bookassign.Text = "Book ID : " + txt_assign_bookid.Text + " is assigned to Student ID : " + txt_assign_studentid.Text + " on the Date of : " + txt_assign_bookdate.Text + " and you have to return on Date : " + returndate + " otherwise Penality per day :  5 Rupees.";
        }
        catch
        {
            con.Close();
        }
        
    }
    protected void txt_assign_bookid_TextChanged(object sender, EventArgs e)
    {
        try
        {
            sql_query = "Select * from BookRecord Where bookid='" + txt_assign_bookid.Text.Trim() + "'";
            da = new SqlDataAdapter(sql_query, con);
            ds = new DataSet();
            da.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                txt_assign_bookid.Text = ds.Tables[0].Rows[0]["bookid"].ToString();
                txt_assign_bookname.Text = ds.Tables[0].Rows[0]["bookname"].ToString();
                txt_assign_bookqty.Text = ds.Tables[0].Rows[0]["bookquantity"].ToString();
                txt_assign_bookdate.Text = DateTime.Today.Date.ToShortDateString();
            }
        }
        catch
        {
            con.Close();
        }
    }
    protected void txt_assign_studentid_TextChanged(object sender, EventArgs e)
    {
        try
        {
            sql_query = "Select * from Student Where studentid='" + txt_assign_studentid.Text.Trim() + "'";
            da = new SqlDataAdapter(sql_query, con);
            ds = new DataSet();
            da.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                txt_assign_studentid.Text = ds.Tables[0].Rows[0]["studentid"].ToString();
                txt_assign_studentname.Text = ds.Tables[0].Rows[0]["studentname"].ToString();
                txt_assign_studentbranch.Text = ds.Tables[0].Rows[0]["studentbranch"].ToString();
                txt_assign_studentyear.Text = ds.Tables[0].Rows[0]["studentyear"].ToString();
                
            }
        }
        catch
        {
            con.Close();
        }
    }
}

Book Pending



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

public partial class Pending : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["bs"].ConnectionString);
    SqlDataAdapter da;
    DataSet ds = new DataSet();
    String query;
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void txt_bookid_TextChanged(object sender, EventArgs e)
        {
            try
            {
                txt_studentid.Text = "";
                query = "select a.bookid, s.studentid, s.studentname, a.assigneddate, a.returndate, a.penality, Status=(Select statusname from statusdetails where statusid=a.statusid) from Assign a inner join Student s ON a.studentid=s.studentid where bookid='" + txt_bookid.Text.Trim() + "'";
                da = new SqlDataAdapter(query, con);
                con.Open();
                da.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    Grd_Pending_Status.DataSource = ds;
                    Grd_Pending_Status.DataBind();
                }
            }
            catch
            {
                con.Close();
            }
    }
    protected void Grd_Pending_Status_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                da = new SqlDataAdapter(query, con);
                //Find the DropDownList in the Row
                DropDownList ddl_status = (e.Row.FindControl("ddl_status") as DropDownList);
                //Select the Country of Customer in DropDownList                
                da.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    SqlDataAdapter da1 = new SqlDataAdapter("select statusid, statusname from statusdetails", con);
                    DataSet ds1 = new DataSet();
                    da1.Fill(ds1);
                    if (ds1.Tables[0].Rows.Count > 0)
                    {
                        ddl_status.DataSource = ds1;
                        ddl_status.DataTextField = "statusname";
                        ddl_status.DataValueField = "statusid";
                        ddl_status.DataBind();
                        string status = (e.Row.FindControl("lblstatus") as Label).Text;
                        ddl_status.Items.FindByText(status).Selected = true;
                        //Add Default Item in the DropDownList
                        ddl_status.Items.Insert(0, new ListItem("Please select"));
                    }
                }
            }
        }
        catch
        {
            con.Close();
        }
    }
       

    protected void ddl_status_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            DropDownList ddl_status = (DropDownList)sender;
            GridViewRow row = (GridViewRow)ddl_status.Parent.Parent;
            int idx = row.RowIndex;
            string statuschangedate = DateTime.Today.Date.ToShortDateString();

            
            //Retrieve bookid and studentid from Gridview and status(dropdownlist)
            String lblbookid = ((Label)row.Cells[0].FindControl("lblbookid")).Text;
            String lblstudentid = ((Label)row.Cells[0].FindControl("lblstudentid")).Text;
            DropDownList ddl = (DropDownList)row.Cells[0].FindControl("ddl_status");

            
            //Update Status            
            string query = "Update Assign set statusid='" + ddl.SelectedValue.ToString() + "', updatestatusdate='" + statuschangedate + "' where bookid='" + lblbookid + "'";
            SqlCommand cmd = new SqlCommand(query, con);
            con.Open();
            cmd.ExecuteNonQuery();

            
            //cmd.ExecuteNonQuery();
            lblresult.Text = "Student : " + lblstudentid.ToString() + " Status is : " + ddl.SelectedItem.Text.ToString() + " Updated Successfully";
        }
        catch
        {
            con.Close();

        }
    }
    protected void txt_studentid_TextChanged(object sender, EventArgs e)
    {
        try
        {
            txt_bookid.Text = "";
            query = "select Bookid, s.studentid, s.studentname, Assigneddate, returndate, Penality, Status=(Select statusname from statusdetails where statusid=a.statusid) from Assign a inner join Student s ON a.studentid=s.studentid Where a.studentid='" + txt_studentid.Text.Trim() + "'";
            da = new SqlDataAdapter(query, con);
            con.Open();
            da.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                Grd_Pending_Status.DataSource = ds;
                Grd_Pending_Status.DataBind();
            }
        }
        catch
        {
            con.Close();
        }
    }
}

Download Project with Source Code and Database


To download project with source code, please Click Here

Post a Comment

2 Comments

  1. download Library Management System Project with Source Code

    ReplyDelete
    Replies
    1. yes you can download just click on above buttons project and Database

      Delete