/// <summary> /// Возвращает названия ингредиентов блюда на ужин /// </summary> public class_ingridients[] get_ingr_list_supper(int date) { class_ingridients[] ingr_list = new class_ingridients[512]; string query = "select distinct I.Id_ingridients,I.ingridient_name from Food_in_menu FIM " + " join Foods F on F.ID_food = FIM.ID_food" + " join Ingridients_in_food IIF on IIF.ID_food = F.ID_food" + " join Ingridients I on I.Id_ingridients = IIF.Id_ingridients" + " where FIM.Serve_time_of_food ='ужин'" + " and day_id = '" + date + "'"; try { SqlCommand com = Program.data_module._conn.CreateCommand(); com.CommandText = query; int i = 0; SqlDataReader rd = com.ExecuteReader(); while (rd.Read()) { i = i + 1; ingr_list[i] = new class_ingridients(); ingr_list[i].result = "OK"; ingr_list[i].name = rd.GetString(1).ToString(); ingr_list[i].ingr_id = rd.GetInt32(0).ToString(); } rd.Close(); rd.Dispose(); com.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message + " " + ex.Data); return null; } return ingr_list; }
/// <summary> /// Возвращает сведения о жирах,белках,углеводах для 9-го ингредиента /// </summary> public class_ingridients[] get_ingr_list9() { class_ingridients[] ingr_list9 = new class_ingridients[512]; string query = "select * from Ingridients where ingridient_name='"; if (this._ingr_list[9] != null) { string query1 = _ingr_list[9].name + "'"; string query2 = query + query1; try { SqlCommand com = Program.data_module._conn.CreateCommand(); com.CommandText = query2; SqlDataReader rd = com.ExecuteReader(); int i = 0; while (rd.Read()) { i = i + 1; ingr_list9[i] = new class_ingridients(); ingr_list9[i].result = "OK"; // customers_list1[i].name = rd.GetString(0).ToString(); // customers_list1[i].ingr_id = rd.GetInt32(1).ToString(); ingr_list9[i].calories = rd.GetDouble(1).ToString(); ingr_list9[i].uglevod = rd.GetDouble(2).ToString(); ingr_list9[i].zhiri = rd.GetDouble(3).ToString(); ingr_list9[i].protein = rd.GetDouble(4).ToString(); ingr_list9[i].ingr_id = rd.GetInt32(5).ToString(); } rd.Close(); rd.Dispose(); com.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message + " " + ex.Data); return null; } } return ingr_list9; }
/// <summary> /// Метод ,возвращает значения о ингридиенте при редактировании на форму /// </summary> /// <param name="id"></param> /// <returns>id ингридиента,имя,калории и т.д</returns> public class_ingridients get_ingr(int id) { class_ingridients ingrid = new class_ingridients(); string query = "select * from Ingridients where Id_ingridients="; query += id.ToString(); try { SqlCommand com = Program.data_module._conn.CreateCommand(); com.CommandText = query; SqlDataReader rd = com.ExecuteReader(); if (rd.Read()) { ingrid.result = "OK"; ingrid.ingr_id = id.ToString(); ingrid.name = rd.GetString(0); if (rd.IsDBNull(2)) { ingrid.uglevod = ""; } else { ingrid.uglevod = rd.GetDouble(2).ToString(); } if (rd.IsDBNull(1)) { ingrid.calories = ""; } else { ingrid.calories = rd.GetDouble(1).ToString(); } if (rd.IsDBNull(3)) { ingrid.zhiri = ""; } else { ingrid.zhiri = rd.GetDouble(3).ToString(); } if (rd.IsDBNull(4)) { ingrid.protein = ""; } else { ingrid.protein = rd.GetDouble(4).ToString(); } } rd.Close(); rd.Dispose(); com.Dispose(); } catch (Exception ex) { ingrid.result = "ERROR_" + ex.Data + " " + ex.Message; } return ingrid; }
/// <summary> /// Возвращает id и название ингредиента /// </summary> public class_ingridients[] get_ingr_list() { class_ingridients[] ingr_list = new class_ingridients[512]; string query = "select Foods.Name_food, ingridient_name, Ingridients.Id_ingridients, InF.ID_food from Ingridients join Ingridients_in_food InF on InF.Id_ingridients = Ingridients.Id_ingridients join Foods on Foods.ID_food = InF.ID_food"; if (this.cb_food.Text != "") query += " where Foods.Name_food = '" + this.cb_food.Text + "'"; string query2 = query; try { SqlCommand com = Program.data_module._conn.CreateCommand(); com.CommandText = query2; int i = 0; SqlDataReader rd = com.ExecuteReader(); while (rd.Read()) { i = i + 1; ingr_list[i] = new class_ingridients(); ingr_list[i].result = "OK"; if (rd.IsDBNull(1)) { ingr_list[i].name = ""; } else ingr_list[i].name = rd.GetString(1).ToString(); if (rd.IsDBNull(2)) { ingr_list[i].ingr_id = ""; } else ingr_list[i].ingr_id = rd.GetInt32(2).ToString(); } rd.Close(); rd.Dispose(); com.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message + " " + ex.Data); return null; } return ingr_list; }