private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (!this.checkRequiredFields())
                return;
            
            BookDAO dao = new BookDAO(_topParent.CurrentDatabase.FullName);

            bool success = dao.LoanBook(_bookId, this.txtLoanTo.Text);
            if (!success)
            {
                MessageBox.Show("An unknown error occurred and this book was not updated.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
            else
            {
                _topParent.SetStatusStripText("Book " + this.lblBook.Text + " was successfully loaned to " + this.txtLoanTo.Text);
                this.Close();
            }
        }
        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();
                        }
                    }
                }
            }
        }
예제 #3
0
 /// <summary>
 /// This calls on the dao to get the results depending on the mode we are currently in
 /// </summary>
 /// <param name="mode"></param>
 /// <param name="value"></param>
 public void Search(Constants.SearchMode mode, string value)
 {
     MainForm main = (MainForm)this.ParentForm.MdiParent;
     BookDAO dao = new BookDAO(main.CurrentDatabase.FullName);
     this.gridBooks.DataSource = dao.SearchBooks(_mode, mode, value).Tables[0];
 }
예제 #4
0
        /// <summary>
        /// refreshes the grid with base results
        /// </summary>
        public override void Refresh()
        {
            base.Refresh();
            MainForm parent = (MainForm)this.ParentForm.MdiParent;
            BookDAO dao = new BookDAO(parent.CurrentDatabase.FullName);
            if (_mode == Constants.LibraryMode.LOANHISTORY)
                this.gridBooks.DataSource = dao.SearchBooks(_mode, Constants.SearchMode.BOOK_ID, _bookId).Tables[0];
            else
                this.gridBooks.DataSource = dao.SearchBooks(_mode, Constants.SearchMode.NONE, null).Tables[0];

            if (_mode == Constants.LibraryMode.LOANHISTORY && this.gridBooks.Rows.Count > 0)
            {
                ViewBooksForm f = this.ParentForm as ViewBooksForm;
                f.SetTitleBar(_mode, this.gridBooks.Rows[0].Cells["short_title"].Value.ToString());
            }
        }
예제 #5
0
        /// <summary>
        /// Called when right click->check in is called
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void checkDetailsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MainForm form = this.ParentForm.MdiParent as MainForm;
            BookDAO dao = new BookDAO(form.CurrentDatabase.FullName);
            foreach (string id in SelectedIds)
            {
                dao.ReturnBook(id);
            }

            this.Refresh();
        }
예제 #6
0
 private void transferBookToWishListToolStripMenuItem_Click(object sender, EventArgs e)
 {
     MainForm form = this.ParentForm.MdiParent as MainForm;
     BookDAO dao = new BookDAO(form.CurrentDatabase.FullName);
     foreach (string id in this.SelectedIds)
     {
         dao.TransferFromLibraryToWishList(id);
     }
     this.Refresh();
 }
예제 #7
0
        /// <summary>
        /// Called when right click ->loan book is called
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void loanBookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MainForm parent = this.ParentForm.MdiParent as MainForm;
            BookDAO dao = new BookDAO(parent.CurrentDatabase.FullName);


            foreach (DataGridViewRow row in this.gridBooks.SelectedRows)
            {
                string id = (row.Cells["id"].Value.ToString());
                string title = (row.Cells["short_title"].Value.ToString());


                if (dao.IsBookLoaned(id))
                {
                    MessageBox.Show("'" + title + "' has already been loaned, please check it in to loan it to someone different.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                LoanBookForm form = new LoanBookForm(id, title, parent);
                form.ShowDialog(this.ParentForm);
            }

            this.Refresh();

        }
예제 #8
0
        /// <summary>
        /// Called when right click ->view details is called
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void viewDetailsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MainForm parent = (MainForm)this.ParentForm.MdiParent;
            BookDAO dao = new BookDAO(parent.CurrentDatabase.FullName);

            foreach (string id in this.SelectedIds)
            {
                AddBookForm form = new AddBookForm(_mode, Constants.AddBookMode.VIEWONLY);
                form.BookData = dao.GetBookById(id);
                form.MdiParent = parent;
                form.Show();
            }

        }
예제 #9
0
        /// <summary>
        /// called when right click->Delete book is called
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteBookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete these books?", "Delete?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                MainForm parent = (MainForm)this.ParentForm.MdiParent;
                BookDAO dao = new BookDAO(parent.CurrentDatabase.FullName);
                foreach (string id in this.SelectedIds)
                    dao.DeleteBook(id);

                this.Refresh();
            }
        }
 /// <summary>
 /// We override refresh to refresh the text boxees from the data
 /// </summary>
 public override void Refresh()
 {
 	if(_bookId != null)
 	{
 		MainForm frm = this.MdiParent as MainForm;
     	BookDAO dao = new BookDAO(frm.CurrentDatabase.Name);
     	this._book = dao.GetBookById(_bookId);
 	}
     Book b = _book;
     base.Refresh();
     txtISBN.Text = b.ISBN;
     txtShortTitle.Text = b.ShortTitle;
     txtLongTitle.Text = b.LongTitle;
     string authors = "";
     foreach (Person p in b.Authors)
         authors += p.FullName + Environment.NewLine;
     txtAuthors.Text = authors;
     string editors = "";
     foreach (Person p in b.Editors)
         editors += p.FullName + Environment.NewLine;
     txtEditors.Text = editors;
     txtPublisher.Text = b.PublisherInfo;
     txtDewey.Text = b.Dewey;
     txtDeweyNorm.Text = b.DeweyNormalized;
     txtLCC.Text = b.LibraryOfCongress;
     txtPhysDesc.Text = b.PhysicalDescription;
     txtEdition.Text = b.Edition;
     txtLanguage.Text = b.Language;
     txtSummary.Text = b.Summary;
     txtNotes.Text = b.Notes;
     txtAwards.Text = b.Awards;
     txtURLs.Text = b.Urls;
     txtNewPrice.Text = b.NewPrice;
     txtUsedPrice.Text = b.UsedPrice;
     string subjects = "";
     foreach (Subject s in b.Subjects)
     {
         subjects += s.Name + "\r\n";
     }
     txtSubjects.Text = subjects;
 }
        /// <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");
            }
 
        }