Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions Lib/Balance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ public Balance(XmlNode ledgerNode, XmlNode avaliableNode)

if (!String.IsNullOrEmpty(tempLedgerBalance))
{
// ***** Forced Invariant Culture.
// If you don't force it, it will use the computer's default (defined in windows control panel, regional settings)
// So, if the number format of the computer in use it's different from OFX standard (i suppose the english/invariant),
// the next line of could crash or (worse) the number would be wrongly interpreted.
// For example, my computer has a brazilian regional setting, with "." as thousand separator and "," as
// decimal separator, so the value "10.99" (ten 'dollars' (or whatever currency) and ninetynine cents) would be interpreted as "1099"
// (one thousand and ninetynine dollars - the "." would be ignored)
LedgerBalance = Convert.ToDecimal(tempLedgerBalance, CultureInfo.InvariantCulture);
// ***** Forced Invariant Culture.
// If you don't force it, it will use the computer's default (defined in windows control panel, regional settings)
// So, if the number format of the computer in use it's different from OFX standard (i suppose the english/invariant),
// the next line of could crash or (worse) the number would be wrongly interpreted.
// For example, my computer has a brazilian regional setting, with "." as thousand separator and "," as
// decimal separator, so the value "10.99" (ten 'dollars' (or whatever currency) and ninetynine cents) would be interpreted as "1099"
// (one thousand and ninetynine dollars - the "." would be ignored)
try
{
LedgerBalance = Convert.ToDecimal(tempLedgerBalance, CultureInfo.InvariantCulture);
} catch { }
}
else
{
throw new OfxParseException("Ledger balance has not been set");
//throw new OfxParseException("Ledger balance has not been set");
}

// ***** OFX files from my bank don't have the 'avaliableNode' node, so i manage a null situation
Expand All @@ -51,12 +54,16 @@ public Balance(XmlNode ledgerNode, XmlNode avaliableNode)

if (!String.IsNullOrEmpty(tempAvaliableBalance))
{
// ***** Forced Invariant Culture. (same commment as above)
AvaliableBalance = Convert.ToDecimal(tempAvaliableBalance, CultureInfo.InvariantCulture);
// ***** Forced Invariant Culture. (same commment as above)
try
{
AvaliableBalance = Convert.ToDecimal(tempAvaliableBalance, CultureInfo.InvariantCulture);
}
catch { }
}
else
{
throw new OfxParseException("Avaliable balance has not been set");
//throw new OfxParseException("Avaliable balance has not been set");
}
AvaliableBalanceDate = avaliableNode.GetValue("//DTASOF").ToDate();
}
Expand Down
6 changes: 3 additions & 3 deletions Lib/OfxDocumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private OfxDocument Parse(string ofxString)
}
else
{
throw new OfxParseException("Currency not found");
ofx.Currency = "BRL"; // default :)
}

//Get sign on node from OFX file
Expand Down Expand Up @@ -256,7 +256,7 @@ private void CheckHeader(string[] header)

if (header[1] != "DATA:OFXSGML")
throw new OfxParseException("Data type unsupported: " + header[1] + ". OFXSGML required");

/*
if (header[2] != "VERSION:102")
throw new OfxParseException("OFX version unsupported. " + header[2]);

Expand All @@ -273,7 +273,7 @@ private void CheckHeader(string[] header)
throw new OfxParseException("Compression unsupported");

if (header[7] != "OLDFILEUID:NONE")
throw new OfxParseException("OLDFILEUID incorrect");
throw new OfxParseException("OLDFILEUID incorrect");*/
}

#region Nested type: OFXSection
Expand Down
12 changes: 10 additions & 2 deletions Lib/OfxHelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public static DateTime ToDate(this string date)
}
catch
{
throw new OfxParseException("Unable to parse date");
return DateTime.MinValue;
//throw new OfxParseException("Unable to parse date");
}
}

Expand All @@ -55,7 +56,14 @@ public static string GetValue(this XmlNode node, string xpath)
fixedNode.Load(new StringReader(node.OuterXml));

var tempNode = fixedNode.SelectSingleNode(xpath);
return tempNode != null ? tempNode.FirstChild.Value : "";
try
{
return tempNode != null ? tempNode.FirstChild.Value : "";
}
catch {
// Colocado pois se o nó estava vazio, levantava exceção - o Sicredi tem nós vazios
return "";
}
}
}
}
38 changes: 19 additions & 19 deletions Lib/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Lib/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Transaction(XmlNode node, string currency)

try
{
Amount = Convert.ToDecimal(node.GetValue("//TRNAMT"), CultureInfo.InvariantCulture);
Amount = Convert.ToDecimal(node.GetValue("//TRNAMT").Replace(",", "."), CultureInfo.InvariantCulture);
}
catch (Exception ex)
{
Expand Down