Example #1
0
 /// <summary>
 /// Page_s the init.
 /// </summary>
 private void Page_Init()
 {
     if (Request.QueryString["ID"] == null)
     {
         ClientScriptHelper.ShowMessage(this.Page,
                                        "未輸入ImageID",
                                        "Default.aspx",
                                        RegisterScriptType.Start);
     }
     else
     {
         Guid id;
         if (!Guid.TryParse(Request.QueryString["ID"], out id))
         {
             ClientScriptHelper.ShowMessage(this.Page,
                                            "ImageID錯誤",
                                            "Default.aspx",
                                            RegisterScriptType.Start);
         }
         else
         {
             this.ImageID = id;
         }
     }
 }
Example #2
0
        /// <summary>
        /// Saves the crop image.
        /// </summary>
        private void SaveCropImage()
        {
            bool isNullOfsectionValue = this.x1.Value == null &&
                                        this.x2.Value == null &&
                                        this.y1.Value == null &&
                                        this.y2.Value == null;

            if (isNullOfsectionValue)
            {
                ClientScriptHelper.ShowMessage(this.Page,
                                               "請選擇相片裁剪區域",
                                               RegisterScriptType.Start);
            }
            else
            {
                var cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, this.CropPath);
                var result    = cropUtils.ProcessImageCrop
                                (
                    this.CurrentImage,
                    new int[]
                {
                    this.x1.Value.ConvertToInt(),
                    this.x2.Value.ConvertToInt(),
                    this.y1.Value.ConvertToInt(),
                    this.y2.Value.ConvertToInt()
                }
                                );

                if (!result["result"].Equals("Success", StringComparison.OrdinalIgnoreCase))
                {
                    ClientScriptHelper.ShowMessage(this.Page,
                                                   result["msg"],
                                                   RegisterScriptType.Start);
                }
                else
                {
                    //裁剪圖片檔名儲存到資料庫
                    _service.Update(this.ImageID, result["CropImage"]);

                    //如果有之前的裁剪圖片,則刪除
                    if (!string.IsNullOrWhiteSpace(result["OldCropImage"]))
                    {
                        cropUtils.DeleteCropImage(result["OldCropImage"]);
                    }

                    //載入裁剪圖片檔
                    LoadCropImage();

                    ClientScriptHelper.ShowMessage(this.Page,
                                                   "相片裁剪完成",
                                                   RegisterScriptType.Start);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Processes the save.
        /// </summary>
        private void ProcessSave()
        {
            if (Session["Upload_File"] != null && !string.IsNullOrWhiteSpace(Session["Upload_File"].ToString()))
            {
                var fileName = Session["Upload_File"].ToString();

                var cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, "");
                var result    = cropUtils.SaveUploadImageToOriginalFolder(fileName);

                if (!result["result"].Equals("Success", StringComparison.OrdinalIgnoreCase))
                {
                    ClientScriptHelper.ShowMessage(this.Page, result["msg"], RegisterScriptType.Start);
                }
                else
                {
                    var instance = new UploadImage
                    {
                        ID            = Guid.NewGuid(),
                        OriginalImage = fileName,
                        CreateDate    = DateTime.Now
                    };
                    instance.UpdateDate = instance.CreateDate;

                    _service.Add(instance);

                    this.HiddenField_ID.Value = instance.ID.ToString();

                    this.Image_Upload.ImageUrl = string.Format("{0}/{1}/{2}",
                                                               this.WebSiteRootPath,
                                                               this.OriginalFolder.Replace("~", ""),
                                                               fileName);

                    this.Button_Save.Visible   = false;
                    this.Button_Cancel.Visible = false;

                    if (!string.IsNullOrWhiteSpace(this.HiddenField_ID.Value))
                    {
                        this.Button_Crop.Visible = true;
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Processes the upload.
        /// </summary>
        private void ProcessUpload()
        {
            string fileName = string.Empty;

            if (FileUpload1.HasFile)
            {
                HttpPostedFileBase uploadFile = new HttpPostedFileWrapper(FileUpload1.PostedFile);

                CropImageUtility            cropUtils = new CropImageUtility(this.UploadPath, this.OriginalPath, "");
                Dictionary <string, string> result    = cropUtils.ProcessUploadImage(uploadFile);

                if (!result["result"].Equals("Success", StringComparison.OrdinalIgnoreCase))
                {
                    Session["Upload_File"] = null;
                    ClientScriptHelper.ShowMessage(this.Page, result["msg"], RegisterScriptType.Start);
                }
                else
                {
                    Session["Upload_File"] = result["msg"];
                }
            }
        }