/// <summary>
 /// 获得数据列表
 /// </summary>
 public List<DiaryEntity> DataTableToList(DataTable dt)
 {
     List<DiaryEntity> modelList = new List<DiaryEntity>();
     int rowsCount = dt.Rows.Count;
     if (rowsCount > 0)
     {
         DiaryEntity model;
         for (int n = 0; n < rowsCount; n++)
         {
             model = new DiaryEntity();
             //model.ID=dt.Rows[n]["ID"].ToString();
             model.Title = dt.Rows[n]["Title"].ToString();
             if (dt.Rows[n]["WorkDate"].ToString() != "")
             {
                 model.WorkDate = DateTime.Parse(dt.Rows[n]["WorkDate"].ToString());
             }
             if (dt.Rows[n]["WorkDuration"].ToString() != "")
             {
                 model.WorkDuration = decimal.Parse(dt.Rows[n]["WorkDuration"].ToString());
             }
             model.Note = dt.Rows[n]["Note"].ToString();
             if (dt.Rows[n]["OwnerID"].ToString() != "")
             {
                 model.OwnerID = int.Parse(dt.Rows[n]["OwnerID"].ToString());
             }
             modelList.Add(model);
         }
     }
     return modelList;
 }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(DiaryEntity model)
 {
     StringBuilder strSql = new StringBuilder();
     strSql.Append("insert into [OA_Diary](");
     strSql.Append("Title,WorkDate,WorkDuration,Note,OwnerID,Comment,CreateTime)");
     strSql.Append(" values (");
     strSql.Append("@Title,@WorkDate,@WorkDuration,@Note,@OwnerID,@Comment,@CreateTime)");
     strSql.Append(";select @@IDENTITY");
     SqlParameter[] parameters = {
             new SqlParameter("@Title", SqlDbType.NVarChar,100),
             new SqlParameter("@WorkDate", SqlDbType.DateTime),
             new SqlParameter("@WorkDuration", SqlDbType.Float,8),
             new SqlParameter("@Note", SqlDbType.NVarChar,1000),
             new SqlParameter("@OwnerID", SqlDbType.Int,4),
             new SqlParameter("@Comment", SqlDbType.NVarChar,500),
             new SqlParameter("@CreateTime", SqlDbType.DateTime)};
     parameters[0].Value = model.Title;
     parameters[1].Value = model.WorkDate;
     parameters[2].Value = model.WorkDuration;
     parameters[3].Value = model.Note;
     parameters[4].Value = model.OwnerID;
     parameters[5].Value = model.Comment;
     parameters[6].Value = DateTime.Now;
     object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
     if (obj == null)
     {
         return 1;
     }
     else
     {
         return Convert.ToInt32(obj);
     }
 }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(DiaryEntity model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update [OA_Diary] set ");
            strSql.Append("Title=@Title,");
            strSql.Append("WorkDate=@WorkDate,");
            strSql.Append("WorkDuration=@WorkDuration,");
            strSql.Append("Note=@Note ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
                    new SqlParameter("@Title", SqlDbType.NVarChar,100),
                    new SqlParameter("@WorkDate", SqlDbType.DateTime),
                    new SqlParameter("@WorkDuration", SqlDbType.Float,8),
                    new SqlParameter("@Note", SqlDbType.NVarChar,1000),
                    new SqlParameter("@ID", SqlDbType.BigInt)};
            parameters[0].Value = model.Title;
            parameters[1].Value = model.WorkDate;
            parameters[2].Value = model.WorkDuration;
            parameters[3].Value = model.Note;
            parameters[4].Value = model.ID;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
 /// <summary>
 /// 是否存在该记录
 /// </summary>
 public DiaryEntity GetModelByDate(int AccountID, DateTime dateTime)
 {
     StringBuilder strSql = new StringBuilder();
     strSql.Append("select ID,Title,WorkDate,WorkDuration,Note,OwnerID,Comment,CreateTime from [OA_Diary]");
     strSql.Append(" where WorkDate=convert(dateTime,'" + dateTime.ToString("yyyy-MM-dd") + "',21) ");
     strSql.Append(" and  OwnerID=@OwnerID");
     SqlParameter[] parameters = {
             new SqlParameter("@WorkDate", SqlDbType.DateTime),
             new SqlParameter("@OwnerID", SqlDbType.Int,4)};
     parameters[0].Value = Convert.ToDateTime(dateTime);
     parameters[1].Value = AccountID;
     DiaryEntity model = new DiaryEntity();
     DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
     if (ds.Tables[0].Rows.Count > 0)
     {
         if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
         {
             model.ID = long.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
         }
         model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
         if (ds.Tables[0].Rows[0]["WorkDate"].ToString() != "")
         {
             model.WorkDate = DateTime.Parse(ds.Tables[0].Rows[0]["WorkDate"].ToString());
         }
         if (ds.Tables[0].Rows[0]["WorkDuration"].ToString() != "")
         {
             model.WorkDuration = decimal.Parse(ds.Tables[0].Rows[0]["WorkDuration"].ToString());
         }
         model.Note = ds.Tables[0].Rows[0]["Note"].ToString();
         if (ds.Tables[0].Rows[0]["OwnerID"].ToString() != "")
         {
             model.OwnerID = int.Parse(ds.Tables[0].Rows[0]["OwnerID"].ToString());
         }
         model.Note = ds.Tables[0].Rows[0]["Note"].ToString();
         model.Comment = ds.Tables[0].Rows[0]["Comment"].ToString();
         if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
         {
             model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
         }
         return model;
     }
     else
     {
         return null;
     }
 }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DiaryEntity GetEntity(long ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,Title,WorkDate,WorkDuration,Note,OwnerID,Comment,CreateTime from [OA_Diary] ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.BigInt)};
            parameters[0].Value = ID;

            DiaryEntity model = new DiaryEntity();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = long.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                if (ds.Tables[0].Rows[0]["WorkDate"].ToString() != "")
                {
                    model.WorkDate = DateTime.Parse(ds.Tables[0].Rows[0]["WorkDate"].ToString());
                }
                if (ds.Tables[0].Rows[0]["WorkDuration"].ToString() != "")
                {
                    model.WorkDuration = decimal.Parse(ds.Tables[0].Rows[0]["WorkDuration"].ToString());
                }
                model.Note = ds.Tables[0].Rows[0]["Note"].ToString();
                if (ds.Tables[0].Rows[0]["OwnerID"].ToString() != "")
                {
                    model.OwnerID = int.Parse(ds.Tables[0].Rows[0]["OwnerID"].ToString());
                }
                model.Note = ds.Tables[0].Rows[0]["Note"].ToString();
                model.Comment = ds.Tables[0].Rows[0]["Comment"].ToString();
                if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(DiaryEntity model)
 {
     return dal.Add(model);
 }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public void Update(DiaryEntity model)
 {
     dal.Update(model);
 }