public Boolean updateSupply(Supply supply, List <SupplyImg> list) { supply.ModifyTime = DateTime.Now; if (list.Count != 0) { //删除原有的图片 SupplyImg supplyImg = supplyImgDao.querySupplyFirstImgBySupplyId(supply.Id); List <SupplyImg> listExsit = supplyImgDao.querySupplyDescImgBySupplyId(supply.Id); listExsit.Add(supplyImg); foreach (SupplyImg s in listExsit) { if (s.ImgPath != null) { File.Delete(s.ImgPath); } } supplyImgDao.deleteSupplyImgBySupplyId(supply.Id); //插入新图片 foreach (SupplyImg s in list) { supplyImgDao.insertSupplyImg(s); } } return(supplyDao.updateSupplyById(supply)); }
public void addSupplyImg(HttpContext context) { SupplyImg supplyImg = new SupplyImg(); supplyImg.Supply.Id = Convert.ToInt32(context.Request["Id"]); Dictionary <String, Object> dictionary = new Dictionary <string, object>(); string savepath = ""; if (context.Request.Files.Count > 0) { HttpPostedFile file1 = context.Request.Files["smallImg"]; savepath = FileUtil.uploadImg(file1, "../images/"); } supplyImg.ImgPath = savepath; supplyImg.ImgStatus = 0; Boolean flag = supplyService.addSupplyImg(supplyImg); if (flag) { dictionary.Add("success", "true"); } else { dictionary.Add("success", "false"); } context.Response.Write(JsonUtil.toJson(dictionary).ToString()); }
public List <SupplyImg> querySupplyImgBySupplyId(int supplyId) { String sql = "SELECT * FROM tb_supply_img WHERE supply_id = @supplyId"; SqlCommand cmd = DbUtil.getCommand(sql); cmd.Parameters.Add(new SqlParameter("@supplyId", supplyId)); List <SupplyImg> list = new List <SupplyImg>(); SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.HasRows) { while (sdr.Read()) { SupplyImg supplyImg = new SupplyImg(); supplyImg.Id = sdr.GetInt32(0); supplyImg.ImgPath = sdr.GetString(1); supplyImg.ImgStatus = sdr.GetInt32(2); supplyImg.Supply.Id = sdr.GetInt32(3); list.Add(supplyImg); } } sdr.Close(); DbUtil.close(cmd); return(list); }
public void listByName(HttpContext context) { context.Response.ContentType = "text/plain"; context.Request.ContentEncoding = Encoding.UTF8; context.Response.ContentEncoding = Encoding.UTF8; List <Supply> list = supplyService.getSupplyListByName(context.Request["searchname"].ToString()); StringBuilder jsonString = new StringBuilder(); Dictionary <String, Object> dictionary = new Dictionary <string, object>(); //jsonString.Append("\"supply\":"); string imgPath = "defaultImg.jpg"; if (list.Count == 0) { context.Response.Write("{\"success\":\"false\"}"); return; } jsonString.Append("["); int i = 1; foreach (Supply supply in list) { SupplyImg supplyImg = supplyService.getSupplyFirstImg(supply.Id); if (supplyImg.ImgPath != null) { imgPath = System.IO.Path.GetFileName(supplyImg.ImgPath); } dictionary.Add("Id", supply.Id); dictionary.Add("Name", supply.SupplyName); dictionary.Add("Desc", supply.SupplyDesc); dictionary.Add("categoryId", supply.SupplyCategory.Id); dictionary.Add("priority", supply.Priority); dictionary.Add("userId", supply.User.Id); dictionary.Add("nickName", supply.User.NickName); dictionary.Add("teleNumber", supply.User.TeleNumber); dictionary.Add("createTime", supply.CreateTime); dictionary.Add("modifyTime", supply.ModifyTime); dictionary.Add("Status", supply.SupplyStatus); dictionary.Add("FirstImgPath", imgPath); dictionary.Add("success", "true"); jsonString.Append(JsonUtil.toJson(dictionary)); if (i < list.Count) { jsonString.Append(","); } i++; dictionary.Clear(); } jsonString.Append("]"); context.Response.Write(jsonString.ToString()); }
public Boolean removeSupplyById(int supplyId) { SupplyImg supplyImg = supplyImgDao.querySupplyFirstImgBySupplyId(supplyId); List <SupplyImg> list = supplyImgDao.querySupplyDescImgBySupplyId(supplyId); list.Add(supplyImg); foreach (SupplyImg s in list) { if (s.ImgPath != null && s.ImgPath != "") { File.Delete(s.ImgPath); } } Boolean flagSupplyImg = supplyImgDao.deleteSupplyImgBySupplyId(supplyId); Boolean flagSupply = supplyDao.deleteSupplyById(supplyId); return(flagSupply); }
public void allSupplyList(HttpContext context) { context.Response.ContentType = "text/plain"; List <Supply> list = supplyService.getAllSupplyListWithoutBanned(); StringBuilder jsonString = new StringBuilder(); Dictionary <String, Object> dictionary = new Dictionary <string, object>(); string imgPath = "defaultImg.jpg"; jsonString.Append("["); int i = 1; foreach (Supply supply in list) { SupplyImg supplyImg = supplyService.getSupplyFirstImg(supply.Id); if (supplyImg.ImgPath != null && supplyImg.ImgPath != "") { imgPath = System.IO.Path.GetFileName(supplyImg.ImgPath); } dictionary.Add("Id", supply.Id); dictionary.Add("Name", supply.SupplyName); dictionary.Add("Desc", supply.SupplyDesc); dictionary.Add("categoryId", supply.SupplyCategory.Id); dictionary.Add("priority", supply.Priority); dictionary.Add("userId", supply.User.Id); dictionary.Add("nickName", supply.User.NickName); dictionary.Add("teleNumber", supply.User.TeleNumber); dictionary.Add("createTime", supply.CreateTime); dictionary.Add("modifyTime", supply.ModifyTime); dictionary.Add("Status", supply.SupplyStatus); dictionary.Add("FirstImgPath", imgPath); dictionary.Add("success", "true"); jsonString.Append(JsonUtil.toJson(dictionary)); if (i < list.Count) { jsonString.Append(","); } i++; dictionary.Clear(); } jsonString.Append("]"); context.Response.Write(jsonString.ToString()); }
public Boolean insertSupplyImg(SupplyImg supplyImg) { String sql = "INSERT INTO tb_supply_img(img_path,img_status,supply_id) VALUES(@img_path,@img_status,@supply_id)"; SqlCommand cmd = DbUtil.getCommand(sql); cmd.Parameters.Add(new SqlParameter("@img_path", supplyImg.ImgPath)); cmd.Parameters.Add(new SqlParameter("@img_status", supplyImg.ImgStatus));//0缩略图,1详情图 cmd.Parameters.Add(new SqlParameter("@supply_id", supplyImg.Supply.Id)); int i = cmd.ExecuteNonQuery(); DbUtil.close(cmd); if (i > 0) { return(true); } else { return(false); } }
public SupplyImg querySupplyFirstImgBySupplyId(int supplyId) { String sql = "SELECT * FROM tb_supply_img WHERE supply_id = @supplyId AND img_status = 0"; SqlCommand cmd = DbUtil.getCommand(sql); cmd.Parameters.Add(new SqlParameter("@supplyId", supplyId)); SqlDataReader sdr = cmd.ExecuteReader(); SupplyImg supplyImg = new SupplyImg(); if (sdr.HasRows) { sdr.Read(); supplyImg.Id = sdr.GetInt32(0); supplyImg.ImgPath = sdr.GetString(1); supplyImg.ImgStatus = sdr.GetInt32(2); supplyImg.Supply.Id = sdr.GetInt32(3); } sdr.Close(); DbUtil.close(cmd); return(supplyImg); }
public void updateMySupply(HttpContext context) { context.Response.ContentType = "text/plain"; Supply supply = new Supply(); supply.Id = Convert.ToInt32(context.Request["Id"]); supply.SupplyName = context.Request["Name"]; supply.SupplyDesc = context.Request["Desc"]; supply.SupplyCategory.Id = Convert.ToInt32(context.Request["CategoryId"]); Dictionary <String, Object> dictionary = new Dictionary <string, object>(); string savepath = ""; List <SupplyImg> list = new List <SupplyImg>(); if (context.Request.Files.Count > 0) { for (int i = 0; i < context.Request.Files.Count; i++) { SupplyImg supplyImg = new SupplyImg(); supplyImg.Supply.Id = Convert.ToInt32(context.Request["Id"]); HttpPostedFile file1 = context.Request.Files["descImg" + i]; supplyImg.ImgStatus = Convert.ToInt32(context.Request["status" + i]); savepath = FileUtil.uploadImg(file1, "../images/"); supplyImg.ImgPath = savepath; list.Add(supplyImg); } } Boolean flag = supplyService.updateSupply(supply, list); if (flag) { dictionary.Add("success", "true"); } else { dictionary.Add("success", "false"); } context.Response.Write(JsonUtil.toJson(dictionary).ToString()); }
public Boolean addSupplyImg(SupplyImg supplyImg) { return(supplyImgDao.insertSupplyImg(supplyImg)); }