コード例 #1
0
 private void GetCurrencyTypes()
 {
     using (var context = new ItsOnlyHeroesEntities())
     {
         currencyTypes = context.CurrencyTypes.ToList();
     }
     currencyTypeComboBox.DisplayMember = "CurrencyTypeName";
     currencyTypeComboBox.ValueMember   = "CurrencyTypeId";
     currencyTypeComboBox.Items.AddRange(currencyTypes.ToArray());
     var really = currencyTypeComboBox.Items.Contains(currencyTypes[0]);
 }
コード例 #2
0
        private void GetItemTypes()
        {
            ItemTypeComboBox.Items.Clear();

            using (var context = new ItsOnlyHeroesEntities())
            {
                itemTypes = context.ItemTypes.ToList();
            }

            ItemTypeComboBox.DisplayMember = "ItemTypeName";
            ItemTypeComboBox.ValueMember   = "ItemTypeId";
            ItemTypeComboBox.Items.AddRange(itemTypes.ToArray());
            typeDescriptionTextBox.Text = "";
        }
コード例 #3
0
        private void GetItems()
        {
            ItemListBox.Items.Clear();

            using (var context = new ItsOnlyHeroesEntities())
            {
                items = context.Items.Where(x => x.Active == true)
                        .Include(x => x.ItemType)
                        .Include(x => x.Stat)
                        .Include(x => x.CurrencyType)
                        .ToList();
            }
            //setting up some defaults.
            ItemListBox.DisplayMember = "Name";
            ItemListBox.ValueMember   = "ItemId";
            ItemListBox.Items.AddRange(items.ToArray());
        }
コード例 #4
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            var itemToDelete = (Item)ItemListBox.SelectedItem;

            if (itemToDelete == null)
            {
                return;
            }

            using (var context = new ItsOnlyHeroesEntities())
            {
                var item = context.Items.Find(itemToDelete.ItemId);
                if (item != null)
                {
                    item.Active = false;
                    context.SaveChanges();
                }
            }
        }
コード例 #5
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            var itemToSave = (Item)ItemListBox.SelectedItem;

            if (itemToSave == null)
            {
                return;
            }

            using (var context = new ItsOnlyHeroesEntities())
            {
                Item item = new Item();

                if (itemToSave.ItemId > 0)
                {
                    item = context.Items.Find(itemToSave.ItemId);
                }
                else
                {
                    context.Items.Add(item);
                }

                //there's probably a better way to copy this over, but you only have context from EF items.
                var updatedItem = GetItemFromView();
                item.Name          = updatedItem.Name;
                item.Stat          = updatedItem.Stat;
                item.SellValue     = updatedItem.SellValue;
                item.BuyValue      = updatedItem.BuyValue;
                item.BuyCurrencyId = updatedItem.BuyCurrencyId;
                item.ItemTypeId    = updatedItem.ItemTypeId;
                item.Active        = updatedItem.Active;
                item.Description   = updatedItem.Description;

                context.SaveChanges();
            }

            //probably not the best way to do this.
            GetItems();
            ItemListBox.SelectedItem = ItemListBox.Items.OfType <Item>()
                                       .Where(i => i.ItemId == itemToSave.ItemId)
                                       .FirstOrDefault();
        }
コード例 #6
0
        private void addCurrencyTypeButton_Click(object sender, EventArgs e)
        {
            var  newType = ItemTypeComboBox.Text;
            bool exists  = ItemTypeComboBox.Items.OfType <ItemType>()
                           .Where(i => i.ItemTypeName == newType).Any();

            if (exists) //if it exists, we should update it.
            {
                return;
            }

            var newItemType = new ItemType();

            newItemType.ItemTypeName        = newType;
            newItemType.ItemTypeDescription = typeDescriptionTextBox.Text;

            using (var context = new ItsOnlyHeroesEntities())
            {
                context.ItemTypes.Add(newItemType);
                context.SaveChanges();
            }
            GetItemTypes();
        }