/// <summary> /// 重命名和删除 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void dt_VotePic_ItemCommand(object source, DataListCommandEventArgs e) { string cmd = e.CommandName; if (cmd == "UP") { //获取图片的编号 int Vote_Id = Convert.ToInt32(e.CommandArgument); Tunnel.BLL.Vote_Info voteInfoBLL = new Tunnel.BLL.Vote_Info(); Tunnel.Model.Vote_Info voteInfoModel = voteInfoBLL.GetModel(Vote_Id); //修改图片的标题 TextBox tb = (TextBox)e.Item.FindControl("txtName"); voteInfoModel.v_title = tb.Text.ToString(); voteInfoBLL.Update(voteInfoModel); ClientScript.RegisterStartupScript(GetType(), "确定", "<script>alert('更新成功!');</script>"); DataLoad(24, 1); } else if (cmd == "DEL") { //获取图片的编号 int id = Convert.ToInt32(e.CommandArgument); Button btnDel = (Button)e.Item.FindControl("btn_DeleteVote"); btnDel.Attributes.Add("OnClientClick", "javascript:return confirm('确认要删除此项投票吗?');"); Tunnel.BLL.Vote_Info voteInfoBLL = new Tunnel.BLL.Vote_Info(); voteInfoBLL.Delete(id); Tunnel.BLL.VoteLog voteLogBLL = new Tunnel.BLL.VoteLog(); //删除该投票选项的投票记录 voteLogBLL.DeleteByVote_ID(id); //重新绑定页面 DataLoad(24, 1); ClientScript.RegisterStartupScript(GetType(), "确定", "<script>alert('删除图片成功!');</script>"); } }
/// <summary> /// 绑定查询图片信息 /// </summary> private void LoadData() { Tunnel.BLL.Vote_Info infoBLL = new Tunnel.BLL.Vote_Info(); int vote_Id = int.Parse(Request.QueryString["v_id"].ToString()); //设置当前图片的标题和作者 Tunnel.Model.Vote_Info info = infoBLL.GetModel(vote_Id); //获取图片的路径 this.imgPic.ImageUrl = "/N_PicVote/Pic/a" + info.v_Img; this.lblTitle.Text = info.v_title; //Tunnel.Model.Tunnel_menber menber = ulBLL.GetUserBean(info.v_author); //设置照片的作者 this.lblAuthor.Text = info.v_author; this.lblRemark.Text = info.v_remark; ListPage(vote_Id, 5, 1); }
//把图片存入数据库 protected void btnAdd_Click(object sender, EventArgs e) { int FileLength = upPhoto.PostedFile.ContentLength; if (FileLength == 0) { ClientScript.RegisterStartupScript(GetType(), "", "alert('请选择上传的图片!')", true); } else { //获得图片名称. FileInfo fi = new FileInfo(upPhoto.FileName); if (fi.Extension.Equals(".jpg") || fi.Extension.Equals(".JPG") || fi.Extension.Equals(".jpge") || fi.Extension.Equals(".JPEG") || fi.Extension.Equals(".gif") || fi.Extension.Equals(".GIF") || fi.Extension.Equals(".PNG") || fi.Extension.Equals(".png")) { string type = Path.GetExtension(upPhoto.FileName); string filedName = DateTime.Now.ToFileTime().ToString() + type; string strpath = Server.MapPath("~/N_PicVote/Pic/"); string temp = strpath + filedName; string _temp = strpath + "_" + filedName; string atemp = strpath + "a" + filedName; this.upPhoto.SaveAs(temp); MakeThumbnail(temp, _temp, 132, 88, "HW"); MakeThumbnail(temp, atemp, 523, 250, "WH"); //实例化一个图片实体类信息 Tunnel.Model.Vote_Info vote_info = new Tunnel.Model.Vote_Info(); vote_info.v_title = txtPicTitle.Text; vote_info.v_Img = filedName; vote_info.v_count = 0; vote_info.v_author = txtAuthor.Text; vote_info.v_remark = txtRemark.Text; //添加图片实体类 Tunnel.BLL.Vote_Info vote_InfoBll = new Tunnel.BLL.Vote_Info(); vote_InfoBll.Add(vote_info); Tunnel.Common.Message.Show("图片添加成功"); } else { Tunnel.Common.Message.Show("只能上传图片"); } } }