#351

New

Multiple sets filter

Reported by kelly on OCTGN · 23/02/2011 21:56:22

Assigned to:
jods
Priority:
Normal
Status:
New
Category:
None
Version:
0.9.*
Issue type:
Feature

Hey I noticed that quite a few people were interested in being able to filter more than one set at a time in the deck editor, so while I was workin on the lobby I wipped that together real quick. Heres the code if you wanna toss it in there.

Basically it pulls out all the conditions looking for the ‘set’ row, and concats them into a single string like so
“(Card.setId=a or Card.setId=b or Card.setId)”
then it appends that onto the condition array(after removing the old set.id’s) as one big string that just flops into the sql query fine(since all the other conditions are and’s).

It’s fairly rough cause it causes you to iterate the conditions twice looking to see if it’s a set condition, but it works, and really iterating an array of anything less than 100 is nothing.

Eather way it’s a fast, simple, bug free solution that I think will make quite a few people happy, I know I find it usefull.

Thanks..

//————————————————————

//in octgn.data.game

public System.Data.DataTable SelectCards(string[] conditions) { var sb = new StringBuilder(“SELECT * FROM Card”); List<string> sets = new List<string>(); if (conditions != null) { string connector; connector = " ( "; int i = 0; bool foundSet = false; sb = new StringBuilder(); foreach (string condition in conditions) { if (condition.Substring(0,10).Equals(“Card.setId”)) { sb.Append(connector); sb.Append(“(”); sb.Append(condition); sb.Append(“)”); connector = " OR "; conditions[i] = ""; foundSet = true; } i++; } sb.Append(“)”); if (foundSet) { Array.Resize<string>(ref conditions, conditions.Length + 1); conditions[conditions.Length – 1] = sb.ToString(); } sb = new StringBuilder(“SELECT * FROM Card”); connector = " WHERE "; foreach (string condition in conditions) { if (!condition.Trim().Equals("")) { sb.Append(connector); sb.Append(“(”); sb.Append(condition); sb.Append(“)”); connector = " AND "; } } } using (var conn = new VistaDB.Provider.VistaDBConnection(db)) { var cmd = new VistaDB.Provider.VistaDBCommand(); cmd.Connection = conn; cmd.CommandText = sb.ToString(); var result = new System.Data.DataTable(); result.Load(cmd.ExecuteReader()); return result; } }

Attachments

No attachment has been uploaded, yet.


Loading comments...