protected void Page_Load(object sender, EventArgs e) { LibraryAddLink.NavigateUrl = addLibraryUrl; if (!IsPostBack) { DataTable dt = DatabaseHelper.Retrieve(@" Select Id, BranchName, Address, Zipcode, State From Library "); Libraries.DataSource = dt.Rows; Libraries.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (edit) { AddOrEdit.Text = "Edit Librarian"; Cancel.Visible = true; if (!int.TryParse(Request.QueryString["ID"], out librarianId)) { Response.Redirect(LibrarianList); } if (!IsPostBack) { DataTable dt = DatabaseHelper.Retrieve(@" select Librarian.LibraryCardNumber, LibraryId from Librarian join Library on (Librarian.LibraryId = Library.Id) join Patron on (Librarian.LibraryCardNumber = Patron.LibraryCardNumber) where Librarian.Id = @LibrarianId ", new SqlParameter("@LibrarianId", librarianId)); if (dt.Rows.Count == 1) { int selectedPatronId = dt.Rows[0].Field <int>("LibraryCardNumber"); int selectedLibraryId = dt.Rows[0].Field <int>("LibraryId"); Patrons.SelectedValue = selectedPatronId.ToString(); Libraries.SelectedValue = selectedLibraryId.ToString(); } else { Response.Redirect(LibrarianList); } } } else { AddOrEdit.Text = "Add Librarian"; } if (!IsPostBack) { DataTable dt = DatabaseHelper.Retrieve(@" select LibraryCardNumber, FirstName + ' ' + LastName As Name from Patron "); Patrons.DataValueField = "LibraryCardNumber"; Patrons.DataTextField = "Name"; Patrons.AppendDataBoundItems = true; Patrons.Items.Add(new ListItem("Select Value...", string.Empty)); Patrons.DataSource = dt; Patrons.DataBind(); DataTable dt2 = DatabaseHelper.Retrieve(@" select BranchName, Id from Library "); Libraries.DataValueField = "Id"; Libraries.DataTextField = "BranchName"; Libraries.AppendDataBoundItems = true; Libraries.Items.Add(new ListItem("Select Value...", string.Empty)); Libraries.DataSource = dt2; Libraries.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (edit) { AddOrEdit.Text = "Edit Book Copy"; Cancel.Visible = true; CheckedOutLabel.Visible = true; CheckedOut.Visible = true; AvailableLabel.Visible = true; Available.Visible = true; if (!int.TryParse(Request.QueryString["ID"], out bookCopyId)) { Response.Redirect(BookCopyList); } if (!IsPostBack) { DataTable dt = DatabaseHelper.Retrieve(@" select Book.Id as BookId, BookCopy.LibraryId as LibraryId, Out, Available from BookCopy join Book on (BookCopy.BookId = Book.Id) where BookCopy.Id = @BookCopyId ", new SqlParameter("@BookCopyId", bookCopyId)); if (dt.Rows.Count == 1) { int selectedBookId = dt.Rows[0].Field <int>("BookId"); int selectedLibraryId = dt.Rows[0].Field <int>("LibraryId"); bool selectedOut = dt.Rows[0].Field <bool>("Out"); bool selectedAvailable = dt.Rows[0].Field <bool>("Available"); Books.SelectedValue = selectedBookId.ToString(); Libraries.SelectedValue = selectedLibraryId.ToString(); CheckedOut.Checked = selectedOut; Available.Checked = selectedAvailable; } else { Response.Redirect(BookCopyList); } } } else { AddOrEdit.Text = "Add Book Copy"; } if (!IsPostBack) { DataTable dt = DatabaseHelper.Retrieve(@" select Book.Id as BookId, Title + ' By: ' + FirstName + ' ' + LastName as BookName from Book join Author on Book.AuthorId = Author.Id "); Books.DataValueField = "BookId"; Books.DataTextField = "BookName"; Books.AppendDataBoundItems = true; Books.Items.Add(new ListItem("Select Value...", string.Empty)); Books.DataSource = dt; Books.DataBind(); DataTable dt2 = DatabaseHelper.Retrieve(@" select BranchName, Id from Library "); Libraries.DataValueField = "Id"; Libraries.DataTextField = "BranchName"; Libraries.AppendDataBoundItems = true; Libraries.Items.Add(new ListItem("Select Value...", string.Empty)); Libraries.DataSource = dt2; Libraries.DataBind(); } }