private void LoadBooks() { taBook.Fill(ds1.Book); taBookHistory.Fill(ds1.BookHistory); dt = new DataTable(); dt.Columns.Add(new DataColumn("Book Id", typeof(string))); dt.Columns.Add(new DataColumn("Book", typeof(string))); dt.Columns.Add(new DataColumn("Author", typeof(string))); dt.Columns.Add(new DataColumn("Publisher", typeof(string))); dt.Columns.Add(new DataColumn("Category", typeof(string))); dt.Columns.Add(new DataColumn("Available", typeof(Int32))); DataRow drTemp; foreach (DataRow dr in ds1.Book.Rows) { drTemp = dt.NewRow(); drTemp[0] = dr["BookID"].ToString(); drTemp[1] = dr["Book"].ToString(); drTemp[2] = dr["Author"].ToString(); drTemp[3] = dr["Publisher"].ToString(); drTemp[4] = dr["Category"].ToString(); drTemp[5] = Convert.ToInt32(dr["Copies"].ToString()) - this.GetTotalReservedBooks(Convert.ToInt32(dr["BookID"].ToString())); dt.Rows.Add(drTemp); } }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { //CommandName is property to find which Commmand Field has been clicked by user if (e.CommandName == "Select") { // Select the row which is clicked by the user GridViewRow row = GridView1.Rows[Convert.ToInt32(e.CommandArgument)]; txtTitleBook.Text = row.Cells[3].Text; txtAuthor.Text = row.Cells[4].Text; txtPublisher.Text = row.Cells[5].Text; txtBkCategory.Text = row.Cells[6].Text; txtCopies.Text = row.Cells[7].Text; updateID = Convert.ToInt16(row.Cells[2].Text); this.btnSave.Text = "Update"; } if (e.CommandName == "Delete") { taBookHistory.Fill(ds1.BookHistory); GridViewRow row = GridView1.Rows[Convert.ToInt32(e.CommandArgument)]; DataRow[] dRows = ds1.BookHistory.Select("MemberID=" + row.Cells[2].Text + " AND DateReturned NOT IS NULL"); if (dRows.Length < 0) { taBook.Fill(ds1.Book); DataRow[] dr = ds1.Book.Select("BookID=" + row.Cells[2].Text); dr[0].Delete(); taBook.Update(ds1.Book); GridView1.DataBind(); } else { this.PromptMessage("Cannot delete member profile with books issued or unpaid overdues."); } } }
private void LoadReservedBooks() { taMember.Fill(ds1.Member); taBookHistory.Fill(ds1.BookHistory); DataView dvBookHistory = ds1.BookHistory.DefaultView; dvBookHistory.RowFilter = "MemberID = " + Convert.ToInt32(this.ddlMember.Text) + " AND DateReturned IS NULL "; foreach (DataRowView dRowView in dvBookHistory) { lstReservedBooks.Items.Add(new ListItem(dRowView[2].ToString(), dRowView[1].ToString())); } }