public ViewUnacknowledgedOrders()
        {
            InitializeComponent();

            //_owners = new List<long>();
            //_corporateOwners = new List<long>();
            //List<CharCorpOption> charcorps = UserAccount.CurrentGroup.GetCharCorpOptions(APIDataType.Orders);
            //foreach (CharCorpOption chop in charcorps)
            //{
            //    if (chop.Corp)
            //    {
            //        _corporateOwners.Add(chop.CharacterObj.CorpID);
            //    }
            //    else
            //    {
            //        _owners.Add(chop.CharacterObj.CharID);
            //    }
            //}

            _orders = new OrdersList();
            //_ordersBindingSource = new BindingSource();
            //_ordersBindingSource.DataSource = _orders;
            UserAccount.Settings.GetFormSizeLoc(this);

            ordersGrid.Tag = "Unacknowledged Orders Data";
            if (Globals.calculator != null)
            {
                Globals.calculator.BindGrid(ordersGrid);
            }
        }
        private void ViewOrders_Load(object sender, EventArgs e)
        {
            try
            {
                _orders = new OrdersList();
                _ordersBindingSource = new BindingSource();
                _ordersBindingSource.DataSource = _orders;

                DataGridViewCellStyle iskStyle = new DataGridViewCellStyle(PriceColumn.DefaultCellStyle);
                iskStyle.Format = IskAmount.FormatString();
                PriceColumn.DefaultCellStyle = iskStyle;
                EscrowColumn.DefaultCellStyle = iskStyle;
                TotalValueColumn.DefaultCellStyle = iskStyle;
                RemainingValueColumn.DefaultCellStyle = iskStyle;
                DataGridViewCellStyle dayStyle = new DataGridViewCellStyle(DurationColumn.DefaultCellStyle);
                dayStyle.Format = "# Days;-# Days;# Days";
                DurationColumn.DefaultCellStyle = dayStyle;

                ordersGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
                ordersGrid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;

                ordersGrid.DataSource = _ordersBindingSource;
                DateIssuedColumn.DataPropertyName = "Date";
                OwnerColumn.DataPropertyName = "Owner";
                ItemColumn.DataPropertyName = "Item";
                PriceColumn.DataPropertyName = "Price";
                StationColumn.DataPropertyName = "Station";
                SystemColumn.DataPropertyName = "System";
                RegionColumn.DataPropertyName = "Region";
                TypeColumn.DataPropertyName = "Type";
                TotalUnitsColumn.DataPropertyName = "TotalVol";
                QuantityColumn.DataPropertyName = "RemainingVol";
                EscrowColumn.DataPropertyName = "Escrow";
                StateColumn.DataPropertyName = "State";
                RangeColumn.DataPropertyName = "RangeText";
                DurationColumn.DataPropertyName = "Duration";
                TotalValueColumn.DataPropertyName = "TotalValue";
                RemainingValueColumn.DataPropertyName = "RemainingValue";

                UserAccount.Settings.GetColumnWidths(this.Name, ordersGrid);

                List<CharCorpOption> charcorps = UserAccount.CurrentGroup.GetCharCorpOptions(APIDataType.Orders);
                _corporateOwners = new List<long>();
                _personalOwners = new List<long>();
                foreach (CharCorpOption chop in charcorps)
                {
                    if (chop.Corp)
                    {
                        _corporateOwners.Add(chop.CharacterObj.CorpID);
                    }
                    else
                    {
                        _personalOwners.Add(chop.CharacterObj.CharID);
                    }
                }
                cmbOwner.DisplayMember = "Name";
                cmbOwner.ValueMember = "Data";
                charcorps.Sort();
                cmbOwner.DataSource = charcorps;
                cmbOwner.SelectedValue = 0;
                cmbOwner.Enabled = false;
                cmbOwner.SelectedIndexChanged += new EventHandler(cmbOwner_SelectedIndexChanged);
                chkIngoreOwner.Checked = true;
                chkIngoreOwner.CheckedChanged += new EventHandler(chkIngoreOwner_CheckedChanged);

                EMMADataSet.OrderStatesDataTable allStates = OrderStates.GetAllStates();
                EMMADataSet.OrderStatesRow newState = allStates.NewOrderStatesRow();
                newState.StateID = 0;
                newState.Description = "All States";
                allStates.AddOrderStatesRow(newState);
                BindingSource stateSource = new BindingSource();
                stateSource.DataSource = allStates;
                stateSource.Sort = "Description";
                cmbStateFilter.DisplayMember = "Description";
                cmbStateFilter.ValueMember = "StateID";
                cmbStateFilter.DataSource = stateSource;
                cmbStateFilter.SelectedIndexChanged += new EventHandler(cmbStateFilter_SelectedIndexChanged);

                _recentStations = UserAccount.CurrentGroup.Settings.RecentStations;
                _recentStations.Sort();
                AutoCompleteStringCollection stations = new AutoCompleteStringCollection();
                stations.AddRange(_recentStations.ToArray());
                txtStation.AutoCompleteCustomSource = stations;
                txtStation.AutoCompleteSource = AutoCompleteSource.CustomSource;
                txtStation.AutoCompleteMode = AutoCompleteMode.Suggest;
                txtStation.Leave += new EventHandler(txtStation_Leave);
                txtStation.KeyDown += new KeyEventHandler(txtStation_KeyDown);
                txtStation.Tag = 0;
                txtStation.Text = "";

                cmbType.SelectedIndexChanged += new EventHandler(cmbType_SelectedIndexChanged);

                this.FormClosing += new FormClosingEventHandler(ViewOrders_FormClosing);

                DisplayOrders();
            }
            catch (Exception ex)
            {
                // Creating new EMMAexception will cause error to be logged.
                EMMAException emmaex = ex as EMMAException;
                if (emmaex == null)
                {
                    emmaex = new EMMAException(ExceptionSeverity.Critical, "Error setting up orders form", ex);
                }
                MessageBox.Show("Problem setting up orders view.\r\nCheck " + Globals.AppDataDir + "Logging\\ExceptionLog.txt" +
                    " for details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void DisplayOrders()
        {
            long ownerID = 0;
            List<int> items = new List<int>();
            items.Add(0);
            List<long> stations = new List<long>();
            try
            {
                stations.Add((long)txtStation.Tag);
            }
            catch (InvalidCastException)
            {
                stations.Add(0);
            }
            int stateID = 0;
            string type = cmbType.Text;

            if (cmbStateFilter.SelectedValue != null)
            {
                stateID = (short)cmbStateFilter.SelectedValue;
            }

            bool corpAssets = false;
            if (cmbOwner.SelectedValue != null && !chkIngoreOwner.Checked)
            {
                CharCorp data = (CharCorp)cmbOwner.SelectedValue;
                ownerID = data.ID;// data.characterObj.CharID;
                corpAssets = data.corp;
            }

            _accessParams = new List<AssetAccessParams>();
            if (ownerID == 0)
            {
                //List<long> ignore = new List<long>();
                foreach (long id in _personalOwners)
                {
                    _accessParams.Add(new AssetAccessParams(id));
                    //_accessParams.Add(new AssetAccessParams(id, true, _corporateOwners.Contains(id)));
                    //ignore.Add(id);
                }
                foreach (long id in _corporateOwners)
                {
                    _accessParams.Add(new AssetAccessParams(id));
                    //if (!ignore.Contains(id))
                    //{
                    //    _accessParams.Add(new AssetAccessParams(id, false, true));
                    //}
                }
            }
            else
            {
                _accessParams.Add(new AssetAccessParams(ownerID));
                //_accessParams.Add(new AssetAccessParams(ownerID, !corpAssets, corpAssets));
            }

            //ListSortDirection sortDirection = ListSortDirection.Descending;
            //DataGridViewColumn sortColumn = ordersGrid.SortedColumn;
            //if (ordersGrid.SortOrder == SortOrder.Ascending) sortDirection = ListSortDirection.Ascending;
            List<SortInfo> sortinfo = ordersGrid.GridSortInfo;

            _orders = Orders.LoadOrders(_accessParams, items, stations, stateID, type);
            _ordersBindingSource.DataSource = _orders;

            //ordersGrid.AutoResizeColumns();
            //ordersGrid.AutoResizeRows();

            //if (sortColumn != null)
            //{
            //    ordersGrid.Sort(sortColumn, sortDirection);
            //}
            //else
            //{
            //    ordersGrid.Sort(DateIssuedColumn, ListSortDirection.Descending);
            //}
            if (sortinfo.Count == 0)
            {
                DataGridViewColumn column = ordersGrid.Columns["DateIssuedColumn"];
                sortinfo.Add(new SortInfo(column.Index, column.DataPropertyName));
            }
            ordersGrid.GridSortInfo = sortinfo;

            Text = "Viewing " + _ordersBindingSource.Count + " orders";
        }
        public void DisplayOrders()
        {
            // Only refresh the display if the number of unacknowledged orders has changed.
            OrdersList unack = Orders.LoadOrders(
                UserAccount.CurrentGroup.GetAssetAccessParams(APIDataType.Orders),
                new List<int>(), new List<long>(), (int)OrderState.ExpiredOrFilledAndUnacknowledged, "Any");
            if (unack.Count != _lastNumberOfOrders)
            {

                //List<int> items = new List<int>();
                //items.Add(0);
                //List<int> stations = new List<int>();
                //stations.Add(0);

                //_accessParams = new List<AssetAccessParams>();

                ////List<long> ignore = new List<long>();
                //foreach (long id in _owners)
                //{
                //    _accessParams.Add(new AssetAccessParams(id));
                //    //_accessParams.Add(new AssetAccessParams(id, true, _corporateOwners.Contains(id)));
                //    //ignore.Add(id);
                //}
                //foreach (long id in _corporateOwners)
                //{
                //    _accessParams.Add(new AssetAccessParams(id));
                ////    if (!ignore.Contains(id))
                ////    {
                ////        _accessParams.Add(new AssetAccessParams(id, false, true));
                ////    }
                //}

                //ListSortDirection sortDirection = ListSortDirection.Descending;
                //DataGridViewColumn sortColumn = ordersGrid.SortedColumn;
                //if (ordersGrid.SortOrder == SortOrder.Ascending) sortDirection = ListSortDirection.Ascending;
                List<SortInfo> sortinfo = ordersGrid.GridSortInfo;

                //_orders = Orders.LoadOrders(_accessParams, items, stations,
                //    (int)OrderState.ExpiredOrFilledAndUnacknowledged, "Any");
                _orders = unack;
                //_ordersBindingSource.DataSource = _orders;
                ordersGrid.DataSource = _orders;

                //ordersGrid.AutoResizeColumns();
                //ordersGrid.AutoResizeRows();

                //if (sortColumn != null)
                //{
                //    ordersGrid.Sort(sortColumn, sortDirection);
                //}
                ordersGrid.GridSortInfo = sortinfo;

                _lastNumberOfOrders = _orders.Count;
                Text = _lastNumberOfOrders + " unacknowledged orders";
            }
        }
        private void ViewUnacknowledgedOrders_Load(object sender, EventArgs e)
        {
            try
            {
                _orders = new OrdersList();
                //_ordersBindingSource = new BindingSource();
                //_ordersBindingSource.DataSource = _orders;

                DataGridViewCellStyle iskStyle = new DataGridViewCellStyle(PriceColumn.DefaultCellStyle);
                iskStyle.Format = IskAmount.FormatString();
                PriceColumn.DefaultCellStyle = iskStyle;
                DataGridViewCellStyle dayStyle = new DataGridViewCellStyle(DurationColumn.DefaultCellStyle);
                dayStyle.Format = "# Days;-# Days;# Days";
                DurationColumn.DefaultCellStyle = dayStyle;

                ordersGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
                ordersGrid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
                ordersGrid.AutoGenerateColumns = false;

                //ordersGrid.DataSource = _ordersBindingSource;
                DateTimeColmun.DataPropertyName = "Date";
                OwnerColumn.DataPropertyName = "Owner";
                ItemColumn.DataPropertyName = "Item";
                PriceColumn.DataPropertyName = "Price";
                StationColumn.DataPropertyName = "Station";
                TypeColumn.DataPropertyName = "Type";
                QuantityColumn.DataPropertyName = "TotalVol";
                RangeColumn.DataPropertyName = "RangeText";
                DurationColumn.DataPropertyName = "Duration";
                AcknowledgeColumn.Image = icons.Images["tick.gif"];
                ordersGrid.CellContentClick += new DataGridViewCellEventHandler(ordersGrid_CellContentClick);

                //ordersGrid.Sort(DateTimeColmun, ListSortDirection.Ascending);
                List<SortInfo> sort = new List<SortInfo>();
                sort.Add(new SortInfo(0, "Date"));
                ordersGrid.GridSortInfo = sort;

                UserAccount.Settings.GetColumnWidths(this.Name, ordersGrid);

                _lastNumberOfOrders = 0;
                this.FormClosing += new FormClosingEventHandler(ViewUnacknowledgedOrders_FormClosing);
                DisplayOrders();
            }
            catch (Exception ex)
            {
                // Creating new EMMAexception will cause error to be logged.
                EMMAException emmaex = ex as EMMAException;
                if (emmaex == null)
                {
                    emmaex = new EMMAException(ExceptionSeverity.Critical, "Error setting up orders form", ex);
                }
                MessageBox.Show("Problem setting up unacknowledged orders view.\r\nCheck " + Globals.AppDataDir + "Logging\\ExceptionLog.txt" +
                    " for details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #6
0
        public static OrdersList LoadOrders(List<AssetAccessParams> accessParams, List<int> itemIDs,
            List<long> stationIDs, int state, string type)
        {
            OrdersList retVal = new OrdersList();
            EMMADataSet.OrdersDataTable table = LoadOrdersData(accessParams, itemIDs, stationIDs, state, type);

            foreach (EMMADataSet.OrdersRow row in table)
            {
                Order order = new Order(row, accessParams);
                retVal.Add(order);
            }
            return retVal;
        }
        private void UpdateOrders()
        {
            try
            {
                // Retrieve data
                _buyOrders = Orders.LoadOrders(_assetParams, _itemIDs, new List<long>(), (int)OrderState.Active, "buy");
                _sellOrders = Orders.LoadOrders(_assetParams, _itemIDs, new List<long>(), (int)OrderState.Active, "sell");

                // Now add placeholder rows for item/owner combos that do not exist in the retrieved data.
                if (_orderPlaceholderType != OrderPlaceholderType.None)
                {
                    foreach (object itemObj in chkItems.CheckedItems)
                    {
                        int maxOwner = _orderPlaceholderType == OrderPlaceholderType.PerItem ? 1 : chkOwners.CheckedItems.Count;

                        for(int currentOwnerIndex = 0; currentOwnerIndex < maxOwner; currentOwnerIndex++)
                        {
                            object ownerObj = chkOwners.CheckedItems[currentOwnerIndex];
                            CharCorpOption owner = (CharCorpOption)ownerObj;
                            long ownerID = owner.Data.ID;
                            int itemID = ((ItemInfo)itemObj).ID;

                            _buyOrders.ItemFilter = "ItemID = " + itemID;
                            if (_orderPlaceholderType == OrderPlaceholderType.PerItemPerEntity)
                            {
                                _buyOrders.ItemFilter = _buyOrders.ItemFilter + " AND OwnerID = " + ownerID;
                            }
                            if (_buyOrders.FiltredItems.Count == 0)
                            {
                                _buyOrders.Add(new Order(ownerID, itemID, true, _assetParams));
                            }

                            _sellOrders.ItemFilter = "ItemID = " + itemID;
                            if (_orderPlaceholderType == OrderPlaceholderType.PerItemPerEntity)
                            {
                                _sellOrders.ItemFilter = _sellOrders.ItemFilter + " AND OwnerID = " + ownerID;
                            }
                            if (_sellOrders.FiltredItems.Count == 0)
                            {
                                _sellOrders.Add(new Order(ownerID, itemID, false, _assetParams));
                            }
                        }
                    }
                    _buyOrders.ItemFilter = "";
                    _sellOrders.ItemFilter = "";
                }
                foreach (object itemObj in chkItems.CheckedItems)
                {
                    int itemID = ((ItemInfo)itemObj).ID;

                    _sellOrders.ItemFilter = "ItemID = " + itemID;
                    if (_sellOrders.FiltredItems.Count > 0)
                    {
                        // Check if there is a buy order for the same item as in this sell order
                        _buyOrders.ItemFilter = "ItemID = " + itemID;
                        foreach (Order o in _sellOrders.FiltredItems)
                        {
                            SortableCollection buyOrders = _buyOrders.FiltredItems;
                            if (buyOrders.Count > 0)
                            {
                                o.BuyOrderExistsForThisItem = (buyOrders[0] as Order).Station != "NO ORDER";
                            }
                        }
                    }
                }
                _buyOrders.ItemFilter = "";
                _sellOrders.ItemFilter = "";

                _ordersDataVisible = true;
                _ordersGettingData = false;
                RefreshOrders();
                RefreshGUI();
            }
            catch (ThreadAbortException)
            {
                // User has aborted, just drop out.
            }
            catch (Exception ex)
            {
                new EMMAException(ExceptionSeverity.Error, "Error when updating orders data in item detail", ex);
            }
        }