protected void lnkSetDefault_Click(object sender, EventArgs e) { int imgid = CommonMethod.ConvertToInt(hidId.Value, 0); string filename = string.Empty; string physicalpath = string.Empty; string thumpath = string.Empty; if (imgid > 0) { XiHuan_GoodsImageEntity defaultimage = new XiHuan_GoodsImageEntity(); defaultimage.Id = imgid; defaultimage.Retrieve(); if (defaultimage.IsPersistent) { physicalpath = Server.MapPath(defaultimage.ImgSrc); filename = Path.GetFileNameWithoutExtension(physicalpath); thumpath = physicalpath.Replace(filename, filename + GlobalVar.DefaultPhotoSize); if (!File.Exists(physicalpath))//没有缩略图,需要生成缩略图 { PicHelper.MakeThumbnail(physicalpath, thumpath, 85, 85); thumpath = physicalpath.Replace(filename, filename + GlobalVar.BigPhotoSize); PicHelper.MakeThumbnail(physicalpath, thumpath, 200, 220); } Query.ProcessSqlNonQuery(@"update XiHuan_GoodsImage set IsDefaultPhoto=0 where IsDefaultPhoto=1 and GoodsId=" + Request["id"] + ";update XiHuan_UserGoods set DefaultPhoto='" + defaultimage.ImgSrc.Replace(filename, filename + GlobalVar.DefaultPhotoSize) + "' where Id=" + Request["id"], GlobalVar.DataBase_Name); defaultimage.IsDefaultPhoto = 1; defaultimage.Save(); CommonMethod.readAspxAndWriteHtmlSoruce("showdetail.aspx?id=" + defaultimage.GoodsId, CommonMethod.FinalString(Request["detailurl"])); Alert("恭喜:成功设置为默认图片!"); BindReceive(); } } }
protected void lnkDelMultiMessage_Click(object sender, EventArgs e) { string[] mid = hidId.Value.Trim().TrimEnd(',').Split(','); string physicalpath = string.Empty; string thumpath = string.Empty; string filename = string.Empty; if (mid.Length > 0) { for (int i = 0; i < mid.Length; i++) { int id = CommonMethod.ConvertToInt(mid[i], 0); if (id > 0) { XiHuan_GoodsImageEntity note = new XiHuan_GoodsImageEntity(); note.Id = id; note.Retrieve(); if (note.IsPersistent) { physicalpath = Server.MapPath(note.ImgSrc); filename = Path.GetFileNameWithoutExtension(physicalpath); if (File.Exists(physicalpath)) { File.Delete(physicalpath); } thumpath = physicalpath.Replace(filename, GlobalVar.DefaultPhotoSize); if (File.Exists(thumpath)) { File.Delete(thumpath); } thumpath = physicalpath.Replace(filename, GlobalVar.BigPhotoSize); if (File.Exists(thumpath)) { File.Delete(thumpath); } note.Delete(); } } } BindReceive(); if (rptGoodsList.Items.Count == 0) { Query.ProcessSqlNonQuery("update XiHuan_UserGoods set IsHavePhoto=0 ,DefaultPhoto='images/none.jpg' where Id=" + Request["id"], GlobalVar.DataBase_Name); } Alert("恭喜:选中的图片已成功删除!"); } }
protected void lnkCancleDefault_Click(object sender, EventArgs e) { int imgid = CommonMethod.ConvertToInt(hidId.Value, 0); if (imgid > 0) { XiHuan_GoodsImageEntity defaultimage = new XiHuan_GoodsImageEntity(); defaultimage.Id = imgid; defaultimage.Retrieve(); if (defaultimage.IsPersistent) { defaultimage.IsDefaultPhoto = 0; defaultimage.Save(); Alert("恭喜:已成功取消默认图片!"); BindReceive(); } } }
protected void lnkDelMessage_Click(object sender, EventArgs e) { int id = CommonMethod.ConvertToInt(hidId.Value, 0); if (id > 0) { XiHuan_GoodsImageEntity note = new XiHuan_GoodsImageEntity(); note.Id = id; note.Retrieve(); if (note.IsPersistent) { string phypath = Server.MapPath(note.ImgSrc); string filename = Path.GetFileNameWithoutExtension(phypath); string thumpath = phypath.Replace(filename, filename + GlobalVar.DefaultPhotoSize); if (File.Exists(phypath)) { File.Delete(phypath); } if (File.Exists(thumpath)) { File.Delete(thumpath); } thumpath = phypath.Replace(filename, filename + GlobalVar.BigPhotoSize); if (File.Exists(thumpath)) { File.Delete(thumpath); } note.Delete(); BindReceive(); if (rptGoodsList.Items.Count == 0) { Query.ProcessSqlNonQuery("update XiHuan_UserGoods set IsHavePhoto=0 ,DefaultPhoto='images/none.jpg' where Id=" + Request["id"], GlobalVar.DataBase_Name); } Alert("恭喜:图片已成功删除!"); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (!IsUserAlreadyLogin) { MemberCenterPageRedirect("", "goodsadd.aspx" + (IsEdit ? "?id=" + CommonMethod.FinalString(Request["id"]) : "")); } else { #region 务器端验证 以后完善 #endregion #region 保存换品信息 Transaction t = new Transaction(); XiHuan_UserGoodsEntity newgoods = null; if (IsEdit) { newgoods = XiHuan_UserGoodsEntityAction.RetrieveAXiHuan_UserGoodsEntity(CommonMethod.ConvertToInt(Request["id"], 0)); } else { newgoods = new XiHuan_UserGoodsEntity(); } newgoods.OwnerId = CurrentUserId; newgoods.OwnerName = CurrentUserName; newgoods.Name = txtGoodName.Text.Trim(); newgoods.IsTJ = chkTJ.Checked ? (byte)1 : (byte)0; newgoods.TypeId = CommonMethod.ConvertToInt(ddlGoodType.SelectedValue, 0); newgoods.ChildId = CommonMethod.ConvertToInt(ddlGoodChildType.SelectedValue, 0); newgoods.IsHavePhoto = rbtYes.Checked ? (byte)XiHuan_UserGoodsFacade.IsGoodHavePhoto. : (byte)XiHuan_UserGoodsFacade.IsGoodHavePhoto.无; newgoods.Description = txtGoodDesc.Value.Trim(); newgoods.NewDeep = byte.Parse(ddlNewOldDeep.SelectedValue.Trim()); newgoods.OnlyCityChange = chkValidCity.Checked ? (byte)1 : (byte)0; newgoods.OnlySchoolChange = chkValidSchool.Checked ? (byte)1 : (byte)0; newgoods.HopeToChangeTypeId = CommonMethod.ConvertToInt(ddlGoodType1.SelectedValue, 0); newgoods.HopeToChangeChildTypeId = CommonMethod.ConvertToInt(ddlGoodChildType1.SelectedValue, 0); newgoods.HopeToChangeDesc = txtHopeToChangeDesc.Text.Trim(); newgoods.ProvinceId = CurrentUser.ProvinceId; newgoods.ProvinceName = CurrentUser.ProvinceName; newgoods.CityId = CurrentUser.CityId; newgoods.CityName = CurrentUser.CityName; newgoods.AreaId = CurrentUser.AreaId; newgoods.AreaName = CurrentUser.AreaName; newgoods.SchoolId = CurrentUser.SchoolId; newgoods.SchoolName = CurrentUser.SchoolName; if (!IsEdit) { newgoods.CreateDate = DateTime.Now; newgoods.ViewCount = new Random().Next(10, 30); newgoods.GoodState = (byte)XiHuan_UserGoodsFacade.GoodsState.新登记; } newgoods.IsChecked = (byte)(SystemConfigFacade.Instance().IsGoodsAddNeedCheck ? 0 : 1); t.DoSaveObject(newgoods); if (!IsEdit) { #region 换品图片上传 string gooddefaultphoto = string.Empty; if (rbtYes.Checked) { string extention = string.Empty; int filesize = 0; string filepath = string.Empty; string savepath = string.Empty; string filename = string.Empty; HttpFileCollection goodimages = HttpContext.Current.Request.Files; for (int i = 0; i < goodimages.Count; i++) { HttpPostedFile currentfile = goodimages[i]; extention = Path.GetExtension(currentfile.FileName); filesize = currentfile.ContentLength; filepath = "images/userupload/goodsimage/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/"; //不符合条件的直接跳过,不进行保存 if (!(currentfile.FileName.Length > 0) || filesize == 0 || !CommonMethod.IsUploadImageValid("", extention) || filesize > 500 * 1024) { continue; } else { if (!Directory.Exists(Server.MapPath(filepath))) { Directory.CreateDirectory(Server.MapPath(filepath)); } filename = newgoods.Id.ToString() + "_" + DateTime.Now.ToString("yyyyMMddhhmmssfff"); currentfile.SaveAs(Server.MapPath(filepath + filename + extention)); XiHuan_GoodsImageEntity newgoodimage = new XiHuan_GoodsImageEntity(); newgoodimage.GoodsId = newgoods.Id; newgoodimage.GoodsName = newgoods.Name; newgoodimage.ImgSrc = filepath + filename + extention; newgoodimage.CreateDate = DateTime.Now; if (i == 0) { gooddefaultphoto = filepath + filename + GlobalVar.DefaultPhotoSize + extention; newgoodimage.IsDefaultPhoto = 1; //生成不同规格的图片 PicHelper.MakeThumbnail(Server.MapPath(filepath + filename + extention), Server.MapPath(filepath + filename + GlobalVar.DefaultPhotoSize + extention), 85, 85); PicHelper.MakeThumbnail(Server.MapPath(filepath + filename + extention), Server.MapPath(filepath + filename + GlobalVar.BigPhotoSize + extention), 200, 220); } t.DoSaveObject(newgoodimage); } } } #endregion #region 默认图片保存 string sql = string.Format("update XiHuan_UserGoods set DefaultPhoto='{0}' where Id={1} ", gooddefaultphoto.Length > 0 ? gooddefaultphoto : "images/none.jpg", newgoods.Id); t.DoSqlNonQueryString(sql, GlobalVar.DataBase_Name); #endregion #region 更新用户换品数量和积分,换币 string updategoodsnumber = string.Format(@"update XiHuan_UserInfo set GoodsNumber=GoodsNumber+1, Score=Score+{0},HuanBi=HuanBi+{1} where Id={2}" , SystemConfigFacade.Instance().AddScoreByAddGoods(), SystemConfigFacade.Instance().AddHBByAddGoods(), CurrentUser.ID); t.DoSqlNonQueryString(updategoodsnumber, GlobalVar.DataBase_Name); #endregion #region 浏览人 XiHuan_GoodsViewUserEntity view = new XiHuan_GoodsViewUserEntity(); view.GoodsId = newgoods.Id; view.Type = 0; view.VisitDate = DateTime.Now; view.VisitorName = "喜换网"; view.VisitorId = 1; view.VisitorHeadImage = "images/userupload/20092113032102_1.png"; t.DoSaveObject(view); #endregion } try { string detailurl = "goods/" + newgoods.CreateDate.Year + "/" + newgoods.CreateDate.Month + "/" + newgoods.CreateDate.Day + "/goods" + newgoods.Id + ".html"; t.DoSqlNonQueryString("update XiHuan_UserGoods set DetailUrl='" + detailurl + "' where Id=" + newgoods.Id, GlobalVar.DataBase_Name); t.Commit(); if (!SystemConfigFacade.Instance().IsGoodsAddNeedCheck) { DataTable dt = Query.ProcessSql("select Id,DetailUrl,GoodState from XiHuan_UserGoods with(nolock) where OwnerId= " + CurrentUserId + " and IsChecked=1 ", GlobalVar.DataBase_Name); foreach (DataRow dr in dt.Rows) { CommonMethod.readAspxAndWriteHtmlSoruce("showdetail.aspx?id=" + dr["Id"], dr["DetailUrl"].ToString()); } } if (IsEdit) { Alert("恭喜:换品信息保存成功" + (SystemConfigFacade.Instance().IsGoodsAddNeedCheck ? ",我们会尽快进行审核" : string.Empty) + "^_^!"); } else { Alert("恭喜:换品登记成功" + (SystemConfigFacade.Instance().IsGoodsAddNeedCheck ? ",我们会尽快进行审核" : string.Empty) + "^_^!"); SendMailFacade.sendEmail("[email protected],[email protected]", "有人在喜换网发换品了", "有人在喜换网发换品:" + txtGoodName.Text); } ExecScript("window.location='goodlist.aspx?s='+Math.random();"); } catch (Exception ex) { t.RollBack(); Alert("抱歉:换品保存出错," + ex.Message); return; } #endregion } }
protected void btnUpLoad_Click(object sender, EventArgs e) { string action = CommonMethod.FinalString(Request["action"]); if (action.Equals("addNewPic") && !flpImage.HasFile) { Alert("您没有选择要上传的图片!"); return; } else { XiHuan_GoodsImageEntity newgoodimage = null; if (action.Equals("addNewPic")) { newgoodimage = new XiHuan_GoodsImageEntity(); } if (action.Equals("ModifyPic")) //删除旧图片 { newgoodimage = XiHuan_GoodsImageEntityAction.RetrieveAXiHuan_GoodsImageEntity(CommonMethod.ConvertToInt(Request["id"], 0)); } newgoodimage.GoodsId = CommonMethod.ConvertToInt(Request["gid"], 0); newgoodimage.GoodsName = Microsoft.JScript.GlobalObject.unescape(CommonMethod.FinalString(Request["gname"])); newgoodimage.ImgDesc = txtImgDesc.Text.Trim(); newgoodimage.CreateDate = DateTime.Now; newgoodimage.IsDefaultPhoto = (byte)(chkIsDefault.Checked ? 1 : 0); if (flpImage.HasFile) { if (chkIsDefault.Checked)//把原来的默认图片更新 { Query.ProcessSqlNonQuery("update XiHuan_GoodsImage set IsDefaultPhoto=0 where IsDefaultPhoto=1 and GoodsId=" + CommonMethod.FinalString(Request["gid"]), GlobalVar.DataBase_Name); } string extention = Path.GetExtension(flpImage.FileName); int filesize = flpImage.PostedFile.ContentLength; string filepath = "images/userupload/goodsimage/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/"; if (!CommonMethod.IsUploadImageValid("", extention)) { Alert("您选择的图片格式不正确!"); return; } if (filesize > 500 * 1024) { Alert("您选择的图片太大了,超过500k了,换个小点的吧!"); return; } if (!Directory.Exists(Server.MapPath(filepath))) { Directory.CreateDirectory(Server.MapPath(filepath)); } filepath += CommonMethod.FinalString(Request["gid"]) + "_" + DateTime.Now.ToString("yyyyMMddhhmmssfff") + extention; flpImage.PostedFile.SaveAs(Server.MapPath(filepath)); if (action.Equals("ModifyPic")) { string imgsrc = CommonMethod.FinalString(newgoodimage.ImgSrc); if (imgsrc.Length > 0 && File.Exists(Server.MapPath(imgsrc)) && !imgsrc.Equals("images/none.jpg")) { File.Delete(Server.MapPath(imgsrc)); //如果有缩略图也要删除掉 string imgname = Path.GetFileNameWithoutExtension(Server.MapPath(imgsrc)); imgsrc = Server.MapPath(newgoodimage.ImgSrc.Replace(imgname, imgname + GlobalVar.DefaultPhotoSize)); if (File.Exists(imgsrc)) { File.Delete(imgsrc); } imgsrc = Server.MapPath(newgoodimage.ImgSrc.Replace(imgname, imgname + GlobalVar.BigPhotoSize)); if (File.Exists(imgsrc)) { File.Delete(imgsrc); } } } newgoodimage.ImgSrc = filepath; } newgoodimage.Save(); if (chkIsDefault.Checked) //更改默认图片 { string filename = Path.GetFileNameWithoutExtension(Server.MapPath(newgoodimage.ImgSrc)); //生成缩略图 PicHelper.MakeThumbnail(Server.MapPath(newgoodimage.ImgSrc), Server.MapPath(newgoodimage.ImgSrc.Replace(filename, filename + GlobalVar.DefaultPhotoSize)), 85, 85); PicHelper.MakeThumbnail(Server.MapPath(newgoodimage.ImgSrc), Server.MapPath(newgoodimage.ImgSrc.Replace(filename, filename + GlobalVar.BigPhotoSize)), 200, 220); Query.ProcessSqlNonQuery(string.Format("update XiHuan_UserGoods set IsHavePhoto=1,DefaultPhoto='{0}' where Id={1} ", newgoodimage.ImgSrc.Replace(filename, filename + GlobalVar.DefaultPhotoSize), newgoodimage.GoodsId), GlobalVar.DataBase_Name); } Alert("恭喜:操作成功!"); ExecScript(string.Format("parent.location='modifypic.aspx?id={0}&name={1}'", CommonMethod.FinalString(Request["gid"]), Server.UrlEncode(CommonMethod.FinalString(Request["gname"])))); } }