public void BorrowBook() { try { //show a loading message View.ShowLoading(); using (IServiceClientProxy proxy = new IServiceClientProxy(binding, new ProtocolVersion11())) { //execute the borrow request int bookId = LibraryModelSingleton.Instance.Book.ID; int userId = LibraryModelSingleton.Instance.User.ID; Borrow borrowRequest = new Borrow() { bookID = bookId, userID = userId }; BorrowResponse response = proxy.Borrow(borrowRequest); //show positive a message if the result is valid otherwise a negative message //and return in the welcome page state = InnerState.WELCOME; string msg = (response.BorrowResult.StartDate.Equals(DateTime.MinValue)) ? BORROW_FAILED_MSG : OPERATION_COMPLETED_MSG; View.ShowMessageWithButton(msg, () => { View.ShowWelcomePage(); }); } } //show a message and then returns in the login page catch (Exception) { View.ShowMessageWithButton(ERROR_MSG, () => { this.Logout(); }); } }
public void RecognizeBarcode(Bitmap bitmap) { if (state != InnerState.BORROWING && state != InnerState.RETURNING) { throw new InvalidOperationException("The user is in an invalid state!"); } if (bitmap == null) { //invalid request, show in the welcome page View.ShowWelcomePage(); return; } try { short port = 0; //show a loading message View.ShowLoading(); //call the web service to send the picture using (IServiceClientProxy proxy = new IServiceClientProxy(binding, new ProtocolVersion11())) { SendBarcodeImage sendImageRequest = new SendBarcodeImage(); SendBarcodeImageResponse response = proxy.SendBarcodeImage(sendImageRequest); port = response.SendBarcodeImageResult; //send the image string code = SendImage(port, GHI.Utilities.Bitmaps.ConvertToFile(bitmap)); if (code == null) { //the bar code was not recognized //show the camera page View.ShowMessageWithButton(CODE_NOT_RECOGNIZED_MSG, () => { View.ShowCamera(); }); return; } //get book info GetBookInformationsResponse bookInfoResponse = proxy.GetBookInformations(new GetBookInformations() { barcode = code }); if (bookInfoResponse.GetBookInformationsResult.ISBN == null) { //the book is not in the WS database View.ShowMessageWithButton(INVALID_BARCODE_MSG, () => { View.ShowCamera(); }); return; } LibraryModelSingleton.Instance.Book = bookInfoResponse.GetBookInformationsResult; if (state == InnerState.BORROWING) { //show the book information View.ShowBooKForLoan(); } else if (state == InnerState.RETURNING) { //call the ws in order to get the loan information GetLoanState loanStateRequest = new GetLoanState(); loanStateRequest.bookID = bookInfoResponse.GetBookInformationsResult.ID; loanStateRequest.userID = LibraryModelSingleton.Instance.User.ID; loanStateRequest.returned = false; GetLoanStateResponse loanStateResponse = proxy.GetLoanState(loanStateRequest); if (loanStateResponse.GetLoanStateResult.LoanStateCompositeType.Length == 0) { //the book was not borrowed by the user View.ShowMessageWithButton(INVALID_BARCODE_MSG, () => { View.ShowWelcomePage(); }); } else { //show the book information LibraryModelSingleton.Instance.StartDate = loanStateResponse.GetLoanStateResult.LoanStateCompositeType[0].LoanStartDate; LibraryModelSingleton.Instance.DueDate = loanStateResponse.GetLoanStateResult.LoanStateCompositeType[0].LoanExpirationDate; View.ShowBooKForReturning(); } } } } catch (Exception) { //show a message and then returns in the login page state = InnerState.INITIAL; View.ShowMessageWithButton(ERROR_MSG, () => { this.Logout(); }); } }
public void Login(string id) { if (state != InnerState.INITIAL) throw new InvalidOperationException("The user is already logged in!"); IServiceClientProxy proxy = null; try { //using (IServiceClientProxy proxy = new IServiceClientProxy(binding, new ProtocolVersion11())) //{ proxy = new IServiceClientProxy(binding, new ProtocolVersion11()); //login request to the WS LogIn loginRequest = new LogIn() { card_number = id }; LogInResponse response = proxy.LogIn(loginRequest); if (response.LogInResult.FirstName == null) { //show a message and return in the login page Action action = () => { View.ShowLoginPage(); }; View.ShowMessageWithButton(UNREGISTERED_USER_MSG, action); return; } //set the the logged user and show the welcome page LibraryModelSingleton.Instance.User = response.LogInResult; state = InnerState.WELCOME; View.ShowWelcomePage(); //} } catch (Exception) { //show a message and then returns in the login page state = InnerState.INITIAL; View.ShowMessageWithButton(ERROR_MSG, () => { View.ShowLoginPage(); }); } finally { // if (proxy != null) { proxy.Dispose(); } } }