public void rangerScanner_TransportSetItemOutput( object sender, AxRANGERLib._DRangerEvents_TransportSetItemOutputEvent e )
{
System.Diagnostics.Debug.WriteLine( string.Format( "{0} : rangerScanner_TransportSetItemOutput", DateTime.Now.ToString( "o" ) ) );
var currentPage = Application.Current.MainWindow.Content;
if ( currentPage != this )
{
// only accept scans when the scanning page is showing
batchPage.micrImage.ClearBuffer();
return;
}
try
{
lblStartupInfo.Visibility = Visibility.Collapsed;
RockConfig rockConfig = RockConfig.Load();
ScannedDocInfo scannedDoc = new ScannedDocInfo();
// mark it as Upload, but we'll set it to false if anything bad happens before we actually upload
scannedDoc.Upload = true;
scannedDoc.CurrencyTypeValue = batchPage.SelectedCurrencyValue;
scannedDoc.SourceTypeValue = batchPage.SelectedSourceTypeValue;
scannedDoc.FrontImageData = GetImageBytesFromRanger( RangerSides.TransportFront );
if ( rockConfig.EnableRearImage )
{
scannedDoc.BackImageData = GetImageBytesFromRanger( RangerSides.TransportRear );
}
if ( scannedDoc.IsCheck )
{
string checkMicr = batchPage.rangerScanner.GetMicrText( 1 );
WriteToDebugLog( string.Format( "[{0}] - '{1}'", DateTime.Now.ToString( "o" ), checkMicr ) );
string remainingMicr = checkMicr;
string accountNumber = string.Empty;
string routingNumber = string.Empty;
string checkNumber = string.Empty;
// there should always be two transit symbols ('d'). The transit number is between them
int transitSymbol1 = remainingMicr.IndexOf( (char)RangerE13BMicrSymbols.E13B_TransitSymbol );
int transitSymbol2 = remainingMicr.LastIndexOf( (char)RangerE13BMicrSymbols.E13B_TransitSymbol );
int transitStart = transitSymbol1 + 1;
int transitLength = transitSymbol2 - transitSymbol1 - 1;
if ( transitLength > 0 )
{
routingNumber = remainingMicr.Substring( transitStart, transitLength );
remainingMicr = remainingMicr.Remove( transitStart - 1, transitLength + 2 );
}
char[] separatorSymbols = new char[] { (char)RangerE13BMicrSymbols.E13B_TransitSymbol, (char)RangerE13BMicrSymbols.E13B_OnUsSymbol, (char)RangerE13BMicrSymbols.E13B_AmountSymbol };
// the last 'On-Us' symbol ('c') signifies the end of the account number
int lastOnUsPosition = remainingMicr.LastIndexOf( (char)RangerE13BMicrSymbols.E13B_OnUsSymbol );
if ( lastOnUsPosition > 0 )
{
int accountNumberDigitPosition = lastOnUsPosition - 1;
// read all digits to the left of the last 'OnUs' until you run into another seperator symbol
while ( accountNumberDigitPosition >= 0 )
{
char accountNumberDigit = remainingMicr[accountNumberDigitPosition];
if ( separatorSymbols.Contains( accountNumberDigit ) )
{
break;
}
else
{
accountNumber = accountNumberDigit + accountNumber;
accountNumber = accountNumber.Trim();
}
accountNumberDigitPosition--;
}
remainingMicr = remainingMicr.Remove( accountNumberDigitPosition + 1, lastOnUsPosition - accountNumberDigitPosition );
}
// any remaining digits that aren't the account number and transit number are probably the check number
string[] remainingMicrParts = remainingMicr.Split( new char[] { (char)RangerE13BMicrSymbols.E13B_OnUsSymbol, ' ' }, StringSplitOptions.RemoveEmptyEntries );
string otherData = null;
if ( remainingMicrParts.Any() )
{
checkNumber = remainingMicrParts.Last();
// throw any remaining data into 'otherData' (a reject symbol could be in the other data)
remainingMicr = remainingMicr.Replace( (char)RangerE13BMicrSymbols.E13B_OnUsSymbol, ' ' );
remainingMicr = remainingMicr.Replace( checkNumber, string.Empty );
otherData = remainingMicr;
}
scannedDoc.RoutingNumber = routingNumber;
scannedDoc.AccountNumber = accountNumber;
scannedDoc.CheckNumber = checkNumber;
scannedDoc.OtherData = otherData;
scannedDoc.ScannedCheckMicrData = checkMicr;
// look for the "can't read" symbol (or completely blank read ) to detect if the check micr couldn't be read
// from http://www.sbulletsupport.com/forum/index.php?topic=172.0
if ( checkMicr.Contains( (char)RangerCommonSymbols.RangerRejectSymbol ) || string.IsNullOrWhiteSpace( checkMicr ) )
{
scannedDoc.BadMicr = true;
scannedDoc.Upload = false;
}
}
ShowScannedDocStatusAndUpload( scannedDoc );
}
catch ( Exception ex )
{
if ( ex is AggregateException )
{
ShowException( ( ex as AggregateException ).Flatten() );
}
else
{
ShowException( ex );
}
}
}