Exemple #1
0
        private void Query_Insert()
        {
            try
            {
                DB.ConnectDB();
                string     sqlcommand = "Insert into Book_Manager (Isbn, Name, Publisher, Page, isBorrowed) values (@p1, @p2, @p3, @p4, @p5)";
                SqlCommand cmd        = new SqlCommand();

                cmd.Connection  = DB.conn;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@p1", textBox_isbn.Text);
                cmd.Parameters.AddWithValue("@p2", textBox_bookName.Text);
                cmd.Parameters.AddWithValue("@p3", textBox_publisher.Text);
                cmd.Parameters.AddWithValue("@p4", textBox_page.Text);
                Book book = new Book();
                cmd.Parameters.AddWithValue("@p5", book.isBorrowed);
                cmd.CommandText = sqlcommand;
                cmd.ExecuteNonQuery();
                DB.conn.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace);
                DB.conn.Close();
            }
        }
Exemple #2
0
        private void Query_Delete()
        {
            try
            {
                DB.ConnectDB();
                string     sqlcommand = "delete from Book_Manager where Isbn = @p1";
                SqlCommand cmd        = new SqlCommand();

                cmd.Connection  = DB.conn;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@p1", textBox_isbn.Text);
                cmd.CommandText = sqlcommand;
                cmd.ExecuteNonQuery();
                DB.conn.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace);
                DB.conn.Close();
            }
        }
Exemple #3
0
        private void Query_Borrow(bool statusBorrow)
        {
            try
            {
                DB.ConnectDB();
                string     sqlcommand = "update Book_Manager set UserId = @p1, UserName = @p2, isBorrowed = @p3, BorrowedAt = @p4 where Isbn = @p5";
                SqlCommand cmd        = new SqlCommand();

                cmd.Connection  = DB.conn;
                cmd.CommandType = CommandType.Text;

                if (statusBorrow == false)
                {
                    cmd.Parameters.AddWithValue("@p1", textBox_id.Text);
                    User user = DB.Users.Single((x) => x.Id.ToString() == textBox_id.Text);
                    cmd.Parameters.AddWithValue("@p2", user.Name);
                    Book book = DB.Books.Single((x) => x.Isbn.ToString() == textBox_isbn.Text);
                    cmd.Parameters.AddWithValue("@p3", !(book.isBorrowed));
                    cmd.Parameters.AddWithValue("@p4", DateTime.Now);
                    cmd.Parameters.AddWithValue("@p5", textBox_isbn.Text);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@p1", "");
                    cmd.Parameters.AddWithValue("@p2", "");
                    Book book = DB.Books.Single((x) => x.Isbn.ToString() == textBox_isbn.Text);
                    cmd.Parameters.AddWithValue("@p3", !(book.isBorrowed));
                    cmd.Parameters.AddWithValue("@p4", "");
                    cmd.Parameters.AddWithValue("@p5", textBox_isbn.Text);
                }
                cmd.CommandText = sqlcommand;
                cmd.ExecuteNonQuery();
                DB.conn.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace);
                DB.conn.Close();
            }
        }
Exemple #4
0
        private void Query_Modify()
        {
            try
            {
                DB.ConnectDB();
                string     sqlcommand = "update User_Manager set Name = @p1 where Id = @p2";
                SqlCommand cmd        = new SqlCommand();

                cmd.Connection  = DB.conn;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@p1", textBox_Name.Text);
                cmd.Parameters.AddWithValue("@p2", textBox_ID.Text);
                cmd.CommandText = sqlcommand;
                cmd.ExecuteNonQuery();
                DB.conn.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace);
                DB.conn.Close();
            }
        }
Exemple #5
0
        private void Query_Insert()
        {
            try
            {
                DB.ConnectDB();
                string     sqlcommand = "Insert into User_Manager (Id, Name) values (@p1, @p2)";
                SqlCommand cmd        = new SqlCommand();

                cmd.Connection  = DB.conn;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@p1", textBox_ID.Text);
                cmd.Parameters.AddWithValue("@p2", textBox_Name.Text);
                cmd.CommandText = sqlcommand;
                cmd.ExecuteNonQuery();
                DB.conn.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace);
                DB.conn.Close();
            }
        }
Exemple #6
0
        private void Query_Modify()
        {
            try
            {
                DB.ConnectDB();
                string     sqlcommand = "update Book_Manager set Name = @p1, Publisher = @p2, Page = @p3 where Isbn = @p4";
                SqlCommand cmd        = new SqlCommand();

                cmd.Connection  = DB.conn;
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@p1", textBox_bookName.Text);
                cmd.Parameters.AddWithValue("@p2", textBox_publisher.Text);
                cmd.Parameters.AddWithValue("@p3", textBox_page.Text);
                cmd.Parameters.AddWithValue("@p4", textBox_isbn.Text);
                cmd.CommandText = sqlcommand;
                cmd.ExecuteNonQuery();
                DB.conn.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace);
                DB.conn.Close();
            }
        }