public GroupLocation(EMMADataSet.GroupLocationRow data)
        {
            if (data != null)
            {
                _name = data.LocationName.Trim();

                char[] delim = {','};
                string[] regions = data.RegionIDs.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                _regions = new List<long>();
                foreach (string region in regions)
                {
                    _regions.Add(long.Parse(region));
                }

                string[] stations = data.StationIDs.Split(delim, StringSplitOptions.RemoveEmptyEntries);
                _stations = new List<long>();
                foreach (string station in stations)
                {
                    _stations.Add(long.Parse(station));
                }

                _stationID = data.StationID;
                _range = data.Range;
                _reportGroupID = data.ReportGroupID;
            }
        }
 public ReprocessItem(EMMADataSet.ReprocessItemRow data)
 {
     _jobID = data.JobID;
     _itemID = data.ItemID;
     _quantity = data.Quantity;
     _buyPrice = data.BuyPrice;
 }
 public static void Store(EMMADataSet.IndustryJobsDataTable table)
 {
     lock (_tableAdapter)
     {
         _tableAdapter.Update(table);
     }
 }
 public JournalEntry(EMMADataSet.JournalRow dataRow, long ownerID)
 {
     if (dataRow != null)
     {
         _ownerIsSender = ownerID == dataRow.SenderID;
         _id = dataRow.ID;
         _date = dataRow.Date;
         if (UserAccount.Settings.UseLocalTimezone)
         {
             _date = _date.AddHours(Globals.HoursOffset);
         }
         _typeID = dataRow.TypeID;
         _senderID = dataRow.SenderID;
         _recieverID = dataRow.RecieverID;
         _argName = _ownerIsSender ? dataRow.SArgName : dataRow.RArgName;
         _argID = _ownerIsSender ? dataRow.SArgID : dataRow.RArgID;
         _amount = dataRow.Amount;
         _balance = _ownerIsSender ? dataRow.SBalance : dataRow.RBalance;
         _reason = dataRow.Reason;
         _sWalletID = dataRow.SWalletID;
         _rWalletID = dataRow.RWalletID;
         _sCorpID = dataRow.SCorpID;
         _rCorpID = dataRow.RCorpID;
     }
 }
Example #5
0
 public WebLink(EMMADataSet.WebLinksRow data)
 {
     _id = data.WebLinkID;
     _link = data.Link;
     _desc = data.Description;
     _corpID = data.CorpID;
 }
Example #6
0
 public Asset(EMMADataSet.AssetsRow dataRow, Asset container)
 {
     if (dataRow != null)
     {
         _id = dataRow.ID;
         _ownerID = dataRow.OwnerID;
         if (dataRow.CorpAsset)
         {
             _corpAsset = true;
             _ownerID = UserAccount.CurrentGroup.GetCharacter(_ownerID).CorpID;
         }
         _locationID = dataRow.LocationID;
         _itemID = dataRow.ItemID;
         _quantity = dataRow.Quantity;
         _autoConExclude = dataRow.AutoConExclude;
         _reprocExclude = dataRow.ReprocExclude;
         _processed = dataRow.Processed;
         _statusID = dataRow.Status;
         _isContainer = dataRow.IsContainer;
         _container = container;
         _containerID = dataRow.ContainerID;
         _regionID = dataRow.RegionID;
         _systemID = dataRow.SystemID;
         _contents = new AssetList();
         _unitBuyPrice = dataRow.Cost;
         _pureUnitBuyPrice = _unitBuyPrice;
         _gotUnitBuyPrice = dataRow.CostCalc;
         _unitBuyPricePrecalc = dataRow.CostCalc;
         _eveItemInstanceID = dataRow.EveItemID;
     }
 }
 public ReprocessJob(EMMADataSet.ReprocessJobRow data)
 {
     _id = data.ID;
     _date = data.JobDate;
     _stationID = data.StationID;
     _reportGroupID = data.GroupID;
     _ownerID = data.OwnerID;
 }
 public Transaction(EMMADataSet.TransactionsRow dataRow)
 {
     if (dataRow != null)
     {
         _id = dataRow.ID;
         Populate(dataRow);
     }
 }
 public static bool GetJob(EMMADataSet.IndustryJobsDataTable table, long jobID)
 {
     _tableAdapter.ClearBeforeFill = false;
     lock (_tableAdapter)
     {
         _tableAdapter.FillByID(table, jobID);
     }
     EMMADataSet.IndustryJobsRow row = table.FindByID(jobID);
     return row != null;
 }
Example #10
0
        /// <summary>
        /// Checks if the specified row exists in the database.
        /// If it does then the table will contain the row (as well as anything else that was in it
        /// before this method was called)
        /// </summary>
        /// <param name="ordersTable"></param>
        /// <param name="orderRow"></param>
        /// <param name="ID">The ID of the order that matches the supplied one</param>
        /// <returns></returns>
        public static bool Exists(EMMADataSet.OrdersDataTable ordersTable, EMMADataSet.OrdersRow orderRow,
            ref int ID, long corpID, long charID)
        {
            bool? exists = false;
            int? orderID = 0;
            EMMADataSet.OrdersDataTable tempTable = new EMMADataSet.OrdersDataTable();
            tableAdapter.ClearBeforeFill = false;

            lock (tableAdapter)
            {
                tableAdapter.FillOrderExists(tempTable, orderRow.OwnerID, orderRow.WalletID,
                    orderRow.StationID, orderRow.ItemID, orderRow.TotalVol, orderRow.RemainingVol,
                    orderRow.Range, orderRow.OrderState, orderRow.BuyOrder, orderRow.Price, orderRow.EveOrderID,
                    ref exists, ref orderID);
            }
            if (orderID.HasValue)
            {
                if (ordersTable.FindByID(orderID.Value) == null)
                {
                    ordersTable.ImportRow(tempTable.FindByID(orderID.Value));
                }
                else
                {
                    EMMADataSet.OrdersRow existingRow = ordersTable.FindByID(orderID.Value);
                    new EMMAException(ExceptionSeverity.Warning, "market order retreived in 'Exists' is not " +
                        "unique. diagnostics follow:" +
                        "\r\n\tCharacter: " + Names.GetName(charID) +
                        "\r\n\tCorporation: " + Names.GetName(corpID) +
                        "\r\n\tOrder ID: " + orderID.Value +
                        "\r\n\tLooking for this order:" +
                        "\r\n\t\tEve order ID: " + orderRow.EveOrderID +
                        "\r\n\t\tCorp order: " + orderRow.ForCorp.ToString() +
                        "\r\n\t\tStation: " + Stations.GetStationName(orderRow.StationID) +
                        "\r\n\t\tItem: " + Items.GetItemName(orderRow.ItemID) +
                        "\r\n\t\tType: " + (orderRow.BuyOrder ? "Buy" : "Sell") +
                        "\r\n\t\tTotal volume: " + orderRow.TotalVol +
                        "\r\n\t\tRemaining volume: " + orderRow.RemainingVol +
                        "\r\n\t\tPrice: " + orderRow.Price +
                        "\r\n\t\tStatus: " + OrderStates.GetStateDescription(orderRow.OrderState) +
                        "\r\n\tAlready have this order loaded:" +
                        "\r\n\t\tEve order ID: " + existingRow.EveOrderID +
                        "\r\n\t\tCorp order: " + existingRow.ForCorp.ToString() +
                        "\r\n\t\tStation: " + Stations.GetStationName(existingRow.StationID) +
                        "\r\n\t\tItem: " + Items.GetItemName(existingRow.ItemID) +
                        "\r\n\t\tType: " + (existingRow.BuyOrder ? "Buy" : "Sell") +
                        "\r\n\t\tTotal volume: " + existingRow.TotalVol +
                        "\r\n\t\tRemaining volume: " + existingRow.RemainingVol +
                        "\r\n\t\tPrice: " + existingRow.Price +
                        "\r\n\t\tStatus: " + OrderStates.GetStateDescription(existingRow.OrderState), true);
                }
            }

            ID = orderID.HasValue ? orderID.Value : 0;
            return exists.HasValue ? exists.Value : false;
        }
 public ReprocessResult(EMMADataSet.ReprocessResultRow data)
 {
     _jobID = data.JobID;
     _jobDate = data.JobDate;
     _itemID = data.ItemID;
     _gotQuantity = true;
     _quantity = data.Quantity;
     _effectiveBuyPrice = data.EffectiveBuyPrice;
     _gotUnitSellPrice = true;
     _unitSellPrice = data.EstSellPrice / data.Quantity;
 }
Example #12
0
 public Dividend(EMMADataSet.DividendsRow data)
 {
     _id = data.DividendID;
     _divDate = data.DateTime;
     if (UserAccount.Settings.UseLocalTimezone)
     {
         _divDate = _divDate.AddHours(Globals.HoursOffset);
     }
     _sharePayout = data.PayoutPerShare;
     _corpID = data.CorpID;
 }
 public EVEAccount(EMMADataSet.EveAccountsRow data)
 {
     _userID = data.UserID;
     _apiKey = data.APIKey.Trim();
     _lastcharListUpdate = data.LastCharListUpdate;
     if (_charList == null)
     {
         _charList = new XmlDocument();
     }
     _charList.LoadXml(data.CharList);
 }
Example #14
0
        public static bool EntryExists(EMMADataSet.JournalDataTable table, long ID, long recieverID)
        {
            bool? exists = false;

            lock (tableAdapter)
            {
                tableAdapter.ClearBeforeFill = false;
                tableAdapter.FillEntryExists(table, ID, recieverID, ref exists);
            }

            return (exists.HasValue ? exists.Value : false);
        }
 public BankTransaction(EMMADataSet.BankTransactionRow data)
 {
     _id = data.TransactionID;
     _date = data.DateTime;
     if (UserAccount.Settings.UseLocalTimezone)
     {
         _date = _date.AddHours(Globals.HoursOffset);
     }
     _accountID = data.AccountID;
     _change = data.Change;
     _type = (BankTransactionType)data.Type;
 }
Example #16
0
 public static long AddRowToDatabase(EMMADataSet.AssetsRow row)
 {
     long? retVal = 0;
     lock (assetsTableAdapter)
     {
         assetsTableAdapter.Insert(row.OwnerID, row.CorpAsset, row.LocationID, row.ItemID, row.SystemID,
             row.RegionID, row.ContainerID, row.Quantity, row.Status, row.Processed, row.AutoConExclude,
             row.IsContainer, row.ReprocExclude, row.Cost, row.CostCalc, row.EveItemID,
             row.BoughtViaContract, out retVal);
     }
     return retVal.HasValue ? retVal.Value : 0;
 }
 public ShareTransaction(EMMADataSet.ShareTransactionRow data)
 {
     _id = data.TransID;
     _reportGroupID = data.ReportGroupID;
     _corpID = data.CorpID;
     _pricePerShare = data.PricePerShare;
     _deltaQuantity = data.DeltaQuantity;
     _transDate = data.DateTime;
     if (UserAccount.Settings.UseLocalTimezone)
     {
         _transDate = _transDate.AddHours(Globals.HoursOffset);
     }
 }
Example #18
0
 public Contract(EMMADataSet.ContractsRow data)
 {
     _id = data.ID;
     _ownerID = data.OwnerID;
     _statusID = data.Status;
     _pickupStationID = data.PickupStationID;
     _destinationStationID = data.DestinationStationID;
     _collateral = data.Collateral;
     _reward = data.Reward;
     _issueDate = data.DateTime;
     if (UserAccount.Settings.UseLocalTimezone)
     {
         _issueDate = _issueDate.AddHours(Globals.HoursOffset);
     }
     _type = (ContractType)data.Type;
     _expectedProfit = 0;
 }
Example #19
0
        /// <summary>
        /// Add the specified asset row to the specified data table
        /// </summary>
        /// <param name="assets"></param>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static void AddAssetToTable(EMMADataSet.AssetsDataTable assets, long ID)
        {
            // Check if the row is already in the table
            EMMADataSet.AssetsRow row = assets.FindByID(ID);
            if (row == null)
            {
                lock (assetsTableAdapter)
                {
                    // If not then retrieve it from the database and place into the table.
                    bool previousClearBeforeFill = assetsTableAdapter.ClearBeforeFill;

                    assetsTableAdapter.ClearBeforeFill = false;
                    assetsTableAdapter.FillByID(assets, ID);

                    assetsTableAdapter.ClearBeforeFill = previousClearBeforeFill;
                }

            }
        }
 public PublicCorp(EMMADataSet.PublicCorpsRow data)
 {
     _id = data.CorpID;
     _name = data.CorpName;
     _ticker = data.Ticker;
     _desc = data.Description;
     _shareValue = data.ValuePerShare;
     _ceo = data.CEO;
     _expectedPayout = data.ExpectedPayoutPerShare;
     _payoutPeriod = (CorpPayoutPeriod)data.PayoutPeriodID;
     _nav = data.EstimatedNAV;
     _navDate = data.NAVTakenAt;
     if (UserAccount.Settings.UseLocalTimezone)
     {
         _navDate = _navDate.AddHours(Globals.HoursOffset);
     }
     _bank = data.Bank;
     _riskRating = (RiskRating)data.RiskRatingID;
 }
 public static void AddTransByCalcProfitFromAssets(EMMADataSet.TransactionsDataTable trans,
     List<FinanceAccessParams> accessParams, int itemID, bool calcProfitFromAssets)
 {
     lock(tableAdapter)
     {
         bool oldClearBeforeFill = tableAdapter.ClearBeforeFill;
         tableAdapter.ClearBeforeFill = false;
         EMMADataSet.TransactionsDataTable tmpTable = new EMMADataSet.TransactionsDataTable();
         tableAdapter.FillByCalcProfitFromAssets(tmpTable, FinanceAccessParams.BuildAccessList(accessParams),
             itemID, calcProfitFromAssets);
         foreach (EMMADataSet.TransactionsRow tmpTrans in tmpTable)
         {
             EMMADataSet.TransactionsRow match = trans.FindByID(tmpTrans.ID);
             if (match == null)
             {
                 trans.ImportRow(tmpTrans);
             }
         }
         tableAdapter.ClearBeforeFill = oldClearBeforeFill;
     }
 }
 public PublicCorp(EMMADataSet.InvestmentsRow data)
 {
     _id = data.CorpID;
     _name = data.CorpName;
     _ticker = data.Ticker;
     _desc = data.Description;
     _shareValue = data.ValuePerShare;
     _ceo = data.CEO;
     _expectedPayout = data.ExpectedPayoutPerShare;
     _payoutPeriod = (CorpPayoutPeriod)data.PayoutPeriodID;
     _nav = data.EstimatedNAV;
     _navDate = data.NAVTakenAt;
     if (!data.IsSharesOwnedNull())
     {
         _sharesOwned = data.SharesOwned;
     }
     else
     {
         _sharesOwned = 0;
     }
     _bank = data.Bank;
     _riskRating = (RiskRating)data.RiskRatingID;
 }
        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;
        }
        /// <summary>
        /// Recursive method to update the supplied assets data table based upon the supplied xml node list.
        /// </summary>
        /// <param name="assetData"></param>
        /// <param name="assetList"></param>
        /// <param name="locationID"></param>
        /// <param name="corc"></param>
        /// <param name="containerID"></param>
        /// <param name="expectedChanges"></param>
        private void UpdateAssets(EMMADataSet.AssetsDataTable assetData, XmlNodeList assetList, long locationID,
            CharOrCorp corc, long containerID, AssetList changes)
        {
            int counter = 0;
            if (containerID == 0)
            {
                UpdateStatus(counter, assetList.Count, "Getting asset data from file", "", false);
            }
            else
            {
                UpdateStatus(-1, -1, "Getting asset data from file", "", false,
                    counter, assetList.Count, "Container progress");
            }

            foreach (XmlNode asset in assetList)
            {
                int itemID;
                long assetID = 0, eveInstanceID, quantity;
                bool isContainer = false, needNewRow = false;

                XmlNode locationNode = asset.SelectSingleNode("@locationID");
                if (locationNode != null)
                {
                    locationID = long.Parse(locationNode.Value);

                    // Translate location ID from a corporate office to a station ID if required.
                    if (locationID >= 66000000 && locationID < 67000000)
                    {
                        // NPC station.
                        locationID -= 6000001;
                    }
                    if (locationID >= 67000000 && locationID < 68000000)
                    {
                        // Conquerable station.
                        locationID -= 6000000;
                    }
                }
                itemID = int.Parse(asset.SelectSingleNode("@typeID").Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                eveInstanceID = long.Parse(asset.SelectSingleNode("@itemID").Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                quantity = long.Parse(asset.SelectSingleNode("@quantity").Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                if (asset.LastChild != null && asset.LastChild.Name.Equals("rowset"))
                {
                    isContainer = true;
                }

                EMMADataSet.AssetsRow assetRow;
                needNewRow = true;

                // Note that if a match is not found for the specific eve instance ID we pass in then
                // EMMA will automatically search for an asset matching all the other parameters.
                if (Assets.AssetExists(assetData, corc == CharOrCorp.Corp ? _corpID : _charID, locationID,
                    itemID, (int)AssetStatus.States.Normal, containerID != 0, containerID, isContainer,
                    false, !isContainer, false, true, eveInstanceID, ref assetID))
                {
                    needNewRow = false;
                }
                else if(!isContainer)
                {
                    // We havn't actually updated the database with anything yet so we may already have a
                    // matching item stack in memory but not in the database. Check for that here.
                    DataRow[] data =
                        assetData.Select("ItemID = " + itemID + " AND OwnerID = " + _charID + " AND CorpAsset = " +
                        (corc == CharOrCorp.Corp ? 1 : 0) + " AND LocationID = " + locationID +
                        " AND Status = " + (int)AssetStatus.States.Normal + " AND ContainerID = " + containerID +
                        " AND EveItemID = " + eveInstanceID);
                    if (data != null && data.Length > 0)
                    {
                        needNewRow = false;
                        assetID = ((EMMADataSet.AssetsRow)data[0]).ID;
                    }
                }

                Asset change = null;
                if (!needNewRow)
                {
                    assetRow = assetData.FindByID(assetID);

                    if (assetRow.Processed)
                    {
                        // Row is already in the database but has been processed so just add the current
                        // quantity to the row.
                        // (i.e. there are multiple stacks of the same item in the same location in-game
                        // EMMA merges these since we don't care how things are stacked and it makes
                        // things a little easier.)
                        assetRow.Quantity = assetRow.Quantity + quantity;
                        // We're stacking multiple eve item instances so just set the eve item ID to zero.
                        assetRow.EveItemID = 0;

                        // Store the changes that are being made to the quantity of
                        // items here.
                        // This means that once the update processing is complete, we
                        // can try and work out where these items came from.
                        #region Remember changes to item quantities
                        changes.ItemFilter = "ID = " + assetRow.ID;
                        if (changes.FiltredItems.Count > 0)
                        {
                            change = (Asset)changes.FiltredItems[0];
                            change.Quantity += quantity;
                            change.EveItemInstanceID = 0;
                            if (change.Quantity == 0) { changes.ItemFilter = ""; changes.Remove(change); }
                        }
                        else
                        {
                            change = new Asset(assetRow);
                            change.Quantity = quantity;
                            change.Processed = false;
                            changes.Add(change);
                        }
                        #endregion
                    }
                    else
                    {
                        if (assetRow.Quantity == quantity)
                        {
                            // The row already exists in the database and quantity is the same so
                            // set the processed flag on the database directly and remove the row
                            // from the dataset without setting it to be deleted when the database
                            // is updated.
                            // Note the processed flag MUST be set on the database for later routines
                            // to work correctly. (e.g. Assets.ProcessSellOrders)
                            if (assetRow.EveItemID != 0)
                            {
                                Assets.SetProcessedFlag(assetID, true);
                                assetData.RemoveAssetsRow(assetRow);
                            }
                            else
                            {
                                // If Eve instance ID is not yet set then set it.
                                Assets.SetProcessedFlag(assetID, true);
                                assetRow.Processed = true;
                                assetRow.EveItemID = eveInstanceID;
                            }
                        }
                        else if (assetRow.Quantity != quantity)
                        {
                            // The row already exists in the database, has not yet been processed
                            // and the quantity does not match what we've got from the XML.

                            // Store the changes that are being made to the quantity of
                            // items here.
                            // This means that once the update processing is complete, we
                            // can try and work out where these items came from.
                            #region Remember changes to item quantities
                            change = new Asset(assetRow);
                            change.Quantity = quantity - assetRow.Quantity;
                            change.EveItemInstanceID = eveInstanceID;
                            change.Processed = false;
                            changes.Add(change);
                            #endregion

                            // All we need to do is update the quantity and set the processed flag.
                            assetRow.Quantity = quantity;
                            assetRow.Processed = true;
                            assetRow.EveItemID = eveInstanceID;
                            // Also set the processed flag on the database directly. This will
                            // stop us from picking up this row later on (e.g. Assets.ProcessSellOrders)
                            Assets.SetProcessedFlag(assetID, true);
                        }
                    }
                }
                else
                {
                    // The row does not currently exist in the database so we need to create it.
                    assetRow = assetData.NewAssetsRow();
                    //assetRow.OwnerID = _charID;
                    assetRow.OwnerID = corc == CharOrCorp.Corp ? _corpID : _charID;
                    assetRow.CorpAsset = corc == CharOrCorp.Corp;
                    assetRow.ItemID = itemID;
                    assetRow.EveItemID = eveInstanceID;
                    assetRow.LocationID = locationID;
                    assetRow.Status = 1;
                    assetRow.Processed = true;
                    assetRow.AutoConExclude = false;
                    assetRow.ReprocExclude = false;
                    assetRow.Cost = 0;
                    assetRow.CostCalc = false;
                    assetRow.BoughtViaContract = false;

                    long systemID = 0, regionID = 0;
                    if (locationID >= 30000000 && locationID < 40000000)
                    {
                        systemID = locationID;
                        EveDataSet.mapSolarSystemsRow system = SolarSystems.GetSystem(locationID);
                        if (system != null)
                        {
                            regionID = system.regionID;
                        }
                        else
                        {
                            new EMMAEveAPIException(ExceptionSeverity.Warning, "Asset row added with unknown " +
                                "solar system ID (" + locationID + ")");
                        }
                    }
                    else
                    {
                        EveDataSet.staStationsRow station = null;
                        try
                        {
                            station = Stations.GetStation(locationID);
                        }
                        catch (EMMADataMissingException) { }

                        if (station != null)
                        {
                            systemID = station.solarSystemID;
                            regionID = station.regionID;
                        }
                        else
                        {
                            new EMMAEveAPIException(ExceptionSeverity.Warning, "Asset row added with unknown " +
                                "station ID (" + locationID + ")");
                        }
                    }
                    assetRow.SystemID = systemID;
                    assetRow.RegionID = regionID;
                    assetRow.Quantity = quantity;
                    assetRow.ContainerID = containerID;
                    assetRow.IsContainer = isContainer;
                    if (isContainer)
                    {
                        // If this asset is a container and has child assets then we must add it to the
                        // database now and get the correct ID number.
                        // (Because IDs are assigned by the database itself)
                        assetID = Assets.AddRowToDatabase(assetRow);
                    }
                    else
                    {
                        // Otherwise, we can just add it to the data table to be stored later along with
                        // everything else.
                        assetData.AddAssetsRow(assetRow);
                    }

                    // Store the changes that are being made to the quantity of
                    // items here.
                    // This means that once the update processing is complete, we
                    // can try and work out where these items came from.
                    #region Remember changes to item quantities
                    change = new Asset(assetRow);
                    if (isContainer) { change.ID = assetID; }
                    change.Quantity = quantity;
                    change.Processed = false;
                    changes.Add(change);
                    #endregion
                }

                if (isContainer)
                {
                    XmlNodeList contained = asset.SelectNodes("rowset/row");
                    UpdateAssets(assetData, contained, locationID, corc, assetID, changes);
                }

                counter++;
                if (containerID == 0)
                {
                    UpdateStatus(counter, assetList.Count, "Getting asset data from file", "", false);
                }
                else
                {
                    UpdateStatus(-1, -1, "Getting asset data from file", "", false,
                        counter, assetList.Count, "Container progress");
                }
            }
        }
        private EMMADataSet.TransactionsRow BuildTransRow(long transID, EMMADataSet.TransactionsDataTable transData,
            XmlNode transEntry, short walletID, SortedList<long, string> nameIDs, bool rowInDatabase)
        {
            EMMADataSet.TransactionsRow newRow = transData.NewTransactionsRow();

            newRow.ID = transID;
            // Set the simple data. i.e. direct conversion from XML field to database field.
            newRow.DateTime = DateTime.Parse(transEntry.SelectSingleNode("@transactionDateTime").Value);
            newRow.Quantity = int.Parse(transEntry.SelectSingleNode("@quantity").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.ItemID = int.Parse(transEntry.SelectSingleNode("@typeID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.Price = Decimal.Parse(transEntry.SelectSingleNode("@price").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.StationID = long.Parse(transEntry.SelectSingleNode("@stationID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.RegionID = Stations.GetStation(newRow.StationID).regionID;

            // Get the data to work out the more complicated fields..
            string transType = transEntry.SelectSingleNode("@transactionType").Value;
            long clientID = long.Parse(transEntry.SelectSingleNode("@clientID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            XmlNode node = transEntry.SelectSingleNode("@characterID");
            long charID = 0;
            if (node != null)
            {
                charID = long.Parse(node.Value,
                    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            }
            bool forCorp =
                transEntry.SelectSingleNode("@transactionFor").Value.Equals("personal") ? false : true;

            newRow.CalcProfitFromAssets = false;
            if (transType.ToLower().Equals("buy"))
            {
                newRow.BuyerID = forCorp ? _corpID : _charID;
                newRow.BuyerForCorp = forCorp;
                newRow.BuyerCharacterID = forCorp ? _charID : 0;
                newRow.BuyerWalletID = (walletID == 0 ? (short)1000 : walletID);
                newRow.SellerID = clientID;
                newRow.SellerForCorp = charID != 0;
                newRow.SellerCharacterID = charID;
                newRow.SellerWalletID = 0;
                newRow.SellerUnitProfit = 0;
                // Update asset quantities.
                if (!rowInDatabase)
                {
                    Assets.BuyAssets(forCorp ? _corpID : _charID, newRow.StationID, newRow.ItemID,
                        newRow.Quantity, newRow.Price,
                        forCorp ? Settings.CorpAssetsEffectiveDate : Settings.CharAssetsEffectiveDate,
                        newRow.DateTime);
                }
            }
            else
            {
                newRow.BuyerID = clientID;
                newRow.BuyerForCorp = charID != 0;
                newRow.BuyerCharacterID = charID;
                newRow.BuyerWalletID = 0;
                newRow.SellerID = forCorp ? _corpID : _charID;
                newRow.SellerForCorp = forCorp;
                newRow.SellerCharacterID = forCorp ? _charID : 0;
                newRow.SellerWalletID = (walletID == 0 ? (short)1000 : walletID);
                // Calculate transaction profit and update asset quantities.
                if (!rowInDatabase)
                {
                    newRow.SellerUnitProfit = Transactions.CalcProfit(forCorp ? _corpID : _charID,
                        transData, newRow,
                        forCorp ? Settings.CorpAssetsEffectiveDate : Settings.CharAssetsEffectiveDate);
                }
            }

            // Get the IDs and associated names in this transaction.
            if (!nameIDs.ContainsKey(clientID))
            {
                nameIDs.Add(clientID, transEntry.SelectSingleNode("@clientName").Value);
            }
            if (charID != 0 && !nameIDs.ContainsKey(charID))
            {
                nameIDs.Add(charID, transEntry.SelectSingleNode("@characterName").Value);
            }

            return newRow;
        }
        private EMMADataSet.OrdersRow BuildOrdersRow(EMMADataSet.OrdersDataTable orderData, XmlNode orderEntry,
            CharOrCorp corc)
        {
            EMMADataSet.OrdersRow newRow = orderData.NewOrdersRow();

            newRow.EveOrderID = long.Parse(orderEntry.SelectSingleNode("@orderID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            //newRow.OwnerID = long.Parse(orderEntry.SelectSingleNode("@charID").Value,
            //    System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.OwnerID = corc == CharOrCorp.Corp ? _corpID : _charID;
            newRow.ForCorp = corc == CharOrCorp.Corp;
            newRow.StationID = long.Parse(orderEntry.SelectSingleNode("@stationID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.TotalVol = int.Parse(orderEntry.SelectSingleNode("@volEntered").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.RemainingVol = int.Parse(orderEntry.SelectSingleNode("@volRemaining").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.MinVolume = int.Parse(orderEntry.SelectSingleNode("@minVolume").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.OrderState = short.Parse(orderEntry.SelectSingleNode("@orderState").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            // We want to store 'Active' state code as 999, not 0.
            if (newRow.OrderState == 0) { newRow.OrderState = (short)OrderState.Active; }
            newRow.ItemID = int.Parse(orderEntry.SelectSingleNode("@typeID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.Range = short.Parse(orderEntry.SelectSingleNode("@range").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.WalletID = short.Parse(orderEntry.SelectSingleNode("@accountKey").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.Duration = short.Parse(orderEntry.SelectSingleNode("@duration").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.Escrow = decimal.Parse(orderEntry.SelectSingleNode("@escrow").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            newRow.Price = decimal.Parse(orderEntry.SelectSingleNode("@price").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            int buyOrder = int.Parse(orderEntry.SelectSingleNode("@bid").Value);
            newRow.BuyOrder = buyOrder == 1;
            newRow.Issued = DateTime.Parse(orderEntry.SelectSingleNode("@issued").Value,
                System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat);
            newRow.Processed = true;

            return newRow;
        }
        public APICharacter(long userID, string apiKey, CharOrCorp accessType, EMMADataSet.APICharactersRow data)
        {
            _userID = userID;
            _apiKey = apiKey;
            _charID = data.ID;
            _apiSettings = new APISettingsAndStatus(_charID);
            if (data.CharSheet.Length > 0)
            {
                _charSheetXMLCache.LoadXml(data.CharSheet);
                _charSheetXMLLastUpdate = data.LastCharSheetUpdate;
                GetDataFromCharXML();
            }
            if (data.CorpSheet.Length > 0)
            {
                _corpSheetXMLCache.LoadXml(data.CorpSheet);
                _corpSheetXMLLastUpdate = data.LastCorpSheetUpdate;
                GetDataFromCorpXML();
            }

            _corpFinanceAccess = data.CorpFinanceAccess;

            if (accessType == CharOrCorp.Char)
            {
                try
                {
                    RefreshCharXMLFromAPI();
                }
                catch { }
            }
            else
            {
                try
                {
                    RefreshCorpXMLFromAPI();
                }
                catch { }
            }

            SetLastAPIUpdateTime(CharOrCorp.Char, APIDataType.Assets, data.LastCharAssetsUpdate);
            SetLastAPIUpdateTime(CharOrCorp.Char, APIDataType.Journal, data.LastCharJournalUpdate);
            SetLastAPIUpdateTime(CharOrCorp.Char, APIDataType.Orders, data.LastCharOrdersUpdate);
            SetLastAPIUpdateTime(CharOrCorp.Char, APIDataType.Transactions, data.LastCharTransUpdate);
            SetLastAPIUpdateTime(CharOrCorp.Corp, APIDataType.Assets, data.LastCorpAssetsUpdate);
            SetLastAPIUpdateTime(CharOrCorp.Corp, APIDataType.Journal, data.LastCorpJournalUpdate);
            SetLastAPIUpdateTime(CharOrCorp.Corp, APIDataType.Orders, data.LastCorpOrdersUpdate);
            SetLastAPIUpdateTime(CharOrCorp.Corp, APIDataType.Transactions, data.LastCorpTransUpdate);
            // Note - don't need to set industry job update dates as they are stored in the settings xml
            // instead of directly on the character record.

            SetHighestID(CharOrCorp.Char, APIDataType.Transactions, data.HighestCharTransID);
            SetHighestID(CharOrCorp.Corp, APIDataType.Transactions, data.HighestCorpTransID);
            SetHighestID(CharOrCorp.Char, APIDataType.Journal, data.HighestCharJournalID);
            SetHighestID(CharOrCorp.Corp, APIDataType.Journal, data.HighestCorpJournalID);

            if (!Settings.UpdatedOwnerIDToCorpID)
            {
                UpdateOwnerIDToCorpID();
            }
        }
        private EMMADataSet.IndustryJobsRow BuildIndustryJobRow(EMMADataSet.IndustryJobsDataTable dataTable,
            XmlNode xmlData)
        {
            EMMADataSet.IndustryJobsRow jobRow = dataTable.NewIndustryJobsRow();
            jobRow.ID = long.Parse(xmlData.SelectSingleNode("@jobID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.ActivityID = int.Parse(xmlData.SelectSingleNode("@activityID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.AssemblyLineID = long.Parse(xmlData.SelectSingleNode("@assemblyLineID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.BeginProductionTime = DateTime.Parse(xmlData.SelectSingleNode("@beginProductionTime").Value,
                System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat);
            jobRow.CharMaterialModifier = double.Parse(xmlData.SelectSingleNode("@charMaterialMultiplier").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.CharTimeMultiplier = double.Parse(xmlData.SelectSingleNode("@charTimeMultiplier").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.Completed = int.Parse(xmlData.SelectSingleNode("@completed").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat) == 1;
            jobRow.CompletedStatus = int.Parse(xmlData.SelectSingleNode("@completedStatus").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.CompletedSuccessfully = int.Parse(xmlData.SelectSingleNode("@completedSuccessfully").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat) == 1;
            jobRow.ContainerID = long.Parse(xmlData.SelectSingleNode("@containerID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.ContainerTypeID = int.Parse(xmlData.SelectSingleNode("@containerTypeID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.EndProductionTime = DateTime.Parse(xmlData.SelectSingleNode("@endProductionTime").Value,
                System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat);
            jobRow.InstalledItemCopy = int.Parse(xmlData.SelectSingleNode("@installedItemCopy").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat) == 1;
            jobRow.InstalledItemFlag = int.Parse(xmlData.SelectSingleNode("@installedItemFlag").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.InstalledItemID = long.Parse(xmlData.SelectSingleNode("@installedItemID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.InstalledItemLocationID = long.Parse(xmlData.SelectSingleNode("@installedItemLocationID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.InstalledItemME = int.Parse(xmlData.SelectSingleNode("@installedItemMaterialLevel").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.InstalledItemPL = int.Parse(xmlData.SelectSingleNode("@installedItemProductivityLevel").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.InstalledItemQuantity = int.Parse(xmlData.SelectSingleNode("@installedItemQuantity").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.InstalledItemRunsRemaining = int.Parse(xmlData.SelectSingleNode("@installedItemLicensedProductionRunsRemaining").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.InstalledItemTypeID = int.Parse(xmlData.SelectSingleNode("@installedItemTypeID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.InstallerID = long.Parse(xmlData.SelectSingleNode("@installerID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.InstallTime = DateTime.Parse(xmlData.SelectSingleNode("@installTime").Value,
                System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat);
            jobRow.JobRuns = int.Parse(xmlData.SelectSingleNode("@runs").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.MaterialModifier = double.Parse(xmlData.SelectSingleNode("@materialMultiplier").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.OutputFlag = int.Parse(xmlData.SelectSingleNode("@outputFlag").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.OutputLcoationID = long.Parse(xmlData.SelectSingleNode("@outputLocationID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.OutputRuns = int.Parse(xmlData.SelectSingleNode("@licensedProductionRuns").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.OutputTypeID = int.Parse(xmlData.SelectSingleNode("@outputTypeID").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
            jobRow.PauseProductionTime = DateTime.Parse(xmlData.SelectSingleNode("@pauseProductionTime").Value,
                System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat);
            jobRow.TimeMultiplier = double.Parse(xmlData.SelectSingleNode("@timeMultiplier").Value,
                System.Globalization.CultureInfo.InvariantCulture.NumberFormat);

            if (jobRow.PauseProductionTime.CompareTo(SqlDateTime.MinValue.Value) < 0) { jobRow.PauseProductionTime = SqlDateTime.MinValue.Value; }
            if (jobRow.PauseProductionTime.CompareTo(SqlDateTime.MaxValue.Value) > 0) { jobRow.PauseProductionTime = SqlDateTime.MaxValue.Value; }
            if (jobRow.EndProductionTime.CompareTo(SqlDateTime.MinValue.Value) < 0) { jobRow.PauseProductionTime = SqlDateTime.MinValue.Value; }
            if (jobRow.EndProductionTime.CompareTo(SqlDateTime.MaxValue.Value) > 0) { jobRow.PauseProductionTime = SqlDateTime.MaxValue.Value; }
            if (jobRow.BeginProductionTime.CompareTo(SqlDateTime.MinValue.Value) < 0) { jobRow.PauseProductionTime = SqlDateTime.MinValue.Value; }
            if (jobRow.BeginProductionTime.CompareTo(SqlDateTime.MaxValue.Value) > 0) { jobRow.PauseProductionTime = SqlDateTime.MaxValue.Value; }
            if (jobRow.InstallTime.CompareTo(SqlDateTime.MinValue.Value) < 0) { jobRow.PauseProductionTime = SqlDateTime.MinValue.Value; }
            if (jobRow.InstallTime.CompareTo(SqlDateTime.MaxValue.Value) > 0) { jobRow.PauseProductionTime = SqlDateTime.MaxValue.Value; }

            return jobRow;
        }
 /// <summary>
 /// Check if the specified transaction exists, if it does that it is added to the supplied
 /// datatable object.
 /// </summary>
 /// <param name="table"></param>
 /// <param name="id"></param>
 /// <returns></returns>
 public static bool TransactionExists(EMMADataSet.TransactionsDataTable table, long id)
 {
     bool? exists = false;
     lock (tableAdapter)
     {
         tableAdapter.ClearBeforeFill = false;
         tableAdapter.FillTransExists(table, id, ref exists);
     }
     return (exists.HasValue ? exists.Value : false);
 }
 /// <summary>
 /// Commit changes made in the specified datatable to the database.
 /// </summary>
 /// <param name="table"></param>
 public static void Store(EMMADataSet.TransactionsDataTable table)
 {
     lock (tableAdapter)
     {
         tableAdapter.Update(table);
     }
 }