Exemplo n.º 1
0
        /// <summary>
        /// возвращает диету по указанному в параметрах идентификатору (коду)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public class_diet get_diet(int id)
        {
            class_diet diet = new class_diet();
            string query = "select * from Diets where ID_Diets=";
            query += id.ToString();
            try
            {
                SqlCommand com = Program.data_module._conn.CreateCommand();
                com.CommandText = query;
                SqlDataReader rd = com.ExecuteReader();
                if (rd.Read())
                {
                    diet.result = "OK";
                    diet.diet_id = id.ToString();
                    diet.numbDiet = rd.GetString(1);
                    if (rd.IsDBNull(2))
                    {
                        diet.description = "";
                    }
                    else
                    {
                        diet.description = rd.GetString(2);
                    }
                }
                rd.Close();
                rd.Dispose();
                com.Dispose();
            }

            catch (Exception ex)
            {
                diet.result = "ERROR_" + ex.Data + " " + ex.Message;
            }

            return diet;
        }
Exemplo n.º 2
0
        /// <summary>
        /// из выбранной в лист боксе диеты передаем в текст бокс расшифровку диеты
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lb_diet_SelectedIndexChanged(object sender, EventArgs e)
        {
            class_diet diet = new class_diet();
            string query = "select Description from Diets "
                         + "where NumOfDiet = '" + lb_diet.Text + "'";
            try
            {
                SqlCommand com = Program.data_module._conn.CreateCommand();
                com.CommandText = query;
                SqlDataReader rd = com.ExecuteReader();
                if (rd.Read())
                {
                    if (rd.IsDBNull(0))
                    {
                        diet.description = "";
                        tb_desc.Text = diet.description;
                    }
                    else
                    {
                        diet.description = rd.GetString(0);
                        tb_desc.Text = diet.description;
                    }

                }
                rd.Close();
                rd.Dispose();
                com.Dispose();
            }

            catch (Exception ex)
            {
                MessageBox.Show("ERROR_" + ex.Data + " " + ex.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// метод выполняет загрузку содержания диеты в текст бокс при выборе конкретного номера диеты в дата гриде
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gw_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //запросом к БД получаем содержание диеты по конкретному ид диеты
            class_diet diet = new class_diet();
            string cell = gw.CurrentCell.Value.ToString();
            string query = "select ID_Diets, NumOfDiet, Description from Diets";
            query += " where NumOfDiet = '" + cell +"'";
            try
            {
                SqlCommand com = Program.data_module._conn.CreateCommand();
                com.CommandText = query;
                SqlDataReader rd = com.ExecuteReader();
                if (rd.Read())
                {
                    diet.result = "OK";
                    diet.diet_id = rd.GetInt32(0).ToString();
                    if (rd.IsDBNull(2))
                    {
                        diet.description = "";
                    }
                    else
                    {
                        diet.description = rd.GetString(2);
                    }
                }
                rd.Close();
                rd.Dispose();
                com.Dispose();
            }

            catch (Exception ex)
            {
                diet.result = "ERROR_" + ex.Data + " " + ex.Message;
            }

            tb_desc.Text = diet.description;//заполняем текст бокс полученными данными
        }
Exemplo n.º 4
0
        /// <summary>
        /// Возвращает id диеты и номер диеты
        /// </summary>
        public class_diet[] diet()
        {
            class_diet[] id_diet = new class_diet[512];
            string query = "select NumofDiet, FD.ID_Diets, FD.ID_food from Diets join Food_In_Diets FD on FD.ID_Diets =Diets.ID_Diets";

            query += " where ID_food ='";

            for (int t = 1; t < this._food_list1.Count(); t++)

                if (this._food_list1[t] != null)
                {

                    string guer1 = this._food_list1[t].food_id;

                    string query4 = query + guer1 + "'";

                    try
                    {
                        SqlCommand com = Program.data_module._conn.CreateCommand();
                        com.CommandText = query4;

                        SqlDataReader rd = com.ExecuteReader();
                        int i = 0;
                        while (rd.Read())
                        {
                            i = i + 1;
                            id_diet[i] = new class_diet();
                            id_diet[i].result = "OK";
                            id_diet[i].diet_id = rd.GetInt32(1).ToString();
                            id_diet[i].numbDiet = rd.GetString(0);
                        }
                        rd.Close();
                        rd.Dispose();
                        com.Dispose();
                    }

                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + " " + ex.Data);
                        return null;
                    }
                }
            return id_diet;
        }