PhoneClass.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Formats.Asn1;
  5. using System.Globalization;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Runtime.Serialization;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using CsvHelper;
  12. namespace wpf_app.Model
  13. {
  14. [DataContract]
  15. public class Product
  16. {
  17. [DataMember]
  18. public string Title { get; set; }
  19. [DataMember]
  20. public string Company { get; set; }
  21. [DataMember]
  22. public int Price { get; set; }
  23. [DataMember]
  24. public string Category { get; set; }
  25. [DataMember]
  26. public bool Existence { get; set; }
  27. [DataMember(Name = "ArrivalDate")]
  28. private string? stringArrivalDate { get; set; }
  29. [IgnoreDataMember]
  30. public DateOnly? ArrivalDate
  31. {
  32. get
  33. {
  34. return stringArrivalDate == null ? null : DateOnly.Parse(stringArrivalDate);
  35. }
  36. set
  37. {
  38. stringArrivalDate = value.ToString();
  39. }
  40. }
  41. [DataMember]
  42. public double Rating { get; set; }
  43. [DataMember]
  44. public string Photo { get; set; }
  45. [IgnoreDataMember]
  46. public string ExistenceString
  47. {
  48. get
  49. {
  50. return Existence ? "Да" : "Нет";
  51. }
  52. }
  53. public string ExistenceStringS { get { return Existence ? "Товар в наличии" : "Нет в наличии"; } }
  54. public Uri? ImageBitmap
  55. {
  56. get
  57. {
  58. var imageName = Environment.CurrentDirectory + "/img/" + (Photo ?? "");
  59. return System.IO.File.Exists(imageName) ? new Uri(imageName) : null;
  60. }
  61. }
  62. public string WindowTitle { get { return $"{Company} {Title}"; }}
  63. }
  64. public class ProductCategory
  65. {
  66. public string title { get; set; }
  67. }
  68. public class ProductPrice
  69. {
  70. public string title { get; set; }
  71. public int priceFrom { get; set; }
  72. public int priceTo { get; set; }
  73. }
  74. public class ProductCompany
  75. {
  76. public string title { get; set; }
  77. }
  78. interface IDataProvider
  79. {
  80. IEnumerable<Product> GetProducts();
  81. IEnumerable<ProductCategory> GetCategories();
  82. IEnumerable<ProductPrice> GetPrices();
  83. IEnumerable<ProductCompany> GetCompanies();
  84. }
  85. public class LocalDataProvider : IDataProvider
  86. {
  87. public IEnumerable<Product> GetProducts()
  88. {
  89. return new Product[]{
  90. new Product
  91. {
  92. Category = "Смартфон",
  93. Company = "Apple",
  94. Title = "13 Pro Max",
  95. Price = 84999
  96. },
  97. new Product
  98. {
  99. Category = "Смартфон",
  100. Company = "Samsung",
  101. Title = "S23",
  102. Price = 89999
  103. },
  104. new Product
  105. {
  106. Category = "Смартфон",
  107. Company = "Huawei",
  108. Title = "Nova Y61",
  109. Price = 9999
  110. },
  111. new Product
  112. {
  113. Category = "Смартфон",
  114. Company = "POCO",
  115. Title = "C51",
  116. Price = 5599
  117. },
  118. new Product
  119. {
  120. Category = "Ноутбук",
  121. Company = "Xiaomi",
  122. Title = "RedmiBook 15",
  123. Price = 49999
  124. },
  125. new Product
  126. {
  127. Category = "Ноутбук",
  128. Company = "Asus",
  129. Title = "Vivobook Go 15",
  130. Price = 25999
  131. },
  132. new Product
  133. {
  134. Category = "Ноутбук",
  135. Company = "Lenovo",
  136. Title = "IdeaPad 1",
  137. Price = 24999
  138. },
  139. new Product
  140. {
  141. Category = "Ноутбук",
  142. Company = "Asus",
  143. Title = "ExpertBook B1502",
  144. Price = 32999
  145. },
  146. new Product
  147. {
  148. Category = "Смарт-Часы",
  149. Company = "Apple",
  150. Title = "SE 2023",
  151. Price = 30599
  152. },
  153. new Product
  154. {
  155. Category = "Смарт-Часы",
  156. Company = "Xiaomi",
  157. Title = "Smart Band 8",
  158. Price = 3999
  159. },
  160. new Product
  161. {
  162. Category = "Смарт-Часы",
  163. Company = "Huawei",
  164. Title = "Watch GT 4",
  165. Price = 13999
  166. },
  167. };
  168. }
  169. public IEnumerable<ProductCategory> GetCategories()
  170. {
  171. return new ProductCategory[]
  172. {
  173. new ProductCategory {title = "Смартфон"},
  174. new ProductCategory {title = "Ноутбук"},
  175. new ProductCategory {title = "Смарт-Часы"},
  176. new ProductCategory {title = "Монитор"}
  177. };
  178. }
  179. public IEnumerable<ProductPrice> GetPrices()
  180. {
  181. return new ProductPrice[]
  182. {
  183. new ProductPrice{title="Все цены", priceFrom = 0, priceTo = 999999},
  184. new ProductPrice{title="До 10.000", priceFrom = 0, priceTo = 10000},
  185. new ProductPrice{title="От 10.000 до 20.000", priceFrom = 10000, priceTo = 20000},
  186. new ProductPrice{title="От 20.000 до 50.000", priceFrom = 20000, priceTo = 50000},
  187. new ProductPrice{title="Дороже 50.000", priceFrom = 50000, priceTo = 999999 }
  188. };
  189. }
  190. public IEnumerable<ProductCompany> GetCompanies()
  191. {
  192. return new ProductCompany[]
  193. {
  194. new ProductCompany{title = "Apple"},
  195. new ProductCompany{title = "Xiaomi"},
  196. new ProductCompany{title = "Huawei"},
  197. new ProductCompany{title = "POCO"},
  198. new ProductCompany{title = "Asus"},
  199. new ProductCompany{title = "Lenovo"},
  200. new ProductCompany{title = "Samsung"},
  201. new ProductCompany{title = "Acer"},
  202. new ProductCompany{title = "AOC"}
  203. };
  204. }
  205. }
  206. }