/// <summary> /// 得到一个对象实体 /// </summary> public Blogs.Model.BlogCommentPhoto DataRowToModel(DataRow row) { Blogs.Model.BlogCommentPhoto model = new Blogs.Model.BlogCommentPhoto(); if (row != null) { if (row["cmpid"] != null && row["cmpid"].ToString() != "") { model.cmpid = int.Parse(row["cmpid"].ToString()); } if (row["cmpauthor"] != null && row["cmpauthor"].ToString() != "") { model.cmpauthor = int.Parse(row["cmpauthor"].ToString()); } if (row["cmpphoto"] != null && row["cmpphoto"].ToString() != "") { model.cmpphoto = int.Parse(row["cmpphoto"].ToString()); } if (row["cmptitle"] != null) { model.cmptitle = row["cmptitle"].ToString(); } if (row["cmpcontent"] != null) { model.cmpcontent = row["cmpcontent"].ToString(); } if (row["cmpaddtime"] != null && row["cmpaddtime"].ToString() != "") { model.cmpaddtime = DateTime.Parse(row["cmpaddtime"].ToString()); } if (row["cmpisdel"] != null && row["cmpisdel"].ToString() != "") { if ((row["cmpisdel"].ToString() == "1") || (row["cmpisdel"].ToString().ToLower() == "true")) { model.cmpisdel = true; } else { model.cmpisdel = false; } } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Blogs.Model.BlogCommentPhoto model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update BlogCommentPhoto set "); strSql.Append("cmpauthor=@cmpauthor,"); strSql.Append("cmpphoto=@cmpphoto,"); strSql.Append("cmptitle=@cmptitle,"); strSql.Append("cmpcontent=@cmpcontent,"); strSql.Append("cmpaddtime=@cmpaddtime,"); strSql.Append("cmpisdel=@cmpisdel"); strSql.Append(" where cmpid=@cmpid "); SQLiteParameter[] parameters = { new SQLiteParameter("@cmpauthor", DbType.Int32, 8), new SQLiteParameter("@cmpphoto", DbType.Int32, 8), new SQLiteParameter("@cmptitle", DbType.String), new SQLiteParameter("@cmpcontent", DbType.String), new SQLiteParameter("@cmpaddtime", DbType.DateTime), new SQLiteParameter("@cmpisdel", DbType.bit, 1), new SQLiteParameter("@cmpid", DbType.Int32, 8) }; parameters[0].Value = model.cmpauthor; parameters[1].Value = model.cmpphoto; parameters[2].Value = model.cmptitle; parameters[3].Value = model.cmpcontent; parameters[4].Value = model.cmpaddtime; parameters[5].Value = model.cmpisdel; parameters[6].Value = model.cmpid; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Blogs.Model.BlogCommentPhoto model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into BlogCommentPhoto("); strSql.Append("cmpid,cmpauthor,cmpphoto,cmptitle,cmpcontent,cmpaddtime,cmpisdel)"); strSql.Append(" values ("); strSql.Append("@cmpid,@cmpauthor,@cmpphoto,@cmptitle,@cmpcontent,@cmpaddtime,@cmpisdel)"); SQLiteParameter[] parameters = { new SQLiteParameter("@cmpid", DbType.Int32, 8), new SQLiteParameter("@cmpauthor", DbType.Int32, 8), new SQLiteParameter("@cmpphoto", DbType.Int32, 8), new SQLiteParameter("@cmptitle", DbType.String), new SQLiteParameter("@cmpcontent", DbType.String), new SQLiteParameter("@cmpaddtime", DbType.DateTime), new SQLiteParameter("@cmpisdel", DbType.bit, 1) }; parameters[0].Value = model.cmpid; parameters[1].Value = model.cmpauthor; parameters[2].Value = model.cmpphoto; parameters[3].Value = model.cmptitle; parameters[4].Value = model.cmpcontent; parameters[5].Value = model.cmpaddtime; parameters[6].Value = model.cmpisdel; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Blogs.Model.BlogCommentPhoto GetModel(int cmpid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select cmpid,cmpauthor,cmpphoto,cmptitle,cmpcontent,cmpaddtime,cmpisdel from BlogCommentPhoto "); strSql.Append(" where cmpid=@cmpid "); SQLiteParameter[] parameters = { new SQLiteParameter("@cmpid", DbType.Int32, 8) }; parameters[0].Value = cmpid; Blogs.Model.BlogCommentPhoto model = new Blogs.Model.BlogCommentPhoto(); DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Blogs.Model.BlogCommentPhoto model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into BlogCommentPhoto("); strSql.Append("cmpauthor,cmpphoto,cmptitle,cmpcontent,cmpaddtime,cmpisdel)"); strSql.Append(" values ("); strSql.Append("@cmpauthor,@cmpphoto,@cmptitle,@cmpcontent,@cmpaddtime,@cmpisdel)"); strSql.Append(";select LAST_INSERT_ROWID()"); SQLiteParameter[] parameters = { new SQLiteParameter("@cmpauthor", DbType.Int32, 8), new SQLiteParameter("@cmpphoto", DbType.Int32, 8), new SQLiteParameter("@cmptitle", DbType.String), new SQLiteParameter("@cmpcontent", DbType.String), new SQLiteParameter("@cmpaddtime", DbType.DateTime), new SQLiteParameter("@cmpisdel", DbType.Boolean) }; parameters[0].Value = model.cmpauthor; parameters[1].Value = model.cmpphoto; parameters[2].Value = model.cmptitle; parameters[3].Value = model.cmpcontent; parameters[4].Value = model.cmpaddtime; parameters[5].Value = model.cmpisdel; object obj = DbHelperSQLite.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }