/// <summary>
        /// Processes the delete.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        private Dictionary <string, string> ProcessDelete(string id)
        {
            var jo = new Dictionary <string, string>();

            if (string.IsNullOrWhiteSpace(id))
            {
                jo.Add("result", "error");
                jo.Add("msg", "無ID編號");
            }
            else
            {
                var imageId = new Guid(id.ToString());

                var item = _service.FindOne(imageId);

                if (item == null)
                {
                    jo.Add("result", "error");
                    jo.Add("msg", "資料不存在");
                }
                else
                {
                    try
                    {
                        _service.Delete(imageId);

                        if (!string.IsNullOrWhiteSpace(item.OriginalImage))
                        {
                            string fileName1 = Server.MapPath(string.Format(@"~/{0}/{1}",
                                                                            OriginalFolder,
                                                                            item.OriginalImage));

                            if (System.IO.File.Exists(fileName1))
                            {
                                System.IO.File.Delete(fileName1);
                            }
                        }
                        if (!string.IsNullOrWhiteSpace(item.CropImage))
                        {
                            string fileName2 = Server.MapPath(string.Format(@"~/{0}/{1}",
                                                                            CropFolder,
                                                                            item.CropImage));

                            if (System.IO.File.Exists(fileName2))
                            {
                                System.IO.File.Delete(fileName2);
                            }
                        }
                        jo.Add("result", "OK");
                        jo.Add("msg", "");
                    }
                    catch (Exception ex)
                    {
                        jo.Add("result", "exception");
                        jo.Add("msg", ex.Message);
                    }
                }
            }
            return(jo);
        }
        protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                ListViewDataItem dataItem   = e.Item as ListViewDataItem;
                object           primaryKey = this.ListView1.DataKeys[dataItem.DisplayIndex]["ID"];
                if (primaryKey != null)
                {
                    Guid imageID = new Guid(primaryKey.ToString());
                    var  item    = service.FindOne(imageID);

                    Image     originalImage = dataItem.FindControl("Image1") as Image;
                    Image     cropImage     = dataItem.FindControl("Image2") as Image;
                    HyperLink HyperLink1    = dataItem.FindControl("HyperLink1") as HyperLink;

                    if (item != null)
                    {
                        if (originalImage != null)
                        {
                            if (string.IsNullOrWhiteSpace(item.OriginalImage))
                            {
                                originalImage.Visible = false;
                            }
                            else
                            {
                                originalImage.ImageUrl = string.Format("{0}/{1}/{2}",
                                                                       this.WebSiteRootPath,
                                                                       this.OriginalFolder.Replace("~", ""),
                                                                       item.OriginalImage);

                                originalImage.Height = new Unit(200);
                            }
                        }

                        if (cropImage != null)
                        {
                            if (string.IsNullOrWhiteSpace(item.CropImage))
                            {
                                cropImage.Visible = false;
                            }
                            else
                            {
                                cropImage.ImageUrl = string.Format("{0}/{1}/{2}",
                                                                   this.WebSiteRootPath,
                                                                   this.CropFolder.Replace("~", ""),
                                                                   item.CropImage);
                            }
                        }

                        if (HyperLink1 != null)
                        {
                            HyperLink1.NavigateUrl = string.Concat("Crop.aspx?ID=", item.ID.ToString());
                        }
                    }
                }
            }
        }
Example #3
0
        private Dictionary <string, string> ProcessDelete(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(MiscUtility.GetErrorMsg("No id"));
            }
            else
            {
                Guid imageID = new Guid(id);
                var  item    = service.FindOne(imageID);

                if (item == null)
                {
                    return(MiscUtility.GetErrorMsg("data not found"));
                }

                try
                {
                    service.Delete(imageID);

                    if (!string.IsNullOrWhiteSpace(item.OriginalImage))
                    {
                        string fileName1 = Server.MapPath(string.Format("~/{0}/{1}", OriginalFolder, item.OriginalImage));
                        if (System.IO.File.Exists(fileName1))
                        {
                            System.IO.File.Delete(fileName1);
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(item.CropImage))
                    {
                        string fileName2 = Server.MapPath(string.Format("~/{0}/{1}", CropFolder, item.CropImage));
                        if (System.IO.File.Exists(fileName2))
                        {
                            System.IO.File.Delete(fileName2);
                        }
                    }

                    return(MiscUtility.GetSuccess());
                }
                catch (Exception ex)
                {
                    return(MiscUtility.GetExceptionMsg(ex.Message));
                }
            }
        }
        /// <summary>
        /// Loads the crop image.
        /// </summary>
        private void LoadCropImage()
        {
            if (this.ImageID != null)
            {
                var instance = service.FindOne(this.ImageID);

                if (instance != null && !string.IsNullOrWhiteSpace(instance.CropImage))
                {
                    this.Image3.ImageUrl = string.Format("{0}/{1}/{2}",
                                                         this.WebSiteRootPath,
                                                         this.CropFolder.Replace("~", ""),
                                                         instance.CropImage);

                    this.Panel1.Visible = true;
                }
                else
                {
                    this.Panel1.Visible = false;
                }
            }
        }