ShowTrxListReadyForPay.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Wayne.Lib.StateEngine;
  7. using Wayne.Lib.StateEngine.Generic;
  8. namespace SinochemInternetPlusApp.States.Shared
  9. {
  10. public class ShowTrxListReadyForPay : TimeoutState<FuelingPoint>
  11. {
  12. private int requestId;
  13. protected override void Enter(StateEntry stateEntry, ref Transition transition)
  14. {
  15. base.Enter(stateEntry, ref transition);
  16. //Don't need send rquest to BigScreen
  17. if (!Main.HasBigSreen())
  18. {
  19. transition = new Transition(this, TransitionType.Done);
  20. return;
  21. }
  22. if (Main.CurrentEpsTrx != null)
  23. {
  24. var validTrx = EpsTransactionQuery.GetValidCarPlateEpsTrxModels(
  25. Main.GetAllNozzlesOnThisSide(),
  26. ConfigurationValues.AlreadyDoneEpsTrxCountPerDisplay,
  27. Main.DebugLogger);
  28. DebugLog("validTrx: " + validTrx.Count());
  29. if (Main.Eps.NozzleMappingGradeName() != null)
  30. {
  31. foreach (var trx in validTrx)
  32. {
  33. if (trx.trx_status == EpsTrxStatus.BeforeFueling || trx.trx_status == EpsTrxStatus.Fueling)
  34. {
  35. trx.AvailableNozzleGrade = Main.GetAvailableNozzleInfo();
  36. }
  37. }
  38. }
  39. var text = Main.Eps.CreateDisplayTrxCommand(validTrx, out requestId, 0);
  40. if (Main.Eps.CarPlateHandler != null)
  41. {
  42. DebugLog(text);
  43. Main.Eps.CarPlateHandler.BroadcastMessageViaFdc(text);
  44. if (!Main.ContainsRequestId(requestId))
  45. Main.AddRequestId(requestId);
  46. }
  47. else
  48. transition = new Transition(this, TransitionType.Done);
  49. }
  50. else
  51. {
  52. transition = new Transition(this, TransitionType.Done);
  53. }
  54. }
  55. protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
  56. {
  57. if (stateEngineEvent.Type.Equals(EventType.DisplayResponseReceived))
  58. {
  59. var e = stateEngineEvent as GenericEvent<DisplayResponseEventArgs>;
  60. if (e != null && e.EventArgs != null)
  61. {
  62. if (requestId == e.EventArgs.DispResponse.RequestId)
  63. {
  64. e.Handled = true;
  65. if (Main.ContainsRequestId(requestId))
  66. Main.RemoveRequestId(requestId);
  67. transition = new Transition(this, TransitionType.Done);
  68. }
  69. }
  70. }
  71. }
  72. protected override void Timeout(ref Transition transition)
  73. {
  74. transition = new Transition(this, TransitionType.Timeout);
  75. }
  76. protected override int TimeoutInterval =>
  77. TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.CarPlateMode_ShowTrxListReadyForPay, 10);
  78. }
  79. }