public int insert(Picture po) { StringBuilder sql = new StringBuilder(); sql.Append("insert into Picture values(newid(), "); sql.Append(String.Format("{0},", DbAccess.parse(po.picName))); sql.Append(String.Format("{0},", DbAccess.parse(po.picPath))); sql.Append(String.Format("{0},", DbAccess.parse(po.picExtension))); sql.Append(String.Format("{0},", DbAccess.parse(po.picDescrip))); sql.Append(String.Format("{0},", DbAccess.parse(po.picTableName))); sql.Append(String.Format("{0},", DbAccess.parse(po.picTableId))); sql.Append("getdate(), getdate())"); return DbAccess.executeUpdate(sql.ToString()); }
public int delete(Picture po) { string sql = "delete from Picture where "; if (!String.IsNullOrEmpty(po.picTableName) && ! String.IsNullOrEmpty(po.picTableId)) { sql += String.Format(" pic_table_name='{0}'", po.picTableName); sql += String.Format(" and pic_table_id='{0}'", po.picTableId); } else { sql += String.Format(" pic_id='{0}'", po.picId); } return DbAccess.executeUpdate(sql); }
public DataSet select(Picture po) { StringBuilder sql = new StringBuilder(); sql.Append("select * from Picture where 1=1"); if (!String.IsNullOrEmpty(po.picName)) { sql.Append(String.Format(" and pic_name={0}", DbAccess.parse(po.picName))); } if (!String.IsNullOrEmpty(po.picPath)) { sql.Append(String.Format(" and pic_path={0}", DbAccess.parse(po.picPath))); } if (!String.IsNullOrEmpty(po.picExtension)) { sql.Append(String.Format(" and pic_extension={0}", DbAccess.parse(po.picExtension))); } if (!String.IsNullOrEmpty(po.picDescrip)) { sql.Append(String.Format(" and pic_descrip={0}", DbAccess.parse(po.picDescrip))); } if (!String.IsNullOrEmpty(po.picTableName)) { sql.Append(String.Format(" and pic_table_name={0}", DbAccess.parse(po.picTableName))); } if (!String.IsNullOrEmpty(po.picTableId)) { sql.Append(String.Format(" and pic_table_id={0}", DbAccess.parse(po.picTableId))); } if (!String.IsNullOrEmpty(po.picId)) { sql.Append(String.Format(" and pic_id='{0}'", po.picId)); } sql.Append(" order by pic_update_time"); return DbAccess.executeQuery(sql.ToString()); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); string method = context.Request.Params["method"]; if ("list".Equals(method)) { string ajax = context.Request.Params["ajax"]; BrandProjectDAO dao = new BrandProjectDAO(); BrandProject bp = new BrandProject(); bp.bpType = context.Request.Params["bpType"]; DataSet ds = dao.select(bp); string result = ""; if (String.IsNullOrEmpty(ajax)) { result = "_list = " + JsonCommon.ds2json(ds); } else { result = JsonCommon.ds2json(ds); } context.Response.Write(result); } else if ("detail".Equals(method)) { BrandProjectDAO dao = new BrandProjectDAO(); BrandProject bp = new BrandProject(); bp.bpId = context.Request.Params["bpId"]; DataSet ds = dao.select(bp); string json = JsonCommon.ds2json(ds); PictureDAO picDao = new PictureDAO(); Picture pic = new Picture(); pic.picTableName = "BrandProject"; pic.picTableId = bp.bpId; DataSet picDs = picDao.select(pic); string picJson = JsonCommon.ds2json(picDs); json = String.Format("[{0},{1}]", json, picJson); context.Response.Write(json); } else if ("save".Equals(method)) { string bpContent = HttpUtility.UrlDecode((context.Request.Params["bpContent"]).Replace("@", "%")); string bpType = context.Request.Params["bpType"]; string bpId = context.Request.Params["bpId"]; BrandProjectDAO dao = new BrandProjectDAO(); BrandProject bp = new BrandProject(); bp.bpContent = bpContent; bp.bpType = bpType; if (!String.IsNullOrEmpty(bpId)) { bp.bpId = bpId; dao.update(bp); } else { bp.bpId = Guid.NewGuid().ToString(); bpId = bp.bpId; dao.insert(bp); } string pics = context.Request.Params["pics"]; string disc = context.Request.Params["disc"]; PictureDAO picDao = new PictureDAO(); //删除要删除的图片 string delPics = context.Request.Params["delPic"]; if (!String.IsNullOrEmpty(delPics)) { string[] arrDelPics = delPics.Split(','); for (int i = 0; i < arrDelPics.Length; i++) { Picture p = new Picture(); p.picId = arrDelPics[i]; picDao.delete(p); } } if (!String.IsNullOrEmpty(pics)) { string[] arrPics = pics.Split(','); string[] arrDisc = disc.Split(','); for (int i = 0; i < arrPics.Length; i++) { string fileName = arrPics[i].Substring(arrPics[i].LastIndexOf("/") + 1); string fromPath = context.Server.MapPath(arrPics[i]); string toPath = context.Server.MapPath(FileHelper.Default_Pic_Forder + fileName); FileHelper.MoveTo(fromPath, toPath); Picture pic = new Picture(); pic.picTableId = bpId; pic.picTableName = "BrandProject"; pic.picDescrip = arrDisc[i]; pic.picExtension = fileName.Substring(fileName.LastIndexOf(".") + 1); pic.picName = fileName; pic.picPath = FileHelper.Default_Pic_Forder + fileName; picDao.insert(pic); } } } else if ("delete".Equals(method)) { string bpId = context.Request.Params["bpId"]; BrandProjectDAO dao = new BrandProjectDAO(); BrandProject bp = new BrandProject(); bp.bpId = bpId; dao.delete(bp); } }
public int update(Picture po) { StringBuilder sql = new StringBuilder(); sql.Append("update Picture set "); sql.Append(String.Format("pic_name={0},", DbAccess.parse(po.picName))); sql.Append(String.Format("pic_path={0},", DbAccess.parse(po.picPath))); sql.Append(String.Format("pic_extension={0},", DbAccess.parse(po.picExtension))); sql.Append(String.Format("pic_descrip={0},", DbAccess.parse(po.picDescrip))); sql.Append(String.Format("pic_table_name={0},", DbAccess.parse(po.picTableName))); sql.Append(String.Format("pic_table_id={0},", DbAccess.parse(po.picTableId))); sql.Append("pic_update_time=getdate()"); sql.Append(String.Format(" where pic_id='{0}'", po.picId)); return DbAccess.executeUpdate(sql.ToString()); }