using System; using System.Globalization; //using System.Diagnostics; //using System.Windows.Forms; using Wayne.Lib; #if _SINP using Wayne.ForecourtControl.Nfs; #endif namespace Wayne.ForecourtControl.Fusion { /*internal*/ public class FUSIONFuelling : IFuellingEx { // Fields private decimal amount; private long authorizationId; private DateTime completionDateTime; private int completionReason; private int fuelGrade; private int fuellingSequenceNumber; private int fuelPeriodId; private FUSIONManager manager; private int nfsFillingType; private FUSIONPump nfsPump; private INozzle nozzle; private PresetType presetType; private decimal presetValue; private decimal price; private PriceGroup priceGroup; private decimal quantity; private int reservedBy; private int authorizedBy; private FuellingState state; private FuellingType type; private ushort _CRC; private string signedReceiptLines; private string signedReceiptLinesWide; private byte reservingDeviceId; //FG, OCT-13-10, Add PayType to show outdoor payment type on FM private string payType; // used for generating Authorization token; it is ok to have one per workstation public static int transactionId = 0; // Methods internal FUSIONFuelling(FUSIONManager manager, FUSIONPump pump) { this.manager = manager; this.nfsPump = pump; this.WritableReservedBy = 0; this.WritableAuthorizedBy = 0; // JDL, AUG-10-10, default to outdoor card payment this.type = FuellingType.OptCardPaid; } internal void Dispose() { this.manager = null; } public void ReserveAsync(EventHandler fuellingReserveCompleted, object userToken) { // call LockFuelSaleTrx // this.WritableReservedBy = this.manager.Id; this.manager.ifsfManager.LockFuelSaleTrx(((FUSIONPump)(this.Pump)).realId, this.FuellingSequenceNumber, (int)(this.AuthorizationId), fuellingReserveCompleted, userToken, this); } private void SendFillingRequest(EventHandler requestCompleted, object userToken, ushort fid) { throw new NotImplementedException("SendFillingRequest - TODO"); } public void SetAsPaidAsync(EventHandler requestCompleted, object userToken) { // call ClearFuelSaleTrx Trace.WriteLine(string.Format("SetAsPaidAsync: fuellingSequenceNumber={0}, State={1}", this.fuellingSequenceNumber, State)); this.manager.ifsfManager.ClearFuelSaleTrx(((FUSIONPump)(this.Pump)).realId, this.FuellingSequenceNumber, (int)(this.AuthorizationId), null, requestCompleted, userToken, this); } public void SetAsPaidAsync(string note, EventHandler requestCompleted, object userToken) { // call ClearFuelSaleTrx Trace.WriteLine(string.Format("SetAsPaidAsync: fuellingSequenceNumber={0}, State={1}", this.fuellingSequenceNumber, State)); this.manager.ifsfManager.ClearFuelSaleTrx(((FUSIONPump)(this.Pump)).realId, this.FuellingSequenceNumber, (int)(this.AuthorizationId), note, requestCompleted, userToken, this); } public override string ToString() { return this.ToString("", CultureInfo.InvariantCulture); } public string ToString(IFormatProvider provider) { return this.ToString("", provider); } public string ToString(string format) { return this.ToString(format, CultureInfo.InvariantCulture); } public string ToString(string format, IFormatProvider provider) { return ("Fuelling, Pump=" + this.nfsPump.Id.ToString(CultureInfo.InvariantCulture) + " SqN=" + this.fuellingSequenceNumber.ToString(CultureInfo.InvariantCulture) + " AuthId=" + this.authorizationId.ToString(CultureInfo.InvariantCulture)); } public void TransferAsync(EventHandler requestCompleted, object userToken) { // does nothing on transfer operation but setting fuelling on state Transferred Trace.WriteLine(string.Format("TransferAsync: fuellingSequenceNumber={0}, State={1}", this.fuellingSequenceNumber, State)); if (this.State != FuellingState.Transferred) { this.WritableState = FuellingState.Transferred; this.nfsPump.FireFuellingStateChange(this, this.WritableState); } if (requestCompleted != null) requestCompleted.BeginInvoke(this, new AsyncCompletedEventArgs(true, userToken), null, null); } public void UndoTransferAsync(EventHandler requestCompleted, object userToken) { // does nothing on undotransfer operation but resetting fuelling on state PayableTransaction if (this.State == FuellingState.Transferred) this.WritableState = FuellingState.PayableTransaction; if (requestCompleted != null) requestCompleted.BeginInvoke(this, new AsyncCompletedEventArgs(true, userToken), null, null); } public void UnreserveAsync(EventHandler requestCompleted, object userToken) { // call UnlockFuelSaleTrx //this.WritableReservedBy = 0; this.manager.ifsfManager.UnlockFuelSaleTrx(((FUSIONPump)(this.Pump)).realId, this.FuellingSequenceNumber, (int)(this.AuthorizationId), requestCompleted, userToken, this); } // Properties public decimal Amount { get { return this.amount; } } public long AuthorizationId { get { return this.authorizationId; } } public DateTime CompletionDateTime { get { return this.completionDateTime; } } public int CompletionReason { get { return this.completionReason; } } private bool Disposed { get { return (this.manager == null); } } public int FuelGrade { get { return this.fuelGrade; } } public int FuellingSequenceNumber { get { return this.fuellingSequenceNumber; } } public int FuelPeriodId { get { return this.fuelPeriodId; } } internal int NfsFillingType { get { return this.nfsFillingType; } set { this.nfsFillingType = value; } } public INozzle Nozzle { get { return this.nozzle; } } public PresetType PresetType { get { return this.presetType; } } public decimal PresetValue { get { return this.presetValue; } } public decimal Price { get { return this.price; } } public int PriceGroup { get { return (int)this.priceGroup; } } public IPump Pump { get { return this.nfsPump; } } public PumpAccumulatorReading PumpAccumulator { get { return null; } } public decimal Quantity { get { return this.quantity; } } public int ReservedBy { get { return this.reservedBy; } } public int AuthorizedBy { get { return this.authorizedBy; } } public FuellingState State { get { return this.state; } } public FuellingType Type { get { return this.type; } } public ushort CRC { get { return this._CRC; } } public string SignedReceiptLines { get { return this.signedReceiptLines; } } public string SignedReceiptLinesWide { get { return this.signedReceiptLinesWide; } } public byte ReservingDeviceId { get { return reservingDeviceId; } } internal decimal WritableAmount { get { return this.amount; } set { this.amount = value; } } internal long WritableAuthorizationId { get { return this.authorizationId; } set { this.authorizationId = value; } } internal DateTime WritableCompletionDateTime { get { return this.completionDateTime; } set { this.completionDateTime = value; } } internal int WritableCompletionReason { get { return this.completionReason; } set { this.completionReason = value; } } internal int WritableFuelGrade { get { return this.fuelGrade; } set { this.fuelGrade = value; } } internal int WritableFuellingSequenceNumber { get { return this.fuellingSequenceNumber; } set { this.fuellingSequenceNumber = value; } } internal int WritableFuelPeriodId { get { return this.fuelPeriodId; } set { this.fuelPeriodId = value; } } internal INozzle WritableNozzle { get { return this.nozzle; } set { this.nozzle = value; } } internal PresetType WritablePresetType { get { return this.presetType; } set { this.presetType = value; } } internal decimal WritablePresetValue { get { return this.presetValue; } set { this.presetValue = value; } } internal decimal WritablePrice { get { return this.price; } set { this.price = value; } } internal PriceGroup WritablePriceGroup { get { return this.priceGroup; } set { this.priceGroup = value; } } internal decimal WritableQuantity { get { return this.quantity; } set { this.quantity = value; } } internal int WritableReservedBy { get { return this.reservedBy; } set { this.reservedBy = value; } } internal int WritableAuthorizedBy { get { return this.authorizedBy; } set { this.authorizedBy = value; } } internal FuellingState WritableState { get { return this.state; } set { this.state = value; } } internal FuellingType WritableType { get { return this.type; } set { this.type = value; } } internal ushort WritableCRC { get { return this._CRC; } set { this._CRC = value; } } internal string WritableSignedReceiptLines { get { return this.signedReceiptLines; } set { this.signedReceiptLines = value; } } //FG, OCT-13-10, Add PayType to show outdoor payment type on FM internal string PayType { get { return this.payType; } set { this.payType = value; } } internal string WritableSignedReceiptLinesWide { get { return this.signedReceiptLinesWide; } set { this.signedReceiptLinesWide = value; } } internal byte WritableReservingDeviceId { get { return reservingDeviceId; } set { reservingDeviceId = value; } } public int convertStatus(int status) { // TODO return status; } #region IFuelling Members public byte PriceRevision { get { return 0; } } #endregion } }