Product.cs


SUBMITTED BY: Guest

DATE: April 21, 2014, 11:20 a.m.

FORMAT: Text only

SIZE: 4.6 kB

HITS: 767

  1. PRODUCT.CS
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Collections;
  7. using System.Xml.Serialization;
  8. using System.IO;
  9. using System.Data;
  10. /// <summary>
  11. /// Summary description for Books
  12. /// </summary>
  13. ///
  14. public class Book
  15. {
  16. private int id;
  17. private string title;
  18. private string author;
  19. private int publishDate;
  20. private string pictureUrl;
  21. private int price;
  22. private int stock;
  23. private string genre;
  24. private string summary;
  25. public Book()
  26. {
  27. }
  28. public Book(int id, string title, string author, int publishDate, string pictureUrl, int price, int stock, string genre, string summary)
  29. {
  30. Id = id;
  31. Title = title;
  32. Author = author;
  33. PublishDate = publishDate;
  34. PictureUrl = pictureUrl;
  35. Price = price;
  36. Stock = stock;
  37. Genre = genre;
  38. Summary = summary;
  39. }
  40. public int Id
  41. {
  42. get
  43. {
  44. return id;
  45. }
  46. set
  47. {
  48. id = value;
  49. }
  50. }
  51. public string Title
  52. {
  53. get
  54. {
  55. return title;
  56. }
  57. set
  58. {
  59. title = value;
  60. }
  61. }
  62. public string Author
  63. {
  64. get
  65. {
  66. return author;
  67. }
  68. set
  69. {
  70. author = value;
  71. }
  72. }
  73. public int PublishDate
  74. {
  75. get
  76. {
  77. return publishDate;
  78. }
  79. set
  80. {
  81. publishDate = value;
  82. }
  83. }
  84. public string PictureUrl
  85. {
  86. get
  87. {
  88. return pictureUrl;
  89. }
  90. set
  91. {
  92. pictureUrl = value;
  93. }
  94. }
  95. public int Price
  96. {
  97. get
  98. {
  99. return price;
  100. }
  101. set
  102. {
  103. price = value;
  104. }
  105. }
  106. public int Stock
  107. {
  108. get
  109. {
  110. return stock;
  111. }
  112. set
  113. {
  114. stock = value;
  115. }
  116. }
  117. public string Genre
  118. {
  119. get
  120. {
  121. return genre;
  122. }
  123. set
  124. {
  125. genre = value;
  126. }
  127. }
  128. public string Summary
  129. {
  130. get
  131. {
  132. return summary;
  133. }
  134. set
  135. {
  136. summary = value;
  137. }
  138. }
  139. }
  140. public class Books : ICollection
  141. {
  142. public string CollectionName;
  143. private ArrayList bookArray = new ArrayList();
  144. public Book this[int index]
  145. {
  146. get { return (Book)bookArray[index]; }
  147. }
  148. public void CopyTo(Array a, int index)
  149. {
  150. bookArray.CopyTo(a, index);
  151. }
  152. public int Count
  153. {
  154. get { return bookArray.Count; }
  155. }
  156. public object SyncRoot
  157. {
  158. get { return this; }
  159. }
  160. public bool IsSynchronized
  161. {
  162. get { return false; }
  163. }
  164. public IEnumerator GetEnumerator()
  165. {
  166. return bookArray.GetEnumerator();
  167. }
  168. public void Add(Book newBook)
  169. {
  170. bookArray.Add(newBook);
  171. }
  172. public void SerializeCollection(string filename)
  173. {
  174. WebService w = new WebService();
  175. Books b2 = new Books();
  176. // Note that only the collection is serialized -- not the
  177. // CollectionName or any other public property of the class.
  178. b2.CollectionName = "Books";
  179. //Book John100 = new Book("John", "100xxx");
  180. DataTable dt = w.GetD("SELECT * FROM books", "books");
  181. for (int i = 0; i < dt.Rows.Count; i++)
  182. {
  183. Book b1 = w.BuildBookById(i+1);
  184. b2.Add(b1);
  185. }
  186. XmlSerializer x = new XmlSerializer(typeof(Books));
  187. TextWriter writer = new StreamWriter(filename);
  188. x.Serialize(writer, b2);
  189. writer.Close();
  190. }

comments powered by Disqus