public Dish getCreatedDish() { Dish res = new Dish(-1, getCreationDishName(), getCreationImageLocation(), getCreationDishType(), -1, getCreationDishReceipe(), getDishConsistance()); return res; }
public void setDishInfo(Dish d) { switch (mainTab.SelectedIndex) { case 0: dishName.Text = d.Name; dishTypeLabel.Text = d.DishType; receipeText.Text = d.Recipe; if (d.LinkToPhoto != "" && File.Exists(Properties.Settings.Default.dishesImagesFolderPath + d.LinkToPhoto)) { dishPicture.Image = Image.FromFile(Properties.Settings.Default.dishesImagesFolderPath + d.LinkToPhoto); } else { dishPicture.Image = null; } dishConsistanceDataGrid.Rows.Clear(); foreach (KeyValuePair<String, Double> p in d.Consistance) { dishConsistanceDataGrid.Rows.Add(p.Key, p.Value); } break; case 1: createDishName.Text = d.Name; createDishType.Text = d.DishType; createDishRecipe.Text = d.Recipe; if (d.LinkToPhoto != "" && File.Exists(Properties.Settings.Default.dishesImagesFolderPath + d.LinkToPhoto)) { createDishImage.Image = Image.FromFile(Properties.Settings.Default.dishesImagesFolderPath + d.LinkToPhoto); createDishImage.ImageLocation = Properties.Settings.Default.dishesImagesFolderPath + d.LinkToPhoto; } else { createDishImage.Image = null; createDishImage.ImageLocation = ""; } createDishContentsDataGrid.Rows.Clear(); foreach (KeyValuePair<String, Double> p in d.Consistance) { createDishContentsDataGrid.Rows.Add(p.Key, p.Value); } break; case 2: label11.Text = d.Name; label12.Text = d.DishType; if (d.LinkToPhoto != "" && File.Exists(Properties.Settings.Default.dishesImagesFolderPath + d.LinkToPhoto)) { pictureBox1.Image = Image.FromFile(Properties.Settings.Default.dishesImagesFolderPath + d.LinkToPhoto); pictureBox1.ImageLocation = Properties.Settings.Default.dishesImagesFolderPath + d.LinkToPhoto; } else { pictureBox1.Image = null; pictureBox1.ImageLocation = ""; } dataGridView5.Rows.Clear(); foreach (KeyValuePair<String, Double> p in d.Consistance) { dataGridView5.Rows.Add(p.Key, p.Value); } break; } }
public void updateDish(Dish d) { connector.openConnection(); connector.executeNonQuery("UPDATE Dishes AS d SET d.Link_To_Photo = \"" + d.LinkToPhoto + "\", d.Dish_Type = \"" + d.DishType + "\", d.Recipe = \"" + d.Recipe + "\" WHERE d.Name_Dish = \"" + d.Name + "\""); connector.executeNonQuery("DELETE FROM Products_Dishes Where ID_Dish = (SELECT d.ID_Dish FROM Dishes d WHERE Name_Dish = \"" + d.Name + "\")"); foreach (KeyValuePair<String, Double> p in d.Consistance) { connector.executeNonQuery("INSERT INTO Products_Dishes (ID_Prod, ID_Dish, Product_Count) SELECT p.ID_Prod, (SELECT d.ID_Dish FROM Dishes d WHERE d.Name_Dish = \"" + d.Name + "\"), " + p.Value.ToString().Replace(",", ".") + " FROM Products p WHERE p.Name_Prod = \"" + p.Key + "\""); } connector.closeConnection(); }
public Double getDishPrice(Dish dish) { Double price = 0; connector.openConnection(); OleDbDataReader reader = null; foreach (KeyValuePair<String, Double> cons in dish.Consistance) { reader = connector.executeQuery("SELECT prod.Price FROM Products prod WHERE prod.Name_Prod = \"" + cons.Key + "\""); if (reader.Read()) { price += Convert.ToDouble(reader[0].ToString()) * cons.Value / 100; } } if (reader != null) { reader.Close(); } connector.closeConnection(); return price; }
public Dish getDish(String name) { Dish result = new Dish(); connector.openConnection(); OleDbDataReader reader = connector.executeQuery("SELECT d.ID_Dish, d.Name_Dish, d.Link_To_Photo, d.Dish_Type, d.Percent, d.Recipe FROM Dishes as d WHERE d.Name_Dish = \"" + name + "\""); if (reader.Read()) { result.IdInDB = Convert.ToInt32(reader[0]); result.Name = reader[1].ToString(); result.LinkToPhoto = reader[2].ToString(); result.DishType = reader[3].ToString(); result.Percent = Convert.ToInt32(reader[4]); result.Recipe = reader[5].ToString(); } reader = connector.executeQuery("SELECT pr.Name_Prod, pd.Product_Count FROM Products_Dishes pd INNER JOIN Products pr ON pd.ID_Prod = pr.ID_Prod WHERE ID_Dish = (SELECT dis.ID_Dish FROM Dishes dis WHERE dis.Name_Dish = \"" + name + "\")"); while (reader.Read()) { result.Consistance.Add(reader[0].ToString(), Convert.ToDouble(reader[1])); } reader.Close(); connector.closeConnection(); return result; }
public void createNewDish(Dish d) { if (d.Name != "") { connector.openConnection(); OleDbDataReader reader = connector.executeQuery("SELECT MAX(ID_Dish) FROM Dishes"); int lastI = 0; if (reader.Read()) { lastI = Convert.ToInt32(reader[0]) + 1; } connector.executeNonQuery("INSERT INTO Dishes VALUES (" + lastI + ", \"" + d.Name + "\", \"" + d.LinkToPhoto + "\", \"" + d.DishType + "\", " + 30 + ", \"" + d.Recipe + "\")"); foreach (KeyValuePair<String, Double> p in d.Consistance) { connector.executeNonQuery("INSERT INTO Products_Dishes (ID_Prod, ID_Dish, Product_Count) SELECT p.ID_Prod, " + lastI + ", " + p.Value.ToString().Replace(",", ".") + " FROM Products p WHERE p.Name_Prod = \"" + p.Key + "\""); } connector.closeConnection(); } }