FUSIONFuelPrice.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. using System;
  2. using System.Collections.Generic;
  3. using Wayne.Lib;
  4. namespace Wayne.ForecourtControl.Fusion
  5. {
  6. internal class FUSIONFuelPrice : IFuelPrice
  7. {
  8. // Fields
  9. private decimal basePrice;
  10. private decimal basePriceAsCurrency;
  11. private int fuelGrade;
  12. private decimal generalPriceDelta;
  13. private decimal generalPriceDeltaAsCurrency;
  14. private decimal maxPrice;
  15. private decimal minPrice;
  16. private FUSIONFuelPriceAddPricePerPriceGroup priceGroupDelta;
  17. private bool reserved;
  18. public Object locker;
  19. private bool changed = false;
  20. private FUSIONManager manager;
  21. // Methods
  22. public FUSIONFuelPrice(int fuelGrade, FUSIONManager manager)
  23. {
  24. this.fuelGrade = fuelGrade;
  25. this.priceGroupDelta = new FUSIONFuelPriceAddPricePerPriceGroup(this);
  26. locker = new object();
  27. this.manager = manager;
  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 = PriceGroup.MinValue; i <= PriceGroup.MaxValue; 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. // We have to send all prices for this product. Mark all deltas as changed
  68. for (int pg = PriceGroup.MinValue; pg <= PriceGroup.MaxValue; pg++)
  69. {
  70. priceGroupDelta.setChanged(new[]{pg}, true);
  71. }
  72. }
  73. }
  74. }
  75. public decimal BasePriceAsCurrency
  76. {
  77. get
  78. {
  79. return this.basePriceAsCurrency;
  80. }
  81. set
  82. {
  83. if (!this.reserved)
  84. {
  85. throw new ObjectNotReservedException("Fuel prices not reserved.");
  86. }
  87. if (value != this.basePriceAsCurrency)
  88. {
  89. changed = true;
  90. this.basePriceAsCurrency = value;
  91. // We have to send all prices for this product. Mark all deltas as changed
  92. for (int pg = PriceGroup.MinValue; pg <= PriceGroup.MaxValue; pg++)
  93. {
  94. priceGroupDelta.setChanged(new[]{pg}, true);
  95. }
  96. }
  97. }
  98. }
  99. public int FuelGrade
  100. {
  101. get
  102. {
  103. if (manager.FuelGradeShift != 0)
  104. return this.fuelGrade + manager.FuelGradeShift;
  105. else
  106. return this.fuelGrade;
  107. }
  108. }
  109. public decimal GeneralPriceDelta
  110. {
  111. get
  112. {
  113. return this.generalPriceDelta;
  114. }
  115. set
  116. {
  117. if (!this.reserved)
  118. {
  119. throw new ObjectNotReservedException("Fuel prices not reserved.");
  120. }
  121. if (value != this.generalPriceDelta)
  122. {
  123. changed = true;
  124. this.generalPriceDelta = value;
  125. // We have to send all prices for this product. Mark all deltas as changed
  126. for (int pg = PriceGroup.MinValue; pg <= PriceGroup.MaxValue; pg++)
  127. {
  128. priceGroupDelta.setChanged(new[]{pg}, true);
  129. }
  130. }
  131. }
  132. }
  133. public decimal GeneralPriceDeltaAsCurrency
  134. {
  135. get { return this.generalPriceDeltaAsCurrency; }
  136. set
  137. {
  138. if (!this.reserved)
  139. {
  140. throw new ObjectNotReservedException("Fuel prices not reserved.");
  141. }
  142. if (value != this.generalPriceDeltaAsCurrency)
  143. {
  144. changed = true;
  145. this.generalPriceDeltaAsCurrency = value;
  146. // We have to send all prices for this product. Mark all deltas as changed
  147. for (int pg = PriceGroup.MinValue; pg <= PriceGroup.MaxValue; pg++)
  148. {
  149. priceGroupDelta.setChanged(new[]{pg}, true);
  150. }
  151. }
  152. }
  153. }
  154. public IFuelPriceAddPricePerPriceGroup PriceGroupDelta
  155. {
  156. get { return this.priceGroupDelta; }
  157. }
  158. public bool Reserved
  159. {
  160. get { return this.reserved; }
  161. }
  162. public bool Changed
  163. {
  164. get { return this.changed; }
  165. set { changed = value; }
  166. }
  167. internal int WritableFuelGrade
  168. {
  169. get
  170. {
  171. return this.fuelGrade;
  172. }
  173. set
  174. {
  175. this.fuelGrade = value;
  176. }
  177. }
  178. internal decimal WritableBasePrice
  179. {
  180. get { return this.basePrice; }
  181. set
  182. {
  183. if (value != this.basePrice)
  184. changed = true;
  185. this.basePrice = value;
  186. }
  187. }
  188. internal decimal WritableGeneralPriceChange
  189. {
  190. get
  191. {
  192. return this.generalPriceDelta;
  193. }
  194. set
  195. {
  196. if (value != this.generalPriceDelta)
  197. changed = true;
  198. this.generalPriceDelta = value;
  199. }
  200. }
  201. internal decimal WritableMaxPrice
  202. {
  203. get
  204. {
  205. return this.maxPrice;
  206. }
  207. set
  208. {
  209. this.maxPrice = value;
  210. }
  211. }
  212. internal decimal WritableMinPrice
  213. {
  214. get
  215. {
  216. return this.minPrice;
  217. }
  218. set
  219. {
  220. this.minPrice = value;
  221. }
  222. }
  223. internal bool WritableReserved
  224. {
  225. get
  226. {
  227. return this.reserved;
  228. }
  229. set
  230. {
  231. this.reserved = value;
  232. this.priceGroupDelta.Reserved = value;
  233. }
  234. }
  235. }
  236. internal class FUSIONFuelPriceAddPricePerPriceGroup : IFuelPriceAddPricePerPriceGroup
  237. {
  238. // Fields
  239. private Dictionary<int, FUSIONPrice> priceDict = new Dictionary<int, FUSIONPrice>();
  240. private bool reserved;
  241. //public int priceGroupDeltaNum = 11;
  242. //public int PriceGroupNumbersMin;
  243. //public int PriceGroupNumbersMax;
  244. public int PriceGroupNumbers;
  245. //private bool changed = false;
  246. private FUSIONFuelPrice fp;
  247. // Methods
  248. public FUSIONFuelPriceAddPricePerPriceGroup(FUSIONFuelPrice _fp)
  249. {
  250. fp = _fp;
  251. //PriceGroupNumbersMin = Convert.ToInt16(1); //PriceGroup.MinValue;
  252. //PriceGroupNumbersMax = Convert.ToInt16(9); //PriceGroup.MaxValue; // TODO using pgrAppl7 arise an exception
  253. //PriceGroupNumbers = PriceGroupNumbersMax - PriceGroupNumbersMin + 1;
  254. PriceGroupNumbers = PriceGroup.MaxValue - PriceGroup.MinValue + 1;
  255. //for (int i = 0; i <= this.PriceGroupNumbersMax; i++)
  256. for (int i = PriceGroup.MinValue; i <= PriceGroup.MaxValue; i++)
  257. {
  258. this.priceDict.Add(i, new FUSIONPrice(0M, false));
  259. }
  260. }
  261. // Properties
  262. internal decimal this[int priceGroup]
  263. {
  264. get
  265. {
  266. return this.priceDict[priceGroup].price;
  267. }
  268. set
  269. {
  270. if (this.priceDict[priceGroup].price != value)
  271. {
  272. this.priceDict[priceGroup].price = value;
  273. fp.Changed = true;
  274. this.priceDict[priceGroup].changed = true;
  275. }
  276. }
  277. }
  278. internal bool Reserved
  279. {
  280. get
  281. {
  282. return this.reserved;
  283. }
  284. set
  285. {
  286. this.reserved = value;
  287. }
  288. }
  289. public bool getChanged(int priceGroup)
  290. {
  291. return this.priceDict[priceGroup].changed;
  292. }
  293. public void setChanged(IEnumerable<int> priceGroups, bool value)
  294. {
  295. foreach (var priceGroup in priceGroups)
  296. {
  297. if (priceGroup != PriceGroup.Unknown)
  298. this.priceDict[priceGroup].changed = value;
  299. }
  300. }
  301. decimal IFuelPriceAddPricePerPriceGroup.this[int priceGroup]
  302. {
  303. get
  304. {
  305. return this.priceDict[priceGroup].price;
  306. }
  307. set
  308. {
  309. if (!this.reserved)
  310. {
  311. throw new ObjectNotReservedException("Fuel prices not reserved.");
  312. }
  313. if (value != this.priceDict[priceGroup].price)
  314. {
  315. fp.Changed = true;
  316. this.priceDict[priceGroup].price = value;
  317. this.priceDict[priceGroup].changed = true;
  318. }
  319. }
  320. }
  321. }
  322. public class FUSIONPrice
  323. {
  324. public decimal price;
  325. public bool changed;
  326. public FUSIONPrice(decimal _price, bool _changed)
  327. {
  328. price = _price;
  329. changed = _changed;
  330. }
  331. }
  332. }