/// <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> public int Add(Tunnel.Model.Vote_Info model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Vote_Info("); strSql.Append("v_title,v_count,v_Img,v_author,v_remark)"); strSql.Append(" values ("); strSql.Append("@v_title,@v_count,@v_Img,@v_author,@v_remark)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@v_title", SqlDbType.NVarChar, 50), new SqlParameter("@v_count", SqlDbType.Int, 4), new SqlParameter("@v_Img", SqlDbType.NVarChar, 100), new SqlParameter("@v_author", SqlDbType.NVarChar, 50), new SqlParameter("@v_remark", SqlDbType.NVarChar, 200) }; parameters[0].Value = model.v_title; parameters[1].Value = model.v_count; parameters[2].Value = model.v_Img; parameters[3].Value = model.v_author; parameters[4].Value = model.v_remark; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Tunnel.Model.Vote_Info model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Vote_Info set "); strSql.Append("v_title=@v_title,"); strSql.Append("v_count=@v_count,"); strSql.Append("v_Img=@v_Img,"); strSql.Append("v_author=@v_author,"); strSql.Append("v_remark=@v_remark"); strSql.Append(" where v_id=@v_id "); SqlParameter[] parameters = { new SqlParameter("@v_id", SqlDbType.Int, 4), new SqlParameter("@v_title", SqlDbType.NVarChar, 50), new SqlParameter("@v_count", SqlDbType.Int, 4), new SqlParameter("@v_Img", SqlDbType.NVarChar, 100), new SqlParameter("@v_author", SqlDbType.NVarChar, 50), new SqlParameter("@v_remark", SqlDbType.NVarChar, 200) }; parameters[0].Value = model.v_id; parameters[1].Value = model.v_title; parameters[2].Value = model.v_count; parameters[3].Value = model.v_Img; parameters[4].Value = model.v_author; parameters[5].Value = model.v_remark; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 获得数据列表 /// </summary> public List <Tunnel.Model.Vote_Info> DataTableToList(DataTable dt) { List <Tunnel.Model.Vote_Info> modelList = new List <Tunnel.Model.Vote_Info>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Tunnel.Model.Vote_Info model; for (int n = 0; n < rowsCount; n++) { model = new Tunnel.Model.Vote_Info(); if (dt.Rows[n]["v_id"].ToString() != "") { model.v_id = int.Parse(dt.Rows[n]["v_id"].ToString()); } model.v_title = dt.Rows[n]["v_title"].ToString(); if (dt.Rows[n]["v_count"].ToString() != "") { model.v_count = int.Parse(dt.Rows[n]["v_count"].ToString()); } model.v_Img = dt.Rows[n]["v_Img"].ToString(); model.v_author = dt.Rows[n]["v_author"].ToString(); model.v_remark = dt.Rows[n]["v_remark"].ToString(); modelList.Add(model); } } return(modelList); }
/// <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("只能上传图片"); } } }
/// <summary> /// 得到一个对象实体 /// </summary> public Tunnel.Model.Vote_Info GetModel(int v_id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 v_id,v_title,v_count,v_Img,v_author,v_remark from Vote_Info "); strSql.Append(" where v_id=@v_id "); SqlParameter[] parameters = { new SqlParameter("@v_id", SqlDbType.Int, 4) }; parameters[0].Value = v_id; Tunnel.Model.Vote_Info model = new Tunnel.Model.Vote_Info(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["v_id"].ToString() != "") { model.v_id = int.Parse(ds.Tables[0].Rows[0]["v_id"].ToString()); } model.v_title = ds.Tables[0].Rows[0]["v_title"].ToString(); if (ds.Tables[0].Rows[0]["v_count"].ToString() != "") { model.v_count = int.Parse(ds.Tables[0].Rows[0]["v_count"].ToString()); } model.v_Img = ds.Tables[0].Rows[0]["v_Img"].ToString(); model.v_author = ds.Tables[0].Rows[0]["v_author"].ToString(); model.v_remark = ds.Tables[0].Rows[0]["v_remark"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Tunnel.Model.Vote_Info model) { dal.Update(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Tunnel.Model.Vote_Info model) { return(dal.Add(model)); }