/// <summary> /// Compares two books according to number of pages /// </summary> /// <param name="other">Book for comparing with current</param> /// <returns>A value that indicates the relative order of the books being compared.</returns> public int CompareTo(Book other) { if (ReferenceEquals(other, null)) { return(1); } return(NumberOfPages.CompareTo(other.NumberOfPages)); }
private void AddLastLabel() { Label label = new Label(); label.ID = "uxLastLabel"; label.Text = String.Format("of {0} pages | view ", NumberOfPages.ToString()); label.CssClass = "Label"; uxPlaceHolder.Controls.Add(label); }
/// <summary> /// Returns representation of book, including <see cref="formatProvider"/> /// <list type="bullet"> /// <item> /// <term>"V"</term> /// <description>Returns representation of book, including Author,Name,Year,PublishingOffice</description> /// </item> /// <item> /// <term>"B"</term> /// <description>Returns representation of book, including Author,Name,Year</description> /// </item> /// <item> /// <term>"S"</term> /// <description>Returns representation of book, including Author,Name</description> /// </item> /// <item> /// <term>"L"</term> /// <description>Returns representation of book, including Name,Year,PublishingOffice</description> /// </item> /// <item> /// <term>"A"</term> /// <description>Returns representation of book, including only Author</description> /// </item> /// <item> /// <term>"N"</term> /// <description>Returns representation of book, including only Name</description> /// </item> /// <item> /// <term>"Y"</term> /// <description>Returns representation of book, including only Year</description> /// </item> /// <item> /// <term>"H"</term> /// <description>Returns representation of book, including only PublishingOffice</description> /// </item> /// <item> /// <term>"I"</term> /// <description>Returns representation of book, including only ISBN</description> /// </item> /// <item> /// <term>"P"</term> /// <description>Returns representation of book, including only Pages</description> /// </item> /// </list> /// </summary> public string ToString(string format, IFormatProvider formatProvider) { if (string.IsNullOrEmpty(format)) { format = "V"; } if (formatProvider == null) { formatProvider = CultureInfo.CurrentCulture; } switch (format.ToUpperInvariant()) { case "A": return(Author?.ToString(formatProvider) ?? string.Empty); case "N": return(Name?.ToString(formatProvider) ?? string.Empty); case "Y": return(Year.ToString(formatProvider)); case "H": return(PublishingOffice != null ? "\"" + PublishingOffice?.ToString(formatProvider) + "\"" : string.Empty); case "I": return("ISBN 13: " + ISBN.ToString(formatProvider)); case "P": return("P. " + NumberOfPages.ToString(formatProvider)); case "V": return(Author?.ToString(formatProvider) + ", " + Name?.ToString(formatProvider) + ", " + Year.ToString(formatProvider) + ", " + PublishingOffice?.ToString(formatProvider)); case "B": return(Author?.ToString(formatProvider) + ", " + Name?.ToString(formatProvider) + ", " + Year.ToString(formatProvider)); case "S": return(Author?.ToString(formatProvider) + ", " + Name?.ToString(formatProvider)); case "L": return(Name?.ToString(formatProvider) + ", " + Year.ToString(formatProvider) + ", " + PublishingOffice?.ToString(formatProvider)); case string str when !str.Except(SimpleFormats).Any(): return(string.Join(", ", format.Select(c => this.ToString(c.ToString(), formatProvider)))); default: throw new FormatException($"The {format} format string is not supported."); } }
/// <summary> /// Calculates hash code for current book /// </summary> /// <returns>Hash code of the book</returns> public override int GetHashCode() { int hashCode = 0; unchecked { hashCode = Title.GetHashCode() + Author.GetHashCode() + Genre.GetHashCode() + NumberOfPages.GetHashCode() + Language.GetHashCode() + Country.GetHashCode(); } return(hashCode); }
protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { NumberOfPages.Dispose(); } Contents = null; FirstPage = null; NumberOfPages = null; _disposedValue = true; } }
public override int GetHashCode() { int hash = 17; hash = hash * 23 + Id.GetHashCode(); hash = hash * 23 + Name.GetHashCode(); hash = hash * 23 + Authors.GetHashCode(); hash = hash * 23 + NumberOfPages.GetHashCode(); hash = hash * 23 + Publisher.GetHashCode(); hash = hash * 23 + MediaType.GetHashCode(); hash = hash * 23 + Country.GetHashCode(); hash = hash * 23 + ReleaseDate.GetHashCode(); hash = hash * 23 + PrecededBy.GetHashCode(); hash = hash * 23 + FollowedBy.GetHashCode(); return(hash); }
public void SaveToXml(string path) { using (XmlWriter writer = XmlWriter.Create(path, new XmlWriterSettings() { Indent = true })) { writer.WriteStartDocument(); writer.WriteStartElement("books"); writer.WriteStartElement("book"); writer.WriteAttributeString("title", Title); writer.WriteAttributeString("author", Author); writer.WriteStartElement("information"); writer.WriteElementString("numberOfPages", NumberOfPages.ToString()); writer.WriteElementString("publishingYear", PublishingYear.ToString()); writer.WriteEndElement(); writer.WriteEndElement(); writer.Flush(); } }
///<summary> /// this function and AddPageNavigator (the next function) are to do pagination of patients list, setting style and events for each page no and first, prev, next and last icons. ///</summary> private void CreatePagesNo() { int intPageCnt = 10; if (cntPatient % intNumberPerSheet == 0) { NumberOfPages = cntPatient / intNumberPerSheet; } else { NumberOfPages = (int)(cntPatient / intNumberPerSheet) + 1; } txtHPageQty.Value = NumberOfPages.ToString(); if (NumberOfPages > 1) { int Xh = 0, Idx = 0; System.Web.UI.HtmlControls.HtmlGenericControl lblPageIntro = new System.Web.UI.HtmlControls.HtmlGenericControl("LABEL"); System.Web.UI.HtmlControls.HtmlGenericControl lblPage = new System.Web.UI.HtmlControls.HtmlGenericControl("LABEL"); System.Web.UI.HtmlControls.HtmlGenericControl lblBlank = new System.Web.UI.HtmlControls.HtmlGenericControl("LABEL"); System.Web.UI.WebControls.TextBox txtGoTo = new System.Web.UI.WebControls.TextBox(); lblPageIntro.InnerText = "Page : "; lblPageIntro.Attributes.Add("style", "font-size:8pt;font-weight:bold"); div_PagesNo.Controls.Add(lblPageIntro); //goto page txtGoTo.Attributes.Add("value", txtHPageNo.Value); txtGoTo.Attributes.Add("id", "txtGoToPage"); txtGoTo.Attributes.Add("style", "font-size:7.5pt"); txtGoTo.Attributes.Add("size", "2"); div_PagesNo.Controls.Add(txtGoTo); AddPageNavigator("G", true); lblBlank.InnerText = " "; div_PagesNo.Controls.Add(lblBlank); if (Convert.ToInt16(txtHPageNo.Value) > intPageCnt) { Xh = Convert.ToInt16(txtHPageNo.Value) - intPageCnt + 1; } else { Xh = 1; } if (NumberOfPages > intPageCnt) { AddPageNavigator("F", (Xh > 1) || (Convert.ToInt16(txtHPageNo.Value) > 1)); AddPageNavigator("P", (Xh > 1) || (Convert.ToInt16(txtHPageNo.Value) > 1)); } for (; (Xh <= NumberOfPages) && (++Idx <= intPageCnt); Xh++) { System.Web.UI.HtmlControls.HtmlAnchor aPage = new System.Web.UI.HtmlControls.HtmlAnchor(); aPage.HRef = "#"; if (txtHPageNo.Value.Equals(Xh.ToString())) { aPage.InnerText = String.Format("[{0}]", Xh.ToString()); aPage.Attributes.Add("class", "selected"); aPage.Attributes.Add("style", "font-size:8pt;font-weight:bold"); } else { aPage.InnerText = Xh.ToString(); aPage.Attributes.Add("style", "font-size:8pt;font-weight:normal"); } aPage.Attributes.Add("onclick", String.Format("javascript:LoadRecordsOfPage({0}, {1});", NumberOfPages, Xh.ToString())); div_PagesNo.Controls.Add(aPage); } if (NumberOfPages > intPageCnt) { AddPageNavigator("N", (Convert.ToInt16(txtHPageNo.Value) < Convert.ToInt16(txtHPageQty.Value))); AddPageNavigator("L", (Convert.ToInt16(txtHPageNo.Value) < Convert.ToInt16(txtHPageQty.Value))); } lblPage = new System.Web.UI.HtmlControls.HtmlGenericControl("LABEL"); lblPage.InnerText = String.Format(" of {0} (Patients: {1})", txtHPageQty.Value, cntPatient.ToString()); lblPage.Attributes.Add("style", "font-size:8pt;font-weight:bold"); div_PagesNo.Controls.Add(lblPage); } }
/// <summary> /// Returns a string representation of the book, using the specified format. /// </summary> /// <param name="format">Avaliable formats: /// "G" - general /// "S" - short /// You can enumerate the components of the book you want to get, separeted by ','. /// In the result the components values will also be separeted by ','. /// Components shortcuts: /// "ISBN" - Books ISBN number /// "AUT" - Books authors /// "TT" - Books Title /// "PB" - Books publisher /// "PBY" - Books publish year /// "PG" - Books number of pages /// "PR" - Books Price /// Example: /// The general format looks like this "ISBN,AUT,TT,PB,PBY,PG,PR". /// The short format "AUT,TT". /// </param> /// <param name="formatProvider"></param> /// <returns></returns> public string ToString(string format, IFormatProvider formatProvider) { string defaultFormat = "G"; if (format == null) { format = defaultFormat; } if (formatProvider == null) { formatProvider = CultureInfo.CurrentCulture; } format = format.ToUpper(); string generalFormat = "ISBN,AUT,TT,PB,PBY,PG,PR"; string shortFormat = "AUT,TT"; if (format == "G") { format = generalFormat; } if (format == "S") { format = shortFormat; } string[] fmtParts = format.Split(','); StringBuilder result = new StringBuilder(); for (int i = 0; i < fmtParts.Length; i++) { if (i != 0) { result.Append(", "); } switch (fmtParts[i]) { case "ISBN": result.Append(ISBN.ToString()); break; case "AUT": result.Append(Author.ToString(formatProvider)); break; case "TT": result.Append(Title.ToString(formatProvider)); break; case "PB": result.Append(Publisher.ToString(formatProvider)); break; case "PBY": result.Append(PublishYear.ToString(formatProvider)); break; case "PG": result.Append($"P.{NumberOfPages.ToString(formatProvider)}"); break; case "PR": result.Append(Price.ToString(formatProvider)); break; default: throw new FormatException($"{fmtParts[i]} format is not supported"); } } return(result.ToString()); }
/// <summary> /// Method of special interface to compare on equality /// </summary> /// <param name="book">object for comparison on equality</param> /// <returns>true or false logical value</returns> public bool Equals(Book book) { return(ISBN.Equals(book.ISBN) & Author.Equals(book.Author) & Title.Equals(book.Title) & PublishingHouse.Equals(book.PublishingHouse) & YearOfPublishing.Equals(book.YearOfPublishing) & NumberOfPages.Equals(book.NumberOfPages) & Cost.Equals(book.Cost)); }
private void BuildBookDetailsList() { //format string format = String.Empty; if (!String.IsNullOrEmpty(Format)) { format = Format + ", "; } if (NumberOfPages > 0) { format += NumberOfPages.ToString() + " pages"; } if (!String.IsNullOrEmpty(format)) { Details.Add(new BookDetail { Key = "Format", Value = format }); } //date published string published = String.Empty; if (!String.IsNullOrEmpty(Publisher)) { published = Publisher + ", "; } if (!String.IsNullOrEmpty(book.Publication_year)) { published += book.Publication_year; } if (!String.IsNullOrEmpty(published)) { Details.Add(new BookDetail { Key = "Published", Value = published }); } if (!String.IsNullOrEmpty(OriginalTitle)) { Details.Add(new BookDetail { Key = "Original Title", Value = OriginalTitle }); } if (!String.IsNullOrEmpty(Isbn13)) { Details.Add(new BookDetail { Key = "ISBN12", Value = Isbn13 }); } if (book != null && book.SeriesWorks != null && book.SeriesWorks.Count > 0 && book.SeriesWorks[0].Series != null && !String.IsNullOrEmpty(book.SeriesWorks[0].Series.Title)) { Details.Add(new BookDetail { Key = "Series", Value = book.SeriesWorks[0].Series.Title.Replace("\n", "").Trim(' ') }); } Stats = String.Empty; if (!String.IsNullOrEmpty(book.Work.Ratings_count)) { Stats += book.Work.Ratings_count + " ratings, "; } if (!String.IsNullOrEmpty(book.Work.Text_reviews_count)) { Stats += book.Work.Text_reviews_count + " reviews"; } }