示例#1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Book b = new Book();
            b.BookNumber = int.Parse(tb_bookNumber.Text);
            b.Title = tb_title.Text;
            b.Authors = tb_authors.Text;
            b.Publisher = tb_publisher.Text;

            if (BookBL.Insert(b)) BookBL.BookNumberMax++;

            Response.Redirect("BookGUI.aspx");
        }
示例#2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Book b = new Book();
            b.BookNumber = int.Parse(txtBookNumber.Text);
            b.Title = txtTitle.Text;
            b.Authors = txtAuthors.Text;
            b.Publisher = txtPublisher.Text;

            BookBL.Update(b);

            Response.Redirect("BookGUI.aspx");
        }
示例#3
0
        public static Boolean Delete(Book b)
        {
            try
            {
                string strConn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
                SqlConnection conn = new SqlConnection(strConn);
                SqlCommand cmd = new SqlCommand("delete Book where bookNumber=@bookNumber", conn);

                cmd.Parameters.Add(new SqlParameter("@bookNumber", b.BookNumber));

                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
                return true;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
示例#4
0
 public static Book GetBook(int bookNumber)
 {
     try
     {
         string strConn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
         SqlConnection cn = new SqlConnection(strConn);
         SqlCommand cmd = new SqlCommand("select * from Book where bookNumber = @bookNumber", cn);
         cmd.Parameters.AddWithValue("@bookNumber", bookNumber);
         cn.Open();
         SqlDataReader rd = cmd.ExecuteReader();
         if (rd.Read())
         {
             Book b = new Book(int.Parse(rd["bookNumber"].ToString()), rd["title"].ToString(), rd["authors"].ToString(), rd["publisher"].ToString());
             return b;
         }
         else return null;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return null;
     }
 }
示例#5
0
        public static bool Update(Book b)
        {
            try
            {
                string strConn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
                SqlConnection conn = new SqlConnection(strConn);
                SqlCommand cmd = new SqlCommand("update Book set title=@title, authors = @authors, publisher = @publisher where bookNumber=@bookNumber", conn);

                cmd.Parameters.Add(new SqlParameter("@bookNumber", b.BookNumber));
                cmd.Parameters.Add(new SqlParameter("@title", b.Title));

                cmd.Parameters.Add(new SqlParameter("@authors", b.Authors));
                cmd.Parameters.Add(new SqlParameter("@publisher", b.Publisher));

                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
                return true;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
示例#6
0
        public static bool Insert(Book b)
        {
            try
            {
                string strConn = ConfigurationManager.ConnectionStrings["LibraryConnectionString"].ConnectionString;
                SqlConnection conn = new SqlConnection(strConn);
                SqlCommand cmd = new SqlCommand("insert into book(bookNumber, title, authors, publisher)" +
                    "values (@bookNumber, @title, @authors, @publisher)", conn);

                cmd.Parameters.Add(new SqlParameter("@bookNumber", b.BookNumber));
                cmd.Parameters.Add(new SqlParameter("@title", b.Title));
                cmd.Parameters.Add(new SqlParameter("@authors", b.Authors));
                cmd.Parameters.Add(new SqlParameter("@publisher", b.Publisher));

                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
                return true;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
示例#7
0
 public static bool Insert(Book b)
 {
     return BookDA.Insert(b);
 }
示例#8
0
 public static bool Delete(Book b)
 {
     return BookDA.Delete(b);
 }
示例#9
0
 public static bool Update(Book b)
 {
     return BookDA.Update(b);
 }