public MagicCard Make(double price)
        {
            MagicCard card = new MagicCard(_name, _desc, _category, _condition, price, _count);

            return(card);
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Boolean inCollection = false;

            _count = Int32.Parse(textBox3.Text);
            List <Item> items = _collection.getCollection();

            foreach (Item item in items)
            {
                if (item.getName().Equals(_name))
                {
                    inCollection = true;
                }
            }
            // when the item is already in the collection
            if (inCollection == true)
            {
                _name = textBox1.Text;
                //_name = _name.Replace(' ', '_');
                string userName = _user.getUsername();
                int    addNumber;
                try
                {
                    addNumber = Int32.Parse(textBox3.Text);
                }
                catch
                {
                    addNumber = 1;
                }
                foreach (Item item in items)
                {
                    Console.WriteLine(item.getName());
                }
                Item temp = _collection.getItem(_name);
                temp.IncrementCount();
                OleDbConnection conn      = new OleDbConnection(_connectionString);
                OleDbCommand    increment = conn.CreateCommand();
                conn.Open();
                increment = new OleDbCommand("SELECT Count FROM Collection WHERE Username = '******' AND ItemName = '" + _name + "'", conn);
                OleDbDataReader reader = increment.ExecuteReader();
                reader.Read();
                int count = Int32.Parse(reader[0].ToString());
                count += addNumber;
                reader.Close();
                OleDbCommand repush = conn.CreateCommand();
                repush = new OleDbCommand("UPDATE [Collection] SET [Count]='" + count + "' WHERE Username='******' AND ItemName='" + _name + "'", conn);
                repush.ExecuteScalar();
                conn.Close();
                _collection.getItem(_name).setCount(count);

                _collection.addToTotal(_collection.getItem(_name).getPrice());
                _collection.getItem(_name).setName(_name.Replace('_', ' '));
                _card.calcTotValue();
                _card.initializeCollection();
                this.Close();
            }
            else // when adding a new item
            {
                _name = _name.Replace(' ', '_');
                MakeMTGCard make  = new MakeMTGCard(_name, _set, _desc, _condition, _category, _count);
                string      price = make.pullPrice();
                //validates that a price was found and throws a spelling error if not
                if (price.Equals(""))
                {
                    label7.Visible = true;
                    label8.Visible = true;
                }
                else
                {
                    MagicCard card = make.Make(Convert.ToDouble(price));
                    _price = card.getPrice();
                    _name  = _name.Replace('_', ' ');
                    card.setName(_name);
                    _collection.AddItem(card);
                    _card.initializeCollection();
                    _card.calcTotValue();
                    //_collection.getItem(_name).setName(_name.Replace('_', ' '));
                    string          username = _user.getUsername();
                    OleDbConnection conn     = new OleDbConnection(_connectionString);
                    OleDbCommand    addItem  = conn.CreateCommand();
                    conn.Open();
                    if (_name.Contains("'"))
                    {
                        _name = _name.Replace("'", "''");
                        Console.WriteLine(_name);
                    }//else if (_name.Contains("//"){ }
                    if (_set.Contains("'"))
                    {
                        _set = _name.Replace("'", "''");
                        Console.WriteLine(_name);
                    }
                    addItem = new OleDbCommand("INSERT INTO [Collection] ([Username], [ItemName], [Description], [Category], [Condition], [Price], [Count]) VALUES('" + username + "', '" + _name + "', '" + _desc + "', '" + _category + "', '" + _condition + "', '" + _price + "', '" + _count + "')", conn);
                    addItem.ExecuteScalar();
                    conn.Close();
                    this.Close();
                }
            }
        }