Ejemplo n.º 1
0
 private lifesense.Model.t_sleepinfo getSleepInfoModel(SleepData sleepData, lifesense.Model.t_userinfo mUserInfoModel)
 {
     lifesense.Model.t_sleepinfo sleepModel = new lifesense.Model.t_sleepinfo();
     sleepModel.UserID          = mUserInfoModel.UserID;
     sleepModel.LongSleepNum    = sleepData.sleep.depthTime;
     sleepModel.SleepingTime    = TimeParser.GetTime(sleepData.sleep.startTime.ToString());
     sleepModel.ShallowSleepNum = sleepData.sleep.shallowTime;
     sleepModel.WakeUpLong      = sleepData.sleep.consciousTime;
     sleepModel.WakingTime      = Convert.ToDateTime(sleepModel.SleepingTime).AddMinutes(sleepData.sleep.totalTime - sleepData.sleep.consciousTime);
     return(sleepModel);
 }
Ejemplo n.º 2
0
        private bool saveSleepData(SleepData sleepData, lifesense.Model.t_userinfo mUserInfoModel)
        {
            if (sleepData == null || sleepData.sleep == null)
            {
                return(false);
            }
            lifesense.Model.t_sleepinfo sleepModel = getSleepInfoModel(sleepData, mUserInfoModel);
            lifesense.BLL.t_sleepinfo   sleepBll   = new lifesense.BLL.t_sleepinfo();
            string strWhere = " UserId='" + mUserInfoModel.UserID + "' and SleepingTime='" + sleepModel.SleepingTime + "'";
            List <lifesense.Model.t_sleepinfo> sleepInfoList = sleepBll.GetModelList(strWhere);

            if (sleepInfoList != null && sleepInfoList.Count <= 0)
            {
                return(sleepBll.Add(sleepModel) > 0 ? true : false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(lifesense.Model.t_sleepinfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update t_sleepinfo set ");
            strSql.Append("UserID=@UserID,");
            strSql.Append("SleepingTime=@SleepingTime,");
            strSql.Append("WakingTime=@WakingTime,");
            strSql.Append("LongSleepNum=@LongSleepNum,");
            strSql.Append("ShallowSleepNum=@ShallowSleepNum,");
            strSql.Append("WakeUpLong=@WakeUpLong,");
            strSql.Append("WakingNum=@WakingNum");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserID",          SqlDbType.NVarChar,  100),
                new SqlParameter("@SleepingTime",    SqlDbType.DateTime),
                new SqlParameter("@WakingTime",      SqlDbType.DateTime),
                new SqlParameter("@LongSleepNum",    SqlDbType.Decimal,     9),
                new SqlParameter("@ShallowSleepNum", SqlDbType.Decimal,     9),
                new SqlParameter("@WakeUpLong",      SqlDbType.Decimal,     9),
                new SqlParameter("@WakingNum",       SqlDbType.Int,         4),
                new SqlParameter("@ID",              SqlDbType.Int, 4)
            };
            parameters[0].Value = model.UserID;
            parameters[1].Value = model.SleepingTime;
            parameters[2].Value = model.WakingTime;
            parameters[3].Value = model.LongSleepNum;
            parameters[4].Value = model.ShallowSleepNum;
            parameters[5].Value = model.WakeUpLong;
            parameters[6].Value = model.WakingNum;
            parameters[7].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public lifesense.Model.t_sleepinfo DataRowToModel(DataRow row)
 {
     lifesense.Model.t_sleepinfo model = new lifesense.Model.t_sleepinfo();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["UserID"] != null)
         {
             model.UserID = row["UserID"].ToString();
         }
         if (row["SleepingTime"] != null && row["SleepingTime"].ToString() != "")
         {
             model.SleepingTime = DateTime.Parse(row["SleepingTime"].ToString());
         }
         if (row["WakingTime"] != null && row["WakingTime"].ToString() != "")
         {
             model.WakingTime = DateTime.Parse(row["WakingTime"].ToString());
         }
         if (row["LongSleepNum"] != null && row["LongSleepNum"].ToString() != "")
         {
             model.LongSleepNum = decimal.Parse(row["LongSleepNum"].ToString());
         }
         if (row["ShallowSleepNum"] != null && row["ShallowSleepNum"].ToString() != "")
         {
             model.ShallowSleepNum = decimal.Parse(row["ShallowSleepNum"].ToString());
         }
         if (row["WakeUpLong"] != null && row["WakeUpLong"].ToString() != "")
         {
             model.WakeUpLong = decimal.Parse(row["WakeUpLong"].ToString());
         }
         if (row["WakingNum"] != null && row["WakingNum"].ToString() != "")
         {
             model.WakingNum = int.Parse(row["WakingNum"].ToString());
         }
     }
     return(model);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(lifesense.Model.t_sleepinfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_sleepinfo(");
            strSql.Append("UserID,SleepingTime,WakingTime,LongSleepNum,ShallowSleepNum,WakeUpLong,WakingNum)");
            strSql.Append(" values (");
            strSql.Append("@UserID,@SleepingTime,@WakingTime,@LongSleepNum,@ShallowSleepNum,@WakeUpLong,@WakingNum)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserID",          SqlDbType.NVarChar,  100),
                new SqlParameter("@SleepingTime",    SqlDbType.DateTime),
                new SqlParameter("@WakingTime",      SqlDbType.DateTime),
                new SqlParameter("@LongSleepNum",    SqlDbType.Decimal,     9),
                new SqlParameter("@ShallowSleepNum", SqlDbType.Decimal,     9),
                new SqlParameter("@WakeUpLong",      SqlDbType.Decimal,     9),
                new SqlParameter("@WakingNum",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.UserID;
            parameters[1].Value = model.SleepingTime;
            parameters[2].Value = model.WakingTime;
            parameters[3].Value = model.LongSleepNum;
            parameters[4].Value = model.ShallowSleepNum;
            parameters[5].Value = model.WakeUpLong;
            parameters[6].Value = model.WakingNum;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public lifesense.Model.t_sleepinfo GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,UserID,SleepingTime,WakingTime,LongSleepNum,ShallowSleepNum,WakeUpLong,WakingNum from t_sleepinfo ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            lifesense.Model.t_sleepinfo model = new lifesense.Model.t_sleepinfo();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }