FUSIONFuelPrice.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. using System;
  2. using System.Collections.Generic;
  3. using Wayne.Lib;
  4. namespace Wayne.ForecourtControl.Fusion
  5. {
  6. public class FUSIONFuelPrice : IFuelPrice
  7. {
  8. // Fields
  9. public static int PriceGroupNumbersMin = 1;
  10. public static int PriceGroupNumbersMax = 11;
  11. private decimal basePrice;
  12. private decimal basePriceAsCurrency;
  13. private int fuelGrade;
  14. private decimal generalPriceDelta;
  15. private decimal generalPriceDeltaAsCurrency;
  16. private decimal maxPrice;
  17. private decimal minPrice;
  18. private FUSIONFuelPriceAddPricePerPriceGroup priceGroupDelta;
  19. private bool reserved;
  20. public Object locker;
  21. private bool changed = false;
  22. // Methods
  23. public FUSIONFuelPrice(int fuelGrade)
  24. {
  25. this.fuelGrade = fuelGrade;
  26. this.priceGroupDelta = new FUSIONFuelPriceAddPricePerPriceGroup(this);
  27. locker = new object();
  28. }
  29. internal void SetAddPrice(int priceGroup, decimal addPrice)
  30. {
  31. if (this.priceGroupDelta[priceGroup] != addPrice)
  32. {
  33. changed = true;
  34. this.priceGroupDelta[priceGroup] = addPrice;
  35. }
  36. }
  37. public bool Validate()
  38. {
  39. //for (int i = priceGroupDelta.PriceGroupNumbersMin; i <= priceGroupDelta.PriceGroupNumbersMax; i++)
  40. for (int i = FUSIONFuelPrice.PriceGroupNumbersMin; i <= FUSIONFuelPrice.PriceGroupNumbersMax; i++)
  41. {
  42. decimal num2 = (this.basePrice + this.generalPriceDelta) + this.priceGroupDelta[i];
  43. if ((num2 < this.minPrice) || (num2 > this.maxPrice))
  44. {
  45. return false;
  46. }
  47. }
  48. return true;
  49. }
  50. // Properties
  51. public decimal BasePrice
  52. {
  53. get
  54. {
  55. return this.basePrice;
  56. }
  57. set
  58. {
  59. if (!this.reserved)
  60. {
  61. throw new ObjectNotReservedException("Fuel prices not reserved.");
  62. }
  63. if (value != this.basePrice)
  64. {
  65. changed = true;
  66. this.basePrice = value;
  67. }
  68. }
  69. }
  70. public decimal BasePriceAsCurrency
  71. {
  72. get
  73. {
  74. return this.basePriceAsCurrency;
  75. }
  76. set
  77. {
  78. if (!this.reserved)
  79. {
  80. throw new ObjectNotReservedException("Fuel prices not reserved.");
  81. }
  82. if (value != this.basePriceAsCurrency)
  83. {
  84. changed = true;
  85. this.basePriceAsCurrency = value;
  86. }
  87. }
  88. }
  89. public int FuelGrade
  90. {
  91. get
  92. {
  93. return this.fuelGrade;
  94. }
  95. }
  96. public decimal GeneralPriceDelta
  97. {
  98. get
  99. {
  100. return this.generalPriceDelta;
  101. }
  102. set
  103. {
  104. if (!this.reserved)
  105. {
  106. throw new ObjectNotReservedException("Fuel prices not reserved.");
  107. }
  108. if (value != this.generalPriceDelta)
  109. {
  110. changed = true;
  111. this.generalPriceDelta = value;
  112. }
  113. }
  114. }
  115. public decimal GeneralPriceDeltaAsCurrency
  116. {
  117. get { return this.generalPriceDeltaAsCurrency; }
  118. set
  119. {
  120. if (!this.reserved)
  121. {
  122. throw new ObjectNotReservedException("Fuel prices not reserved.");
  123. }
  124. if (value != this.generalPriceDeltaAsCurrency)
  125. {
  126. changed = true;
  127. this.generalPriceDeltaAsCurrency = value;
  128. }
  129. }
  130. }
  131. public IFuelPriceAddPricePerPriceGroup PriceGroupDelta
  132. {
  133. get { return this.priceGroupDelta; }
  134. }
  135. public bool Reserved
  136. {
  137. get { return this.reserved; }
  138. }
  139. public bool Changed
  140. {
  141. get { return this.changed; }
  142. set { changed = value; }
  143. }
  144. internal decimal WritableBasePrice
  145. {
  146. get { return this.basePrice; }
  147. set
  148. {
  149. if (value != this.basePrice)
  150. changed = true;
  151. this.basePrice = value;
  152. }
  153. }
  154. internal decimal WritableGeneralPriceChange
  155. {
  156. get
  157. {
  158. return this.generalPriceDelta;
  159. }
  160. set
  161. {
  162. if (value != this.generalPriceDelta)
  163. changed = true;
  164. this.generalPriceDelta = value;
  165. }
  166. }
  167. internal decimal WritableMaxPrice
  168. {
  169. get
  170. {
  171. return this.maxPrice;
  172. }
  173. set
  174. {
  175. this.maxPrice = value;
  176. }
  177. }
  178. internal decimal WritableMinPrice
  179. {
  180. get
  181. {
  182. return this.minPrice;
  183. }
  184. set
  185. {
  186. this.minPrice = value;
  187. }
  188. }
  189. internal bool WritableReserved
  190. {
  191. get
  192. {
  193. return this.reserved;
  194. }
  195. set
  196. {
  197. this.reserved = value;
  198. this.priceGroupDelta.Reserved = value;
  199. }
  200. }
  201. }
  202. public class FUSIONFuelPriceAddPricePerPriceGroup : IFuelPriceAddPricePerPriceGroup
  203. {
  204. // Fields
  205. private Dictionary<int, FUSIONPrice> priceDict = new Dictionary<int, FUSIONPrice>();
  206. private bool reserved;
  207. //public int priceGroupDeltaNum = 11;
  208. //public int PriceGroupNumbersMin;
  209. //public int PriceGroupNumbersMax;
  210. public int PriceGroupNumbers;
  211. //private bool changed = false;
  212. private FUSIONFuelPrice fp;
  213. // Methods
  214. public FUSIONFuelPriceAddPricePerPriceGroup(FUSIONFuelPrice _fp)
  215. {
  216. fp = _fp;
  217. //PriceGroupNumbersMin = Convert.ToInt16(1); //PriceGroup.MinValue;
  218. //PriceGroupNumbersMax = Convert.ToInt16(9); //PriceGroup.MaxValue; // TODO using pgrAppl7 arise an exception
  219. //PriceGroupNumbers = PriceGroupNumbersMax - PriceGroupNumbersMin + 1;
  220. PriceGroupNumbers = FUSIONFuelPrice.PriceGroupNumbersMax - FUSIONFuelPrice.PriceGroupNumbersMin + 1;
  221. //for (int i = 0; i <= this.PriceGroupNumbersMax; i++)
  222. for (int i = 0; i <= FUSIONFuelPrice.PriceGroupNumbersMax; i++)
  223. {
  224. this.priceDict.Add(i, new FUSIONPrice(0M, false));
  225. }
  226. }
  227. // Properties
  228. internal decimal this[int priceGroup]
  229. {
  230. get
  231. {
  232. return this.priceDict[priceGroup].price;
  233. }
  234. set
  235. {
  236. if (this.priceDict[priceGroup].price != value)
  237. {
  238. this.priceDict[priceGroup].price = value;
  239. this.priceDict[priceGroup].changed = true;
  240. }
  241. }
  242. }
  243. internal bool Reserved
  244. {
  245. get
  246. {
  247. return this.reserved;
  248. }
  249. set
  250. {
  251. this.reserved = value;
  252. }
  253. }
  254. public bool getChanged(int priceGroup)
  255. {
  256. return this.priceDict[priceGroup].changed;
  257. }
  258. public void setChanged(int priceGroup, bool value)
  259. {
  260. this.priceDict[priceGroup].changed = value;
  261. }
  262. decimal IFuelPriceAddPricePerPriceGroup.this[int priceGroup]
  263. {
  264. get
  265. {
  266. return this.priceDict[priceGroup].price;
  267. }
  268. set
  269. {
  270. if (!this.reserved)
  271. {
  272. throw new ObjectNotReservedException("Fuel prices not reserved.");
  273. }
  274. if (value != this.priceDict[priceGroup].price)
  275. {
  276. fp.Changed = true;
  277. this.priceDict[priceGroup].price = value;
  278. this.priceDict[priceGroup].changed = true;
  279. }
  280. }
  281. }
  282. }
  283. public class FUSIONPrice
  284. {
  285. public decimal price;
  286. public bool changed;
  287. public FUSIONPrice(decimal _price, bool _changed)
  288. {
  289. price = _price;
  290. changed = _changed;
  291. }
  292. }
  293. }