Exemple #1
0
        public FoodNutrient LoadEatFood(string id, string date)
        {
            // 해당 일에 id 가 먹은 음식 조회
            ViewLog(id, "LoadEatFood try");
            int mid = DBM.FindMIDByID(id);

            ArrayList fid = DBM.FindFID(mid, date);

            if (fid == null)
            {
                ViewLog(id, "LoadEatFood fail");
                return(null);
            }
            //영양소 합
            FoodNutrient allfoodnutrient = LoadFoodAll(fid);

            if (allfoodnutrient == null)
            {
                ViewLog(id, "LoadEatFood fail");
                return(null);
            }
            ViewLog(id, "LoadEatFood success");

            return(allfoodnutrient);
        }
Exemple #2
0
        public FoodNutrient ImageAnalysis(string id, byte[] img)
        {
            ViewLog(id, "ImageAnalysis try");

            // 이미지 파일명 생성및 저장
            ViewLog(id, "ImageSave try");
            string imgfath = SaveImg(id, img);

            if (imgfath == "f")
            {
                ViewLog(id, "ImageSave fail");
                return(null);
            }
            ViewLog(id, "ImageSave success");

            // WCF -> 인공지능 분석요청(이미지)
            ViewLog(id, "SendImgforTen try");
            int fid = SendImgforTen(imgfath);

            switch (fid)
            {
            case -1: ViewLog(id, "SendImgforTen Fail"); return(null);

            case 0: ViewLog(id, "SendImgforTen  Can not Find Food"); return(null);
            }
            ViewLog(id, "SendImgforTen success");

            //분석결과로 음식영양소 조회
            ViewLog(id, "FindFoodFid try");
            FoodNutrient foodnutrient = DBM.FindFoodbyFid(fid);

            if (foodnutrient == null)
            {
                ViewLog(id, "FindFoodFid fail");
                return(null);
            }
            foodnutrient.IMG = img;
            ViewLog(id, "FindFoodFid success");

            //WCF -> DB 저장 (조회 아이디랑 음식종류결과, 분석요청한시간 저장)
            ViewLog(id, "SaveEatFood try");
            int  mid        = DBM.FindMIDByID(id);
            bool saveresult = DBM.SaveEatFood(fid, mid, DateTime.Now.ToString());

            if (saveresult == false)
            {
                ViewLog(id, "SaveEatFood fail");
                return(null);
            }
            ViewLog(id, "SaveEatFood success");
            ViewLog(id, "ImageAnalysis success");
            //WCF -> 안드로이드 전송 (음식정보 반환)
            return(foodnutrient);
        }
Exemple #3
0
        private FoodNutrient LoadFoodAll(ArrayList fid)
        {
            FoodNutrient allFoodNutrient = new FoodNutrient();

            for (int i = 0; i < fid.Count; i++)
            {
                FoodNutrient FoodNutrient = DBM.FindFoodbyFid((int)fid[i]);
                allFoodNutrient.Kcal    = allFoodNutrient.Kcal + FoodNutrient.Kcal;
                allFoodNutrient.Cho     = allFoodNutrient.Cho + FoodNutrient.Cho;
                allFoodNutrient.Fat     = allFoodNutrient.Fat + FoodNutrient.Fat;
                allFoodNutrient.Protein = allFoodNutrient.Protein + FoodNutrient.Protein;
                allFoodNutrient.Na      = allFoodNutrient.Na + FoodNutrient.Na;
            }
            return(allFoodNutrient);
        }
Exemple #4
0
        internal FoodNutrient FindFoodbyFid(int resultfood)
        {
            string sql = string.Format("SELECT * FROM food where fid ='{0}'", resultfood);

            using (MySqlCommand scom = new MySqlCommand(sql, scon))
            {
                scom.Connection.Open();
                using (MySqlDataReader reader = scom.ExecuteReader())
                {
                    if (reader == null)
                    {
                        scom.Connection.Close();
                        return(null); // 에러
                    }
                    try
                    {
                        reader.Read();
                        string name    = reader["name"].ToString();
                        int    kcal    = int.Parse(reader["kcal"].ToString());
                        double cho     = double.Parse(reader["cho"].ToString());
                        double fat     = double.Parse(reader["fat"].ToString());
                        double protein = double.Parse(reader["protein"].ToString());
                        double na      = double.Parse(reader["m_na"].ToString());

                        FoodNutrient foodnutrient = new FoodNutrient(name, kcal, cho, fat, protein, na);
                        scom.Connection.Close();
                        return(foodnutrient); // 정상반환
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("FindFoodByFid :" + e);
                        scom.Connection.Close();
                        return(null);
                    }
                }
            }
        }