/// <summary> /// Check Out button event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnCheckOut_Click(object sender, EventArgs e) { int selectedBookID = 0; if (!String.IsNullOrWhiteSpace(Request.QueryString["bookID"])) { selectedBookID = int.Parse(Request.QueryString["bookID"]); } else { Utilities.Utilities.setPageMessage("Please select a book.", Utilities.Utilities.severity.error, Page.Master); return; } BusinessLogicDBOperations dbOperations = new BusinessLogicDBOperations(); string bookName = txtName.Text; string mobileNo = txtMobile.Text; string nationalID = txtNationalID.Text; DateTime checkOutDate = DateTime.Parse(lblCheckOutDate.Text); DateTime returnDate = DateTime.Parse(lblReturnDate.Text); var book = dbOperations.RetrieveBooksList().Where(x => x.BookID == selectedBookID).FirstOrDefault(); if (book != null && book.CheckOutStatusID == 1) // CheckOutStatusID 1 is check in { int result = dbOperations.CheckOut(selectedBookID, bookName, mobileNo, nationalID, checkOutDate, returnDate ); if (result == 0) { Utilities.Utilities.setPageMessage("Encountered an error while checking out.", Utilities.Utilities.severity.error, Page.Master); return; } Utilities.Utilities.setPageMessage("Book has been checked out in the name of " + txtName.Text, Utilities.Utilities.severity.info, Page.Master); displayBookCheckOutHistory(selectedBookID); } else { Utilities.Utilities.setPageMessage("Book is already checkout", Utilities.Utilities.severity.error, Page.Master); } }
/// <summary> /// Check Out button event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void BtnCheckOut_Click(object sender, EventArgs e) { btnCheckOut.Enabled = false; int selectedBookID = 0; if (!String.IsNullOrWhiteSpace(Request.QueryString["bookID"])) { selectedBookID = int.Parse(Request.QueryString["bookID"]); BusinessLogicDBOperations dbOperations = new BusinessLogicDBOperations(); string bookName = txtName.Text; string mobileNo = txtMobile.Text; string nationalID = txtNationalID.Text; DateTime checkOutDate = DateTime.Parse(lblCheckOutDate.Text); DateTime returnDate = DateTime.Parse(lblReturnDate.Text); DateTime dt; try { dt = hdnField.Value.FromJson <DateTime>(); } catch (Exception) { Utilities.Instance.SetPageMessage("Either the book is not available or already checked out. Please try to refresh again", Utilities.Severity.Error, Page.Master); return; } int result = dbOperations.CheckOut(selectedBookID, bookName, mobileNo, nationalID, checkOutDate, returnDate, dt ); switch (result) { case 0: { Utilities.Instance.SetPageMessage("There was an error occured. Request can not be fulfil at the current movement.", Utilities.Severity.Error, Page.Master); return; } case 404: { Utilities.Instance.SetPageMessage("Either the book is not available or already checked out", Utilities.Severity.Error, Page.Master); return; } default: { Utilities.Instance.SetPageMessage("Book has been checked out in the name of " + txtName.Text, Utilities.Severity.Info, Page.Master); DisplayBookCheckOutHistory(selectedBookID); break; } } } else { Utilities.Instance.SetPageMessage("The resource you are trying to access is not available", Utilities.Severity.Error, Page.Master); } }