public bool add_book(Book_node book) { bool back_value = false; string str_sql = "insert into bookos_book (book_id, book_name, book_author, book_count) values ( "; str_sql += "\"" + book.book_id + "\","; str_sql += "\"" + book.book_name + "\","; str_sql += "\"" + book.book_author + "\","; str_sql += book.book_count.ToString(); str_sql += ")"; MySqlCommand cmd = new MySqlCommand(str_sql, this.con); this.con.Open(); back_value = (cmd.ExecuteNonQuery() == 0 ? false : true); this.con.Close(); return(back_value); }
private void button_change_book_information_Click(object sender, EventArgs e) { ArrayList arr = new ArrayList(); foreach (DataGridViewRow select_row in dataGridView_book_list.SelectedRows) { Book_node add_node = new Book_node(); add_node.book_id = select_row.Cells["book_id"].Value.ToString(); add_node.book_name = select_row.Cells["book_name"].Value.ToString(); add_node.book_author = select_row.Cells["book_author"].Value.ToString(); add_node.book_count = Convert.ToInt32(select_row.Cells["book_count"].Value); arr.Add(add_node); } Form form_change = new Form_change_info(arr); form_change.Show(); }
public Form_change_info(ArrayList arr) { InitializeComponent(); wait_change_list = arr; while (dataGridView_book_list.Rows.Count != 0) { dataGridView_book_list.Rows.RemoveAt(0); } for (int i = 0; i < wait_change_list.Count; i++) { Book_node node = (Book_node)wait_change_list[i]; dataGridView_book_list.Rows.Add( i.ToString(), node.book_id, node.book_name, node.book_author, node.book_count.ToString() ); } dataGridView_book_list.ReadOnly = false; dataGridView_book_list.EditMode = DataGridViewEditMode.EditOnEnter; }
public ArrayList get_book() { //获取存储在数据库中的所有图书 ArrayList back_list = new ArrayList(); string str_sql = "select * from bookos_book"; MySqlCommand cmd = new MySqlCommand(str_sql, this.con); this.con.Open(); MySqlDataReader result = cmd.ExecuteReader(); while (result.Read()) { Book_node add_node = new Book_node(); add_node.book_id = result.GetString("book_id"); add_node.book_name = result.GetString("book_name"); add_node.book_author = result.GetString("book_author"); add_node.book_count = result.GetInt32("book_count"); back_list.Add(add_node); } this.con.Close(); return(back_list); }
private void button_renew_book_list_Click(object sender, EventArgs e) { operate op = new operate(); ArrayList arr_book = new ArrayList(); arr_book = op.get_book(); while (dataGridView_book_list.Rows.Count != 0) { dataGridView_book_list.Rows.RemoveAt(0); } for (int i = 0; i < arr_book.Count; i++) { Book_node node = (Book_node)arr_book[i]; dataGridView_book_list.Rows.Add( i.ToString(), node.book_id, node.book_name, node.book_author, node.book_count.ToString() ); } }