⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m_tenancybook.aspx.cs

📁 自己写的一个网上图书馆 可实现图书上传借阅等功能
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace e_librarys
{
	/// <summary>
	/// WebForm2 的摘要说明。
	/// </summary>
	public partial class WebForm2 : System.Web.UI.Page
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void Button_Tenancy_Click(object sender, System.EventArgs e)
		{
			if(TextBox_ID.Text.ToString()!="" && Textbox_UserID.Text.ToString()!="")
			{
				SqlConnection Conn = new SqlConnection("server=(local);database=e_library;uid=sa;pwd=");
				Conn.Open();
				string StrSql="select * from Tenancy where T_B_ID='"+TextBox_ID.Text.ToString()+"' and T_U_ID='"+Textbox_UserID.Text.ToString()+"'";
				SqlCommand Comm =new SqlCommand(StrSql,Conn);
				SqlDataReader Dr=Comm.ExecuteReader();
				if(Dr.Read())
				{
					string statue=Dr["T_Status"].ToString();
					Conn.Close();

					if(statue=="1")
					{

						StrSql="update Book_Info set B_Status=2 where B_ID='"+TextBox_ID.Text.ToString()+"' ";
						Conn.Open();
						Comm =new SqlCommand(StrSql,Conn);
						Comm.ExecuteNonQuery();
						Conn.Close();

						StrSql="update Tenancy set T_Status=2 where T_B_ID='"+TextBox_ID.Text.ToString()+"' and T_U_ID='"+Textbox_UserID.Text.ToString()+"' ";
						Conn.Open();
						Comm =new SqlCommand(StrSql,Conn);
						Comm.ExecuteNonQuery();
						Conn.Close();

						this.TextBox_ID.Text="";
						this.TextBox_TenancyBookName.Text="";
						this.Textbox_UserID.Text="";
						this.TextBox_UserName.Text="";
                        Response.Write("<script language='javascript'>alert('租赁图书成功')</script>");
					}
					else
					{Response.Write("<script language='javascript'>alert('此图书已出租!')</script>");}
				}
				else
				{
					Conn.Close();
					Conn.Open();
					StrSql="insert into Tenancy(T_B_ID,T_U_ID,T_Lease,T_Status) values('"+TextBox_ID.Text.ToString()+"','"+Textbox_UserID.Text.ToString()+"','"+DropDownList_Lease.SelectedItem.Text.ToString()+"',2)";
					Comm =new SqlCommand(StrSql,Conn);
					Comm.ExecuteNonQuery();
					Conn.Close();
			
					Conn = new SqlConnection("server=(local);database=e_library;uid=sa;pwd=");
					Conn.Open();
					StrSql="update Book_Info set B_Status=2 where B_ID='"+TextBox_ID.Text.ToString()+"'";
					Comm =new SqlCommand(StrSql,Conn);
					Comm.ExecuteNonQuery();
					Conn.Close();
                    Response.Write("<script language='javascript'>alert('租赁图书成功')</script>");
 
					
					this.TextBox_ID.Text="";
					this.TextBox_TenancyBookName.Text="";
					this.Textbox_UserID.Text="";
					this.TextBox_UserName.Text="";
               
				}

                StrSql = "update User_Info set U_RentCount=U_RentCount+1 where U_ID='" + Textbox_UserID.Text.ToString() + "'  ";
                Conn.Open();
                Comm = new SqlCommand(StrSql, Conn);
                Comm.ExecuteNonQuery();
                Conn.Close();
				
			}
			else
			{
				Response.Write("<script language='javascript'>alert('请输入租赁图书信息!')</script>");
			}
		}

		protected void Button_Return_Click(object sender, System.EventArgs e)
		{
			if(Textbox_ReturnBookID.Text.ToString()!="" && Textbox_ReturnUserID.Text.ToString()!="")
			{
				SqlConnection Conn = new SqlConnection("server=(local);database=e_library;uid=sa;pwd=");
				Conn.Open();
                string StrSql = "update Book_Info set B_Status=0 where B_ID='" + Textbox_ReturnBookID.Text.ToString() + "' ";
				SqlCommand Comm =new SqlCommand(StrSql,Conn);
				Comm.ExecuteNonQuery();
				Conn.Close();

                StrSql = "delete from Tenancy  where T_B_ID='" + Textbox_ReturnBookID.Text.ToString() + "' and T_U_ID='" + Textbox_ReturnUserID.Text.ToString() + "' ";
				Conn.Open();
				Comm =new SqlCommand(StrSql,Conn);
				Comm.ExecuteNonQuery();
				Conn.Close();

               Response.Write("<script language='javascript'>alert('归还图书成功!')</script>");

			}
			else
			{Response.Write("<script language='javascript'>alert('请输入归还图书信息!')</script>");}
		}




        protected void Button_Browse_Click(object sender, EventArgs e)
        {
            SqlConnection Conn = new SqlConnection("server=(local);database=e_library;uid=sa;pwd=");
			Conn.Open();
			string StrSql="select * from User_Info ,Tenancy,Book_Info,Payment  where B_ID='"+Textbox_ReturnBookID.Text+"' and U_ID=T_U_ID and T_B_ID=B_ID and P_ID=B_PMT_ID";
			SqlCommand Comm = new SqlCommand(StrSql,Conn);
			SqlDataReader Dr=Comm.ExecuteReader();
			if(Dr.Read())
			{
                   Label13.Text=Dr["B_Name"].ToString();
				Label14.Text=Dr["U_Name"].ToString();
				Label15.Text=Dr["T_ReserveTime"].ToString();
                 Label6.Text=Dr["T_StartTime"].ToString();
				Label5.Text=Dr["T_EndTime"].ToString();
                Label7.Text = Dr["T_TimeOut"].ToString();

                


				if(Dr["T_TimeOut"].ToString()=="0")
				{Label6.Text="未超期";
                //租金
                int i = Convert.ToInt32(Dr["P_Price"]);
                int j = Convert.ToInt32(Dr["T_Lease"]);
                int k = i * j;
                Label8.Text = k.ToString();
                }
				else
				{Label6.Text="已超期";
                //租金
                int i = Convert.ToInt32(Dr["P_Price"]);
                int j = Convert.ToInt32(Dr["T_Lease"]);
                int m = Convert.ToInt32(Dr["T_TimeOut"]);
                int k = i*j*m;
                Label8.Text = k.ToString();


                }

                //租期
				Label12.Text=Dr["T_Lease"].ToString();

                

				Label9.Text=Dr["P_Deposit"].ToString();
				Label10.Text=Dr["P_Price"].ToString();
				Label11.Text=Dr["P_LateFee"].ToString();
				Label12.Text=Dr["T_Lease"].ToString();
				
			}
		}
        }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -