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

📄 admmanage.aspx.cs

📁 一个简单的图书管理系统,赋有设计的说明书。可以实现一般的管理操作。
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class AdmManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = "";
        Label4.Text = "";
      
    }
    protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
    {
        if (e.Item.Value == "Borrow")
            MultiView1.ActiveViewIndex = 0;
        else if (e.Item.Value == "Return")
            MultiView1.ActiveViewIndex = 1;
        
        else if( e.Item.Value=="ManageBook")
        {

            ShowBookInfo();               
            MultiView1.ActiveViewIndex = 3;
         
        }
        else if (e.Item.Value == "UserInfo")
        {       
            MultiView1.ActiveViewIndex = 4;        
        }
        else if (e.Item.Value == "Stu")
        {
            ShowStuInfo();
            MultiView1.ActiveViewIndex = 7;
        }

    }
    protected void Submit_Click(object sender, EventArgs e)
    {
      /* string str = "server=localhost;Database=library1;User ID=sa";
       SqlConnection conn = new SqlConnection(str);
       conn.Open();
       SqlDataAdapter sqlda = new SqlDataAdapter(); 
       sqlda.SelectCommand = new SqlCommand("GetBookInfoByBookID", conn);
       sqlda.SelectCommand .CommandType = CommandType.StoredProcedure;
       SqlParameter sqlpr = new SqlParameter("@BookID",SqlDbType.Char,10);
       sqlpr.Value = tbBookID.Text.ToString();
       sqlda.SelectCommand.Parameters.Add(sqlpr);
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        DataList1.DataSource = ds;
        
        DataList1.DataBind();*/ //datalist的连接数据库的过程 ,但是还要在 dataview里循环输出
        //Session["BookID"] = tbBookID.Text.ToString();
        //Response.Redirect("BookInfo.aspx");

        //string str = "server=localhost;Database=library1;User ID=sa";
        //SqlConnection conn = new SqlConnection(str);
        //conn.Open();
        DataControl.ConnectionControl conn = new DataControl.ConnectionControl();
        conn.DataConnetion();       
        SqlDataAdapter sqlda = new SqlDataAdapter();
        //sqlda.SelectCommand = new SqlCommand("GetBorrowInfoByBookID", conn);  //用存储过程获得用户所借的书
        sqlda.SelectCommand = conn.DataCmd("GetBorrowInfoByBookID");
        sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
        SqlParameter sqlpr = new SqlParameter("@BookID", SqlDbType.Char, 10);//传参数BOOKID
        sqlpr.Value = tbBookID.Text.ToString().Trim();
        sqlda.SelectCommand.Parameters.Add(sqlpr);
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
        conn.Close();
    }
    public void SqlCon(SqlCommand cmd,SqlDataReader dr1,DataControl.ConnectionControl conn)
    {
                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter ParaBookID = new SqlParameter("@BookID", SqlDbType.Char, 10);//command的参数
                ParaBookID.Value = tbBookID.Text.ToString().Trim();
                cmd.Parameters.Add(ParaBookID);
                SqlParameter ParaUserID = new SqlParameter("@UserID", SqlDbType.Char, 10);//command的参数
                ParaUserID.Value = tbUserID.Text.ToString().Trim();
                cmd.Parameters.Add(ParaUserID);
                SqlDataReader dr;
                try
                {
                    dr1.Close();
                    dr = cmd.ExecuteReader();
                    if (!dr.Read())
                        Label1.Text = "借书成功!";   //返回借书结果
                    else
                        Label1.Text = "借书不成功!";
                }
                catch (Exception e2)
                {
                    Response.Write(e2.Message.ToString());
                }
                finally
                {
                    conn.Close();
                    
                }
    }

    protected void ReSubmit_Click(object sender, EventArgs e)
    {
        Label1.Text = "";
       
        //string connstr = "server=localhost;Database=library1;User ID=sa;Password=''";
        //SqlConnection conn = new SqlConnection(connstr);       
        //SqlCommand cmd1 = new SqlCommand("select IsReturned from BorrowInfo where BookID='" +tbBookID.Text.ToString().Trim() + "'", conn);
       // conn.Open();
        DataControl.ConnectionControl conn = new DataControl.ConnectionControl();
        conn.DataConnetion();
        SqlCommand cmd1 = conn.DataCmd("select IsReturned from BorrowInfo where BookID='" + tbBookID.Text.Trim() + "'");
            SqlDataReader dr1 = cmd1.ExecuteReader(); 
            if (dr1.Read())
            {
                if (dr1.GetBoolean(0).Equals(false))  //这本书已经被借出
                {
                    Label1.Text = "书号为" + tbBookID.Text + "已经借出!";
                    conn.Close();
                   
                }
                else
                {
                    SqlCommand  cmd = conn.DataCmd("ReBorrow");
                    //Response.Write("dd"); 
                     SqlCon(cmd,dr1,conn);
                }
            }     
            else
            {               
                 SqlCommand  cmd = conn.DataCmd("BorrowBook");
                SqlCon(cmd,dr1,conn);
            }
               
      }      
    
      

    protected void btReturn_Click(object sender, EventArgs e)
    {
        //string connstr = "server=localhost;Database=library1;User ID=sa;Password=''";
        //SqlConnection conn = new SqlConnection(connstr);
        DataControl.ConnectionControl conn = new DataControl.ConnectionControl();
        conn.DataConnetion();
        SqlCommand cmd = conn.DataCmd("ReturnBook");
        //SqlCommand cmd = new SqlCommand("ReturnBook", conn);   //调用存储过程还书,让IsReturn为1,更改还书时间 
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter ParaBookID = new SqlParameter("@BookID", SqlDbType.Char, 10);//command的参数
        ParaBookID.Value = tbBookID1.Text.Trim();
        cmd.Parameters.Add(ParaBookID);
        //SqlCommand cmd = new SqlCommand("update BorrowInfo set IsReturned=1,ReturnDate=getdate() where BookID='" + tbBookID1.Text + "'", conn);
        //SqlDataReader dr;
        try
        {
           // conn.Open();
           //dr=cmd.ExecuteReader();
           //;
           if (cmd.ExecuteNonQuery()==1)
            {                
                Label4.Text = "还书成功!";
            }
        }
        catch (Exception es)
        {
            Response.Write( es.Message.ToString());
        }
        finally
        {
            conn.Close();
        }
       
    }

    protected void NewPsw1_Load(object sender, EventArgs e)
    {

    }
    //显示图书信息
    public void ShowBookInfo()
    {
        DataControl.ConnectionControl conn = new DataControl.ConnectionControl();
        conn.DataConnetion();
        SqlCommand cmd = conn.DataCmd("GetBookInfo");
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataReader dr = cmd.ExecuteReader();
        GridView2.DataSource = dr;
        GridView2.DataBind();
        conn.Close();
    }
 
    protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
    //    string connstr = "server=localhost;Database=library1;User ID=sa;Password=''";
    //    SqlConnection conn = new SqlConnection(connstr);   
        DataControl.ConnectionControl conn = new DataControl.ConnectionControl();
        conn.DataConnetion();
        SqlCommand cmd = conn.DataCmd("delete from BookInfo where BookID='" + GridView2.Rows[e.RowIndex].Cells[1].Text.Trim().ToString() + "'");
        //SqlCommand cmd=new SqlCommand();
        //cmd.CommandText = "delete from BookInfo where BookID='"+GridView2.Rows[e.RowIndex].Cells[1].Text.Trim().ToString()+"'";     
        //cmd.Connection = conn;  
        //Label6.Text= GridView2.Rows[e.RowIndex].Cells[1].Text.Trim().ToString();
        try
        {
            //conn.Open();
            cmd.ExecuteNonQuery();
      
        }
        catch (Exception es)
        {
            Response.Write(es.Message.ToString());
        }
        finally
        {         
            conn.Close(); 
            ShowBookInfo();           
        }
        
    }

    protected void AddBook_Click(object sender, EventArgs e)
    {
        
        DataControl.ConnectionControl conn = new DataControl.ConnectionControl();
        conn.DataConnetion();
        SqlCommand cmd = conn.DataCmd("insert into BookInfo values('" + BookID.Text.Trim() + "','" + ISBN.Text.Trim() + "','" + BookName.Text.Trim() + "','" + Author.Text.Trim() + "','" + Publisher.Text.Trim() + "','" + PublishDate.Text.Trim() + "','" + PageCount.Text.Trim() + "','" + ClassID.Text.Trim() + "')");
        SqlDataReader dr =cmd.ExecuteReader();
        try
        {
            if (!dr.Read())
            {
                Label6.Text = "增加了'" + BookName.Text + "'这本书!";
            }
        }
        catch (Exception es)
        {
            Response.Write(es.Message.ToString());
        }
        finally
        {
            conn.Close();
            BookID.Text = "";
            ISBN.Text = "";
            BookName.Text = "";
            Author.Text = "";
            PublishDate.Text = "";
            Publisher.Text = "";
            PageCount.Text = "";
            ClassID.Text = "";
            Label6.Text = "";
            ShowBookInfo();
        }
       
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 5;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 6;
    }


    protected void Button1_Click1(object sender, EventArgs e)
    {
        DataControl.ConnectionControl conn = new DataControl.ConnectionControl();
        conn.DataConnetion();
        string sql="update BookInfo set BookID='"+BookID.Text.Trim()+"'";
        if (ISBN.Text != "")
            sql += ",ISBN='" + ISBN.Text.Trim() + "'";
        if(BookName.Text != "")
            sql+=",BookName='" + BookName.Text.Trim() + "'";    
        if(Author.Text!="")
           sql+=",Author='"+Author.Text.Trim()+"'";
        if(Publisher.Text!="")
            sql+=",Publisher='"+Publisher.Text.Trim()+"'";
         
        SqlCommand cmd = conn.DataCmd(sql + "where BookID='" + BookID.Text.Trim() + "'");
        SqlDataReader dr = cmd.ExecuteReader();
        try
        {
            if (!dr.Read())
            {
                Label6.Text = "修改了'" + BookName.Text + "'这本书!";
            }
        }
        catch (Exception es)
        {
            Response.Write(es.Message.ToString());
        }
        finally
        {
            conn.Close();
            BookID.Text = "";
            ISBN.Text = "";
            BookName.Text = "";
            Author.Text = "";
            PublishDate.Text = "";
            Publisher.Text = "";
            PageCount.Text = "";
            ClassID.Text = "";
            Label6.Text = "";
            ShowBookInfo();
        }
    }
    //学生信息的删除事件
    protected void GridView3_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        DataControl.ConnectionControl conn = new DataControl.ConnectionControl();
        conn.DataConnetion();
        SqlCommand cmd = conn.DataCmd("delete from UserInfo where UserID='" + GridView3.Rows[e.RowIndex].Cells[1].Text.Trim().ToString() + "'");
        cmd.ExecuteNonQuery();
        ShowStuInfo();
    }
    //返回学生信息
    public void ShowStuInfo()
    {
        DataControl.ConnectionControl conn = new DataControl.ConnectionControl();
        conn.DataConnetion();
        SqlCommand cmd = conn.DataCmd("GetAllUsers");
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataReader dr = cmd.ExecuteReader();
        GridView3.DataSource = dr;
        GridView3.DataBind();
        conn.Close();
    }
    protected void xiugai_Click(object sender, EventArgs e)
    {
        DataControl.ConnectionControl conn = new DataControl.ConnectionControl();
        conn.DataConnetion();
        string sql = "update UserInfo set UserID='" +UserID.Text.Trim() + "'";
        if (Sex.Text != "")
            sql += ",Sex='" + Sex.Text.Trim() + "'";
        if (Pas.Text != "")
            sql += ",Password='" + Pas .Text.Trim() + "'";
        if (Email.Text != "")
            sql += ",Email='" + Email.Text.Trim() + "'";
        if (Class.Text != "")
            sql += ",Class='" + Class.Text.Trim() + "'";
        if(Tel.Text!="")
            sql+=",Telephone='"+Tel.Text.Trim()+"'";
        SqlCommand cmd = conn.DataCmd(sql + "where UserID='" + UserID.Text.Trim() + "'");
        SqlDataReader dr = cmd.ExecuteReader();
        try
        {
            if (!dr.Read())
            {
                Label6.Text = "修改了'" + UserID.Text + "'的信息!";
            }
        }
        catch (Exception es)
        {
            Response.Write(es.Message.ToString());
        }
        finally
        {
            conn.Close();
            UserID.Text = "";
            Sex.Text = "";
            Pas.Text = "";
            Class.Text = "";
            Email.Text = "";
            Tel.Text = "";            
            ShowStuInfo();
        }
    }
    protected void chaxu_Click(object sender, EventArgs e)
    {
        DataControl.ConnectionControl conn = new DataControl.ConnectionControl();
        conn.DataConnetion();
        SqlCommand cmd = conn.DataCmd("GetUsersInfoBy");
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter ParaUserID = new SqlParameter("@UserID",SqlDbType.Char,10);
        ParaUserID.Value = UserID.Text.Trim();
        cmd.Parameters.Add(ParaUserID);
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            Sex.Text = dr.GetString(0);
            Pas.Text = dr.GetString(1);
            Email.Text = dr.GetString(2);
            Class.Text = dr.GetString(3);
            Tel.Text = dr.GetString(4);
        }
        else
        {
            Label9.Text = "用户名输入有误!";
        }

    }
}

⌨️ 快捷键说明

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