public EMMADataSet.JournalRow BuildJournalEntry(EMMADataSet.JournalDataTable journalData,
            XmlNode journEntry, long IDOffset, short walletID, CharOrCorp corc)
        {
            EMMADataSet.JournalRow retVal = null;
            XmlNode entryIDNode = journEntry.SelectSingleNode("@refID");
            long entryID = long.Parse(entryIDNode.Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);

            // Actually create the line and add it to the data table
            retVal = journalData.NewJournalRow();
            retVal.ID = entryID + IDOffset;
            retVal.Date = DateTime.Parse(journEntry.SelectSingleNode("@date").Value);
            retVal.TypeID = short.Parse(journEntry.SelectSingleNode("@refTypeID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            retVal.SenderID = long.Parse(journEntry.SelectSingleNode("@ownerID1").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            retVal.RecieverID = long.Parse(journEntry.SelectSingleNode("@ownerID2").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            decimal amount = decimal.Parse(journEntry.SelectSingleNode("@amount").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            retVal.Amount = Math.Abs(amount);
            // Entries of type 42 (market escrow) do not have a reciever ID whene retrieved from the API.
            // ID 1000132 is the secure commerce commission.
            // If the sender is the secure commerce commission then the receiver must be the current
            // char/corp and vice versa.
            if (retVal.TypeID == 42 && retVal.RecieverID == 0)
            {
                if (retVal.SenderID == 1000132)
                {
                    retVal.RecieverID = corc == CharOrCorp.Char ? _charID : _corpID;
                }
                else
                {
                    retVal.RecieverID = 1000132;
                }
            }

            if (corc == CharOrCorp.Corp)
            {
                // This is a special case.
                // When bounty prizes are received by the player, corp tax is applied.
                // This corp tax does not appear as a seperate journal entry for the
                // character. It is specified by the taxReceiverID and taxAmount fields
                // on the bounty prize entry itself in the XML.
                // On the corp side, there is a specifc entry for the tax but it has
                // the same journalentryID and ownerID2 as the character entry.
                // This means that EMMA does not differentiate between them and the
                // corp tax part is lost.
                // In order to resolve this we simply set receiver ID to be the corp
                // instead of character and the sender to be the character instead
                // of concord.
                if (int.Parse(journEntry.SelectSingleNode("@refTypeID").Value) == 85)
                {
                    retVal.SenderID = retVal.RecieverID;
                    retVal.RecieverID = _corpID;
                }
            }

            if (amount < 0)
            {
                retVal.SBalance = decimal.Parse(journEntry.SelectSingleNode("@balance").Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                retVal.SWalletID = walletID == 0 ? (short)1000 : walletID;
                retVal.SArgName = journEntry.SelectSingleNode("@argName1").Value;
                retVal.SArgID = long.Parse(journEntry.SelectSingleNode("@argID1").Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                retVal.SCorpID = corc == CharOrCorp.Corp ? _corpID : 0;

                retVal.RBalance = 0;
                retVal.RWalletID = 0;
                retVal.RArgName = "";
                retVal.RArgID = 0;
                retVal.RCorpID = 0;
            }
            else
            {
                retVal.RBalance = decimal.Parse(journEntry.SelectSingleNode("@balance").Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                retVal.RWalletID = walletID == 0 ? (short)1000 : walletID;
                retVal.RArgName = journEntry.SelectSingleNode("@argName1").Value;
                retVal.RArgID = long.Parse(journEntry.SelectSingleNode("@argID1").Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                retVal.RCorpID = corc == CharOrCorp.Corp ? _corpID : 0;

                retVal.SBalance = 0;
                retVal.SWalletID = 0;
                retVal.SArgName = "";
                retVal.SArgID = 0;
                retVal.SCorpID = 0;
            }
            // Reason text can be longer than 50 chars so truncate it if needed...
            string reason = journEntry.SelectSingleNode("@reason").Value;
            retVal.Reason = (reason.Length > 50 ? reason.Remove(50) : reason);

            return retVal;
        }
        private EMMADataSet.JournalRow BuildRow(long corpID, XmlNode node, long id, long recieverID,
            EMMADataSet.JournalDataTable table)
        {
            EMMADataSet.JournalRow newRow = table.NewJournalRow();
            XmlNode child = null;
            newRow.ID = id;
            newRow.RecieverID = recieverID;
            newRow.SenderID = long.Parse(node.SelectSingleNode("OwnerID1").FirstChild.Value);
            newRow.Date = DateTime.Parse(node.SelectSingleNode("Date").FirstChild.Value,
                System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat);
            newRow.TypeID = short.Parse(node.SelectSingleNode("TypeID").FirstChild.Value);
            decimal amount = decimal.Parse(node.SelectSingleNode("Amount").FirstChild.Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.Amount = Math.Abs(amount);
            if (amount < 0)
            {
                newRow.SBalance = decimal.Parse(node.SelectSingleNode("Balance").FirstChild.Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                newRow.SWalletID = short.Parse(node.SelectSingleNode("WalletID").FirstChild.Value);
                child = node.SelectSingleNode("ArgName1").FirstChild;
                newRow.SArgName = child == null ? "" : child.Value;
                child = node.SelectSingleNode("ArgID1").FirstChild;
                newRow.SArgID = long.Parse(child == null ? "0" : child.Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                newRow.SCorpID = corpID;

                newRow.RBalance = 0;
                newRow.RWalletID = 0;
                newRow.RArgName = "";
                newRow.RArgID = 0;
                newRow.RCorpID = 0;
            }
            else
            {
                newRow.RBalance = decimal.Parse(node.SelectSingleNode("Balance").FirstChild.Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                newRow.RWalletID = short.Parse(node.SelectSingleNode("WalletID").FirstChild.Value);
                child = node.SelectSingleNode("ArgName1").FirstChild;
                newRow.RArgName = child == null ? "" : child.Value;
                child = node.SelectSingleNode("ArgID1").FirstChild;
                newRow.RArgID = long.Parse(child == null ? "0" : child.Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                newRow.RCorpID = corpID;

                newRow.SBalance = 0;
                newRow.SWalletID = 0;
                newRow.SArgName = "";
                newRow.SArgID = 0;
                newRow.SCorpID = 0;
            }
            // Reason text can be no longer than 50 chars so truncate it if needed...
            child = node.SelectSingleNode("Reason").FirstChild;
            string reason = child == null ? "" : child.Value;
            newRow.Reason = (reason.Length > 50 ? reason.Remove(50) : reason);
            return newRow;
        }