/// <summary> /// 增加一条数据 /// </summary> public int Add(SmallImgEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into sns_smallImg("); strSql.Append("ImgUrl,addtime,Status)"); strSql.Append(" values ("); strSql.Append("@ImgUrl,@addtime,@Status)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ImgUrl", SqlDbType.VarChar, 50), new SqlParameter("@addtime", SqlDbType.DateTime), new SqlParameter("@Status", SqlDbType.Int, 4) }; parameters[0].Value = model.ImgUrl; parameters[1].Value = model.addtime; parameters[2].Value = model.Status; object obj = SqlHelper.Instance.ExecSqlScalar(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> private SmallImgEntity DataRowToModel(DataRow row) { SmallImgEntity model = new SmallImgEntity(); if (row != null) { if (row["ImgId"] != null && row["ImgId"].ToString() != "") { model.ImgId = int.Parse(row["ImgId"].ToString()); } if (row["ImgUrl"] != null) { model.ImgUrl = row["ImgUrl"].ToString(); } if (row["addtime"] != null && row["addtime"].ToString() != "") { model.addtime = DateTime.Parse(row["addtime"].ToString()); } if (row["Status"] != null && row["Status"].ToString() != "") { model.Status = int.Parse(row["Status"].ToString()); } } return(model); }
/// <summary> /// 获取封面地址 /// </summary> /// <param name="cover">封面id</param> /// <returns></returns> protected string GetCover(string cover) { if (!string.IsNullOrEmpty(cover)) { SmallImgEntity smallImgEntity = SmallImgBll.Instance.GetModel(Convert.ToInt32(cover)); return(smallImgEntity.ImgUrl); } return(""); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(SmallImgEntity model) { try { return(SmallImgDb.Instance.Add(model)); } catch (Exception ex) { WriteLog.WriteError(ex); throw ex; } }
public void ProcessRequest(HttpContext context) { string img = context.Request.Form["b"]; //原图base64 string img2 = context.Request.Form["b2"]; //缩略图base64 string s = "{\"status\":\"error\"}"; //获取时间戳 TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); Random ro = new Random(); string tt = Convert.ToInt64(ts.TotalSeconds).ToString() + ro.Next(); ImgEntity imgEntity = new ImgEntity(); imgEntity.ImgUrl = UploadFile.UploadImg(img, "Upload\\COS\\", tt); imgEntity.addtime = DateTime.Now; imgEntity.Status = 1; if ((imgEntity.ImgId = ImgBll.Instance.Add(imgEntity)) > 0) { SmallImgEntity smallImgEntity = new SmallImgEntity(); smallImgEntity.ImgUrl = UploadFile.UploadImg(img2, "Upload\\COS\\", tt + "320x180"); smallImgEntity.addtime = DateTime.Now; smallImgEntity.Status = 1; if ((smallImgEntity.ImgId = SmallImgBll.Instance.Add(smallImgEntity)) > 0) { s = "{\"status\":\"success\",\"imgid\":\"" + imgEntity.ImgId + "\",\"img2id\":\"" + smallImgEntity.ImgId + "\",\"img\":\"" + imgEntity.ImgUrl.Replace("\\", "\\\\") + "\",\"img2\":\"" + smallImgEntity.ImgUrl.Replace("\\", "\\\\") + "\"}"; } else { s = "{\"status\":\"error\"}"; } } else { s = "{\"status\":\"error\"}"; } context.Response.ContentType = "text/plain"; context.Response.Write(s); }
/// <summary> /// 得到一个对象实体 /// </summary> public SmallImgEntity GetModel(int imgId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ImgId,ImgUrl,addtime,Status from sns_smallImg "); strSql.Append(" where ImgId=@ImgId"); SqlParameter[] parameters = { new SqlParameter("@ImgId", SqlDbType.Int, 4) }; parameters[0].Value = imgId; SmallImgEntity model = new SmallImgEntity(); DataSet ds = SqlHelper.Instance.ExecSqlDataSet(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }