// /// <summary> /// Performs the auto cash dispense. /// </summary> /// <returns>True if succeeded; otherwise false.</returns> public bool AutoCashDispense(string fieldName, string fieldValue, decimal value) { DispenserWorkerResult result = DispenserWorkerResult.None; string message = string.Empty; this.EnsureDecksAreLoaded(); IDictionary <string, DeckDenomValue> pairs = new SortedDictionary <string, DeckDenomValue>(StringComparer.InvariantCultureIgnoreCase); string keyLower = "LOWER"; string keyUpper = "UPPER"; decimal upperCount = 0; decimal lowerCount = 0; decimal receiptAmount = 0; try { // Determine the number of counts from lower and upper deck decimal upperAvailAmount = this.UpperDeck.RemainingValueCalculated; decimal lowerAvailAmount = this.LowerDeck.RemainingValueCalculated; // denominations decimal upperDenom = this.UpperDeck.Denimination; decimal lowerDenom = this.LowerDeck.Denimination; if (lowerDenom > upperDenom) { // denom decimal tempDenom = lowerDenom; lowerDenom = upperDenom; upperDenom = tempDenom; // total amount decimal tempAmount = lowerAvailAmount; lowerAvailAmount = upperAvailAmount; upperAvailAmount = tempAmount; keyLower = "UPPER"; keyUpper = "LOWER"; } // mapping for upper and lower deck pairs.Add(keyLower, new DeckDenomValue() { Denomination = lowerDenom, Value = lowerAvailAmount }); pairs.Add(keyUpper, new DeckDenomValue() { Denomination = upperDenom, Value = upperAvailAmount }); // if valid amount is passed if (value > 0) { decimal inputValue = value; // upper count upperCount = Math.Floor(inputValue / pairs[keyUpper].Denomination); if (upperCount > pairs[keyUpper].TotalCount) { upperCount = pairs[keyUpper].TotalCount; } inputValue -= (upperCount * pairs[keyUpper].Denomination); // lower count lowerCount = Math.Floor(inputValue / pairs[keyLower].Denomination); if (lowerCount > pairs[keyLower].TotalCount) { lowerCount = pairs[keyLower].TotalCount; } inputValue -= (lowerCount * pairs[keyLower].Denomination); // updated values pairs[keyUpper].Value = upperCount; pairs[keyLower].Value = lowerCount; receiptAmount = inputValue; } // dispense result = this.Dispense(pairs["UPPER"].Value, pairs["LOWER"].Value, out message); if (result != (DispenserWorkerResult.Success | DispenserWorkerResult.LowerDeckOK | DispenserWorkerResult.UpperDeckOK)) { LogManager.WriteLog(message, LogManager.enumLogLevel.Error); } else { LogManager.WriteLog(message, LogManager.enumLogLevel.Info); } // try to print the remaing amount as receipt if (receiptAmount > 0) { try { using (CReportViewer objReportViewer = new CReportViewer()) { objReportViewer.PrintCashDispenserReceipt(System.Environment.MachineName, fieldName, fieldValue, Convert.ToDecimal(receiptAmount)); } } catch (Exception ex) { ExceptionManager.Publish(ex); } } WriteAuditLog(this.UpperDeck, this.LowerDeck, upperCount, lowerCount, "Receipt", receiptAmount); } catch (Exception ex) { ExceptionManager.Publish(ex); } return(result == (DispenserWorkerResult.Success | DispenserWorkerResult.LowerDeckOK | DispenserWorkerResult.UpperDeckOK)); }