public void BreathAPI(GSRAPI A)
        {
            G3_Measure_GSR B = new G3_Measure_GSR();

            B.Userid = A.Userid;
            int temp  = (int)A.SkinConductance;
            int temp2 = (int)((A.SkinConductance - temp) * 100);

            B.SkinConductance = temp + ((float)temp2 / 100);

            long temp3 = (int)A.SkinResistance;
            int  temp4 = (int)((A.SkinResistance - temp) * 100);

            B.SkinResistance = temp3 + ((float)temp4 / 100);

            int temp5 = (int)A.SkinConductanceVoltage;
            int temp6 = (int)((A.SkinConductanceVoltage - temp) * 10000);

            B.SkinConductanceVoltage = temp5 + ((float)temp6 / 10000);
            B.MeasurementDate        = DateTime.Now;
            if (B.SkinResistance < 1000)
            {
                B.Status = "出汗異常,有立即性危險,應盡速送醫";
                B.Score  = 10;
            }
            else
            {
                B.Status = "出汗正常";
                B.Score  = 0;
            }
            using (GSR db = new GSR())
            {
                db.G3_Measure_GSR.Add(B);
                db.SaveChanges();
            }
        }
        public ActionResult Create(string Name = null)
        {
            SystemNutrition        D       = new SystemNutrition();
            G3_Nutrition_Nutrition B       = new G3_Nutrition_Nutrition();
            HealthyScore           Healthy = new HealthyScore();
            UserHealthyInformation C       = new UserHealthyInformation();

            using (AIPEntities18 db = new AIPEntities18())
            {
                var reuslt = db.G1_User_Account.ToList();
                foreach (var item in reuslt)
                {
                    if (Name == item.email)
                    {
                        B.UserId = item.id;
                    }
                }
            }
            D.UserName  = Name;
            D.Nutrition = B;

            using (AIPEntities7 db = new AIPEntities7())
            {
                int number = 1;
                var reuslt = db.G3_Measure_BloodPressure.ToList();
                G3_Measure_BloodPressure History = new G3_Measure_BloodPressure();
                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.SBP             = item.SBP;
                        History.DBP             = item.DBP;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.SBP             = item.SBP;
                            History.DBP             = item.DBP;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.BloodPressure = History;
                }
            }

            using (AIPEntities9 db = new AIPEntities9())
            {
                int            number  = 1;
                var            reuslt  = db.G3_Measure_ABG.ToList();
                G3_Measure_ABG History = new G3_Measure_ABG();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.SpO2            = item.SpO2;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.SpO2            = item.SpO2;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.ABG = History;
                }
            }

            using (AIPEntities8 db = new AIPEntities8())
            {
                int number = 1;
                var reuslt = db.G3_Measure_BloodGlucose.ToList();
                G3_Measure_BloodGlucose History = new G3_Measure_BloodGlucose();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.GLU_AC          = item.GLU_AC;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.GLU_AC          = item.GLU_AC;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.BloodGlucose = History;
                }
            }

            using (AIPEntities11 db = new AIPEntities11())
            {
                int            number  = 1;
                var            reuslt  = db.G3_Measure_BMI.ToList();
                G3_Measure_BMI History = new G3_Measure_BMI();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.BMI             = item.BMI;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.BMI             = item.BMI;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.BMI = History;
                }
            }
            using (AIPEntities25 db = new AIPEntities25())
            {
                int            number  = 1;
                var            reuslt  = db.G3_Measure_Air.ToList();
                G3_Measure_Air History = new G3_Measure_Air();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.Air             = item.Air;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.Air             = item.Air;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.Air = History;
                }
            }
            using (GSR db = new GSR())
            {
                int            number  = 1;
                var            reuslt  = db.G3_Measure_GSR.ToList();
                G3_Measure_GSR History = new G3_Measure_GSR();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid                 = item.Userid;
                        History.SkinConductance        = item.SkinConductance;
                        History.SkinResistance         = item.SkinResistance;
                        History.SkinConductanceVoltage = item.SkinConductanceVoltage;
                        History.MeasurementDate        = item.MeasurementDate;
                        History.Status                 = item.Status;
                        History.Score = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.SkinConductance        = item.SkinConductance;
                            History.SkinResistance         = item.SkinResistance;
                            History.SkinConductanceVoltage = item.SkinConductanceVoltage;
                            History.MeasurementDate        = item.MeasurementDate;
                            History.Status = item.Status;
                            History.Score  = item.Score;
                        }
                    }
                    C.GSR = History;
                }
            }
            using (GyroValues db = new GyroValues())
            {
                int number = 1;
                var reuslt = db.G3_Measure_GyroValues.ToList();
                G3_Measure_GyroValues History = new G3_Measure_GyroValues();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.RawX            = item.RawX;
                        History.RawY            = item.RawY;
                        History.RawZ            = item.RawZ;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.RawX            = item.RawX;
                            History.RawY            = item.RawY;
                            History.RawZ            = item.RawZ;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.GyroValues = History;
                }
            }
            using (bodyTemperature db = new bodyTemperature())
            {
                int number = 1;
                var reuslt = db.G3_Measure_Temperature.ToList();
                G3_Measure_Temperature History = new G3_Measure_Temperature();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.Temperature     = item.Temperature;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.Temperature     = item.Temperature;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.Temperature = History;
                }
            }
            using (Pulse db = new Pulse())
            {
                int number = 1;
                var reuslt = db.G3_Measure_Pulse.ToList();
                G3_Measure_Pulse History = new G3_Measure_Pulse();

                foreach (var item in reuslt)
                {
                    if (B.UserId == item.Userid && number == 1)
                    {
                        History.Userid          = item.Userid;
                        History.Pulse           = item.Pulse;
                        History.MeasurementDate = item.MeasurementDate;
                        History.Status          = item.Status;
                        History.Score           = item.Score;

                        number = number + 1;
                    }
                    else if (B.UserId == item.Userid && number != 1)
                    {
                        if (DateTime.Compare(item.MeasurementDate, History.MeasurementDate) > 0)
                        {
                            History.Pulse           = item.Pulse;
                            History.MeasurementDate = item.MeasurementDate;
                            History.Status          = item.Status;
                            History.Score           = item.Score;
                        }
                    }
                    C.Pulse = History;
                }
            }

            Healthy.HealthyInformation = C;
            Healthy.Total = C.ABG.Score + C.BloodGlucose.Score + C.BloodPressure.Score + C.BMI.Score +
                            C.Air.Score + C.GSR.Score + C.GyroValues.Score + C.Pulse.Score +
                            C.Temperature.Score;

            D.UserHealthy = Healthy;

            ViewBag.Message = "新增建議";
            return(View(D));
        }