ASP.NET Detailed explanation of the steps to realize the library management system

Time:2021-3-25

1、 Database add

1. User information

用户信息表

2. Book information table

图书信息表

3. Book borrowing information table

图书借阅表

2、 Version page

vs2010+sqlserver2008

页面 数据库

3、 Implementation function

1. User login
2. Two identities: administrator and reader
3. Readers can register their own account and password and fill in their own personal information
4. Readers can borrow and return books according to their own needs. 5. Administrators can add, subtract, check and change book information, and modify user information to be improved

4、 Main page display

1. Login page用户登录页面2. User registration用户注册页面3. Personal information form个人信息表4. Users return books

用户归还书籍5. Users borrow books用户借阅书籍6. Users search books用户检索书籍7. Administrator page管理员页面

5、 Simple code

1. Registration page (excluding content judgment)

try
 {
  //Give SQL string data
  string strsql1 = "insert into yhxx (zh,mima) values ('" + Tet_zh.Text + "','" + Tet_mima.Text + "')";
  //Create string object
  mycom = new SqlCommand(strsql1, myconn);
  mycom.ExecuteNonQuery();
  //Close the database
  myconn.Close();
  Response.Write ("< script > alert ('added successfully!)!! ')</script>");
  //Save account number
  //str = Tet_zh.Text;
  //Save user name
  Application["name"] = Tet_zh.Text;
  //If successful, successful transfer in
  Response.Redirect("Useradd.aspx");
 }
 catch (Exception ex)
 {
  Response.Write ("< script > alert ('user already exists!! ')</script>");
 }

2. Personal information page (excluding content judgment)

protected void tianjia()
 {
 //Add user information
 try
 {
  //Give SQL string data
  
  string strsql1 = "update yhxx set xm='"+Tet_xm.Text+"',xb='"+tet_xb.Text+"',qq='"+Tet_qq.Text+"',Email='"+Tet_email.Text+"',dizhi='"+tet_home.Text+"',enjioy='"+Tet_enjoy.Text+"' where zh='"+Application["name"]+"'";
  //Create string object
  mycom = new SqlCommand(strsql1, myconn);
  mycom.ExecuteNonQuery();
  //Close the database
  myconn.Close();
  Response.Write ("< script > alert ('added successfully!)!! ')</script>");
  Response.Redirect("denglu.aspx");
 }
 catch (Exception ex)
 {
  Response.Write ("< script > alert ('add failed!! ')</script>"+ ex.Message.ToString ());
 }
 }

3. Login page (content is not included)

//Ordinary user login, administrator login is the same
 try
 {
  string sql = "select * from yhxx where zh='"+Tet_zh.Text+"' and mima='"+Tet_mm.Text+"' and yhlb='"+tet_dz.Text+"'";
  //Create command object
  SqlCommand com = new SqlCommand(sql,myconn);
  //Create read object
  SqlDataReader dr = com.ExecuteReader();
  //The prompt box pops up successfully
  // MessageBox.Show (read successfully!)!! ");
  if (dr.Read())
  {
  dr.Close();
  myconn.Close();
  Application["name1"] = Tet_zh.Text;
  Response.Redirect("index.aspx");
  }
  else
  {
  Response.Write ("< script > alert ('wrong user name or password!! ')</script>");
  }

 }
 catch (Exception ex)
 {
  Response.Write ("< script > alert ('login failed!! ')</script>");
 }

4. Book Search

try
 {
  //Open database
  myconn.Open();
 }
 catch (Exception ex)
 {
  Response.Write ("< script > alert ('Database open failed ') < / script >");
 }
 try
 {
  //Create data string
  if (tet_name.Text == "")
  {
  Response.Write ("< script > alert ('name cannot be empty! ')</script>");
  }
  else
  {
  String strsql3 = "select bookid as book number, bookname as book name,"
    +"Booklb as book category, bookzz as book author, booklr as book content,"
    +"Bookfm as book cover, bookjg as book price, bookzt as book borrowing status"
    + " from Bookxx where BookName='" + tet_name.Text + "'";
  mycom = new SqlCommand(strsql3, myconn);
  //Open database
  //myconn.Open();
  //
  myread = mycom.ExecuteReader();
  GridView1.DataSource = myread;
  GridView1.DataBind();
  GridView1.Visible = true;
  //Close data
  myread.Close();
  myconn.Close();
  }
 }
 catch (Exception ex)
 {
  Response.Write ("< script > alert ('query failed! ')</script>" +  ex.Message.ToString ());
 }

5. Book borrowing

1. Add books first
 if (myread.Read())
 {
  if (tet_zt.Text == "0")
  {
  //Add borrowing information table
  myread.Close();
  string strsql5 = "insert into Bookjyxx (ISBookID,ISBookname,ISBookzt,ISname,ISid) " +
  " values (" + Tet_Bookid.Text + ",'" + tet_Name.Text + "'," + tet_zt.Text + ",'" + Tet_xm.Text + "'," + Tet_ID.Text + ")";
  mycom = new SqlCommand(strsql5, myconn);
  mycom.ExecuteNonQuery();
  //Closing
  myconn.Close();
  myread.Close();
 //////////////////////////////////////
  xiugai();
  chaxun();
  }
  if (tet_zt.Text == "1")
  {
  Response.Write ("< script > alert ('the book is being borrowed ') < / script >");
  chaxun();
  }
 2. Modify the borrowing status
  //Create
 //First modify the status information of the book table
 string strsql7 = "update Bookxx set Bookzt='1' where BookID='" + Tet_Bookid.Text + "'";
 mycom = new SqlCommand(strsql7, myconn);
 myconn.Close();
 myconn.Open();
 mycom.ExecuteNonQuery();
 //Then modify the borrowing status table information
 string strsql8 = "update Bookjyxx set ISBookzt='1' where ISBookID='" + Tet_Bookid.Text + "'";
 mycom = new SqlCommand(strsql8, myconn);
 mycom.ExecuteNonQuery();
 Response.Write ("< script > alert ('borrowing succeeded! ')</script>");
 //Closing
 myconn.Close();

6. Book return

//Delete his borrowing information
 string strsql3="delete from bookjyxx where ISid='"+Tet_id.Text+"'";
 mycom = new SqlCommand(strsql3, myconn);
 myconn.Open();
 mycom.ExecuteNonQuery();
 //////////////////////////////
 //Refresh information
 //Query information
 String strsql4 = "select isname as borrower, ISID as card number, isbookid as book number,"
  +"Isbookname as borrowing data name, isbookzt as borrowing status, IsDate as borrowing date from bookjyxx where ISID = '" + Tet_ id.Text  + "'";
 mydata = new SqlDataAdapter(strsql4, myconn);
 DataSet set = new DataSet();
 mydata.Fill(set);
 GridView1.DataSource = set.Tables[0];
 GridView1.DataBind();
 GridView1.Visible = true;
 //Modification status
 //First modify the status information of the book table
 string strsql7 = "update Bookxx set Bookzt='0' where BookID='" +tet_Bookid.Text+ "'";
 mycom = new SqlCommand(strsql7, myconn);
 mycom.ExecuteNonQuery();
 Response.Write ("< script > alert ('returned successfully ') < / script >");
 //Closing
 myconn.Close();
 set.Clear();

summary

The above is the introduction of Xiaobian ASP.NET The steps to achieve the library management system, I hope to help you, if you have any questions, please leave me a message, Xiaobian will reply to you in time. Thank you very much for your support to developer!
If you think this article is helpful to you, please reprint, please indicate the source, thank you!