一、數據庫添加
1.用戶信息
2.圖書信息表
3.圖書借閱信息表
二、版本頁面
vs2010+sqlserver2008
三、實現功能
1. 用戶註冊登錄
2. 兩種身份:管理員和讀者
3. 讀者能夠註冊自己的賬號和密碼還有填寫自己的個人信息
4. 讀者根據自己需求的借閱和歸還圖書
5. 管理員可以增、減、查、改等圖書信息,修改用戶信息待完善
四、主要頁面展示
1.登錄頁面
2.用戶註冊
3.個人信息表
4.用戶歸還圖書
5.用戶借閱書籍
6.用戶檢索書籍
7.管理員頁面
五、簡單代碼
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 (不白給) 有任何問題都可以問我,給調試 感謝大家的閱讀和支持,能給你們帶來幫助也是我成長的一步
直接加我