Пример #1
0
 private void buttonBEdit_Click(object sender, EventArgs e)
 {
     if (!isSelectedBook())
     {
         MessageBox.Show("Please select a book to edit");
         return;
     }
     if (buttonBEdit.Text == "Finish")
     {
         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);
         refreshBook();
     }
     else
     {
         buttonBEdit.Text = "Finish";
         txtBookNumber.Enabled = false;
         txtTitle.Enabled = true;
         txtAuthors.Enabled = true;
         txtPublisher.Enabled = true;
     }
 }
Пример #2
0
        private void buttonBAdd_Click(object sender, EventArgs e)
        {
            txtBookNumber.Enabled = false;
            txtTitle.Enabled = true;
            txtAuthors.Enabled = true;
            txtPublisher.Enabled = true;
            if (buttonBAdd.Text == "Finish")
            {
                Book b = new Book();
                b.BookNumber = int.Parse(txtBookNumber.Text);
                b.Title = txtTitle.Text;
                b.Authors = txtAuthors.Text;
                b.Publisher = txtPublisher.Text;
                BookBL.Insert(b);
                refreshBook();

                buttonBAdd.Text = "Add";

            }
            else
            {
                buttonBAdd.Text = "Finish";
                int max = ++BookBL.bookNumberMax;
                txtBookNumber.Text = max.ToString();
                txtTitle.Focus();
            }
        }
Пример #3
0
        private void buttonBDelete_Click(object sender, EventArgs e)
        {
            if (!isSelectedBook())
            {
                MessageBox.Show("Please select a book to delete");
                return;
            }

            Book b = new Book();
            b.BookNumber = int.Parse(dataGridViewBook.SelectedRows[0].Cells["bookNumber"].Value.ToString());
            BookBL.Delete(b);
            refreshBook();
        }
Пример #4
0
        public static bool Delete(Book b)
        {
            try
            {
                SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True");
                SqlCommand cmd = new SqlCommand("Delete Book where bookNumber = @bookNumber", cn);
                cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
Пример #5
0
        public static bool Insert(Book b)
        {
            try
            {
                SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True");
                SqlCommand cmd = new SqlCommand("Insert into Book(bookNumber, title, authors, publisher)"+"values(@bookNumber, @title, @authors, @publisher)", cn);
                cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber);
                cmd.Parameters.AddWithValue("@title", b.Title);
                cmd.Parameters.AddWithValue("@authors", b.Authors);
                cmd.Parameters.AddWithValue("@publisher", b.Publisher);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();
                return true;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
Пример #6
0
 public static bool Update(Book b)
 {
     return BookDA.Update(b);
 }
Пример #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)
        {
            try
            {
                SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True");
                SqlCommand cmd = new SqlCommand("Update Book set title = @title, "
                + "authors = @authors, publisher = @publisher where bookNumber = @bookNumber", cn);
                cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber);
                cmd.Parameters.AddWithValue("@title", b.Title);
                cmd.Parameters.AddWithValue("@authors", b.Authors);
                cmd.Parameters.AddWithValue("@publisher", b.Publisher);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }