Example #1
0
    protected void lvProductImageList_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        DBLL.clsProductImage ProductImage = new DBLL.clsProductImage();
        Label lblnID = (Label)lvProductImageList.Items[e.ItemIndex].FindControl("lblnPImageID");
        int _nID = 0;
        if (int.TryParse(lblnID.Text.Trim(), out _nID) && _nID > 0)
        {
            bool Result = ProductImage.sp_DeleteNormalTableByIDProductImage(int.Parse(_nID.ToString()), "tb_ProductImage");
            if (Result)
            {
                //判断文件是不是存在
                Image ImsPImagePath = (Image)lvProductImageList.Items[e.ItemIndex].FindControl("ImsPImagePath");
                string sSaveFolderFullPath = Server.MapPath(ImsPImagePath.ImageUrl);
                if (File.Exists(sSaveFolderFullPath))
                {
                    //如果存在则删除
                    File.Delete(sSaveFolderFullPath);

                    System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(sSaveFolderFullPath.Substring(0, sSaveFolderFullPath.LastIndexOf("\\")).ToString());
                    System.IO.FileInfo[] dirs = dir.GetFiles();
                    if (dirs.Length > 0)
                    {
                        //有子文件夹
                    }
                    else
                    {
                        Directory.Delete(sSaveFolderFullPath.Substring(0, sSaveFolderFullPath.LastIndexOf("\\")).ToString());
                    }

                    DataTable Imagedt = new DataTable();
                    Imagedt = ProductImage.Select_tb_ProductImageBynProductID(int.Parse(hfProductUpdateID.Value));
                    if (Imagedt != null)
                    {
                        ProductImageList.Clear();
                        ProductImageList.Merge(Imagedt);
                        lvProductImageList.DataSource = ProductImageList;
                        lvProductImageList.DataBind();
                    }
                    else
                    {
                        ProductImageList.Clear();
                        lvProductImageList.DataSource = ProductImageList;
                        lvProductImageList.DataBind();
                    }
                }
            }
        }
    }