Пример #1
0
        //Конструктор, вызываемый для редактирования
        public add_food_in_book(db_connect data_module, string food_in_book_card, string food_in_book_food, string food_in_book_book, int card_id, int food_id, int book_id)
        {
            InitializeComponent();

            food_in_book[] food_in_book = new food_in_book[512];
            food_in_book = Program.add_read_module.get_list_food_in_book_id(book_id);
            if (food_in_book != null)
            {
                this.lb_food.Items.Clear();
                for (int i = 1; i < food_in_book.Count(); i++)
                {
                    if (food_in_book[i] != null)
                    {
                        this.lb_food.Items.Add(food_in_book[i].food_id);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            this.food_id = food_id.ToString();

            this.set_state("OLD");

            this.food = food_in_book_food.ToString();

            this.fill_food_in_book_data();
            this._data_module = data_module;
        }
Пример #2
0
        // Конструктор, вызываемый при нажатии "Добавить"
        public add_food_in_book(db_connect data_module, int book_id, string _author, string _year)
        {
            InitializeComponent();
            author = _author;
            year = _year;

            food_in_book[] food_in_book = new food_in_book[512];
            food_in_book = Program.add_read_module.get_list_food_in_book_id(book_id);
            if (food_in_book != null)
            {
                this.lb_food.Items.Clear();
                for (int i = 1; i < food_in_book.Count(); i++)
                {
                    if (food_in_book[i] != null)
                    {
                        this.lb_food.Items.Add(food_in_book[i].food);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            this._data_module = data_module;
            this.set_state("NEW");
        }
Пример #3
0
        /// <summary>
        /// возвращает рецепт для блюда по указанному в параметрах идентификатору (коду)
        /// </summary>
        /// <param name="food"></param>
        /// <returns></returns>
        public food_in_book get_food_in_book(string food)
        {
            food_in_book food_in_book = new food_in_book();
            string query = "select C.Number_Card, F.Name_food, B.Name, FIB.IDBook "
                         + "from FoodInBook FIB "
                         + "join Cards C on C.Id_Cards = FIB.Id_Cards "
                         + "join Foods F on F.ID_food = FIB.ID_food "
                         + "join Book B on B.IDBook = FIB.IDBook ";
            query += "where F.Name_food = '" + food.ToString() + "'";
            try
            {
                SqlCommand com = Program.data_module._conn.CreateCommand();
                com.CommandText = query;
                SqlDataReader rd = com.ExecuteReader();
                if (rd.Read())
                {
                    food_in_book.result = "OK";
                    food_in_book.food = rd.GetString(1);

                    if (rd.IsDBNull(0))
                    {
                        food_in_book.card = "";
                    }
                    else
                    {
                        food_in_book.card = rd.GetString(0);
                    }
                    if (rd.IsDBNull(2))
                    {
                        food_in_book.book = "";
                    }
                    else
                    {
                        food_in_book.book = rd.GetString(2);
                    }
                    if (rd.IsDBNull(3))
                    {
                        food_in_book.book_id = "";
                    }
                    else
                    {
                        food_in_book.book_id = rd.GetInt32(3).ToString();
                    }

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

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

            return food_in_book;
        }
Пример #4
0
        /// <summary>
        /// получаем список блюд
        /// </summary>
        /// <param name="_id_book"></param>
        /// <returns></returns>
        public food_in_book[] get_list_food_in_book_id(int _id_book)
        {
            food_in_book[] card = new food_in_book[512];
            string query = "select C.ID_food, F.Name_food from Cards C "
                         + "join Foods F on F.ID_food = C.ID_food "
                         + "where C.ID_food not in "
                         + "(select ID_food from FoodInBook "
                         + "where IDBook = '" + _id_book + "')";
            try
            {
                SqlCommand com = Program.data_module._conn.CreateCommand();
                com.CommandText = query;
                SqlDataReader rd = com.ExecuteReader();
                int i = 0;
                while (rd.Read())
                {
                    i++;
                    card[i] = new food_in_book();
                    card[i].result = "OK";
                    card[i].food_id = rd.GetInt32(0).ToString();
                    card[i].food = rd.GetString(1);
                }
                rd.Close();
                rd.Dispose();
                com.Dispose();
            }

            catch (Exception ex)
            {
                card[0].result = "ERROR_" + ex.Data + " " + ex.Message;
            }

            return card;
        }