Esempio n. 1
0
        public void AddCellListToSale(DataGridView itemsToSaleGrid, params DataGridViewRow[] rows)
        {
            foreach (var row in rows)
            {
                var countTextBoxCell    = this.GetGridCountTextBoxCell(row.Index);
                var hiddenItemsListCell = this.GetGridHiddenItemsListCell(row.Index);

                var itemsCount = int.Parse(countTextBoxCell.Value.ToString());
                if (itemsCount <= 0)
                {
                    return;
                }

                ItemsToSaleGridUtils.AddItemsToSale(itemsToSaleGrid, hiddenItemsListCell.Value?.ItemsList);

                this.dataGrid.Rows.RemoveAt(row.Index);
            }
        }
Esempio n. 2
0
        public void GridAddButtonClick(int row, DataGridView itemsToSaleGrid)
        {
            var countTextBoxCell        = this.GetGridCountTextBoxCell(row);
            var amountToAddComboBoxCell = this.GetGridCountToAddComboBoxCell(row);
            var hiddenItemsList         = this.GetGridHiddenItemsListCell(row)?.Value?.ItemsList;

            var itemsToAddCount = int.Parse(amountToAddComboBoxCell.Value);

            if (itemsToAddCount <= 0)
            {
                return;
            }

            if (hiddenItemsList == null)
            {
                hiddenItemsList = new List <FullRgItem>();
            }

            var itemsToAdd = new List <FullRgItem>();
            var addedCount = 0;

            for (var i = hiddenItemsList.Count - 1; i >= 0; i--)
            {
                var item = hiddenItemsList[i];

                if (item.Asset.Amount.Equals("1"))
                {
                    // если это не стакающийся предмет
                    itemsToAdd.Add(item);
                    hiddenItemsList.RemoveAt(i);
                    addedCount++;
                }
                else
                {
                    // если это стакающийся предмет
                    var itemsInSlotCount = int.Parse(item.Asset.Amount);
                    if (itemsInSlotCount + addedCount > itemsToAddCount)
                    {
                        // если нам нужно добавить НЕ ВСЕ предметы с 1 слота
                        var neededCount        = itemsToAddCount - addedCount;
                        var neededAmountOfItem = item.CloneAsset();
                        neededAmountOfItem.Asset.Amount = neededCount.ToString();
                        itemsToAdd.Add(neededAmountOfItem);
                        item.Asset.Amount = (int.Parse(item.Asset.Amount) - neededCount).ToString();
                    }
                    else
                    {
                        // если нам нужно добавить ВСЕ предметы с 1 слота
                        itemsToAdd.Add(item);
                        hiddenItemsList.RemoveAt(i);
                        addedCount += itemsInSlotCount;
                    }
                }

                if (addedCount == itemsToAddCount)
                {
                    break;
                }
            }

            ItemsToSaleGridUtils.AddItemsToSale(itemsToSaleGrid, itemsToAdd);

            var totalAmount = int.Parse(countTextBoxCell.Value.ToString()); // изменение ячейки Общее количество

            if (itemsToAddCount == totalAmount)
            {
                this.dataGrid.Rows.RemoveAt(row);
            }
            else
            {
                countTextBoxCell.ChangeCellValue(totalAmount - itemsToAddCount);
                SetDefaultAmountToAddComboBoxCellValue(amountToAddComboBoxCell);
            }
        }