private void addBtn_Click(object sender, EventArgs e) { try { Convert.ToInt32(amountField.Text); } catch (FormatException e2) { MessageBox.Show("กรุณากรอกจำนวนเล่มที่ถูกต้อง"); return; } try { if(editionField.Text != "-") Convert.ToInt32(editionField.Text); } catch (FormatException e2) { MessageBox.Show("กรุณากรอกครั้งที่พิมพ์ที่ถูกต้อง"); return; } try { if(publishedYrBox.Text != "-") Convert.ToInt32(publishedYrBox.Text); } catch (FormatException e2) { MessageBox.Show("กรุณากรอกปีที่พิมพ์ที่ถูกต้อง"); return; } Book b = new Book(nameField.Text, subNameField.Text, writerField.Text, subwriterField.Text, translatorField.Text, editionField.Text, amountField.Text, publisherField.Text, publishedYrBox.Text, ISBNField.Text, deweyField.Text, categoryBox.Text); DBCommand.addBook(b); }
private void borrowBtn_Click(object sender, EventArgs e) { if(ISBNField.Text == "") { MessageBox.Show("กรุณากรอกเลขประจำหนังสือ (ISBN) ให้ถูกต้อง"); return; } //ยังคิดไม่ออก แต่ยืมได้ละ ขาดเวลาเล่มเดียวกันแต่คนละ edition (ซึ่งใน db จริงยังไม่มีกรณีนี้) Book b = new Book(nameField.Text, "", writerField.Text, "", "", "", "", "", "", ISBNField.Text, "", ""); DBCommand.brwBook(b, new Borrower(borrowerField.Text)); }
private void delBtn_Click(object sender, EventArgs e) { try { if(delISBNField.Text == "") { MessageBox.Show("กรุณากรอกเลขประจำหนังสือ (ISBN)"); } Book b = new Book(delnameField.Text, "", "", "", "", 0, Int32.Parse(delamountField.Text), "", 0, delISBNField.Text, "", ""); DBCommand.delBook(b); } catch (FormatException e2) { if (delamountField.Text == "") MessageBox.Show("กรุณากรอกจำนวนเล่ม"); else if (Int32.Parse(delamountField.Text) <= 0) MessageBox.Show("กรุณากรอกจำนวนเล่มที่ถูกต้อง"); } }
private void addBtn_Click(object sender, EventArgs e) { try { Book b = new Book(nameField.Text, subNameField.Text, writerField.Text, subwriterField.Text, translatorField.Text, Int32.Parse(editionField.Text), Int32.Parse(amountField.Text), publisherField.Text, Int32.Parse(publishedYrBox.Text), ISBNField.Text, deweyField.Text, categoryBox.Text); DBCommand.addBook(b); } catch (FormatException e2) { if (amountField.Text == "") MessageBox.Show("กรุณากรอกจำนวนเล่ม"); else if(Int32.Parse(amountField.Text) <= 0) MessageBox.Show("กรุณากรอกจำนวนเล่มที่ถูกต้อง"); else if(editionField.Text == "") MessageBox.Show("กรุณากรอกครั้งที่พิมพ์"); else if (Int32.Parse(editionField.Text) <= 0) MessageBox.Show("กรุณากรอกครั้งที่พิมพ์ที่ถูกต้อง"); else if (publishedYrBox.Text == "") MessageBox.Show("กรุณากรอกปีที่พิมพ์"); else if (Int32.Parse(publishedYrBox.Text) <= 0) MessageBox.Show("กรุณากรอกปีที่พิมพ์ที่ถูกต้อง"); } }
// submits a status update for a book to goodreads public static void submitBookStatus(Book book) { OAuth oAuth = new OAuth(); string statusURL = oAuth.getOAuthDataUrl("http://www.goodreads.com/user_status.xml"); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(statusURL); httpRequest.Method = "POST"; httpRequest.ContentType = "application/x-www-form-urlencoded"; string postData = "user_status[book_id]=" + book.GoodreadsId + "&user_status[page]=" + book.CurrentPage + "&user_status[body]=Added%20By%20Bibliomania"; httpRequest.ContentLength = postData.Length; StreamWriter stOut = new StreamWriter(httpRequest.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(postData); stOut.Close(); StreamReader stIn = new StreamReader(httpRequest.GetResponse().GetResponseStream()); string strResponse = stIn.ReadToEnd(); stIn.Close(); Console.WriteLine(strResponse); }
// adds a book to the currently reading shelf (statuses cannot be added for books not on this shelf) public static void addBookToShelf(Book book) { OAuth oAuth = new OAuth(); string shelfURL = oAuth.getOAuthDataUrl("http://www.goodreads.com/shelf/add_to_shelf.xml"); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(shelfURL); httpRequest.Method = "POST"; httpRequest.ContentType = "application/x-www-form-urlencoded"; string postData = "book_id=" + book.GoodreadsId + "&name=currently-reading"; httpRequest.ContentLength = postData.Length; StreamWriter stOut = new StreamWriter(httpRequest.GetRequestStream(), System.Text.Encoding.ASCII); stOut.Write(postData); stOut.Close(); StreamReader stIn = new StreamReader(httpRequest.GetResponse().GetResponseStream()); string strResponse = stIn.ReadToEnd(); stIn.Close(); Console.WriteLine(strResponse); }
public void ShowResults(Book b) { dataGridView1.Rows.Add(b.className, b.mas[0], b.mas[1], b.mas[2], b.mas[3], b.e, b.h, b.bc); }
private void delBtn_Click(object sender, EventArgs e) { try { Convert.ToInt32(delamountField); if(delISBNField.Text == "") { MessageBox.Show("กรุณากรอกเลขประจำหนังสือ (ISBN)"); return; } Book b = new Book(delnameField.Text, "", "", "", "", "", delamountField.Text, "", "", delISBNField.Text, "", ""); DBCommand.delBook(b); } catch (FormatException e2) { MessageBox.Show("กรุณากรอกจำนวนเล่ม"); } }
public static void delBook(Book b) { SQLiteConnection conn = new SQLiteConnection("data source=libDB.sqlite;"); SQLiteCommand cmd; string sql; try { conn.Open(); sql = $"SELECT * FROM bookData WHERE bookName = \"{b.bookName}\" AND ISBN = \"{b.ISBN}\";"; cmd = new SQLiteCommand(sql, conn); SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { sql = $"UPDATE bookData SET total = \"{Convert.ToInt32(reader["total"]) - Convert.ToInt32(b.total)}\", left = \"{Convert.ToInt32(reader["left"]) - Convert.ToInt32(b.total)}\" WHERE bookName = \"{b.bookName}\" AND ISBN = \"{b.ISBN}\";"; cmd = new SQLiteCommand(sql, conn); cmd.ExecuteNonQuery(); MessageBox.Show("ลบหนังสือจำนวน " + b.total + " เล่ม\nเรียบร้อยแล้ว"); if (Convert.ToInt32(reader["total"]) <= 0) { try { sql = $"DELETE FROM bookData WHERE bookName = \"{b.bookName}\" AND ISBN = \"{b.ISBN}\";"; cmd = new SQLiteCommand(sql, conn); cmd.ExecuteNonQuery(); } catch (SQLiteException e) { Console.WriteLine(e); } } } } finally { if (conn.State != System.Data.ConnectionState.Closed) conn.Close(); } }
public static void brwBook(Book b, Borrower br) { SQLiteConnection conn = new SQLiteConnection("data source=libDB.sqlite;"); SQLiteCommand cmd; string sql; int rowID = 0; try { conn.Open(); sql = $"SELECT ROWID FROM bookData WHERE bookName = \"{b.bookName}\" AND ISBN = \"{b.ISBN}\" AND writer LIKE \"%{b.writer}%\";"; cmd = new SQLiteCommand(sql, conn); SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) rowID = Convert.ToInt32(reader["ROWID"]); sql = $"SELECT * FROM bookData WHERE bookName = \"{b.bookName}\" AND ISBN = \"{b.ISBN}\" AND writer LIKE \"%{b.writer}%\";"; cmd = new SQLiteCommand(sql, conn); reader = cmd.ExecuteReader(); if (reader.HasRows) { if (Convert.ToInt32(reader["left"]) > 0) { try { sql = $"INSERT INTO borrowData VALUES (\"{br.name}\", \"{DateTime.Now}\", \"{rowID}\");"; cmd = new SQLiteCommand(sql, conn); cmd.ExecuteNonQuery(); sql = $"UPDATE bookData SET left = \"{Convert.ToInt32(reader["left"]) - 1}\" WHERE bookName = \"{b.bookName}\" AND ISBN = \"{b.ISBN}\" AND writer LIKE \"%{b.writer}%\""; cmd = new SQLiteCommand(sql, conn); cmd.ExecuteNonQuery(); MessageBox.Show("ยืมสำเร็จ"); } catch (SQLiteException e) { Console.WriteLine(e); } } else { MessageBox.Show("ยืมไม่สำเร็จ"); } } } finally { if (conn.State != System.Data.ConnectionState.Closed) conn.Close(); } }
public static void addBook(Book b) { SQLiteConnection conn = new SQLiteConnection("data source=libDB.sqlite;"); SQLiteCommand cmd; try { conn.Open(); string sql = String.Format("SELECT * FROM bookData WHERE bookName = \"{0}\" AND ISBN LIKE \"%{1}%\";", b.bookName, b.ISBN); cmd = new SQLiteCommand(sql, conn); SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { try { int total = Int32.Parse(reader["total"].ToString()); int left = Int32.Parse(reader["left"].ToString()); string sql2 = String.Format("UPDATE bookData SET total = \"{0}\",left = \"{1}\" WHERE bookName = \"{2}\" AND ISBN LIKE \"%{3}%\";", total + b.total, left + b.total, b.bookName, b.ISBN); cmd = new SQLiteCommand(sql2, conn); cmd.ExecuteNonQuery(); MessageBox.Show("เพิ่มหนังสือเรียบร้อยแล้ว"); } catch (SQLiteException e) { Console.WriteLine(e); } } } else { try { string sql3 = $"INSERT INTO bookData VALUES (\"{b.bookName}\", \"{b.bookSubname}\", \"{b.writer}\", \"{b.subwriter}\", \"{b.translator}\", \"{b.edition}\", " + $"\"{b.total}\", \"{b.publisher}\", \"{b.publishedYr}\", \"{b.ISBN}\", \"{b.deweyNumber}\", \"{b.category}\", \"{b.total}\", \"true\")"; cmd = new SQLiteCommand(sql3, conn); cmd.ExecuteNonQuery(); MessageBox.Show("เพิ่มหนังสือเรียบร้อยแล้ว"); } catch (SQLiteException e) { Console.WriteLine(e); } } } finally { if (conn.State != System.Data.ConnectionState.Closed) conn.Close(); } }