// public static List <rsp_GetCashDispenserErrorCodes> GetCashDispenserErrorCodes() { LogManager.WriteLog("|=> (GetCashDispenserErrorCodes) : Inside GetCashDispenserErrorCodes.", LogManager.enumLogLevel.Info); ISingleResult <rsp_GetCashDispenserErrorCodes> items; try { try { using (CashDispenserDBDataContext context = new CashDispenserDBDataContext(ExchangeConnectionString)) { items = context.GetCashDispenserErrorCodes(); return(items.ToList()); } } finally { } } catch (Exception ex) { ExceptionManager.Publish(ex); } return(null); }
/// <summary> /// Gets the dispenser. /// </summary> /// <returns>ICashDispenser</returns> public static ICashDispenser GetDispenser() { ICashDispenser dispenser = new CashDispenserImpl(new List <CashDispenserItem>()); LogManager.WriteLog("|=> (GetDispenser) : Inside Get Cash Dispenser.", LogManager.enumLogLevel.Info); try { try { using (CashDispenserDBDataContext context = new CashDispenserDBDataContext(ExchangeConnectionString)) { ISingleResult <rsp_GetCashDispenserItemsResult> items = context.GetCashDispenserItems(); if (items != null) { CashDispenserItem.TypeOfDeck prevDeckType = CashDispenserItem.TypeOfDeck.None; foreach (rsp_GetCashDispenserItemsResult item in items) { CashDispenserItem item2 = new CashDispenserItem(item.CassetteName, item.CassetteAlias); item2.CassetteID = item.CassetteID; item2.Denimination = item.Denomination; item2.TotalValue = item.TotalValue; item2.IssuedValue = item.IssuedValue; item2.RejectedValue = item.RejectedValue; LogManager.WriteLog(string.Format("|=> (GetDispenser) : Cassette [{0}], Denonimation : [{1:D}], Balance : [{2:F}].", item2.CassetteAlias, item2.Denimination, item2.RemainingValueCalculated), LogManager.enumLogLevel.Debug); if (prevDeckType == CashDispenserItem.TypeOfDeck.Upper) { item2.DeckType = CashDispenserItem.TypeOfDeck.Lower; //LogManager.WriteLog(string.Format("|=> (GetDispenser) : Upper Deck [{0}].", item2.CassetteAlias), LogManager.enumLogLevel.Info); } else { prevDeckType = item2.DeckType; //LogManager.WriteLog(string.Format("|=> (GetDispenser) : Lower Deck [{0}].", item2.CassetteAlias), LogManager.enumLogLevel.Info); } dispenser.DispenserItems.Add(item2); } } } } finally { } } catch (Exception ex) { ExceptionManager.Publish(ex); } return(dispenser); }
/// <summary> /// Updates the item. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public static bool UpdateItem(CashDispenserItem item) { bool result = false; LogManager.WriteLog("|=> (UpdateItem) : Inside Update Item.", LogManager.enumLogLevel.Info); try { using (CashDispenserDBDataContext context = new CashDispenserDBDataContext(ExchangeConnectionString)) { int userID = 0; string userName = string.Empty; if (SecurityHelper.CurrentUser != null && SecurityHelper.CurrentUser.SecurityUserID != 0 && SecurityHelper.CurrentUser.UserName != null) { userID = SecurityHelper.CurrentUser.SecurityUserID; userName = SecurityHelper.CurrentUser.DisplayName; } int?iResult = 0; context.UpdateCashDispenserItem(item.CassetteID, item.CassetteAlias, item.Denimination, item.TotalValue, userID, userName, ref iResult); if (iResult != null && iResult.HasValue) { result = iResult.Value > 0; } LogManager.WriteLog("|=> (UpdateItem) : Result : " + result.ToString(), LogManager.enumLogLevel.Info); } } catch (Exception ex) { ExceptionManager.Publish(ex); } return(result); }
/// <summary> /// Dispenses the specified value. /// </summary> /// <param name="value">The value.</param> /// <returns>DispenseResult</returns> public DispenseResult Dispense(decimal value) { ICoinDispenser coinDispenser = null; DispenseResult result = new DispenseResult(); decimal issuedValue = value; decimal rejectedValue = 0; decimal? issuedValue2 = 0; decimal? rejectedValue2 = 0; CoinDispStatus dispStatus = null; bool success = false; LogManager.WriteLog("|=> (Dispense) : " + ((this.DeckType == TypeOfDeck.Lower) ? "Lower" : "Upper") + " " + "Value : " + value.ToString(), LogManager.enumLogLevel.Info); bool canUpdateToDB = false; try { // COM API CALL result.Value = value; try { coinDispenser = GetCoinDispenser(); if (this.DeckType == TypeOfDeck.Lower) { dispStatus = coinDispenser.DispenseLowDeck((ushort)value); } else { dispStatus = coinDispenser.DispenseUPDeck((ushort)value); } } catch (Exception ex) { ExceptionManager.Publish(ex); } finally { if (dispStatus != null) { LogManager.WriteLog("|=> (Dispense) : Error Code : " + dispStatus.ErrorCode.ToString(), LogManager.enumLogLevel.Info); success = IsSucceeded(dispStatus.ErrorCode); canUpdateToDB = true; string outputMessage = "Output Message => Deck => {0}, Dispensed Value => {1:F}, Rejected Value => {2:F}"; if (this.DeckType == TypeOfDeck.Lower) { issuedValue = dispStatus.LowDispNotes; rejectedValue = dispStatus.LowRejNotes; try { outputMessage = string.Format(outputMessage, "Lower", issuedValue, rejectedValue); } catch { } } else { issuedValue = dispStatus.UPDispNotes; rejectedValue = dispStatus.UPRejNotes; try { outputMessage = string.Format(outputMessage, "Upper", issuedValue, rejectedValue); } catch { } } result.ErrorDescription = dispStatus.ErrDesc; LogManager.WriteLog(outputMessage, LogManager.enumLogLevel.Info); } else { result.ErrorDescription = "Unable to dispense from " + this.CassetteAlias + "."; result.Failed = true; } LogManager.WriteLog("|=> (Dispense) : " + result.ErrorDescription, LogManager.enumLogLevel.Info); coinDispenser = null; } if (canUpdateToDB) { // UPDATE IT INTO DATABASE using (CashDispenserDBDataContext context = new CashDispenserDBDataContext(CashDispenserFactory.ExchangeConnectionString)) { int?iResult = 0; context.UpdateCashDispenserItemValues(this.CassetteID, issuedValue, rejectedValue, ref issuedValue2, ref rejectedValue2, ref iResult); if (iResult != null && iResult.HasValue) { result.Result = (iResult.Value > 0); } LogManager.WriteLog("|=> (Dispense) : Result : " + result.Result.ToString(), LogManager.enumLogLevel.Info); } } } catch (Exception ex) { ExceptionManager.Publish(ex); } finally { if (result != null) { result.Result = success; if (canUpdateToDB) { result.IssuedValue = issuedValue; result.RejectedValue = rejectedValue; if (issuedValue2 != null && issuedValue2.HasValue) { this.IssuedValue = issuedValue2.Value; } if (rejectedValue2 != null && rejectedValue2.HasValue) { this.RejectedValue = rejectedValue2.Value; } } } } return(result); }
/// <summary> /// Tests the status. /// </summary> /// <param name="errorDesc">The error desc.</param> /// <returns>DispenserStatus</returns> public DispenserStatus TestStatus(out string errorDesc) { DispenserStatus status = DispenserStatus.NotAvailable; ICoinDispenser coinDispenser = null; errorDesc = string.Empty; string deckMsg = "Deck Type : " + ((this.DeckType == TypeOfDeck.Lower) ? "Lower" : "Upper"); CoinDispStatus dispStatus = null; bool canUpdateToDB = false; decimal issuedValue = 0; decimal rejectedValue = 0; decimal? issuedValue2 = 0; decimal? rejectedValue2 = 0; try { coinDispenser = GetCoinDispenser(); if (this.DeckType == TypeOfDeck.Lower) { dispStatus = coinDispenser.TestLowerDeck(); } else { dispStatus = coinDispenser.TestUpperDeck(); } if (dispStatus != null) { if (IsSucceeded(dispStatus.ErrorCode)) { status = DispenserStatus.Available; } errorDesc = dispStatus.ErrDesc; } else { errorDesc = "Unable to connect cash dispenser."; } LogManager.WriteLog("|=> (TestStatus) : " + deckMsg + ", " + errorDesc, LogManager.enumLogLevel.Info); } catch (Exception ex) { ExceptionManager.Publish(ex); } finally { try { if (dispStatus != null) { LogManager.WriteLog("|=> (Dispense) : Error Code : " + dispStatus.ErrorCode.ToString(), LogManager.enumLogLevel.Info); canUpdateToDB = true; if (this.DeckType == TypeOfDeck.Lower) { issuedValue = dispStatus.LowDispNotes; rejectedValue = dispStatus.LowRejNotes; } else { issuedValue = dispStatus.UPDispNotes; rejectedValue = dispStatus.UPRejNotes; } } if (canUpdateToDB) { // UPDATE IT INTO DATABASE using (CashDispenserDBDataContext context = new CashDispenserDBDataContext(CashDispenserFactory.ExchangeConnectionString)) { int?iResult = 0; context.UpdateCashDispenserItemValues(this.CassetteID, issuedValue, rejectedValue, ref issuedValue2, ref rejectedValue2, ref iResult); LogManager.WriteLog("|=> (TestStatus) : Result : " + (iResult.Value > 0).ToString(), LogManager.enumLogLevel.Info); } } } catch (Exception ex) { ExceptionManager.Publish(ex); } coinDispenser = null; } return(status); }