private List <cardWrapper> findCardsWithName(string cardName) { List <cardWrapper> returnList = new List <cardWrapper>(); List <int> tempIDs = new List <int>(); connection.Open(); using (var cmd = new NpgsqlCommand("get_cards_containing_name", connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("in_name", cardName); //tempID = var reader = cmd.ExecuteReader(); //if(reader.HasRows) while (reader.Read()) { string temp; cardWrapper tempWrapper = new cardWrapper(); CardObject tempCard = new CardObject(); tempCard.cardID = Convert.ToInt32(reader[0].ToString()); tempCard.name = reader[2].ToString(); tempCard.type = reader[3].ToString(); tempCard.manaCost = reader[4].ToString(); tempCard.setCode = reader[5].ToString(); tempCard.multiverseId = Convert.ToInt32(reader[9].ToString()); tempCard.power = reader[10].ToString(); tempCard.toughness = reader[11].ToString(); temp = reader[13].ToString().TrimEnd('}'); temp = temp.TrimStart('{'); tempCard.colors = temp.Split(',').ToList <string>(); temp = reader[14].ToString().TrimEnd('}'); temp = temp.TrimStart('{'); tempCard.colorIdentity = temp.Split(',').ToList <string>(); tempCard.text = reader[15].ToString(); tempCard.convertedManaCost = float.Parse(reader[16].ToString()); tempCard.flavorText = reader[17].ToString(); tempCard.rarity = reader[18].ToString(); tempCard.borderColor = reader[19].ToString(); tempCard.loyalty = reader[20].ToString(); tempCard.artist = reader[21].ToString(); tempCard.number = reader[24].ToString(); tempWrapper.card = tempCard; returnList.Add(tempWrapper); } } connection.Close(); return(returnList); }
private void Enter() { databaseList.Clear(); if (Name_Textbox.Text.Length != 0) { connection.Open(); var str = "SELECT * FROM public.card WHERE card_name ILIKE '%" + Name_Textbox.Text + "%'"; /*if(Card_Type_TextBox.Text != null) * { * str += "AND card_type ILIKE '%" + Card_Type_TextBox.Text + "%'"; * }*/ var cmd = new NpgsqlCommand("SELECT * FROM public.card WHERE card_name ILIKE '%" + Name_Textbox.Text + "%'", connection); NpgsqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { string temp; cardWrapper tempWrapper = new cardWrapper(); CardObject tempCard = new CardObject(); tempCard.cardID = System.Convert.ToInt32(reader[0].ToString()); tempCard.name = reader[2].ToString(); tempCard.type = reader[3].ToString(); tempCard.manaCost = reader[4].ToString(); tempCard.setCode = reader[5].ToString(); tempCard.multiverseId = System.Convert.ToInt32(reader[9].ToString()); tempCard.power = reader[10].ToString(); tempCard.toughness = reader[11].ToString(); temp = reader[13].ToString().TrimEnd('}'); temp = temp.TrimStart('{'); tempCard.colors = temp.Split(',').ToList <string>(); temp = reader[14].ToString().TrimEnd('}'); temp = temp.TrimStart('{'); tempCard.colorIdentity = temp.Split(',').ToList <string>(); tempCard.text = reader[15].ToString(); tempCard.convertedManaCost = float.Parse(reader[16].ToString()); tempCard.flavorText = reader[17].ToString(); tempCard.rarity = reader[18].ToString(); tempCard.borderColor = reader[19].ToString(); tempCard.loyalty = reader[20].ToString(); tempCard.artist = reader[21].ToString(); tempCard.number = reader[24].ToString(); tempWrapper.card = tempCard; databaseList.Add(tempWrapper); } connection.Close(); } else { cardExists = false; } if (databaseList.Count != 0) { cardExists = true; button2.Enabled = true; textBox1.Text = ""; Name_Textbox.ReadOnly = true; populate(databaseList[0]); } else { Name_Textbox.Text = "Card not valid"; } }
private cardWrapper findCardWithName(string cardName) { cardWrapper returnCard = new cardWrapper(); cardWrapper tempWrapper = new cardWrapper(); connection.Open(); using (var cmd = new NpgsqlCommand("get_cards_containing_name", connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("in_name", cardName); var reader = cmd.ExecuteReader(); int rowsAffected = 0; while (reader.Read()) { if (reader[2].ToString().Contains("FOIL") || reader[2].ToString().Contains("PRERELEASE")) { rowsAffected++; } } if (rowsAffected > 1) { tempWrapper.cardStatus = Color.Gold; } else { tempWrapper.cardStatus = this.BackColor; } } connection.Close(); connection.Open(); using (var cmd = new NpgsqlCommand("get_card_with_name", connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("in_name", cardName); CardObject tempCard = new CardObject(); tempCard.cardID = Convert.ToInt32(cmd.ExecuteScalar()); returnCard.card = tempCard; } connection.Close(); connection.Open(); using (var cmd = new NpgsqlCommand("SELECT * FROM public.card WHERE card_id = " + returnCard.card.cardID, connection)) { NpgsqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { string temp; CardObject tempCard = new CardObject(); tempCard.cardID = Convert.ToInt32(reader[0].ToString()); tempCard.name = reader[2].ToString(); tempCard.type = reader[3].ToString(); tempCard.manaCost = reader[4].ToString(); tempCard.setCode = reader[5].ToString(); tempCard.multiverseId = Convert.ToInt32(reader[9].ToString()); tempCard.power = reader[10].ToString(); tempCard.toughness = reader[11].ToString(); temp = reader[13].ToString().TrimEnd('}'); temp = temp.TrimStart('{'); tempCard.colors = temp.Split(',').ToList <string>(); temp = reader[14].ToString().TrimEnd('}'); temp = temp.TrimStart('{'); tempCard.colorIdentity = temp.Split(',').ToList <string>(); tempCard.text = reader[15].ToString(); tempCard.convertedManaCost = float.Parse(reader[16].ToString()); tempCard.flavorText = reader[17].ToString(); tempCard.rarity = reader[18].ToString(); tempCard.borderColor = reader[19].ToString(); tempCard.loyalty = reader[20].ToString(); tempCard.artist = reader[21].ToString(); tempCard.number = reader[24].ToString(); tempWrapper.card = tempCard; returnCard = tempWrapper; Card_Set_Combobox.Items.Add(tempCard.setCode); CardName.Items.Add(tempCard.name); } } connection.Close(); if (returnCard.card != null) { textBox1.Text += " Success!"; } else { textBox1.Text += " Failed!"; } CardName.Text = returnCard.card.name; Card_Set_Combobox.Text = returnCard.card.setCode; Card_Type_TextBox.Text = returnCard.card.type; if (returnCard.card.text != "n/a") { cardTextTextbox.Visible = true; cardTextLabel.Visible = true; cardTextTextbox.Text = returnCard.card.text; } else { cardTextLabel.Visible = false; cardTextTextbox.Visible = false; } if (returnCard.card.flavorText != "n/a") { cardFlavorLabel.Visible = true; cardFlavorTextbox.Visible = true; cardFlavorTextbox.Text = returnCard.card.flavorText; } else { cardFlavorLabel.Visible = false; cardFlavorTextbox.Visible = false; } if (returnCard.card.loyalty != "n/a") { cardLoyaltyLabel.Visible = true; cardPTLabel.Visible = false; cardPTLTextbox.Visible = true; cardPTLTextbox.Text = returnCard.card.loyalty; } else if (returnCard.card.power != "n/a") { cardPTLabel.Visible = true; cardPTLTextbox.Visible = true; cardLoyaltyLabel.Visible = false; cardPTLTextbox.Text = returnCard.card.power + "/" + returnCard.card.toughness; } else { cardPTLabel.Visible = false; cardPTLTextbox.Visible = false; cardLoyaltyLabel.Visible = false; } currentCard = returnCard; return(returnCard); }
/* * List of variables returned: * */ private List <cardWrapper> Get_Inventory() { // create list of cards List <cardWrapper> cards = new List <cardWrapper>(); // open connection to server connection.Open(); // return entire inventory table, go through it, // populate cards inside list with their card IDs, // check for duplicates // query the database again, looking for those same card IDs within the database // go back to the system so it can read all the return data from the database so // it can be returned to the calling function using (var cmd = new NpgsqlCommand("SELECT * FROM public.inventory", connection)) { NpgsqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { cardWrapper card = new cardWrapper(); card.card_ID = System.Convert.ToInt32(reader[1].ToString()); card.count = System.Convert.ToInt32(reader[2].ToString()); cards.Add(card); } } connection.Close(); string cmdhold = ""; for (int i = 0; i < cards.Count; i++) { if (cards[i].count <= 0) { cards.RemoveAt(i); i--; } else if (i != 0) { cmdhold += "OR card_id = " + cards[i].card_ID; } else { cmdhold = "card_id = " + cards[i].card_ID; } } // TO DO: // add ability to grab card expansion if (cards.Count != 0) { connection.Open(); using (var cmd = new NpgsqlCommand("SELECT * FROM public.card WHERE " + cmdhold, connection)) { NpgsqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { string temp; CardObject tempCard = new CardObject(); tempCard.cardID = System.Convert.ToInt32(reader[0].ToString()); tempCard.name = reader[2].ToString(); tempCard.type = reader[3].ToString(); tempCard.manaCost = reader[4].ToString(); tempCard.setCode = reader[5].ToString(); tempCard.multiverseId = System.Convert.ToInt32(reader[9].ToString()); tempCard.power = reader[10].ToString(); tempCard.toughness = reader[11].ToString(); temp = reader[13].ToString().TrimEnd('}'); temp = temp.TrimStart('{'); tempCard.colors = temp.Split(',').ToList <string>(); temp = reader[14].ToString().TrimEnd('}'); temp = temp.TrimStart('{'); tempCard.colorIdentity = temp.Split(',').ToList <string>(); tempCard.text = reader[15].ToString(); tempCard.convertedManaCost = float.Parse(reader[16].ToString()); tempCard.flavorText = reader[17].ToString(); tempCard.rarity = reader[18].ToString(); tempCard.borderColor = reader[19].ToString(); tempCard.loyalty = reader[20].ToString(); tempCard.artist = reader[21].ToString(); tempCard.number = reader[24].ToString(); for (int i = 0; i < cards.Count; i++) { if (cards[i].card_ID == tempCard.cardID) { cards[i].card = tempCard; } } } } connection.Close(); } return(cards); }