Exemplo n.º 1
0
 protected void Delete_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < DataList1.Items.Count; i++)
     {
         if (((CheckBox)DataList1.Items[i].FindControl("selected")).Checked == true)
         {
             object       s            = ((System.Web.UI.WebControls.HyperLink)DataList1.Items[i].FindControl("Hyperlink3")).Text;
             NewsImageBLL NewsImageBLL = new NewsImageBLL();
             if (NewsImageBLL.Delete1(s))
             {
                 string             url1        = ((System.Web.UI.WebControls.Image)DataList1.Items[i].FindControl("CommodityImage")).ImageUrl.ToString();
                 string             webFilePath = Server.MapPath(url1);//用来删除原有的图片
                 System.IO.FileInfo file        = new System.IO.FileInfo(webFilePath);
                 if (file.Exists)
                 {
                     file.Delete();//删除
                 }
                 string             url2         = ((System.Web.UI.WebControls.Image)DataList1.Items[i].FindControl("basicImage")).ImageUrl.ToString();
                 string             webFilePath2 = Server.MapPath(url2);//用来删除原有的图片
                 System.IO.FileInfo file2        = new System.IO.FileInfo(webFilePath2);
                 if (file2.Exists)
                 {
                     file2.Delete();//删除
                 }
             }
         }
     }
     this.Response.Redirect(this.Request.Url.ToString());
 }
Exemplo n.º 2
0
        protected void DataList1_DeleteCommand(object sender, DataListCommandEventArgs e)
        {
            string url1        = ((System.Web.UI.WebControls.Image)e.Item.FindControl("CommodityImage")).ImageUrl.ToString();
            string webFilePath = Server.MapPath(url1);//用来删除原有的图片

            System.IO.FileInfo file = new System.IO.FileInfo(webFilePath);
            if (file.Exists)
            {
                file.Delete();//删除
            }
            string url3         = ((System.Web.UI.WebControls.Image)e.Item.FindControl("basicImage")).ImageUrl.ToString();
            string webFilePath2 = Server.MapPath(url3);//用来删除原有的图片

            System.IO.FileInfo file2 = new System.IO.FileInfo(webFilePath2);
            if (file2.Exists)
            {
                file2.Delete();//删除
            }
            NewsImageBLL newsimagebll2 = new NewsImageBLL();
            string       id            = e.CommandArgument.ToString();

            if (newsimagebll2.Delete1(id))
            {
                Response.Write("<script>alert('删除成功');</script>");
            }
            this.Response.Redirect(this.Request.Url.ToString());
        }
Exemplo n.º 3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     newsimagebll = new NewsImageBLL();
     if (!IsPostBack)
     {
         DateBind();
     }
 }
Exemplo n.º 4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     newsimagebll = new NewsImageBLL();
     if (!IsPostBack)
     {
         string id = Request["id"].ToString();
         listview1(int.Parse(id));
     }
 }
Exemplo n.º 5
0
        public void DateBind(object id)//绑定要修改的信息
        {
            NewsImageBLL newsimagelbll = new NewsImageBLL();
            RightImage   ni            = new RightImage();

            ni                   = newsimagelbll.GetNewsImage1(id);
            TxtTitle.Text        = ni.Title;
            this.Image1.ImageUrl = "~/IndexImages/" + ni.Url;
            TxtDate.Text         = ni.AddDate.ToString("d");
        }
Exemplo n.º 6
0
        protected void Add_Click(object sender, EventArgs e)
        {
            RightImage   na           = new RightImage();
            NewsImageBLL newsimagebll = new NewsImageBLL();
            string       newname      = "";

            if (FileUp.HasFile)
            {
                FileInfo file = new FileInfo(FileUp.PostedFile.FileName);
                if (file.Extension.ToLower() != ".bmp" && file.Extension.ToLower() != ".jpg" && file.Extension.ToLower() != ".jpeg" && file.Extension.ToLower() != ".png" && file.Extension.ToLower() != ".gif")
                {
                    Response.Write("<script>alert('上传的资料格式应为bmp/jpg/jpeg/png/gif格式');history.back(-1);</script>");
                    return;
                }

                string filename = FileUp.PostedFile.FileName;
                filename = System.IO.Path.GetFileName(filename);
                //改文件名
                int    index    = filename.LastIndexOf(".");
                string lastName = filename.Substring(index, filename.Length - index);//获得文件后缀类型
                //新文件名称,以时间年月日时分秒作为文件名
                newname = "RightImage" + DateTime.Now.ToString("yyyyMMddhhmmss") + lastName;
                double size        = FileUp.PostedFile.ContentLength;
                string webFilePath = Server.MapPath("/NewsImages/" + newname);
                if (!File.Exists(webFilePath))
                {
                    FileUp.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件
                    System.Drawing.Image image = System.Drawing.Image.FromFile(webFilePath);
                    float a = image.Width / image.Height;
                    if (a > 5)
                    {
                        image.Dispose();
                        File.Delete(webFilePath);
                        Response.Write("<script>alert('高宽比例不合适');</script>");
                        return;
                    }
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image, 168, 155);
                    string path = Server.MapPath("/IndexImages/" + newname);
                    if (!File.Exists(path))
                    {
                        bmp.Save(path);
                    }
                    image.Dispose();
                    bmp.Dispose();
                }
                else
                {
                    Response.Write("<script>alert('上传失败,请重试!')</script>");
                    return;
                }
            }
            na.Url     = newname;
            na.AddDate = Convert.ToDateTime(TxtDate.Text);

            string title = Server.HtmlEncode(TxtTitle.Text.Trim());

            na.Title = title;
            if (newsimagebll.Add1(na))
            {
                Response.Write("<script>alert('添加成功');window.location.href='RightMgr.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('添加失败');history.back();</script>");
            }
        }
Exemplo n.º 7
0
        protected void Save_Click(object sender, EventArgs e)
        {
            object       id           = Request.QueryString["id"];//有待改善不安全
            RightImage   ni           = new RightImage();
            NewsImageBLL newsimagebll = new NewsImageBLL();
            string       title        = Server.HtmlEncode(TxtTitle.Text.Trim());

            ni.AddDate = Convert.ToDateTime(TxtDate.Text);

            ni.Title = title;
            ni.Id    = id;
            string name = this.Image1.ImageUrl.Substring(14);//原来图片的URL

            if (FileUp.PostedFile.ContentLength == 0)
            {
                ni.Url = name;
            }
            else
            {
                FileInfo file1 = new FileInfo(FileUp.PostedFile.FileName);
                if (file1.Extension.ToLower() != ".bmp" && file1.Extension.ToLower() != ".jpg" && file1.Extension.ToLower() != ".jpeg" && file1.Extension.ToLower() != ".png" && file1.Extension.ToLower() != ".gif")
                {
                    Response.Write("<script>alert('上传的资料格式应为bmp/jpg/jpeg/png/gif格式');history.back(-1);</script>");
                    return;
                }

                string webFilePath = Server.MapPath("~/NewsImages/" + name);//用来删除原有的图片
                string indexpath   = Server.MapPath(this.Image1.ImageUrl);

                string filename = FileUp.PostedFile.FileName;
                filename = System.IO.Path.GetFileName(filename);
                //改文件名
                int    index    = filename.LastIndexOf(".");
                string lastName = filename.Substring(index, filename.Length - index);//获得文件后缀类型
                //新文件名称,以时间年月日时分秒作为文件名
                string newname = "NewImage" + DateTime.Now.ToString("yyyyMMddhhmmss") + lastName;

                string             newpath      = Server.MapPath("/NewsImages/" + newname);//用来保存新上传的图片
                string             newindexpath = Server.MapPath("/IndexImages/" + newname);
                System.IO.FileInfo file         = new System.IO.FileInfo(webFilePath);
                System.IO.FileInfo indexfile    = new System.IO.FileInfo(indexpath);
                if (file.Exists)
                {
                    file.Delete();//删除
                }

                if (indexfile.Exists)
                {
                    indexfile.Delete();//删除
                }
                if (!File.Exists(newpath))
                {
                    FileUp.SaveAs(newpath);// 使用 SaveAs 方法保存文件
                    System.Drawing.Image image = System.Drawing.Image.FromFile(newpath);
                    float a = image.Width / image.Height;
                    if (a > 5)
                    {
                        image.Dispose();
                        File.Delete(newpath);
                        Response.Write("<script>alert('高宽比例不合适');</script>");
                        return;
                    }
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image, 168, 155);
                    if (!File.Exists(newindexpath))
                    {
                        bmp.Save(newindexpath);
                    }
                    image.Dispose();
                    bmp.Dispose();
                }
                ni.Url = newname;
            }
            if (newsimagebll.Update1(ni))
            {
                Response.Write("<script>alert('更新成功');window.location.href='RightMgr.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('更新失败');history.back();</script>");
            }
        }
Exemplo n.º 8
0
 public void newimages() //图片新闻
 {
     newsimagesbll = new NewsImageBLL();
     this.DatalistNewsImages.DataSource = newsimagesbll.Gettable(4);
     this.DatalistNewsImages.DataBind();
 }