//Return Button private void btnReturn_Click(object sender, EventArgs e) { //Assign Return Date and Update Return Date of the selected Items in BookRentalItems File String strCurrentDate = Convert.ToString(DateTime.Today.ToString("dd-MMM-yy")); LoanItems.updLoanItems(intLoanID, intBookID, strCurrentDate); //Instantiate DateTime object and Calculate Number of Days DateTime dtToday = DateTime.Today.Date; DateTime dtDue = dtpDueDate.Value.Date; double dblTotalDays = numberOfDays(dtToday, dtDue); //Check if book is overdue //If book is not overdue (Total Days <= 0) if (dblTotalDays <= 0) { //Method to do Updates updDetails(); } else //Fine Detected { //Display Error Message MessageBox.Show("Book '" + txtBookTitle.Text + "' Overdue", "Overdue", MessageBoxButtons.OK, MessageBoxIcon.Information); //Calculates Fine double dblFine = dblTotalDays * Loans.PENALTY; //Update Fine Amount of LoanItem LoanItems.updLoanItemFine(intLoanID, intBookID, dblFine); //Display Fine Details on UI dtpFDueDate.Value = Convert.ToDateTime(strReturnDate); dtpReturnDate.Value = DateTime.Today; txtFine.Text = dblFine.ToString("0.00"); grpFineDetails.Visible = true; //Hide Loan Details Return Button //Hide Clear Button to prevent User from exiting current steps btnClear.Visible = false; btnSMem.SetBounds(253, 16, 83, 23); btnReturn.Visible = false; } }
} //End click event //Private Method to Save Rental Items private void saveRentalItems() { //For item in lstCart from 0 to lstCart total items - 1 for (int i = 0; i < lstCart.Items.Count; i++) { //Instantiate LoanItems Object LoanItems aLoanItem = new LoanItems(); aLoanItem.setLoanID(Convert.ToInt32(txtLoanID.Text)); aLoanItem.setBookID(Convert.ToInt32(lstCart.Items[i].ToString().Substring(0, 4))); //Save Rental Item Detials aLoanItem.regLoanItems(); //Update book status in Book File Loans.updBookStatus(Convert.ToInt32(lstCart.Items[i].ToString().Substring(0, 4)), 'U'); //Update No. Books Borrow of the member in Member File Loans.updBooksBorrowIncrement(aMember.getMemID()); } //End For } //End saveRentalItems();
} //End Update //Method to prompt user more books to be returned for same Member? public void returnMoreBooks() { //Check if RowCount is not equal to 1. //1 indicate that there is only one book left on grdLoanItemList if (grdLoanItemList.RowCount != 1) { DialogResult result = MessageBox.Show("More books to be return for Member '" + txtMemName.Text + "'?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { //Display Loan Items on DataGridView for the selected Member //Initiate DataSet Object DataSet ds = new DataSet(); //Reload data onto DataGridView //LoanItemList grdLoanItemList.DataSource = LoanItems.getLoanItems(ds, intMemID).Tables["loan"]; //Display UI grpLoanItemList.Visible = true; //Hide grpLoanDetails and grpFineDetails grpLoanDetails.Visible = false; btnReturn.Visible = true; grpFineDetails.Visible = false; } else { //Reset UI because Member may return only one book clearUI(); } } else { //Display Information Message MessageBox.Show("All books has been returned", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); //Reset UI clearUI(); } } //End Method
} //End Search Member Button Event //MemList cell click event private void grdMemList_CellClick(object sender, DataGridViewCellEventArgs e) { //Extract MemID from column 0 of selected row intMemID = Convert.ToInt32(grdMemList.Rows[grdMemList.CurrentCell.RowIndex].Cells[0].Value); //Instantiate Members object Members aMember = new Members(); aMember.getMember(intMemID); String strName = aMember.getForename() + " " + aMember.getSurname(); //Display Loan Items on DataGridView for the selected Member //Initiate DataSet Object DataSet ds = new DataSet(); //Load data onto DataGridView //LoanItemList grdLoanItemList.DataSource = LoanItems.getLoanItems(ds, intMemID).Tables["loan"]; if (grdLoanItemList.DataSource == null || grdLoanItemList.RowCount == 0) { //Display error message if no data returned MessageBox.Show("No Rental Items found for Member '" + strName + "'", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); grpLoanItemList.Visible = false; grpLoanDetails.Visible = false; txtSurname.Focus(); } else { //Display UI grpLoanItemList.Visible = true; //Disable Sorting when clicking Column Header foreach (DataGridViewColumn column in grdLoanItemList.Columns) { column.SortMode = DataGridViewColumnSortMode.NotSortable; } } } //End Cell Click Event
} //End Search Button Event //Cell Click Event private void grdMemberList_CellClick(object sender, DataGridViewCellEventArgs e) { //Variable to store Member ID int intMemID = Convert.ToInt32(grdMemberList.Rows[grdMemberList.CurrentCell.RowIndex].Cells[0].Value); //List Loan Item Details of the Member //Instantiate DataSet object DataSet ds = new DataSet(); //Load Data onto data grid grdLoanList.DataSource = LoanItems.getLoanItemsHistory(ds, intMemID).Tables["loan"]; //Check if any data source return, if no data return display message if (grdLoanList.DataSource == null || grdLoanList.RowCount == 0) { //Reset UI MessageBox.Show("No details found", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); txtSurname.Text = ""; txtForename.Text = ""; txtSurname.Focus(); grpLoanItems.Visible = false; grdMemberList.Visible = false; } else { //Set Visibility grpLoanItems.Visible = true; //Disable Sorting when clicking Column Header foreach (DataGridViewColumn column in grdLoanList.Columns) { column.SortMode = DataGridViewColumnSortMode.NotSortable; } //Set lblMemName Text lblMemName.Text = txtForename.Text.ToUpperInvariant() + " " + txtSurname.Text.ToUpperInvariant(); } } //End Cell Click Event