示例#1
0
 /// <summary>
 /// 添加图片
 /// </summary>
 /// <param name="p">图片信息</param>
 /// <returns>受影响的行数</returns>
 public int AddPhoto(Photos p)
 {
     string sql = "insert into Photos (PTypeId, PTitle, PUrl, PDes) values (@PTypeId,@PTitle, @PUrl, @PDes)";
     SqlParameter[] param = {
                            new SqlParameter("@PTypeId",SqlDbType.Int){Value=p.PTypeId},
                            new SqlParameter("@PTitle",SqlDbType.NVarChar){Value=p.PTitle},
                            new SqlParameter("@PUrl",SqlDbType.NVarChar){Value=p.PUrl},
                            new SqlParameter("@PDes",SqlDbType.NVarChar){Value=p.PDes}
                            };
     return SQLHelper.ExecuteNonQuery(sql,CommandType.Text,param);
 }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int pid;
                if (int.TryParse(Request.QueryString["pid"], out pid))
                {
                    Photos p = new PhotosBLL().GetPhotoByPid(pid);
                    if (p != null)
                    {
                        title = p.PTitle;
                        url = p.PUrl;
                        des = p.PDes;
                        id = p.PId.ToString() ;
                    }
                    else
                    {
                        Response.Write("<script>alert('加载失败!');location.href='Default.aspx'</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('参数错误!');location.href='Default.aspx'</script>");
                }
            }
            else
            {
                Photos p = new Photos();
                p.PTitle = Request.Form["txtTitle"];
                p.PUrl = Request.Form["url"];
                p.PDes = Request.Form["txtDes"];
                p.PId = Convert.ToInt32(Request.Form["pid"]);
                p.PTypeId = 1;

                if (new PhotosBLL().Update(p))
                {
                    Response.Write("<script>alert('修改成功!');location.href='Default.aspx'</script>");
                }
                else
                {
                    msg.Text = "<script>alert('修改失败');</script>";
                }
            }
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                string msg = "";
                HttpPostedFile file = Request.Files[0];
                if (file.ContentLength != 0)
                {
                    if (file.ContentType == "image/jpeg" || file.ContentType == "image/pjpeg")
                    {
                        string ext = System.IO.Path.GetExtension(file.FileName);
                        string name = DateTime.Now.ToString("yyMMddhhmmss") + new Random().Next(1000, 10000) + ext;
                        string fullName = Request.MapPath("../images/" + name);
                        file.SaveAs(fullName);
                        Photos p = new Photos();
                        p.PTypeId = 1;
                        p.PTitle = Request.Form["txtTitle"];
                        p.PUrl = name;
                        p.PDes = Request.Form["txtDes"];

                        if (new PhotosBLL().Insert(p))
                        {
                            Response.Write("<script>alert('添加成功!');location.href='Default.aspx';</script>");
                        }
                        else
                        {
                            msg = "添加失败!";
                        }
                    }
                    else
                    {
                        msg = "请选择jpg类型文件!";
                    }
                }
                else
                {
                    msg = "请选择文件!";
                }
                lblMsg.Text = msg;
                lblMsg.ForeColor = Color.Red;
            }
        }
示例#4
0
 /// <summary>
 /// 获得SqlParameter数组
 /// </summary>
 /// <param name="p">photos对象</param>
 /// <param name="flag">0--增加,1--更新</param>
 /// <returns></returns>
 private SqlParameter[] GetParam(Photos p, int flag)
 {
     List<SqlParameter> list = new List<SqlParameter>();
     list.AddRange(new SqlParameter[]{
                                 new SqlParameter("@PTitle",SqlDbType.NVarChar),
                                 new SqlParameter("@PUrl",SqlDbType.NVarChar),
                                 new SqlParameter("@PDes",SqlDbType.NVarChar),
                                 new SqlParameter("@PTypeId",SqlDbType.NVarChar)});
     list[0].Value = p.PTitle;
     list[1].Value = p.PUrl;
     list[2].Value = p.PDes;
     list[3].Value = p.PTypeId;
     if (flag == 1)
     {
         list.Add(new SqlParameter("@PId", p.PId));
         list[list.Count - 1].Value = p.PId;
     }
     return list.ToArray();
 }
示例#5
0
        /// <summary>
        /// DataTable转换成photos对象
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        private List<Photos> DTToList(DataTable dt)
        {
            List<Photos> list = new List<Photos>();
            foreach (DataRow dr in dt.Rows)
            {
                Photos p = new Photos();
                //dr["PClicks"] != DBNull.Value 判断dr["PClicks"]是否为空
                p.PClicks = Convert.ToInt32(dr["PClicks"]);
                p.PDes = dr["PDes"].ToString();
                p.PDown = Convert.ToInt32(dr["PDown"]);
                p.PId = Convert.ToInt32(dr["PId"]);
                p.PTime = Convert.ToDateTime(dr["PTime"]);
                p.PTitle = dr["PTitle"].ToString();
                p.PTypeId = Convert.ToInt32(dr["PTypeId"]);
                p.PUp = Convert.ToInt32(dr["PUp"]);
                p.PUrl = dr["PUrl"].ToString();
                list.Add(p);
            }

            return list;
        }
示例#6
0
 /// <summary>
 /// 更新数据
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public bool Update(Photos p)
 {
     string sql = "update Photos set PTitle=@PTitle,PUrl=@PUrl,PDes=@PDes,PTypeId=@PTypeId where PId=@PId";
     return SQLHelper.ExecuteNonQuery(sql, GetParam(p, 1)) > 0;
 }
示例#7
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public bool Insert(Photos p)
        {
            string sql = "insert into Photos (PTypeId, PTitle, PUrl, PDes) values(@PTypeId, @PTitle, @PUrl, @PDes)";

            return SQLHelper.ExecuteNonQuery(sql, GetParam(p, 0)) > 0;
        }
示例#8
0
 public int DeletePhoto(Photos p)
 {
     return DeletePhoto(p.PId);
 }
示例#9
0
 /// <summary>
 /// 添加图片
 /// </summary>
 /// <param name="p">图片信息</param>
 /// <returns>受影响的行数</returns>
 public int AddPhoto(Photos p)
 {
     return photoDAl.AddPhoto(p);
 }
示例#10
0
 /// <summary>
 /// 更新图片
 /// </summary>
 /// <param name="p">图片信息</param>
 /// <returns>受影响的行数</returns>
 public int UpdatePhoto(Photos p)
 {
     return photoDAl.UpdatePhoto(p);
 }
示例#11
0
 /// <summary>
 /// 添加跟修改照片 
 /// </summary>
 /// <param name="action">add添加   edit修改</param>
 /// <param name="p">照片对象</param>
 /// <returns></returns>
 public bool Save(string action,Photos p)
 {
     bool r = false;
     if (action=="add")
     {
         r = AddPhoto(p) > 0 ? true : false;
     }
     else if (action=="edit")
     {
         r = UpdatePhoto(p) > 0 ? true : false;
     }
     return r;
 }
示例#12
0
 /// <summary>
 /// 更新图片
 /// </summary>
 /// <param name="p">图片信息</param>
 /// <returns>受影响的行数</returns>
 public int UpdatePhoto(Photos p)
 {
     string sql = "update photos set PTypeId=@PTypeId, PTitle=@PTitle, PUrl=@PUrl, PDes=@PDes where PId=" + p.PId;
     SqlParameter[] param ={
                               new SqlParameter("@PTypeId",SqlDbType.Int){Value=p.PTypeId},
                               new SqlParameter("@PTitle",SqlDbType.NVarChar){Value=p.PTitle},
                               new SqlParameter("@PUrl",SqlDbType.NVarChar){Value=p.PUrl},
                               new SqlParameter("@PDes",SqlDbType.NVarChar){Value=p.PDes}
                          };
     return SQLHelper.ExecuteNonQuery(sql, CommandType.Text, param);
 }
示例#13
0
 /// <summary>
 /// 根据对象删除数据
 /// </summary>
 /// <param name="id">photos对象id</param>
 /// <returns></returns>
 public bool Delete(Photos p)
 {
     return Delete(p.PId);
 }
示例#14
0
 /// <summary>
 /// 更新数据
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public bool Update(Photos p)
 {
     return pd.Update(p);
 }
示例#15
0
 /// <summary>
 /// 插入数据
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public bool Insert(Photos p)
 {
     return pd.Insert(p);
 }