Exemplo n.º 1
0
        public static void DeleteAllCopy(Book b)
        {
            try {
                SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True");
                SqlCommand cmd = new SqlCommand("Delete Copy where bookNumber = @bookNumber", cn);
                cmd.Parameters.AddWithValue("@bookNumber", b.BookNumber);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();
            } catch(Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
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(Exception ex) {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
Exemplo n.º 3
0
 public static bool Update(Book b)
 {
     return BookDA.Update(b);
 }
Exemplo n.º 4
0
 public static bool Insert(Book b)
 {
     return BookDA.Insert(b);
 }
Exemplo n.º 5
0
 public static bool Delete(Book b)
 {
     return BookDA.Delete(b);
 }
Exemplo n.º 6
0
        private void btnAdd_Click_1(object sender, EventArgs e)
        {
            if (AddSave == 0)
            {
                btnAdd.Text = "Save";
                SqlConnection cn=new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True");
                SqlDataAdapter da = new SqlDataAdapter("SELECT MAX(bookNumber) FROM Book", cn);
                DataSet ds = new DataSet();
                da.Fill(ds);
                int Num = int.Parse(ds.Tables[0].Rows[0][0].ToString()) + 1;
                txtBookNumber.Enabled = false;
                txtBookNumber.Text = Num + "";
                txtTitle.Enabled = true;
                txtTitle.Text = "";
                txtPublisher.Enabled = true;
                txtPublisher.Text = "";
                txtAuthors.Enabled = true;
                txtAuthors.Text = "";
                btnDelete.Enabled = false;
                btnEdit.Enabled = false;
                button7.Enabled = false;
                AddSave = 1;//Save
            }
            else
            {
                int bookNum = int.Parse(txtBookNumber.Text);
                string title = txtTitle.Text.Trim();
                string author = txtAuthors.Text.Trim();
                string publisher = txtPublisher.Text.Trim();
                Book book = new Book(bookNum, title, author, publisher);

                btnDelete.Enabled = true;
                btnEdit.Enabled = true;
                button7.Enabled = true;
                AddSave = 0;//Add
                btnAdd.Text = "Add";

                try
                {
                    BookBL.Insert(book);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                InitializeData();
                txtBookNumber.Enabled = true;
            }
        }
Exemplo n.º 7
0
 private void btnEdit_Click(object sender, EventArgs e)
 {
     if (!isSelected())
     {
         MessageBox.Show("Please select a book to edit");
         return;
     }
     if (EditSave == 0)
     {
         btnEdit.Text = "Save";
         txtBookNumber.Enabled = false; ;
         txtTitle.Enabled = true;
         txtPublisher.Enabled = true;
         txtAuthors.Enabled = true;
         btnDelete.Enabled = false;
         btnAdd.Enabled = false;
         button7.Enabled = false;
         EditSave = 1;//Save
     }
     else
     {
         int bookNum = int.Parse(txtBookNumber.Text);
         string title = txtTitle.Text.Trim();
         string author = txtAuthors.Text.Trim();
         string publisher = txtPublisher.Text.Trim();
         Book book = new Book(bookNum, title, author, publisher);
         try
         {
             BookBL.Update(book);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         btnDelete.Enabled = true;
         btnAdd.Enabled = true;
         button7.Enabled = true;
         EditSave = 0;//Edit
         btnEdit.Text = "Edit";
         InitializeData();
     }
 }
Exemplo n.º 8
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (!isSelected())
            {
                MessageBox.Show("Please select a book to delete");
                return;
            }

            Book b = new Book();
            b.BookNumber = int.Parse(Book_BookTable.SelectedRows[0].Cells["bookNumber"].Value.ToString());
            DialogResult result = MessageBox.Show("Do you really want to delete this book", "Confirm", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                BookDA.DeleteAllCopy(b);
                BookBL.Delete(b);
            }
            else { }
            InitializeData();
        }