天天看點

ASP.NET圖書管理系統簡單實作步驟

一、資料庫添加

1.使用者資訊

ASP.NET圖書管理系統簡單實作步驟

2.圖書資訊表

ASP.NET圖書管理系統簡單實作步驟

3.圖書借閱資訊表

ASP.NET圖書管理系統簡單實作步驟

二、版本頁面

vs2010+sqlserver2008

ASP.NET圖書管理系統簡單實作步驟
ASP.NET圖書管理系統簡單實作步驟

三、實作功能

1.  使用者注冊登入
2.  兩種身份:管理者和讀者
3.  讀者能夠注冊自己的賬号和密碼還有填寫自己的個人資訊
4.  讀者根據自己需求的借閱和歸還圖書
5.  管理者可以增、減、查、改等圖書資訊,修改使用者資訊待完善
           

四、主要頁面展示

1.登入頁面

ASP.NET圖書管理系統簡單實作步驟

2.使用者注冊

ASP.NET圖書管理系統簡單實作步驟

3.個人資訊表

ASP.NET圖書管理系統簡單實作步驟

4.使用者歸還圖書

ASP.NET圖書管理系統簡單實作步驟

5.使用者借閱書籍

ASP.NET圖書管理系統簡單實作步驟

6.使用者檢索書籍

ASP.NET圖書管理系統簡單實作步驟

7.管理者頁面

ASP.NET圖書管理系統簡單實作步驟

五、簡單代碼

1.注冊頁面(内容判斷不在内)

try
        {
            //賦予sql字元串資料
            string strsql1 = "insert into yhxx (zh,mima) values ('" + Tet_zh.Text + "','" + Tet_mima.Text + "')";
            //建立字元串對象
            mycom = new SqlCommand(strsql1, myconn);
            mycom.ExecuteNonQuery();
            //關閉資料庫
            myconn.Close();
            Response.Write("<script>alert('添加成功!!')</script>");
            //儲存賬号
            //str = Tet_zh.Text;
            //儲存使用者名
            Application["name"] = Tet_zh.Text;
            //如果成功了成功轉入
            Response.Redirect("Useradd.aspx");
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('使用者已存在!!')</script>");
        }
           

2.個人資訊頁面(内容判斷不在内)

protected void tianjia()
    {
        //添加使用者資訊
        try
        {
            //賦予sql字元串資料
            
            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"]+"'";
            // 建立字元串對象
            mycom = new SqlCommand(strsql1, myconn);
            mycom.ExecuteNonQuery();
            //關閉資料庫
            myconn.Close();
            Response.Write("<script>alert('添加成功!!')</script>");
            Response.Redirect("denglu.aspx");
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('添加失敗!!')</script>"+ex.Message.ToString());
        }
    }
           

3.登入頁面(内容判斷不在内)

//普通使用者登入,管理者登入雷同
        try
        {
            string sql = "select * from yhxx where zh='"+Tet_zh.Text+"' and mima='"+Tet_mm.Text+"' and yhlb='"+tet_dz.Text+"'";
            //建立指令對象
            SqlCommand com = new SqlCommand(sql,myconn);
            //建立讀取對象
            SqlDataReader dr = com.ExecuteReader();
            //成功彈出提示框
            //MessageBox.Show("讀取成功!!");
            if (dr.Read())
            {
                dr.Close();
                myconn.Close();
                Application["name1"] = Tet_zh.Text;
                Response.Redirect("index.aspx");
            }
            else
            {
                Response.Write("<script>alert('使用者名或密碼有誤!!')</script>");
            }

        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登入失敗!!')</script>");
        }
           

4.圖書檢索

try
        {
            //打開資料庫
            myconn.Open();
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('資料庫打開失敗')</script>");
        }
        try
        {
            //建立資料字元串
            if (tet_name.Text == "")
            {
                Response.Write("<script>alert('名稱不能為空!')</script>");
            }
            else
            {
                string strsql3 = "select BookID as 圖書編号,BookName as 圖書名稱,"
                                + "Booklb as 圖書類别,Bookzz as 圖書作者,Booklr as 圖書内容,"
                                + "Bookfm as 圖書封面,Bookjg as 圖書價格,Bookzt as 圖書借閱狀态 "
                                + " from Bookxx where BookName='" + tet_name.Text + "'";
                mycom = new SqlCommand(strsql3, myconn);
                //打開資料庫
                //myconn.Open();
                //
                myread = mycom.ExecuteReader();
                GridView1.DataSource = myread;
                GridView1.DataBind();
                GridView1.Visible = true;
                //關閉資料
                myread.Close();
                myconn.Close();
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('查詢失敗!')</script>" + ex.Message.ToString());
        }
           

5.圖書借閱

1.先添加圖書
 if (myread.Read())
        {
            if (tet_zt.Text == "0")
            {
                //添加借閱資訊表
                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();
                //關閉
                myconn.Close();
                myread.Close();
        //
                xiugai();
                chaxun();
            }
            if (tet_zt.Text == "1")
            {
                Response.Write("<script>alert('該書正在借閱中')</script>");
                chaxun();
            }
 2.再分别修改借閱狀态
             //建立
        //先修改圖書表狀态資訊
        string strsql7 = "update Bookxx set Bookzt='1' where BookID='" + Tet_Bookid.Text + "'";
        mycom = new SqlCommand(strsql7, myconn);
        myconn.Close();
        myconn.Open();
        mycom.ExecuteNonQuery();
        //再修改借閱狀态表資訊
        string strsql8 = "update Bookjyxx set ISBookzt='1' where ISBookID='" + Tet_Bookid.Text + "'";
        mycom = new SqlCommand(strsql8, myconn);
        mycom.ExecuteNonQuery();
        Response.Write("<script>alert('借閱成功!')</script>");
        //關閉
        myconn.Close();
           

6.圖書歸還

//删除他的借閱圖書資訊
        string strsql3="delete from bookjyxx where ISid='"+Tet_id.Text+"'";
        mycom = new SqlCommand(strsql3, myconn);
        myconn.Open();
        mycom.ExecuteNonQuery();
        //
       //重新整理資訊
        //查詢資訊
        string strsql4= "select ISname as 借閱者,ISid as 借閱證号碼,ISBookID as 借閱書籍編号,"
           + "ISBookname as 借閱資料名稱,ISBookzt as 借閱狀态,ISdate as借閱日期 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;
        //修改狀态
        //先修改圖書表狀态資訊
        string strsql7 = "update Bookxx set Bookzt='0' where BookID='" +tet_Bookid.Text+ "'";
        mycom = new SqlCommand(strsql7, myconn);
        mycom.ExecuteNonQuery();
        Response.Write("<script>alert('歸還成功!')</script>");
        //關閉
        myconn.Close();
        set.Clear();
           

六、總結

本人第一次寫部落格,有什麼錯的地方希望大神們指教,我也希望給才接觸的asp.net的人有所幫助,有需要直接加我:1076396021 (不白給) 有任何問題都可以問我,給調試 感謝大家的閱讀和支援,能給你們帶來幫助也是我成長的一步

直接加我

繼續閱讀