FUSIONFuelling.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. using System;
  2. using System.Globalization;
  3. //using System.Diagnostics;
  4. //using System.Windows.Forms;
  5. using Wayne.Lib;
  6. #if _SINP
  7. using Wayne.ForecourtControl.Nfs;
  8. #endif
  9. namespace Wayne.ForecourtControl.Fusion
  10. {
  11. /*internal*/
  12. public class FUSIONFuelling : IFuellingEx
  13. {
  14. // Fields
  15. private decimal amount;
  16. private long authorizationId;
  17. private DateTime completionDateTime;
  18. private int completionReason;
  19. private int fuelGrade;
  20. private int fuellingSequenceNumber;
  21. private int fuelPeriodId;
  22. private FUSIONManager manager;
  23. private int nfsFillingType;
  24. private FUSIONPump nfsPump;
  25. private INozzle nozzle;
  26. private PresetType presetType;
  27. private decimal presetValue;
  28. private decimal price;
  29. private PriceGroup priceGroup;
  30. private decimal quantity;
  31. private int reservedBy;
  32. private int authorizedBy;
  33. private FuellingState state;
  34. private FuellingType type;
  35. private ushort _CRC;
  36. private string signedReceiptLines;
  37. private string signedReceiptLinesWide;
  38. private byte reservingDeviceId;
  39. //FG, OCT-13-10, Add PayType to show outdoor payment type on FM
  40. private string payType;
  41. // used for generating Authorization token; it is ok to have one per workstation
  42. public static int transactionId = 0;
  43. // Methods
  44. internal FUSIONFuelling(FUSIONManager manager, FUSIONPump pump)
  45. {
  46. this.manager = manager;
  47. this.nfsPump = pump;
  48. this.WritableReservedBy = 0;
  49. this.WritableAuthorizedBy = 0;
  50. // JDL, AUG-10-10, default to outdoor card payment
  51. this.type = FuellingType.OptCardPaid;
  52. }
  53. internal void Dispose()
  54. {
  55. this.manager = null;
  56. }
  57. public void ReserveAsync(EventHandler<AsyncCompletedEventArgs> fuellingReserveCompleted, object userToken)
  58. {
  59. // call LockFuelSaleTrx
  60. // this.WritableReservedBy = this.manager.Id;
  61. this.manager.ifsfManager.LockFuelSaleTrx(((FUSIONPump)(this.Pump)).realId, this.FuellingSequenceNumber, (int)(this.AuthorizationId), fuellingReserveCompleted, userToken, this);
  62. }
  63. private void SendFillingRequest(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken, ushort fid)
  64. {
  65. throw new NotImplementedException("SendFillingRequest - TODO");
  66. }
  67. public void SetAsPaidAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  68. {
  69. // call ClearFuelSaleTrx
  70. Trace.WriteLine(string.Format("SetAsPaidAsync: fuellingSequenceNumber={0}, State={1}", this.fuellingSequenceNumber, State));
  71. this.manager.ifsfManager.ClearFuelSaleTrx(((FUSIONPump)(this.Pump)).realId, this.FuellingSequenceNumber, (int)(this.AuthorizationId), null, requestCompleted, userToken, this);
  72. }
  73. public void SetAsPaidAsync(string note, EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  74. {
  75. // call ClearFuelSaleTrx
  76. Trace.WriteLine(string.Format("SetAsPaidAsync: fuellingSequenceNumber={0}, State={1}", this.fuellingSequenceNumber, State));
  77. this.manager.ifsfManager.ClearFuelSaleTrx(((FUSIONPump)(this.Pump)).realId, this.FuellingSequenceNumber, (int)(this.AuthorizationId), note, requestCompleted, userToken, this);
  78. }
  79. public override string ToString()
  80. {
  81. return this.ToString("", CultureInfo.InvariantCulture);
  82. }
  83. public string ToString(IFormatProvider provider)
  84. {
  85. return this.ToString("", provider);
  86. }
  87. public string ToString(string format)
  88. {
  89. return this.ToString(format, CultureInfo.InvariantCulture);
  90. }
  91. public string ToString(string format, IFormatProvider provider)
  92. {
  93. return ("Fuelling, Pump=" + this.nfsPump.Id.ToString(CultureInfo.InvariantCulture) + " SqN=" + this.fuellingSequenceNumber.ToString(CultureInfo.InvariantCulture) + " AuthId=" + this.authorizationId.ToString(CultureInfo.InvariantCulture));
  94. }
  95. public void TransferAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  96. {
  97. // does nothing on transfer operation but setting fuelling on state Transferred
  98. Trace.WriteLine(string.Format("TransferAsync: fuellingSequenceNumber={0}, State={1}", this.fuellingSequenceNumber, State));
  99. if (this.State != FuellingState.Transferred)
  100. {
  101. this.WritableState = FuellingState.Transferred;
  102. this.nfsPump.FireFuellingStateChange(this, this.WritableState);
  103. }
  104. if (requestCompleted != null)
  105. requestCompleted.BeginInvoke(this, new AsyncCompletedEventArgs(true, userToken), null, null);
  106. }
  107. public void UndoTransferAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  108. {
  109. // does nothing on undotransfer operation but resetting fuelling on state PayableTransaction
  110. if (this.State == FuellingState.Transferred)
  111. this.WritableState = FuellingState.PayableTransaction;
  112. if (requestCompleted != null)
  113. requestCompleted.BeginInvoke(this, new AsyncCompletedEventArgs(true, userToken), null, null);
  114. }
  115. public void UnreserveAsync(EventHandler<AsyncCompletedEventArgs> requestCompleted, object userToken)
  116. {
  117. // call UnlockFuelSaleTrx
  118. //this.WritableReservedBy = 0;
  119. this.manager.ifsfManager.UnlockFuelSaleTrx(((FUSIONPump)(this.Pump)).realId, this.FuellingSequenceNumber, (int)(this.AuthorizationId), requestCompleted, userToken, this);
  120. }
  121. // Properties
  122. public decimal Amount
  123. {
  124. get
  125. {
  126. return this.amount;
  127. }
  128. }
  129. public long AuthorizationId
  130. {
  131. get
  132. {
  133. return this.authorizationId;
  134. }
  135. }
  136. public DateTime CompletionDateTime
  137. {
  138. get
  139. {
  140. return this.completionDateTime;
  141. }
  142. }
  143. public int CompletionReason
  144. {
  145. get
  146. {
  147. return this.completionReason;
  148. }
  149. }
  150. private bool Disposed
  151. {
  152. get
  153. {
  154. return (this.manager == null);
  155. }
  156. }
  157. public int FuelGrade
  158. {
  159. get
  160. {
  161. return this.fuelGrade;
  162. }
  163. }
  164. public int FuellingSequenceNumber
  165. {
  166. get
  167. {
  168. return this.fuellingSequenceNumber;
  169. }
  170. }
  171. public int FuelPeriodId
  172. {
  173. get
  174. {
  175. return this.fuelPeriodId;
  176. }
  177. }
  178. internal int NfsFillingType
  179. {
  180. get
  181. {
  182. return this.nfsFillingType;
  183. }
  184. set
  185. {
  186. this.nfsFillingType = value;
  187. }
  188. }
  189. public INozzle Nozzle
  190. {
  191. get
  192. {
  193. return this.nozzle;
  194. }
  195. }
  196. public PresetType PresetType
  197. {
  198. get
  199. {
  200. return this.presetType;
  201. }
  202. }
  203. public decimal PresetValue
  204. {
  205. get
  206. {
  207. return this.presetValue;
  208. }
  209. }
  210. public decimal Price
  211. {
  212. get
  213. {
  214. return this.price;
  215. }
  216. }
  217. public int PriceGroup
  218. {
  219. get
  220. {
  221. return (int)this.priceGroup;
  222. }
  223. }
  224. public IPump Pump
  225. {
  226. get
  227. {
  228. return this.nfsPump;
  229. }
  230. }
  231. public PumpAccumulatorReading PumpAccumulator
  232. {
  233. get
  234. {
  235. return null;
  236. }
  237. }
  238. public decimal Quantity
  239. {
  240. get
  241. {
  242. return this.quantity;
  243. }
  244. }
  245. public int ReservedBy
  246. {
  247. get
  248. {
  249. return this.reservedBy;
  250. }
  251. }
  252. public int AuthorizedBy
  253. {
  254. get
  255. {
  256. return this.authorizedBy;
  257. }
  258. }
  259. public FuellingState State
  260. {
  261. get
  262. {
  263. return this.state;
  264. }
  265. }
  266. public FuellingType Type
  267. {
  268. get
  269. {
  270. return this.type;
  271. }
  272. }
  273. public ushort CRC
  274. {
  275. get
  276. {
  277. return this._CRC;
  278. }
  279. }
  280. public string SignedReceiptLines
  281. {
  282. get
  283. {
  284. return this.signedReceiptLines;
  285. }
  286. }
  287. public string SignedReceiptLinesWide
  288. {
  289. get
  290. {
  291. return this.signedReceiptLinesWide;
  292. }
  293. }
  294. public byte ReservingDeviceId
  295. {
  296. get { return reservingDeviceId; }
  297. }
  298. internal decimal WritableAmount
  299. {
  300. get
  301. {
  302. return this.amount;
  303. }
  304. set
  305. {
  306. this.amount = value;
  307. }
  308. }
  309. internal long WritableAuthorizationId
  310. {
  311. get
  312. {
  313. return this.authorizationId;
  314. }
  315. set
  316. {
  317. this.authorizationId = value;
  318. }
  319. }
  320. internal DateTime WritableCompletionDateTime
  321. {
  322. get
  323. {
  324. return this.completionDateTime;
  325. }
  326. set
  327. {
  328. this.completionDateTime = value;
  329. }
  330. }
  331. internal int WritableCompletionReason
  332. {
  333. get
  334. {
  335. return this.completionReason;
  336. }
  337. set
  338. {
  339. this.completionReason = value;
  340. }
  341. }
  342. internal int WritableFuelGrade
  343. {
  344. get
  345. {
  346. return this.fuelGrade;
  347. }
  348. set
  349. {
  350. this.fuelGrade = value;
  351. }
  352. }
  353. internal int WritableFuellingSequenceNumber
  354. {
  355. get
  356. {
  357. return this.fuellingSequenceNumber;
  358. }
  359. set
  360. {
  361. this.fuellingSequenceNumber = value;
  362. }
  363. }
  364. internal int WritableFuelPeriodId
  365. {
  366. get
  367. {
  368. return this.fuelPeriodId;
  369. }
  370. set
  371. {
  372. this.fuelPeriodId = value;
  373. }
  374. }
  375. internal INozzle WritableNozzle
  376. {
  377. get
  378. {
  379. return this.nozzle;
  380. }
  381. set
  382. {
  383. this.nozzle = value;
  384. }
  385. }
  386. internal PresetType WritablePresetType
  387. {
  388. get
  389. {
  390. return this.presetType;
  391. }
  392. set
  393. {
  394. this.presetType = value;
  395. }
  396. }
  397. internal decimal WritablePresetValue
  398. {
  399. get
  400. {
  401. return this.presetValue;
  402. }
  403. set
  404. {
  405. this.presetValue = value;
  406. }
  407. }
  408. internal decimal WritablePrice
  409. {
  410. get
  411. {
  412. return this.price;
  413. }
  414. set
  415. {
  416. this.price = value;
  417. }
  418. }
  419. internal PriceGroup WritablePriceGroup
  420. {
  421. get
  422. {
  423. return this.priceGroup;
  424. }
  425. set
  426. {
  427. this.priceGroup = value;
  428. }
  429. }
  430. internal decimal WritableQuantity
  431. {
  432. get
  433. {
  434. return this.quantity;
  435. }
  436. set
  437. {
  438. this.quantity = value;
  439. }
  440. }
  441. internal int WritableReservedBy
  442. {
  443. get
  444. {
  445. return this.reservedBy;
  446. }
  447. set
  448. {
  449. this.reservedBy = value;
  450. }
  451. }
  452. internal int WritableAuthorizedBy
  453. {
  454. get
  455. {
  456. return this.authorizedBy;
  457. }
  458. set
  459. {
  460. this.authorizedBy = value;
  461. }
  462. }
  463. internal FuellingState WritableState
  464. {
  465. get
  466. {
  467. return this.state;
  468. }
  469. set
  470. {
  471. this.state = value;
  472. }
  473. }
  474. internal FuellingType WritableType
  475. {
  476. get
  477. {
  478. return this.type;
  479. }
  480. set
  481. {
  482. this.type = value;
  483. }
  484. }
  485. internal ushort WritableCRC
  486. {
  487. get
  488. {
  489. return this._CRC;
  490. }
  491. set
  492. {
  493. this._CRC = value;
  494. }
  495. }
  496. internal string WritableSignedReceiptLines
  497. {
  498. get
  499. {
  500. return this.signedReceiptLines;
  501. }
  502. set
  503. {
  504. this.signedReceiptLines = value;
  505. }
  506. }
  507. //FG, OCT-13-10, Add PayType to show outdoor payment type on FM
  508. internal string PayType
  509. {
  510. get
  511. {
  512. return this.payType;
  513. }
  514. set
  515. {
  516. this.payType = value;
  517. }
  518. }
  519. internal string WritableSignedReceiptLinesWide
  520. {
  521. get
  522. {
  523. return this.signedReceiptLinesWide;
  524. }
  525. set
  526. {
  527. this.signedReceiptLinesWide = value;
  528. }
  529. }
  530. internal byte WritableReservingDeviceId
  531. {
  532. get { return reservingDeviceId; }
  533. set { reservingDeviceId = value; }
  534. }
  535. public int convertStatus(int status)
  536. {
  537. // TODO
  538. return status;
  539. }
  540. #region IFuelling Members
  541. public byte PriceRevision
  542. {
  543. get { return 0; }
  544. }
  545. #endregion
  546. }
  547. }