Пример #1
0
        public BookHandler(Books BookInfo, frmBookViewer.SaveOrUpdateDelete saveOrUpdateDelete, string old_ISBN, out bool success)
        {
            if (saveOrUpdateDelete == frmBookViewer.SaveOrUpdateDelete.Save)
            {
                qry = "INSERT INTO Books (Title,Author,ISBN,Year,Pages,Price,In_Stock,Hired_Out,pic)" +
                      "VALUES (@Title,@Author,@ISBN,@Year,@Pages,@Price,@In_Stock,@Hired_Out,@pic)";
            }
            else if (saveOrUpdateDelete == frmBookViewer.SaveOrUpdateDelete.Update)
            {
                qry = "UPDATE Books SET Title = @Title,Author = @Author,ISBN = @ISBN,Year = @Year," +
                      "Pages = @Pages,Price = @Price,In_Stock = @In_Stock,Hired_Out = @Hired_Out, pic = @pic WHERE ISBN = @OLD_ISBN";
            }
            else
            {
                qry = "DELETE FROM Books WHERE ISBN = @ISBN";
            }

            using (MySqlConnection Connection = new MySqlConnection(MyConString))
            {
                success = false;

                try
                {
                    MySqlCommand cmd = new MySqlCommand(qry, Connection);
                    cmd.Parameters.Add(new MySqlParameter("@Title", (object)BookInfo.Title));
                    cmd.Parameters.Add(new MySqlParameter("@Author", (object)BookInfo.Author));
                    cmd.Parameters.Add(new MySqlParameter("@ISBN", (object)BookInfo.ISBN));
                    cmd.Parameters.Add(new MySqlParameter("@Year", (object)BookInfo.Year));
                    cmd.Parameters.Add(new MySqlParameter("@Pages", (object)BookInfo.Pages));
                    cmd.Parameters.Add(new MySqlParameter("@Price", (object)BookInfo.Price));
                    cmd.Parameters.Add(new MySqlParameter("@In_Stock", (object)BookInfo.In_Stock));
                    cmd.Parameters.Add(new MySqlParameter("@Hired_Out", (object)BookInfo.Hired_Out));
                    cmd.Parameters.Add(new MySqlParameter("@pic", (object)BookInfo.pic));
                    cmd.Parameters.Add(new MySqlParameter("@OLD_ISBN", (object)old_ISBN));

                    Connection.Open();
                    cmd.ExecuteNonQuery();
                    success = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    Connection.Close();
                }
            }
        }
Пример #2
0
        private void List()
        {
            using (MySqlConnection Connection = new MySqlConnection(MyConString))
            {
                try
                {
                    Connection.Open();
                    MySqlCommand cmd = new MySqlCommand(qry, Connection);
                    MySqlDataReader reader;
                    reader = cmd.ExecuteReader();
                    int Count = 0;

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            Books BookInfo = new Books
                            {
                                Title = reader["Title"].ToString(),
                                Author = reader["Author"].ToString(),
                                ISBN = reader["ISBN"].ToString(),
                                Year = reader["Year"].ToString(),
                                Pages = int.Parse(reader["Pages"].ToString()),
                                Price = decimal.Parse(reader["Price"].ToString()),
                                In_Stock = int.Parse(reader["In_Stock"].ToString()),
                                Hired_Out = int.Parse(reader["Hired_Out"].ToString()),
                                pic = (byte[])reader["pic"],
                            };

                           Test[Count] = BookInfo;
                           Count++;
                        }
                    }
                    else
                    {
                        MessageBox.Show("No Books where found", "Books", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    Connection.Close();
                }
            }
        }
Пример #3
0
 public BookHandler(out Books[] books)
 {
     ListWithOutFilter();
     books = Test;
 }
Пример #4
0
 public BookHandler(out Books[] books, string Column, string Value)
 {
     ListWithFilter(Column, Value);
     books = Test;
 }
Пример #5
0
        private bool SaveOrUpdateOrDeleteSQL(SaveOrUpdateDelete saveOrUpdateDelete)
        {
            bool success;

            if (coverPictureBox.ImageLocation == null)
            {
                coverPictureBox.ImageLocation = Application.StartupPath + "\\No_Image.jpeg";
            }

            Books BookInfo = new Books
            {
                Title = titleTextBox.Text,
                Author = authorTextBox.Text,
                ISBN = isbnTextBox.Text,
                Year = yearTextBox.Text,
                Pages = int.Parse(pagesTextBox.Text),
                Price = decimal.Parse(priceTextBox.Text, NumberStyles.Any),
                pic = ReadFile(coverPictureBox.ImageLocation),
                In_Stock = int.Parse(instocktextBox.Text),
                Hired_Out = int.Parse(hiredtextBox.Text),
            };

            new BookHandler(BookInfo, saveOrUpdateDelete, Old_ISBN, out success);
            return success;
        }