private void btnSave_Click(object sender, EventArgs e) { MainForm form = (MainForm)this.MdiParent; BookDAO dao = new BookDAO(form.CurrentDatabase.FullName); this.clearErrors(); for (int i = 0; i < _textboxes.Length; i++) { string isbn = _textboxes[i].Text; string uri = Constants.GetWebServiceURI("isbn", isbn); if (isbn == null || isbn.Equals("")) continue; TextBox txtbox = _textboxes[i]; Label lbl = _resultLabels[i]; this.setTextBox(txtbox, lbl, "Processing...", Color.Blue, true, true); WebRequest request = null; WebResponse response = null; try { request = WebRequest.Create(uri); response = request.GetResponse(); } catch(WebException e2) { MessageBox.Show(ErrorMessages.Common.WEB_SERVICE_ERROR, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.setTextBox(txtbox,lbl,"No Connection",Color.Red,true,false); return; } catch (Exception e1) { ExceptionHandler.HandleException(e1); this.setTextBox(txtbox, lbl, "Failure", Color.Red, true, false); continue; } Element element = XMLParser.ParseXML(response.GetResponseStream()); #if DEBUG string tree = ""; int level = 0; XMLParser.GetParseTreeInfo(element, ref tree, ref level); Console.Out.WriteLine(tree); #endif Book book = new Book(); Constants.XMLResultReturnValue result = book.FillFromXMLResults(element); if (result == Constants.XMLResultReturnValue.NOT_FOUND) this.setTextBox(txtbox, lbl, "Not Found", Color.Red, true, false); else if (result == Constants.XMLResultReturnValue.UNKNOWN) this.setTextBox(txtbox, lbl, "Failure", Color.Red, true, false); else if (book != null) { if (_mode == Constants.LibraryMode.LIBRARY && dao.ExistsInLibrary(book)) this.setTextBox(txtbox, lbl, "Already Exists", Color.Red, true, false); else if (_mode == Constants.LibraryMode.WISHLIST && dao.ExistsInWishList(book)) this.setTextBox(txtbox, lbl, "Already Exists", Color.Red, true, false); else if (_mode == Constants.LibraryMode.LIBRARY && !dao.InsertIntoLibrary(book)) this.setTextBox(txtbox, lbl, "Failure", Color.Red, true, false); else if (_mode == Constants.LibraryMode.WISHLIST && !dao.InsertIntoWishList(book)) this.setTextBox(txtbox, lbl, "Failure", Color.Red, true, false); else { this.setTextBox(txtbox, lbl, "Success", Color.Green, true, false); foreach (Form f in this.MdiParent.MdiChildren) { if (f is ViewBooksForm) (f as ViewBooksForm).Refresh(); } } } } }
/// <summary> /// Erm...well...it saves. /// </summary> private void save() { if (!this.isRequiredFieldsFilled()) return; MainForm parent = (MainForm)this.MdiParent; BookDAO dao = new BookDAO(parent.CurrentDatabase.FullName); if(_addMode == Constants.AddBookMode.EDIT) { if(dao.Updatebook(_book)) this.setInfoLabel("Success"); else this.setInfoLabel("Failed"); return; } if (dao.ExistsInLibrary(_book)) { if (this.chkAutoAdd.Checked == true) this.errorProvider1.SetError(this.txtLookup, ErrorMessages.Common.BOOK_EXISTS_IN_LIBRARY); else this.errorProvider1.SetError(this.txtShortTitle, ErrorMessages.Common.BOOK_EXISTS_IN_LIBRARY); this.setInfoLabel("Failed"); this.btnClear.Focus(); return; } else { this.errorProvider1.SetError(this.txtShortTitle, ""); this.errorProvider1.SetError(this.txtLookup, ""); } if (dao.InsertIntoLibrary(_book)) { this.setInfoLabel("Success"); this.clear(); this.errorProvider1.SetError(this.txtShortTitle, ""); this.errorProvider1.SetError(this.txtLookup, ""); foreach (Form f in this.MdiParent.MdiChildren) { if (f is ViewBooksForm) { ViewBooksForm frm = (ViewBooksForm)f; frm.Refresh(); } } } else { this.setInfoLabel("Failed"); } }