/// <summary> /// This is not an actual constructor but the code runs whenever the User Control gets visible. /// </summary> private void UCAddBook_VisibleChanged(object sender, EventArgs e) { if (Visible) { if (UIExtension.operation == UIExtension.Operation.Add) { lblTitle.Text = "Add New Book"; pbNew.Visible = true; ClearAuthorFilter(); UIExtension.ClearTextBoxesInPanel(pnlBookInfo); lvBookAuthors.Items.Clear(); ToggleBookCopyVisibility(false); UIExtension.EnableTextbox(txtISBN); } else if (UIExtension.operation == UIExtension.Operation.Edit) { currentBook = UIExtension.currentItem as Book; StoreTemporaryBook(currentBook); lblTitle.Text = $"Edit {currentBook}"; pbNew.Visible = false; ToggleBookCopyVisibility(true); InsertAuthors(); txtISBN.Text = currentBook.ISBN; txtTitle.Text = currentBook.Title; txtYear.Text = currentBook.Year.ToString(); txtDescription.Text = currentBook.Description; UIExtension.DisableTextbox(txtISBN); } } else { ClearAuthorFilter(sender, e); } }
/// <summary> /// This is not an actual constructor but the code runs whenever the User Control gets visible. /// </summary> private void UCReturnBook_VisibleChanged(object sender, EventArgs e) { if (Visible) { currentLoan = UIExtension.currentItem as Loan; UIExtension.ClearTextBoxesInPanel(pnlBookInfo); UIExtension.ClearTextBoxesInPanel(pnlLoanInfo); btnReturnLoan.Enabled = true; btnReturnLoan.BackColor = btnReturnLoanBackColor; lblMessage.Visible = false; lblBookTitle.Text = currentLoan.BookCopy.Book.ToString(); txtISBN.Text = currentLoan.BookCopy.Book.ISBN; txtBookCopy.Text = currentLoan.BookCopy.ToString(); txtAuthor.Text = currentLoan.BookCopy.Book.AuthorsToString(); txtYear.Text = currentLoan.BookCopy.Book.Year.ToString(); txtDescription.Text = currentLoan.BookCopy.Book.Description; lblOnTime.Visible = false; txtOnTime.Visible = false; lblReturned.Visible = false; txtReturned.Visible = false; lblDebt.Visible = false; txtDebt.Visible = false; UpdateLoanInfo(); } }
// <-- Local methods. // Misc. functionality. --> private void btnSave_Click(object sender, EventArgs e) { if (lvBookAuthors.Items.Count == 0 || txtISBN.Text.Trim() == "" || txtTitle.Text.Trim() == "" || txtYear.Text.Trim() == "") { UIExtension.ShowMessage(messageTimer, lblMessage, $"You must enter values for all required fields!", Color.Red); } else { try { List <Author> authorList = new List <Author>(); foreach (ListViewItem author in lvBookAuthors.Items) { authorList.Add(author.Tag as Author); } if (UIExtension.operation == UIExtension.Operation.Add) { Book book = new Book(txtISBN.Text.Trim(), txtTitle.Text.Trim(), authorList, Convert.ToInt64(txtYear.Text.Trim()), txtDescription.Text.Trim()); form.bookService.Add(book); form.bookCopyService.Add(new BookCopy(book)); UIExtension.ShowMessage(messageTimer, lblMessage, $"{txtTitle.Text.Trim()} was successfully added to the library!", Color.Green); ClearAuthorFilter(sender, e); UIExtension.ClearTextBoxesInPanel(pnlBookInfo); lvBookAuthors.Items.Clear(); } else { currentBook.Authors = authorList; currentBook.Title = txtTitle.Text.Trim(); currentBook.Year = Convert.ToInt64(txtYear.Text.Trim()); currentBook.Description = txtDescription.Text.Trim(); form.bookService.Edit(currentBook); lblTitle.Text = $"Edit {currentBook}"; UIExtension.ShowMessage(messageTimer, lblMessage, $"{currentBook} was successfully edited!", Color.Green); } } catch (FormatException) { UIExtension.ShowMessage(messageTimer, lblMessage, $"You need to enter a valid value for Year", Color.Red); if (UIExtension.operation == UIExtension.Operation.Edit) { RestoreBook(currentBook); } } catch (Exception exception) { UIExtension.ShowMessage(messageTimer, lblMessage, exception.Message, Color.Red); if (UIExtension.operation == UIExtension.Operation.Edit) { RestoreBook(currentBook); } } } }
/// <summary> /// This is not an actual constructor but the code runs whenever the User Control gets visible. /// </summary> private void UCViewMember_VisibleChanged(object sender, EventArgs e) { if (Visible) { this.currentMember = UIExtension.currentItem as Member; UpdateMemberInformation(); UpdatelvLoans(); UIExtension.ClearTextBoxesInPanel(pnlLoanInformation); ActiveControl = null; pnlLoanInformation.Visible = false; } }
// Focus events. --> private void lvLoans_SelectedIndexChanged(object sender, EventArgs e) { if (lvLoans.SelectedItems.Count == 0) { UIExtension.ClearTextBoxesInPanel(pnlLoanInformation); } else { pnlLoanInformation.Visible = true; UpdateLoanInformation(sender, e); } }
private void UpdateLoanInformation(object sender, EventArgs e) { UIExtension.ClearTextBoxesInPanel(pnlLoanInformation); if (lvLoans.SelectedItems.Count > 0) { Loan selectedLoan = lvLoans.SelectedItems[0].Tag as Loan; double daysOverdue = form.loanService.CalculateDaysOverdue(selectedLoan); txtBook.Text = selectedLoan.BookCopy.Book.Title; txtDateOfLoan.Text = selectedLoan.DateOfLoan.Value.ToShortDateString(); txtDueDate.Text = selectedLoan.DueDate.Value.ToShortDateString(); txtOverdue.Text = daysOverdue.ToString() + " day(s)"; txtDebt.Text = $"{selectedLoan.Debt} kr"; if (selectedLoan.DateOfReturn == null) { txtTimeOfReturn.Text = "-"; UIExtension.HideLabelAndTextbox(lblOnTime, txtOnTime); } else { txtTimeOfReturn.Text = selectedLoan.DateOfReturn.Value.ToShortDateString(); UIExtension.ShowLabelAndTextbox(lblOnTime, txtOnTime); } if (daysOverdue > 0) { UIExtension.ShowLabelAndTextbox(lblOverdue, txtOverdue); txtOnTime.ForeColor = Color.Red; txtOnTime.Text = "No"; UIExtension.ShowLabelAndTextbox(lblOnTime, txtOnTime); UIExtension.ShowLabelAndTextbox(lblDebt, txtDebt); } else { UIExtension.HideLabelAndTextbox(lblOverdue, txtOverdue); txtOnTime.ForeColor = Color.Green; txtOnTime.Text = "Yes"; UIExtension.HideLabelAndTextbox(lblDebt, txtDebt); } } }
private void UpdateMemberInformation() { UIExtension.ClearTextBoxesInPanel(pnlMemberInformation); if (currentMember != null) { double totalDebt = form.memberService.CalculateTotalDebt(currentMember); txtFirstname.Text = currentMember.FirstName; txtLastName.Text = currentMember.LastName; txtUsername.Text = currentMember.Username; txtPersonalID.Text = currentMember.PersonalID; txtRegistered.Text = currentMember.Registered.Value.ToShortDateString(); if (totalDebt == 0) { txtTotalDebt.ForeColor = Color.Green; } else { txtTotalDebt.ForeColor = Color.Red; } txtTotalDebt.Text = $"{totalDebt.ToString()} kr"; } }