public TournamentFormats() { string formatsFile = Path.Combine(Helper.DataDirectory, "formats.xml"); formats.Add(new TournamentFormat("", "")); string group = string.Empty; TournamentFormat format = null; using (XmlReader reader = XmlReader.Create(formatsFile)) { while (reader.Read()) { XmlNodeType type = reader.NodeType; if (type == XmlNodeType.Element && reader.Name == "group") { group = reader.GetAttribute("name"); } else if (type == XmlNodeType.Element && reader.Name == "format") { string name = reader.GetAttribute("name"); format = new TournamentFormat(group, name); formats.Add(format); } else if (type == XmlNodeType.Element && reader.Name == "block") { string name = reader.GetAttribute("name"); format = new TournamentFormat(group, /*"Block -" +*/ name); formats.Add(format); } // Sub elements for sets else if (type == XmlNodeType.Element && reader.Name == "set") { reader.Read(); if (reader.NodeType == XmlNodeType.Text) { format.AddSet(reader.Value); } } else if (type == XmlNodeType.Element && reader.Name == "banned") { reader.Read(); if (reader.NodeType == XmlNodeType.Text) { format.AddBanned(reader.Value); } } else if (type == XmlNodeType.Element && reader.Name == "restricted") { reader.Read(); if (reader.NodeType == XmlNodeType.Text) { format.AddRestricted(reader.Value); } } } } }
private void InitSearchExpansionList() { listBoxSearchExpansion.Items.Clear(); listBoxSearchExpansion.Items.Add("(All)"); listBoxSearchExpansion.SelectedIndex = 0; Database database = DatabaseCreatorFactory.CreateDatabase(); IDbConnection connection = database.CreateConnection(); if (connection.State != ConnectionState.Open) { connection.Open(); } IDbCommand cmd = database.CreateCommand(); cmd.Connection = connection; cmd.CommandText = "SELECT NAME FROM EXTENSION"; if (comboBoxSearchFormat.SelectedIndex > 0) { TournamentFormat format = comboBoxSearchFormat.SelectedItem as TournamentFormat; if (format.Set.Count() > 0) { string list = ""; foreach (string sel in format.Set) { if (sel.Contains("\"")) { list += "'" + sel + "', "; } else { list += "\"" + sel + "\", "; } } list = list.Remove(list.Length - 2, 2); cmd.CommandText += " WHERE NAME IN (" + list + ")"; } } cmd.CommandText += " ORDER BY NAME"; IDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { listBoxSearchExpansion.Items.Add(reader.GetString(0)); } reader.Close(); }
private void UpdateCardList() { dgCards.DataSource = null; string whereclause = ""; List <object> data = new List <object>(); // Card name if (textBoxSearchName.Text != "") { whereclause += " AND NAME LIKE ?"; data.Add("%" + textBoxSearchName.Text + "%"); } // Rule text if (textBoxSearchText.Text != "") { whereclause += " AND RULE LIKE ?"; data.Add("%" + textBoxSearchText.Text + "%"); } // Card cost object[] comboBoxes = { comboBoxSearchU, comboBoxSearchB, comboBoxSearchW, comboBoxSearchR, comboBoxSearchG }; foreach (ComboBox cb in comboBoxes) { string color = cb.Tag.ToString(); if (cb.Text == "Must") { whereclause += " AND COST LIKE ?"; data.Add("%" + color + "%"); } else if (cb.Text == "Must not") { whereclause += " AND COST NOT LIKE ?"; data.Add("%" + color + "%"); } } // Type if (listBoxSearchType.SelectedIndex > 0) { string list = ""; foreach (string sel in listBoxSearchType.SelectedItems) { list += "\"" + sel + "\", "; } list = list.Remove(list.Length - 2, 2); whereclause += " AND TYPE IN (" + list + ")"; } // Type text if (textBoxSearchType.Text != "") { whereclause += " AND TYPE LIKE ?"; data.Add("%" + textBoxSearchType.Text + "%"); } // Expansion if (listBoxSearchExpansion.SelectedIndex > 0) { string list = ""; foreach (string sel in listBoxSearchExpansion.SelectedItems) { if (sel.Contains("\"")) { list += "'" + sel + "', "; } else { list += "\"" + sel + "\", "; } } list = list.Remove(list.Length - 2, 2); whereclause += " AND EXTENSION IN (" + list + ")"; } // Flavor text // Format if (comboBoxSearchFormat.SelectedIndex > 0) { TournamentFormat format = comboBoxSearchFormat.SelectedItem as TournamentFormat; // Set list if (format.Set.Count() > 0) { string list = ""; foreach (string sel in format.Set) { list += "\"" + sel + "\", "; } list = list.Remove(list.Length - 2, 2); whereclause += " AND EXTENSION IN (" + list + ")"; } // Banned card list if (format.Banned.Count() > 0) { string list = ""; foreach (string sel in format.Banned) { list += "\"" + sel + "\", "; } list = list.Remove(list.Length - 2, 2); whereclause += " AND NAME NOT IN (" + list + ")"; } } // Build the whereclause, 1=1 to allow every statement start with AND if (!String.IsNullOrEmpty(whereclause)) { whereclause = " WHERE 1=1 " + whereclause; } bwUpdateCardList.RunWorkerAsync(new object[] { whereclause, data }); }
private void btnFormatCheck_Click(object sender, EventArgs e) { bool valid = true; pbFormat.BackColor = Color.Green; lvFormatSummary.Items.Clear(); if (comboBoxFormat.SelectedIndex == 0) { return; } TournamentFormat format = comboBoxFormat.SelectedItem as TournamentFormat; string validSetList = ""; if (format.Set.Count() > 0) { foreach (string sel in format.Set) { validSetList += sel + ", "; } validSetList = validSetList.Remove(validSetList.Length - 2, 2); } IDbConnection connection = DataBuider.database.CreateOpenConnection(); Database database = DataBuider.database; foreach (Card c in cards) { bool cardValid = true; // Set list if (format.Set.Count() > 0) { bool setFound = false; IDbCommand cmdEditon = database.CreateCommand(); cmdEditon.CommandText = "SELECT EXTENSION FROM CARD WHERE NAME = ?"; cmdEditon.Connection = connection; IDbDataParameter p1Editon = cmdEditon.CreateParameter(); p1Editon.Value = c.Name; cmdEditon.Parameters.Add(p1Editon); IDataReader readerEditon = cmdEditon.ExecuteReader(); while (readerEditon.Read()) { if (format.Set.Contains(readerEditon.GetString(0))) { setFound = true; } } if (!setFound) { cardValid = false; ListViewItem item = new ListViewItem(c.Name + " was not found in the valid sets: " + validSetList); item.BackColor = Color.OrangeRed; lvFormatSummary.Items.Add(item); } } // Banned card list if (format.Banned.Count() > 0) { if (format.Banned.Contains(c.Name)) { cardValid = false; ListViewItem item = new ListViewItem(c.Name + " is banned."); item.BackColor = Color.Red; lvFormatSummary.Items.Add(item); } } // Restricted card list if (format.Restricted.Count() > 0) { if (c.Amount > 1 && format.Restricted.Contains(c.Name)) { cardValid = false; ListViewItem item = new ListViewItem(c.Name + " is restricted."); item.BackColor = Color.Orange; lvFormatSummary.Items.Add(item); } } if (cardValid) { lvFormatSummary.Items.Add(c.Name + " is valid."); } else { valid = false; } } if (!valid) { pbFormat.BackColor = Color.Red; } }