public void LoadFoodstuff(FoodStuff inFS) { //fill out controls based on what inFS contains fstoUpdate = inFS; txtName.Text = inFS.Name; txtServingSize.Text = inFS.Servings.ToString(); txtPriceSold.Text = inFS.Cost.ToString(); txtPrepTime.Text = inFS.PrepTime.ToString(); txtCookTime.Text = inFS.CookTime.ToString(); txtDirections.Text = inFS.Directions; foreach (string s in inFS.ReturnTagList()) { lbxTags.Items.Add(s); } //get recipematerials for it... List <Recipe> inFSmats = DataConnection.ListOfIngredients(inFS.ID); foreach (Recipe r in inFSmats) { ListViewItem lvi = new ListViewItem(); lvi.Text = r.FractionAmount(); lvi.SubItems.Add(r.Unit); lvi.SubItems.Add(DataConnection.GetFoodstuffWithID(r.MadeOf).Name); lsvIngredients.Items.Add(lvi); } }
public static List <FoodStuff> ListAllFoodstuffs() { //displays all foodstuffs that are not atomic items (that is, base ingredients) //this is determined by the RecipeMaterials entries: items where the Makes and MadeOf fields are identical //are atomic items. These are the ones we DO NOT want this function to return. List <FoodStuff> lstFoods = new List <FoodStuff>(); try { string query = "Select * from Foodstuff where FoodstuffID in (select Makes from RecipeMaterials where Makes <> MadeOf)"; //Not equals for Access is <> not != OleDbCommand cmd = new OleDbCommand(query, conn); DataConnection.OpenConnection(); OleDbDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { List <Recipe> lstMats = DataConnection.ListOfIngredients(reader.GetString(0)); FoodStuff fs = new FoodStuff(reader.GetString(0), reader.GetString(1), reader.IsDBNull(2) ? "" : reader.GetString(2), reader.IsDBNull(3) ? -1 : reader.GetInt32(3), reader.IsDBNull(4) ? -1 : reader.GetInt32(4), reader.IsDBNull(5) ? -1.0 : reader.GetDouble(5), reader.IsDBNull(6) ? -1 : reader.GetInt32(6), null, lstMats); //tokenize the tags from their long string stored in the database. if (!(reader[7] is System.DBNull)) { string[] strTagList = reader.GetString(7).Split(','); if (strTagList.Length > 0) { foreach (string t in strTagList) { fs.AddTag(t); } } } lstFoods.Add(fs); } reader.Close(); } catch (Exception ex) { //don't do anything, apparently can't post messageboxes out of this thing ex.ToString(); } finally { DataConnection.CloseConnection(); } return(lstFoods); }
public static List <FoodStuff> FindFoodstuffsNamed(string inName) { //return a list of foodstuffs whose names contain the passed in value //does not distinguish between base ingredients and final items. List <FoodStuff> lstFoods = new List <FoodStuff>(); try { string query = "Select * from Foodstuff where Name like ?"; OleDbCommand cmd = new OleDbCommand(query, conn); cmd.Parameters.Add("?", OleDbType.VarChar).Value = inName; OleDbDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { List <Recipe> lstMats = DataConnection.ListOfIngredients(reader.GetString(0)); FoodStuff fs = new FoodStuff(reader.GetString(0), reader.GetString(1), reader.IsDBNull(2) ? "" : reader.GetString(2), reader.IsDBNull(3) ? -1 : reader.GetInt32(3), reader.IsDBNull(4) ? -1 : reader.GetInt32(4), reader.IsDBNull(5) ? -1.0 : reader.GetDouble(5), reader.IsDBNull(6) ? -1 : reader.GetInt32(6), null, lstMats); //tokenize the tags from their long string stored in the database. string[] strTagList = reader.IsDBNull(7) ? new string[0] : reader.GetString(7).Split(','); foreach (string t in strTagList) { fs.AddTag(t); } lstFoods.Add(fs); } reader.Close(); } catch (Exception ex) { } finally { DataConnection.CloseConnection(); } return(lstFoods); }
public static FoodStuff GetFoodstuffWithID(string fsID) { //really simple, match the foodstuff ID passed in with the ID in the table and return it. FoodStuff fs = new FoodStuff(); try { string query = "Select * from Foodstuff where FoodstuffID like ?"; OleDbCommand cmd = new OleDbCommand(query, conn); cmd.Parameters.Add("?", OleDbType.VarChar).Value = fsID; OleDbDataReader reader = cmd.ExecuteReader(); reader.Read(); string id = reader.IsDBNull(0) ? "" : reader.GetString(0); List <Recipe> lstMats = DataConnection.ListOfIngredients(reader.GetString(0)); fs = new FoodStuff(reader.GetString(0), reader.GetString(1), reader.IsDBNull(2) ? "" : reader.GetString(2), reader.IsDBNull(3) ? -1 : reader.GetInt32(3), reader.IsDBNull(4) ? -1 : reader.GetInt32(4), reader.IsDBNull(5) ? -1.0 : reader.GetDouble(5), reader.IsDBNull(6) ? -1 : reader.GetInt32(6), null, lstMats); //tokenize the tags from their long string stored in the database. string[] strTagList = reader.IsDBNull(7) ? new string[0] : reader.GetString(7).Split(','); if (strTagList.Length != 0) { foreach (string t in strTagList) { fs.AddTag(t); } } reader.Close(); } catch (Exception ex) { } finally { DataConnection.CloseConnection(); } return(fs); }
private void Form1_Load(object sender, EventArgs e) { fsTestItem = new FoodStuff(); lblTestItem.Text = fsTestItem.ToString(); string[] strTagList = fsTestItem.GetTags().Split(','); foreach (string element in strTagList) { cboTags.Items.Add(element); } lstRecipes = DataConnection.ListOfIngredients(); foreach (Recipe r in lstRecipes) { ListViewItem lvi = new ListViewItem(r.Makes); lvi.SubItems.Add(r.MadeOf); lvi.SubItems.Add(r.FractionAmount()); lvi.SubItems.Add(r.Unit); lbxRecipeList.Items.Add(lvi); } }
public static List <FoodStuff> FindFoodstuffsTagged(List <string> TagsToMatch) { //find a match for the tags in the passed-in list of tags in the foodstuff's tag string List <FoodStuff> FoodstuffsFound = new List <FoodStuff>(); try { if (TagsToMatch.Count > 0) { OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; string query = "select * from foodstuffs where tags like ?"; cmd.Parameters.Add(TagsToMatch[0]); if (TagsToMatch.Count > 1) { for (int i = 1; i < TagsToMatch.Count - 1; i++) { query += " or tags like ?"; cmd.Parameters.Add(TagsToMatch[i]); } } cmd.CommandText = query; OleDbDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { List <Recipe> lstMats = DataConnection.ListOfIngredients(reader.GetString(0)); FoodStuff fs = new FoodStuff(reader.GetString(0), reader.GetString(1), reader.IsDBNull(2) ? "" : reader.GetString(2), reader.IsDBNull(3) ? -1 : reader.GetInt32(3), reader.IsDBNull(4) ? -1 : reader.GetInt32(4), reader.IsDBNull(5) ? -1.0 : reader.GetDouble(5), reader.IsDBNull(6) ? -1 : reader.GetInt32(6), null, lstMats); //tokenize the tags from their long string stored in the database. if (!(reader[7] is System.DBNull)) { string[] strTagList = reader.GetString(7).Split(','); if (strTagList.Length > 0) { foreach (string t in strTagList) { fs.AddTag(t); } } } FoodstuffsFound.Add(fs); } reader.Close(); } } catch (Exception ex) { // throw; } finally { DataConnection.CloseConnection(); } return(FoodstuffsFound); }