Пример #1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Blogs.Model.BlogCommentArticle DataRowToModel(DataRow row)
 {
     Blogs.Model.BlogCommentArticle model = new Blogs.Model.BlogCommentArticle();
     if (row != null)
     {
         if (row["cmaid"] != null && row["cmaid"].ToString() != "")
         {
             model.cmaid = int.Parse(row["cmaid"].ToString());
         }
         if (row["cmaarticle"] != null && row["cmaarticle"].ToString() != "")
         {
             model.cmaarticle = int.Parse(row["cmaarticle"].ToString());
         }
         if (row["cmaauthor"] != null && row["cmaauthor"].ToString() != "")
         {
             model.cmaauthor = int.Parse(row["cmaauthor"].ToString());
         }
         if (row["cmatitle"] != null)
         {
             model.cmatitle = row["cmatitle"].ToString();
         }
         if (row["cmacontent"] != null)
         {
             model.cmacontent = row["cmacontent"].ToString();
         }
         if (row["cmaaddtime"] != null && row["cmaaddtime"].ToString() != "")
         {
             model.cmaaddtime = DateTime.Parse(row["cmaaddtime"].ToString());
         }
         if (row["cmaisdel"] != null && row["cmaisdel"].ToString() != "")
         {
             if ((row["cmaisdel"].ToString() == "1") || (row["cmaisdel"].ToString().ToLower() == "true"))
             {
                 model.cmaisdel = true;
             }
             else
             {
                 model.cmaisdel = false;
             }
         }
     }
     return(model);
 }
Пример #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Blogs.Model.BlogCommentArticle model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BlogCommentArticle set ");
            strSql.Append("cmaarticle=@cmaarticle,");
            strSql.Append("cmaauthor=@cmaauthor,");
            strSql.Append("cmatitle=@cmatitle,");
            strSql.Append("cmacontent=@cmacontent,");
            strSql.Append("cmaaddtime=@cmaaddtime,");
            strSql.Append("cmaisdel=@cmaisdel");
            strSql.Append(" where cmaid=@cmaid");
            SQLiteParameter[] parameters =
            {
                new SQLiteParameter("@cmaarticle", DbType.Int32,     4),
                new SQLiteParameter("@cmaauthor",  DbType.Int32,     4),
                new SQLiteParameter("@cmatitle",   DbType.String),
                new SQLiteParameter("@cmacontent", DbType.String),
                new SQLiteParameter("@cmaaddtime", DbType.DateTime),
                new SQLiteParameter("@cmaisdel",   DbType.Boolean),
                new SQLiteParameter("@cmaid",      DbType.Int32, 8)
            };
            parameters[0].Value = model.cmaarticle;
            parameters[1].Value = model.cmaauthor;
            parameters[2].Value = model.cmatitle;
            parameters[3].Value = model.cmacontent;
            parameters[4].Value = model.cmaaddtime;
            parameters[5].Value = model.cmaisdel;
            parameters[6].Value = model.cmaid;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Blogs.Model.BlogCommentArticle model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into BlogCommentArticle(");
            strSql.Append("cmaid,cmaarticle,cmaauthor,cmatitle,cmacontent,cmaaddtime,cmaisdel)");
            strSql.Append(" values (");
            strSql.Append("@cmaid,@cmaarticle,@cmaauthor,@cmatitle,@cmacontent,@cmaaddtime,@cmaisdel)");
            SQLiteParameter[] parameters =
            {
                new SQLiteParameter("@cmaid",      DbType.Int32,     8),
                new SQLiteParameter("@cmaarticle", DbType.Int32,     4),
                new SQLiteParameter("@cmaauthor",  DbType.Int32,     4),
                new SQLiteParameter("@cmatitle",   DbType.String),
                new SQLiteParameter("@cmacontent", DbType.String),
                new SQLiteParameter("@cmaaddtime", DbType.DateTime),
                new SQLiteParameter("@cmaisdel",   DbType.bit, 1)
            };
            parameters[0].Value = model.cmaid;
            parameters[1].Value = model.cmaarticle;
            parameters[2].Value = model.cmaauthor;
            parameters[3].Value = model.cmatitle;
            parameters[4].Value = model.cmacontent;
            parameters[5].Value = model.cmaaddtime;
            parameters[6].Value = model.cmaisdel;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Blogs.Model.BlogCommentArticle model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into BlogCommentArticle(");
            strSql.Append("cmaarticle,cmaauthor,cmatitle,cmacontent,cmaaddtime,cmaisdel)");
            strSql.Append(" values (");
            strSql.Append("@cmaarticle,@cmaauthor,@cmatitle,@cmacontent,@cmaaddtime,@cmaisdel)");
            strSql.Append(";select LAST_INSERT_ROWID()");
            SQLiteParameter[] parameters =
            {
                new SQLiteParameter("@cmaarticle", DbType.Int32,     4),
                new SQLiteParameter("@cmaauthor",  DbType.Int32,     4),
                new SQLiteParameter("@cmatitle",   DbType.String),
                new SQLiteParameter("@cmacontent", DbType.String),
                new SQLiteParameter("@cmaaddtime", DbType.DateTime),
                new SQLiteParameter("@cmaisdel",   DbType.Boolean)
            };
            parameters[0].Value = model.cmaarticle;
            parameters[1].Value = model.cmaauthor;
            parameters[2].Value = model.cmatitle;
            parameters[3].Value = model.cmacontent;
            parameters[4].Value = model.cmaaddtime;
            parameters[5].Value = model.cmaisdel;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Blogs.Model.BlogCommentArticle GetModel(int cmaid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select cmaid,cmaarticle,cmaauthor,cmatitle,cmacontent,cmaaddtime,cmaisdel from BlogCommentArticle ");
            strSql.Append(" where cmaid=@cmaid");
            SQLiteParameter[] parameters =
            {
                new SQLiteParameter("@cmaid", DbType.Int32, 4)
            };
            parameters[0].Value = cmaid;

            Blogs.Model.BlogCommentArticle model = new Blogs.Model.BlogCommentArticle();
            DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters);

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