/// <summary>
        /// Receives a HashTable of Element objects that is received
        /// from the XMLParser class, breaks down the Elements that are relevant,
        /// and fills necessary text boxes
        /// </summary>
        /// <param name="table"></param>
        public Constants.XMLResultReturnValue FillFromXMLResults(Element element)
        {
            Element bookListElement = element.GetFirstElementOf("BookList");
            Element bookDataElement = element.GetFirstElementOf("BookData");
            Element titleElement = element.GetFirstElementOf("Title");
            Element titleLongElement = element.GetFirstElementOf("TitleLong");
            Element authorsTextElement = element.GetFirstElementOf("Authors");
            Element authorElement = element.GetFirstElementOf("AuthorsText");
            Element publisherTextElement = element.GetFirstElementOf("PublisherText");
            Element detailsElement = element.GetFirstElementOf("Details");
            Element summaryElement = element.GetFirstElementOf("Summary");
            Element notesElement = element.GetFirstElementOf("Notes");
            Element awardsTextElement = element.GetFirstElementOf("AwardsText");
            Element urlsTextElement = element.GetFirstElementOf("UrlsText");
            Element editorsElement = element.GetFirstElementOf("EditorsText");
            Element subjectsElement = element.GetFirstElementOf("Subjects");
            Element pricesElement = element.GetFirstElementOf("Prices");

            if (bookListElement.GetAttribute("total_results").Equals("0"))
                return Constants.XMLResultReturnValue.NOT_FOUND; 
           
            this.Id = bookDataElement.GetAttribute("book_id");
            this.ISBN = bookDataElement.GetAttribute("isbn");
            this.ShortTitle = titleElement.Value;
            this.LongTitle = titleLongElement.Value;
            this.PublisherInfo = publisherTextElement.Value;
            this.PublisherId = publisherTextElement.GetAttribute("publisher_id");
            this.PhysicalDescription = detailsElement.GetAttribute("physical_description_text");
            this.Language = detailsElement.GetAttribute("language");
            this.Dewey = detailsElement.GetAttribute("dewey_decimal");
            this.DeweyNormalized = detailsElement.GetAttribute("dewey_decimal_normalized");
            this.Edition = detailsElement.GetAttribute("edition_info");
            this.LibraryOfCongress = detailsElement.GetAttribute("lcc_number");
            this.Summary = summaryElement.Value;
            this.Notes = notesElement.Value;
            //do subject info
            this.Urls = urlsTextElement.Value;
            this.Awards = awardsTextElement.Value;

            //if there isn't any person elements, we do the best we can with what we have
            if (authorsTextElement.Children.Count == 0 && !authorElement.Value.Equals(""))
            {
                Person p = new Person();
                p.FirstName = Person.GetFirstNameFromPersonValue(authorElement.Value);
                p.LastName = Person.GetLastNameFromPersonValue(authorElement.Value);
                p.Id = Utils.CreateIdFromString(authorElement.Value);
                this.Authors.Add(p);
            }
            else
            {
                foreach (Element child in authorsTextElement.FindChildElements("Person"))
                {
                    Person p = new Person();
                    p.FillFromElement(child);
                    this.Authors.Add(p);
                }
            }

            if (editorsElement.Children.Count == 0 && !editorsElement.Value.Equals(""))
            {
                Person p = new Person();
                p.FirstName = Person.GetFirstNameFromPersonValue(editorsElement.Value);
                p.LastName = Person.GetLastNameFromPersonValue(editorsElement.Value);
                p.Id = Utils.CreateIdFromString(editorsElement.Value);
                this.Editors.Add(p);
            }
            else
            {
                foreach (Element child in editorsElement.FindChildElements("Person"))
                {
                    Person p = new Person();
                    p.FillFromElement(child);
                    this.Editors.Add(p);
                }
            }

            foreach (Element subject in subjectsElement.FindChildElements("Subject"))
            {
                Subject s = new Subject();
                s.Id = subject.GetAttribute("subject_id");
                s.Name = subject.Value;
                this.Subjects.Add(s);
            }

            int newCount = 0;
            int usedCount = 0;
            double newTotal = 0.0;
            double usedTotal = 0.0;
            foreach (Element price in pricesElement.FindChildElements("Price"))
            {
                string val = price.GetAttribute("price");
                string isNew = price.GetAttribute("is_new");
                if(isNew.Equals("1"))
                {
                    try
                    {
                        newTotal += Double.Parse(val);
                        newCount++;
                    }
                    catch(Exception e)
                    {
                    	Log.Instance.Out(e);
                    }
                }
                else if (isNew.Equals("0"))
                {
                    try
                    {
                        usedTotal += Double.Parse(val);
                        usedCount++;
                    }
                    catch (Exception e)
                    {
                    	Log.Instance.Out(e);
                    }
                }
            }
            double newAvg = newTotal / newCount;
            double usedAvg = usedTotal / usedCount;
          
            this.NewPrice = newAvg.ToString("C");
            this.UsedPrice = usedAvg.ToString("C");

            if (this.NewPrice.Contains("NaN"))
                this.NewPrice = "";

            if (this.UsedPrice.Contains("NaN"))
                this.UsedPrice = "";

            return Constants.XMLResultReturnValue.SUCCESS;
        }
        /// <summary>
        /// Receives a DataSet, and fills the domain objects Properties from it
        /// </summary>
        /// <param name="ds"></param>
        /// <param name="book"></param>
        /// <returns></returns>
        public bool FillBookFromDataSet(DataSet ds, Book book)
        {
            if (ds == null || ds.Tables[0].Rows.Count < 1)
                return false;
            DataRow dr = ds.Tables[0].Rows[0];

            book.Id = dr["id"].ToString();
            book.ISBN = dr["isbn"].ToString();
            book.Language = dr["language"].ToString();
            book.LibraryOfCongress = dr["lcc_number"].ToString();
            book.LongTitle = dr["long_title"].ToString();
            book.Notes = dr["notes"].ToString();
            book.PhysicalDescription = dr["physical_desc"].ToString();
            book.PublisherId = dr["publisher_id"].ToString();
            book.ShortTitle = dr["short_title"].ToString();
            book.Summary = dr["summary"].ToString();
            book.Urls = dr["urls"].ToString();
            book.NewPrice = dr["new_price"].ToString();
            book.UsedPrice = dr["used_price"].ToString();
            book.PricePaid = dr["price_paid"].ToString();

            //get book_subject data
            DataSet subjectDS = this.ExecuteQuery(SQL.Subject.SELECT_BY_BOOK_ID, new object[] { book.Id });
            if (subjectDS != null)
                foreach (DataRow dr1 in subjectDS.Tables[0].Rows)
                {
                    Subject s = new Subject();
                    s.Id = dr1["id"].ToString();
                    s.Name = dr1["subject"].ToString();
                    book.Subjects.Add(s);
                }

            //get publisher data
            DataSet publisherDS = this.ExecuteQuery(SQL.Publisher.SELECT_PUBLISHER_BY_ID, new object[] { book.PublisherId });
            if (publisherDS != null)
                foreach (DataRow dr2 in publisherDS.Tables[0].Rows)
                {
                    book.PublisherInfo = dr2["publisher_info"].ToString();
                }

            //get author data
            DataSet authorDS = this.ExecuteQuery(SQL.Person.SELECT_AUTHORS_BY_BOOK_ID, new object[] { book.Id });
            if (authorDS != null)
                foreach (DataRow dr3 in authorDS.Tables[0].Rows)
                {
                    Person p = new Person();
                    p.Id = dr3["id"].ToString();
                    p.FirstName = dr3["first_name"].ToString();
                    p.LastName = dr3["last_name"].ToString();
                    book.Authors.Add(p);
                }

            //get editor data
            DataSet editorDS = this.ExecuteQuery(SQL.Person.SELECT_EDITORS_BY_BOOK_ID, new object[] { book.Id });
            if (editorDS != null)
                foreach (DataRow dr4 in editorDS.Tables[0].Rows)
                {
                    Person p = new Person();
                    p.Id = dr4["id"].ToString();
                    p.FirstName = dr4["first_name"].ToString();
                    p.LastName = dr4["last_name"].ToString();
                    book.Editors.Add(p);
                }
            return true;
        }
        private void fillDataFromForm()
        {
            string[] authors = this.txtAuthors.Text.Replace("\r\n",";").Split(new char[]{ ';' });
            string[] editors = this.txtEditors.Text.Replace("\r\n", ";").Split(new char[] { ';' });
            string[] subjects = this.txtSubjects.Text.Replace("\r\n", ";").Split(new char[] { ';' });
            
            _book.Authors.Clear();
            _book.Editors.Clear();
            _book.Subjects.Clear();
            
            foreach(string s in authors)
            {
                if(s.Equals("")) 
                    continue;
                Person p = new Person();
                p.FirstName = Person.GetFirstNameFromFull(s);
                p.LastName = Person.GetLastNameFromFull(s);
                p.Id = Utils.CreateIdFromString(p.FullName);
                _book.Authors.Add(p);
            }

            foreach (string s in editors)
            {
                if (s.Equals(""))
                    continue;
                Person p = new Person();
                p.FirstName = Person.GetFirstNameFromFull(s);
                p.LastName = Person.GetLastNameFromFull(s);
                p.Id = Utils.CreateIdFromString(p.FullName);
                _book.Editors.Add(p);
            }

            foreach (string s in subjects)
            {
                if (s.Equals(""))
                    continue;
                Subject su = new Subject();
                su.Name = s;
                su.Id = Utils.CreateIdFromString(s);
                _book.Subjects.Add(su);
            }

            _book.ShortTitle = this.txtShortTitle.Text.Trim();
            _book.LongTitle = this.txtLongTitle.Text.Trim();
            _book.ISBN = this.txtISBN.Text;
            _book.Language = this.txtLanguage.Text;
            _book.LibraryOfCongress = this.txtLCC.Text;
            _book.Notes = this.txtNotes.Text;
            _book.PhysicalDescription = this.txtPhysDesc.Text;
            _book.PublisherInfo = this.txtPublisher.Text;
            if (!_book.PublisherInfo.Equals(""))
                _book.PublisherId = Utils.CreateIdFromString(_book.PublisherInfo);

            _book.Summary = this.txtSummary.Text;
            _book.Urls = this.txtURLs.Text;
            _book.Awards = this.txtAwards.Text;
            _book.DateAdded = DateTime.Now.ToShortDateString();
            _book.Dewey = this.txtDewey.Text;
            _book.NewPrice = this.txtNewPrice.Text;
            _book.UsedPrice = this.txtUsedPrice.Text;
            _book.PricePaid = this.txtPricePaid.Text;
            _book.DeweyNormalized = this.txtDeweyNorm.Text;
            _book.Edition = this.txtEdition.Text;
            string title = this.txtShortTitle.Text.Equals("") ? this.txtLongTitle.Text : this.txtShortTitle.Text;
            _book.Id = Utils.CreateIdFromString(title);
        }