예제 #1
0
        /// <summary>
        /// 插入一条记录
        /// </summary>
        /// <param name="model">Diaries类的对象</param>
        /// <returns>插入是否成功</returns>
        public int Insert(DiaryModel model)
        {
            SQLiteParameter[] parameters ={
                                              new SQLiteParameter("@PubTime")
                                              , new SQLiteParameter("@Title")
                                              , new SQLiteParameter("@Contents")
                                          };
            parameters[0].Value = model.PubTime;
            parameters[1].Value = model.Title;
            parameters[2].Value = model.Contents;

            object count = SQLiteHelper.ExecuteScalar(@"INSERT INTO Diaries(PubTime, Title, Contents) VALUES(@PubTime, @Title, @Contents)", parameters);
            if (count != null)
            {
                return Convert.ToInt32(count);
            }
            return -1;
        }
예제 #2
0
        internal bool Save(FlowDocument fd, string diaryTime)
        {
            bool isok = false;

            DateTime datetime = Convert.ToDateTime(diaryTime);
            TextRange textRange = new TextRange(fd.ContentStart, fd.ContentEnd);
            DiaryModel diaOld = getTodayDiary(datetime);
            DiaryDAL diaryDal = new DiaryDAL();
            TreeBLL treeBll = new TreeBLL();

            //如果内容清空表示删除日记
            if (textRange.Text.Length <= 0)
            {
                if (diaOld != null)
                {
                    diaryDal.DeleteById(diaOld.ID);
                    treeBll.Delete(diaOld.ID);
                }
                return true;
            }

            //保存日记内容
            DiaryModel diaNew = new DiaryModel();
            string contents = XamlHelper.ToXaml(fd);
            int pubTime = TimesTampHelper.ConvertDateTimeInt(datetime);
            string title = datetime.ToString("yyyy-MM-dd") + " " + datetime.DayOfWeek;

            diaNew.Title = title;
            diaNew.PubTime = pubTime;
            diaNew.Contents = contents;

            //查找是否有当天内容
            if (diaOld != null)
            {
                diaNew.ID = diaOld.ID;
                diaNew.PubTime = diaOld.PubTime;
                return diaryDal.Update(diaNew);
            }

            int lastID = diaryDal.Insert(diaNew);
            isok = treeBll.Save(lastID, datetime);
            return isok;
        }
예제 #3
0
 public DiaryModel ToModel(DataRow row)
 {
     DiaryModel model = new DiaryModel();
     model.ID = Convert.ToInt32(row["ID"]);
     model.PubTime = Convert.ToInt32(row["PubTime"]);
     model.Title = Convert.ToString(row["Title"]);
     model.Contents = Convert.ToString(row["Contents"]);
     return model;
 }
예제 #4
0
        /// <summary>
        /// 更新一条记录
        /// </summary>
        /// <param name="model">T_GuideTypes类的对象</param>
        /// <returns>更新是否成功</returns>
        public bool Update(DiaryModel model)
        {
            SQLiteParameter[] parameters ={
                                              new SQLiteParameter("@ID")
                                              , new SQLiteParameter("@PubTime")
                                              , new SQLiteParameter("@Title")
                                              , new SQLiteParameter("@Contents")
                                          };
            parameters[0].Value = model.ID;
            parameters[1].Value = model.PubTime;
            parameters[2].Value = model.Title;
            parameters[3].Value = model.Contents;

            int count = SQLiteHelper.ExecuteNonQuery("UPDATE Diaries SET PubTime=@PubTime, Title=@Title, Contents=@Contents WHERE ID=@ID", parameters);
            return count > 0;
        }