protected void AccessDataSource1_Deleting(object sender, SqlDataSourceCommandEventArgs e) { // Delete the image files // Get the image file name string picture1FileName; using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "SELECT [Picture1_FileName_thumbnail] FROM [Ex_A_507] WHERE [ID]=@Id"; command.Parameters.AddWithValue("@Id", e.Command.Parameters["Id"].Value); picture1FileName = Convert.ToString(command.ExecuteScalar()); } } if (!string.IsNullOrEmpty(picture1FileName)) { // Delete the main image string picture1FilePath_main = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_507/picture1/main/"), picture1FileName); if (System.IO.File.Exists(picture1FilePath_main)) { System.IO.File.Delete(picture1FilePath_main); } // Delete the thumbnail string picture1FilePath_thumbnail = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_507/picture1/thumbnail/"), picture1FileName); if (System.IO.File.Exists(picture1FilePath_thumbnail)) { System.IO.File.Delete(picture1FilePath_thumbnail); } } }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI(); initializeExampleUI();", true); } if (!this.ScriptManager1.IsInAsyncPostBack) { // Load the colorpicker script ExamplesHelper.LoadLibrary_ColorPicker(this); } if (!this.IsPostBack) { this.PopulateDropdownLists(); this.txtText.Text = "Piczard - " + DateTime.Now.ToString(); } // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; this.phOutputContainer.Visible = false; this.phCodeContainer.Visible = false; }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI(); initializeExampleUI();", true); } if (!this.ScriptManager1.IsInAsyncPostBack) { // Load the Galleria Script ExamplesHelper.LoadLibrary_Galleria(this); } if (!this.IsPostBack) { // Display the source images this.displaySourceImages(); } // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; this.ddlImageFormat.Enabled = this.rbFormatCustom.Checked; this.phOutputContainer.Visible = false; this.phCodeContainer.Visible = false; }
protected void EditImage3() { // Load the image and the value from the DB using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "SELECT [SourceImage],[PictureTrimmerValue] FROM [Ex_A_305] WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Id", RecordID3); using (OleDbDataReader reader = command.ExecuteReader()) { reader.Read(); byte[] imageBytes = (byte[])reader["SourceImage"]; string contentImageUrl = GetImageUrl_Content(RecordID3, this.popupPictureTrimmer3.ImageBackColor.Value, this.popupPictureTrimmer3.ImageBackColorApplyMode); this.popupPictureTrimmer3.LoadImageFromByteArray(imageBytes, contentImageUrl, new FixedCropConstraint(320, 180)); // NOTE: // The content image URL can be setted also after image load. // This is useful to generate dynamic content images. // Example: // this.popupPictureTrimmer1.ContentImageUrl = "..."; this.popupPictureTrimmer3.Value = PictureTrimmerValue.FromJSON((string)reader["PictureTrimmerValue"]); } } } // Open the image edit popup this.popupPictureTrimmer3.OpenPopup(800, 510); }
protected void popupPictureTrimmer1_PopupClose(object sender, PictureTrimmerPopupCloseEventArgs e) { if (e.SaveChanges) { // User clicked the "Ok" button // Save the cropped image in the file system this.popupPictureTrimmer1.SaveProcessedImageToFileSystem(string.Format("~/repository/store/ex_A_305/output/{0}.jpg", RecordID1)); // Save the PictureTrimmer value in the DB using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "UPDATE [Ex_A_305] SET [PictureTrimmerValue]=@PictureTrimmerValue WHERE [Id]=@Id"; command.Parameters.AddWithValue("@PictureTrimmerValue", CodeCarvings.Piczard.Serialization.JSONSerializer.SerializeToString(this.popupPictureTrimmer1.Value)); command.Parameters.AddWithValue("@Id", RecordID1); command.ExecuteNonQuery(); } } // Display the new output image this.displayOutputImage1(); } // Unload the image from the control this.popupPictureTrimmer1.UnloadImage(); }
protected void popupPictureTrimmer1_PopupClose(object sender, PictureTrimmerPopupCloseEventArgs e) { if (e.SaveChanges) { // User clicked the "Ok" button // Save the PictureTrimmer value and the output image in the DB using (SqlConnection connection = ExamplesHelper.GetNewOpenDbConnection_SqlServer()) { using (SqlCommand command = connection.CreateCommand()) { command.CommandText = "UPDATE [Ex_A_306] SET [PictureTrimmerValue]=@PictureTrimmerValue, [OutputImage]=@OutputImage WHERE [Id]=@Id"; command.Parameters.AddWithValue("@PictureTrimmerValue", CodeCarvings.Piczard.Serialization.JSONSerializer.SerializeToString(this.popupPictureTrimmer1.Value)); command.Parameters.AddWithValue("@OutputImage", this.popupPictureTrimmer1.SaveProcessedImageToByteArray(new JpegFormatEncoderParams())); command.Parameters.AddWithValue("@Id", RecordID1); command.ExecuteNonQuery(); } } // Display the new image this.displayImage1(); } // Unload the image from the control this.popupPictureTrimmer1.UnloadImage(); }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI();", true); } if (!this.ScriptManager1.IsInAsyncPostBack) { // Load the fancybox script ExamplesHelper.LoadLibrary_FancyBox(this); } // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; // Reset the OnClientControlLoad event hanlder (used to display the output image when the btnProcessImage is clicked this.InlinePictureTrimmer1.OnClientControlLoadFunction = ""; if (!this.IsPostBack) { // Load the image FixedCropConstraint cropConstraint = new FixedCropConstraint(250, 150); cropConstraint.Margins.SetZero(); this.InlinePictureTrimmer1.LoadImageFromFileSystem(SourceImageFileName, cropConstraint); } }
protected void Page_Load(object sender, EventArgs e) { if (!this.Page.IsPostBack) { // Check the SQL Server DB configuration. ExamplesHelper.CheckDbConnection_SqlServer(Request["skipcscheck"] == "1"); } }
protected void EditImage1() { // Load the image in the control (the image file is stored in the file system) this.popupPictureTrimmer1.LoadImageFromFileSystem(string.Format("~/repository/store/ex_A_305/source/{0}.jpg", RecordID1), new FixedCropConstraint(320, 180)); // Load the value (stored in the DB) using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "SELECT [PictureTrimmerValue] FROM [Ex_A_305] WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Id", RecordID1); this.popupPictureTrimmer1.Value = PictureTrimmerValue.FromJSON((string)command.ExecuteScalar()); } } // Open the image edit popup this.popupPictureTrimmer1.OpenPopup(800, 510); }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI();", true); } if (!this.IsPostBack) { // Check the SQL Server DB configuration. ExamplesHelper.CheckDbConnection_SqlServer(Request["skipcscheck"] == "1"); // Display the picture this.displayImage1(); } // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI(); initializeExampleUI();", true); } if (!this.ScriptManager1.IsInAsyncPostBack) { // Load the custom CSS used by the PopupPictureTrimmer System.Web.UI.HtmlControls.HtmlLink lightBoxCustomCSS = new System.Web.UI.HtmlControls.HtmlLink(); lightBoxCustomCSS.Href = this.ResolveUrl("CodeCarvings.Piczard.LightBox.Custom.css"); lightBoxCustomCSS.Attributes.Add("rel", "stylesheet"); lightBoxCustomCSS.Attributes.Add("type", "text/css"); this.Header.FindControl("phHeader").Controls.Add(lightBoxCustomCSS); // Load the colorpicker script ExamplesHelper.LoadLibrary_ColorPicker(this); } if (!this.IsPostBack) { // Load the image CropConstraint cropConstraint = new FixedCropConstraint(100, 100); cropConstraint.DefaultImageSelectionStrategy = CropConstraintImageSelectionStrategy.DoNotResize; this.InlinePictureTrimmer1.LoadImageFromFileSystem("~/repository/source/flowers2.png", cropConstraint); this.PopupPictureTrimmer1.LoadImageFromFileSystem("~/repository/source/flowers2.png", cropConstraint); } // Configure the PictureTrimmer instances this.SetPictureTrimmerConfiguration(this.InlinePictureTrimmer1); this.SetPictureTrimmerConfiguration(this.PopupPictureTrimmer1); this.PopupPictureTrimmer1.LightBoxCssClass = this.ddlPopupLightBoxCssClass.SelectedValue; this.cbShowResizePanel.Enabled = this.cbAllowResize.Checked; // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI(); initializeExampleUI();", true); } else { // Load the colorpicker script ExamplesHelper.LoadLibrary_ColorPicker(this); // Load the fancybox script ExamplesHelper.LoadLibrary_FancyBox(this); } if (!this.Page.IsPostBack) { this.PopulateDropdownLists(); // Load the image this.LoadImageIntoPictureTrimmer(true); // Initialize the zoom factor this.InlinePictureTrimmer1.UserState.UIParams.ZoomFactor = float.Parse(this.ddlZoomFactor.SelectedValue, System.Globalization.CultureInfo.InvariantCulture); } // Update the canvas color and the image back color this.InlinePictureTrimmer1.CanvasColor = System.Drawing.ColorTranslator.FromHtml(this.txtCanvasColor.Text); this.InlinePictureTrimmer1.ImageBackColor = this.InlinePictureTrimmer1.CanvasColor.Clone(); // Update the UI Unit this.InlinePictureTrimmer1.UIUnit = (GfxUnit)Enum.Parse(typeof(GfxUnit), this.ddlGfxUnit.SelectedValue); // Reset the OnClientControlLoad event hanlder (used to display the preview when the btnPreview is clicked this.InlinePictureTrimmer1.OnClientControlLoadFunction = ""; // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; }
protected void EditImage1() { // Load the image and the value from the DB using (SqlConnection connection = ExamplesHelper.GetNewOpenDbConnection_SqlServer()) { using (SqlCommand command = connection.CreateCommand()) { command.CommandText = "SELECT [SourceImage],[PictureTrimmerValue] FROM [Ex_A_306] WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Id", RecordID1); using (SqlDataReader reader = command.ExecuteReader()) { reader.Read(); this.popupPictureTrimmer1.LoadImageFromByteArray((byte[])reader["SourceImage"], new FixedCropConstraint(320, 180)); this.popupPictureTrimmer1.Value = PictureTrimmerValue.FromJSON((string)reader["PictureTrimmerValue"]); } } } // Open the image edit popup this.popupPictureTrimmer1.OpenPopup(800, 510); }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI(); initializeExampleUI();", true); } if (!this.ScriptManager1.IsInAsyncPostBack) { // Load the colorpicker script ExamplesHelper.LoadLibrary_ColorPicker(this); } // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; this.phOutputContainer.Visible = false; this.phCodeContainer.Visible = false; this.phResizeMode_Fixed.Visible = false; this.phResizeMode_Scaled.Visible = false; this.UpdatePanel1.FindControl("phResizeMode_" + this.ddlResizeMode.SelectedValue).Visible = true; }
protected void popupPictureTrimmer3_PopupClose(object sender, PictureTrimmerPopupCloseEventArgs e) { if (e.SaveChanges) { // User clicked the "Ok" button using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { // Load the source image (this operation is required when temporary files are disabled!) byte[] sourceImageBytes; using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "SELECT [SourceImage] FROM [Ex_A_305] WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Id", RecordID3); sourceImageBytes = (byte[])command.ExecuteScalar(); } // Save the PictureTrimmer value and the output image in the DB using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "UPDATE [Ex_A_305] SET [PictureTrimmerValue]=@PictureTrimmerValue, [OutputImage]=@OutputImage WHERE [Id]=@Id"; command.Parameters.AddWithValue("@PictureTrimmerValue", CodeCarvings.Piczard.Serialization.JSONSerializer.SerializeToString(this.popupPictureTrimmer3.Value)); byte[] outputImageBytes = this.popupPictureTrimmer3.SaveProcessedImageToByteArray(sourceImageBytes, new JpegFormatEncoderParams()); command.Parameters.AddWithValue("@OutputImage", outputImageBytes); command.Parameters.AddWithValue("@Id", RecordID3); command.ExecuteNonQuery(); } } // Display the new output image this.displayOutputImage3(); } // Unload the image from the control this.popupPictureTrimmer3.UnloadImage(); }
protected void btnSave_Click(object sender, EventArgs e) { // Save the record if (!this.IsValid) { return; } #region Save the Record into the DB #region Prepare the byte arrays to store in the DB byte[] picture1_file_main = new byte[0]; byte[] picture1_file_thumbnail = new byte[0]; if (this.Picture1.HasNewImage) { // New image to save // Ensure that the temporary file exists if (File.Exists(this.Picture1.TemporarySourceImageFilePath)) { // Load the main image picture1_file_main = this.Picture1.SaveProcessedImageToByteArray(new JpegFormatEncoderParams()); // Generate the thumbnail ImageProcessingJob job = this.Picture1.GetImageProcessingJob(); job.Filters.Add(new FixedResizeConstraint(48, 48)); picture1_file_thumbnail = job.SaveProcessedImageToByteArray(this.Picture1.TemporarySourceImageFilePath, new JpegFormatEncoderParams(80)); } } #endregion if (this.RecordId != 0) { // UPDATE... using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { // Update the record using (OleDbCommand command = connection.CreateCommand()) { if ((!this.Picture1.HasImage) || (this.Picture1.HasNewImage)) { // ### IMAGE NOT SELECTED -OR- NEW IMAGE command.CommandText = "UPDATE [Ex_A_504] SET [Title]=@Title, [Picture1_file_main]=@Picture1_file_main, [Picture1_file_thumbnail]=@Picture1_file_thumbnail WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Title", this.txtTitle.Text); // Store the files command.Parameters.AddWithValue("@Picture1_file_main", picture1_file_main); command.Parameters.AddWithValue("@Picture1_file_thumbnail", picture1_file_thumbnail); command.Parameters.AddWithValue("@Id", this.RecordId); } else { // ### IMAGE NOT UPDATED command.CommandText = "UPDATE [Ex_A_504] SET [Title]=@Title WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Title", this.txtTitle.Text); command.Parameters.AddWithValue("@Id", this.RecordId); } command.ExecuteNonQuery(); } } } else { // INSERT... using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { // Insert the new record using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "INSERT INTO [Ex_A_504] ([Title], [Picture1_file_main], [Picture1_file_thumbnail]) VALUES (@Title, @Picture1_file_main, @Picture1_file_thumbnail)"; command.Parameters.AddWithValue("@Title", this.txtTitle.Text); // Store the files command.Parameters.AddWithValue("@Picture1_file_main", picture1_file_main); command.Parameters.AddWithValue("@Picture1_file_thumbnail", picture1_file_thumbnail); command.ExecuteNonQuery(); } } } #endregion // Clear the temporary files this.Picture1.ClearTemporaryFiles(); this.ReturnToList(); }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI();", true); } if (!this.IsPostBack) { // Get the record id passed as query parameter if (!string.IsNullOrEmpty(Request.QueryString["id"])) { this.RecordId = int.Parse(Request.QueryString["id"]); } // Setup the Picture1 Post Processing Filter (Resize + Watermark) this.Picture1.PostProcessingFilter = new ScaledResizeConstraint(250, 250) + new ImageWatermark("~/repository/watermark/piczardWatermark1.png", ContentAlignment.BottomRight); #region Load the Record if (this.RecordId != 0) { // UPDATE this.labelRecordId.Text = this.RecordId.ToString(); // Load the database data using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { using (OleDbCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = "SELECT [Title], [Picture1_FileName_main], [Picture1_FileName_thumbnail] FROM [Ex_A_507] WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Id", this.RecordId); using (OleDbDataReader reader = command.ExecuteReader()) { if (reader.Read()) { // Record found // Get the title this.txtTitle.Text = Convert.ToString(reader["Title"]); // Get the picture1 file names this.Picture1FileName_main = Convert.ToString(reader["Picture1_FileName_main"]); this.Picture1FileName_thumbnail = Convert.ToString(reader["Picture1_FileName_thumbnail"]); if (!string.IsNullOrEmpty(this.Picture1FileName_main)) { // Load the image into the SimpleImageUpload ASCX control string picture1FilePath_main = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_507/picture1/main/"), this.Picture1FileName_main); this.Picture1.LoadImageFromFileSystem(picture1FilePath_main); } } else { // Record not found, return to list this.ReturnToList(); return; } } } } } else { // NEW RECORD this.labelRecordId.Text = "New record"; } #endregion } // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI();", true); } if (!this.IsPostBack) { // Get the record id passed as query parameter if (!string.IsNullOrEmpty(Request.QueryString["id"])) { this.RecordId = int.Parse(Request.QueryString["id"]); } // Setup the Picture1 preview filter ScaledResizeConstraint previewFilter = new ScaledResizeConstraint(300, 200); previewFilter.EnlargeSmallImages = false; this.Picture1.PreviewFilter = previewFilter; #region Load the Record if (this.RecordId != 0) { // UPDATE this.labelRecordId.Text = this.RecordId.ToString(); // Load the database data using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { using (OleDbCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = "SELECT [Title], [Picture1_file_main] FROM [Ex_A_504] WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Id", this.RecordId); using (OleDbDataReader reader = command.ExecuteReader()) { if (reader.Read()) { // Record found // Get the title this.txtTitle.Text = Convert.ToString(reader["Title"]); // Get the picture1 main image bytes byte[] picture1_file_main = (byte[])(reader["Picture1_file_main"]); if (picture1_file_main.Length > 0) { // Load the image into the SimpleImageUpload ASCX control this.Picture1.LoadImageFromByteArray(picture1_file_main); } } else { // Record not found, return to list this.ReturnToList(); return; } } } } } else { // NEW RECORD this.labelRecordId.Text = "New record"; } #endregion } // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { // Get the record id passed as query parameter if (!string.IsNullOrEmpty(Request.QueryString["id"])) { this.RecordId = int.Parse(Request.QueryString["id"]); } if (this.RecordId != 0) { // UPDATE this.labelRecordId.Text = this.RecordId.ToString(); // Load the database data using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { using (OleDbCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = "SELECT [Title] FROM [Ex_A_511] WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Id", this.RecordId); using (OleDbDataReader reader = command.ExecuteReader()) { if (reader.Read()) { // Record found this.txtTitle.Text = Convert.ToString(reader["Title"]); } else { // Record not found, return to list this.ReturnToList(); return; } } } } // Picture 1 preview visible this.phPicture1Preview.Visible = true; this.imgPicture1Preview.ImageUrl = string.Format("~/repository/store/ex_A_511/picture1/main/{0}.jpg", this.RecordId); // Picture 1 not required (alrady exists an image...) // Hide the required field validator this.fvPicture1.Visible = false; } else { // NEW RECORD this.labelRecordId.Text = "New record"; // Picture 1 preview not visible this.phPicture1Preview.Visible = false; // Picture 1 required // Show the required field validator this.fvPicture1.Visible = true; } } }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI();", true); } if (!this.IsPostBack) { // Get the record id passed as query parameter if (!string.IsNullOrEmpty(Request.QueryString["id"])) { this.RecordId = int.Parse(Request.QueryString["id"]); } // Setup the Picture1 CropConstraint and Preview this.Picture1.CropConstraint = new FixedCropConstraint(350, 350); this.Picture1.PreviewFilter = new FixedResizeConstraint(100, 100); #region Load the Record if (this.RecordId != 0) { // UPDATE this.labelRecordId.Text = this.RecordId.ToString(); // Load the database data using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { using (OleDbCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = "SELECT [Title] FROM [Ex_A_502] WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Id", this.RecordId); using (OleDbDataReader reader = command.ExecuteReader()) { if (reader.Read()) { // Record found // Get the title this.txtTitle.Text = Convert.ToString(reader["Title"]); string picture1FileName = string.Format("{0}.jpg", this.RecordId); string picture1FilePath_main = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_502/picture1/main/"), picture1FileName); if (System.IO.File.Exists(picture1FilePath_main)) { // Image exists... Load the picture1 main image this.Picture1.LoadImageFromFileSystem(picture1FilePath_main); } } else { // Record not found, return to list this.ReturnToList(); return; } } } } } else { // NEW RECORD this.labelRecordId.Text = "New record"; } #endregion } // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; }
protected void btnSave_Click(object sender, EventArgs e) { // Save the record if (!this.IsValid) { return; } #region Delete the previous image files if (this.RecordId != 0) { // UPDATE... if (!this.Picture1.HasImage) { // Image removed -> Delete the old files // Get the picture file name string picture1FileName = string.Format("{0}.jpg", this.RecordId); // Delete the main image string picture1FilePath_main = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_502/picture1/main/"), picture1FileName); if (System.IO.File.Exists(picture1FilePath_main)) { System.IO.File.Delete(picture1FilePath_main); } // Delete the thumbnail string picture1FilePath_thumbnail = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_502/picture1/thumbnail/"), picture1FileName); if (System.IO.File.Exists(picture1FilePath_thumbnail)) { System.IO.File.Delete(picture1FilePath_thumbnail); } } } #endregion #region Save the Record into the DB if (this.RecordId != 0) { // UPDATE... using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { // Update the record using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "UPDATE [Ex_A_502] SET [Title]=@Title WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Title", this.txtTitle.Text); command.Parameters.AddWithValue("@Id", this.RecordId); command.ExecuteNonQuery(); } } } else { // INSERT... using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { // Insert the new record using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "INSERT INTO [Ex_A_502] ([Title]) VALUES (@Title)"; command.Parameters.AddWithValue("@Title", this.txtTitle.Text); command.ExecuteNonQuery(); } // Get the new record id using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "SELECT @@IDENTITY"; this.RecordId = Convert.ToInt32(command.ExecuteScalar()); } } } #endregion #region Save the new image files (using the record id as file name) if (this.Picture1.HasNewImage) { // Get the picture file name string picture1FileName = string.Format("{0}.jpg", this.RecordId); // Save the main image string picture1FilePath_main = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_502/picture1/main/"), picture1FileName); this.Picture1.SaveProcessedImageToFileSystem(picture1FilePath_main); // Genereate the thumbnail image (Resize -> Fixed size: 48x48 Pixel, Jpeg 80% quality) string picture1FilePath_thumbnail = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_502/picture1/thumbnail/"), picture1FileName); ImageProcessingJob job = this.Picture1.GetImageProcessingJob(); job.Filters.Add(new FixedResizeConstraint(48, 48)); job.SaveProcessedImageToFileSystem(this.Picture1.TemporarySourceImageFilePath, picture1FilePath_thumbnail, new JpegFormatEncoderParams(80)); } #endregion // Clear the temporary files this.Picture1.ClearTemporaryFiles(); this.ReturnToList(); }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI();", true); } if (!this.IsPostBack) { // Get the record id passed as query parameter if (!string.IsNullOrEmpty(Request.QueryString["id"])) { this.RecordId = int.Parse(Request.QueryString["id"]); } // Setup the size of the preview image displayed in the Picture1 control (fixed size: 200x200 pixel) this.Picture1.PreviewFilter = new FixedResizeConstraint(200, 200); this.Picture1.Text_ConfigurationLabel = "<strong>Image orientation: </strong>"; this.Picture1.Configurations = new string[] { "Landscape", "Portrait" }; #region Load the Record if (this.RecordId != 0) { // UPDATE this.labelRecordId.Text = this.RecordId.ToString(); // Load the database data using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { using (OleDbCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = "SELECT [Title], [Picture1_Configuration], [Picture1_PictureTrimmerValue], [Picture1_FileName_upload], [Picture1_FileName_main], [Picture1_FileName_thumbnail] FROM [Ex_A_506] WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Id", this.RecordId); using (OleDbDataReader reader = command.ExecuteReader()) { if (reader.Read()) { // Record found // Get the title this.txtTitle.Text = Convert.ToString(reader["Title"]); // Get the configuration index (0=landscape, 1=portrait) // and apply the right crop constrait depending on the configuration this.Picture1.SelectedConfigurationIndex = Convert.ToInt32(reader["Picture1_Configuration"]); this.Picture1.CropConstraint = this.GetCropConstraint(this.Picture1.SelectedConfigurationIndex.Value); // Get the PictureTrimmer previous state PictureTrimmerValue picture1Value = PictureTrimmerValue.FromJSON(Convert.ToString(reader["Picture1_PictureTrimmerValue"])); // Get the picture1 file names this.Picture1FileName_upload = Convert.ToString(reader["Picture1_FileName_upload"]); this.Picture1FileName_main = Convert.ToString(reader["Picture1_FileName_main"]); this.Picture1FileName_thumbnail = Convert.ToString(reader["Picture1_FileName_thumbnail"]); if (!string.IsNullOrEmpty(this.Picture1FileName_upload)) { // Load the image into the SimpleImageUpload ASCX control string picture1FilePath_upload = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_506/picture1/upload/"), this.Picture1FileName_upload); this.Picture1.LoadImageFromFileSystem(picture1FilePath_upload, picture1Value); } } else { // Record not found, return to list this.ReturnToList(); return; } } } } } else { // NEW RECORD this.labelRecordId.Text = "New record"; } #endregion } // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI(); initializeExampleUI();", true); } if (!this.ScriptManager1.IsInAsyncPostBack) { // Load the colorpicker script ExamplesHelper.LoadLibrary_ColorPicker(this); // Load the fancybox script ExamplesHelper.LoadLibrary_FancyBox(this); } // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; switch (this.ddlInterfaceMode.SelectedValue) { case "Full": this.InlinePictureTrimmer1.ShowRulers = true; this.InlinePictureTrimmer1.ShowCropAlignmentLines = true; this.InlinePictureTrimmer1.ShowDetailsPanel = true; this.InlinePictureTrimmer1.ShowZoomPanel = true; this.InlinePictureTrimmer1.ShowResizePanel = true; this.InlinePictureTrimmer1.ShowRotatePanel = true; this.InlinePictureTrimmer1.ShowFlipPanel = true; this.InlinePictureTrimmer1.ShowImageAdjustmentsPanel = true; break; case "Standard": this.InlinePictureTrimmer1.ShowRulers = true; this.InlinePictureTrimmer1.ShowCropAlignmentLines = true; this.InlinePictureTrimmer1.ShowDetailsPanel = true; this.InlinePictureTrimmer1.ShowZoomPanel = true; this.InlinePictureTrimmer1.ShowResizePanel = true; this.InlinePictureTrimmer1.ShowRotatePanel = true; this.InlinePictureTrimmer1.ShowFlipPanel = true; this.InlinePictureTrimmer1.ShowImageAdjustmentsPanel = false; break; case "Easy": this.InlinePictureTrimmer1.ShowRulers = true; this.InlinePictureTrimmer1.ShowCropAlignmentLines = true; this.InlinePictureTrimmer1.ShowDetailsPanel = false; this.InlinePictureTrimmer1.ShowZoomPanel = false; this.InlinePictureTrimmer1.ShowResizePanel = true; this.InlinePictureTrimmer1.ShowRotatePanel = true; this.InlinePictureTrimmer1.ShowFlipPanel = true; this.InlinePictureTrimmer1.ShowImageAdjustmentsPanel = false; break; case "Minimal": this.InlinePictureTrimmer1.ShowRulers = true; this.InlinePictureTrimmer1.ShowCropAlignmentLines = true; this.InlinePictureTrimmer1.ShowDetailsPanel = false; this.InlinePictureTrimmer1.ShowZoomPanel = false; this.InlinePictureTrimmer1.ShowResizePanel = false; this.InlinePictureTrimmer1.ShowRotatePanel = false; this.InlinePictureTrimmer1.ShowFlipPanel = false; this.InlinePictureTrimmer1.ShowImageAdjustmentsPanel = false; break; case "Poor": this.InlinePictureTrimmer1.ShowRulers = false; this.InlinePictureTrimmer1.ShowCropAlignmentLines = false; this.InlinePictureTrimmer1.ShowDetailsPanel = false; this.InlinePictureTrimmer1.ShowZoomPanel = false; this.InlinePictureTrimmer1.ShowResizePanel = false; this.InlinePictureTrimmer1.ShowRotatePanel = false; this.InlinePictureTrimmer1.ShowFlipPanel = false; this.InlinePictureTrimmer1.ShowImageAdjustmentsPanel = false; break; } this.InlinePictureTrimmer1.UIUnit = (GfxUnit)Enum.Parse(typeof(GfxUnit), this.ddlGfxUnit.SelectedValue); this.InlinePictureTrimmer1.CanvasColor = System.Drawing.ColorTranslator.FromHtml(this.txtCanvasColor.Text); // Reset the OnClientControlLoad event hanlder (used to display the output image when the btnProcessImage is clicked this.InlinePictureTrimmer1.OnClientControlLoadFunction = ""; }
protected void btnSave_Click(object sender, EventArgs e) { // Save the record if (!this.IsValid) { return; } #region Manage the image files #region Delete the previous image files if (this.RecordId != 0) { // UPDATE... if ((!this.Picture1.HasImage) || (this.Picture1.HasNewImage)) { // Delete the previous image if (!string.IsNullOrEmpty(this.Picture1FileName_upload)) { // Delete the uploaded image string picture1FilePath_upload = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_506/picture1/upload/"), this.Picture1FileName_upload); if (System.IO.File.Exists(picture1FilePath_upload)) { System.IO.File.Delete(picture1FilePath_upload); } this.Picture1FileName_upload = ""; // Delete the main image string picture1FilePath_main = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_506/picture1/main/"), this.Picture1FileName_main); if (System.IO.File.Exists(picture1FilePath_main)) { System.IO.File.Delete(picture1FilePath_main); } this.Picture1FileName_main = ""; // Delete the thumbnail string picture1FilePath_thumbnail = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_506/picture1/thumbnail/"), this.Picture1FileName_thumbnail); if (System.IO.File.Exists(picture1FilePath_thumbnail)) { System.IO.File.Delete(picture1FilePath_thumbnail); } this.Picture1FileName_thumbnail = ""; } } } #endregion #region Save the new image if (this.Picture1.HasNewImage) { // Save the uploaded image string picture1folderPath_upload = Server.MapPath("~/repository/store/ex_A_506/picture1/upload/"); this.Picture1FileName_upload = CodeCarvings.Piczard.Helpers.IOHelper.GetUniqueFileName(picture1folderPath_upload, this.Picture1.SourceImageClientFileName); string picture1FilePath_upload = System.IO.Path.Combine(picture1folderPath_upload, this.Picture1FileName_upload); System.IO.File.Copy(this.Picture1.TemporarySourceImageFilePath, picture1FilePath_upload, true); // Generate the main image string picture1folderPath_main = Server.MapPath("~/repository/store/ex_A_506/picture1/main/"); // Get the original file name (but always use the .jpg extension) this.Picture1FileName_main = CodeCarvings.Piczard.Helpers.IOHelper.GetUniqueFileName(picture1folderPath_main, System.IO.Path.GetFileNameWithoutExtension(this.Picture1.SourceImageClientFileName) + ImageArchiver.GetFileExtensionFromImageFormatId(System.Drawing.Imaging.ImageFormat.Jpeg.Guid)); string picture1FilePath_main = System.IO.Path.Combine(picture1folderPath_main, this.Picture1FileName_main); this.Picture1.SaveProcessedImageToFileSystem(picture1FilePath_main); // Genereate the thumbnail image (Resize -> Fixed size: 48x48 Pixel, Jpeg 80% quality) string picture1folderPath_thumbnail = Server.MapPath("~/repository/store/ex_A_506/picture1/thumbnail/"); // Get the original file name (but always use the .jpg extension) this.Picture1FileName_thumbnail = CodeCarvings.Piczard.Helpers.IOHelper.GetUniqueFileName(picture1folderPath_thumbnail, System.IO.Path.GetFileNameWithoutExtension(this.Picture1.SourceImageClientFileName) + ImageArchiver.GetFileExtensionFromImageFormatId(System.Drawing.Imaging.ImageFormat.Jpeg.Guid)); string picture1FilePath_thumbnail = System.IO.Path.Combine(picture1folderPath_thumbnail, this.Picture1FileName_thumbnail); ImageProcessingJob job = this.Picture1.GetImageProcessingJob(); job.Filters.Add(new FixedResizeConstraint(48, 48)); job.SaveProcessedImageToFileSystem(this.Picture1.TemporarySourceImageFilePath, picture1FilePath_thumbnail, new JpegFormatEncoderParams(80)); } #endregion #endregion #region Save the Record into the DB if (this.RecordId != 0) { // UPDATE... using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { // Update the record using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "UPDATE [Ex_A_506] SET [Title]=@Title, [Picture1_Configuration]=@Picture1_Configuration, [Picture1_PictureTrimmerValue]=@Picture1_PictureTrimmerValue, [Picture1_FileName_upload]=@Picture1_FileName_upload, [Picture1_FileName_main]=@Picture1_FileName_main, [Picture1_FileName_thumbnail]=@Picture1_FileName_thumbnail WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Title", this.txtTitle.Text); // Store the selected configuration index (landscape / portrait) command.Parameters.AddWithValue("@Picture1_Configuration", this.Picture1.SelectedConfigurationIndex); // Store the picture trimmer vale command.Parameters.AddWithValue("@Picture1_PictureTrimmerValue", JSONSerializer.SerializeToString(this.Picture1.Value)); // Store the file names command.Parameters.AddWithValue("@Picture1_FileName_upload", this.Picture1FileName_upload); command.Parameters.AddWithValue("@Picture1_FileName_main", this.Picture1FileName_main); command.Parameters.AddWithValue("@Picture1_FileName_thumbnail", this.Picture1FileName_thumbnail); command.Parameters.AddWithValue("@Id", this.RecordId); command.ExecuteNonQuery(); } } } else { // INSERT... using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { // Insert the new record using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "INSERT INTO [Ex_A_506] ([Title], [Picture1_Configuration], [Picture1_PictureTrimmerValue], [Picture1_FileName_upload], [Picture1_FileName_main], [Picture1_FileName_thumbnail]) VALUES (@Title, @Picture1_Configuration, @Picture1_PictureTrimmerValue, @Picture1_FileName_upload, @Picture1_FileName_main, @Picture1_FileName_thumbnail)"; command.Parameters.AddWithValue("@Title", this.txtTitle.Text); // Store the selected configuration index (landscape / portrait) command.Parameters.AddWithValue("@Picture1_Configuration", this.Picture1.SelectedConfigurationIndex); // Store the picture trimmer vale command.Parameters.AddWithValue("@Picture1_PictureTrimmerValue", JSONSerializer.SerializeToString(this.Picture1.Value)); // Store the file names command.Parameters.AddWithValue("@Picture1_FileName_upload", this.Picture1FileName_upload); command.Parameters.AddWithValue("@Picture1_FileName_main", this.Picture1FileName_main); command.Parameters.AddWithValue("@Picture1_FileName_thumbnail", this.Picture1FileName_thumbnail); command.ExecuteNonQuery(); } } } #endregion // Clear the temporary files this.Picture1.ClearTemporaryFiles(); this.ReturnToList(); }
protected void Page_Load(object sender, EventArgs e) { // Load the fancybox script ExamplesHelper.LoadLibrary_FancyBox(this); }
protected void Page_Load(object sender, EventArgs e) { if (this.ScriptManager1.IsInAsyncPostBack) { // After every Ajax postback re-initialize the JQuery UI elements ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "initializeUI", "initializeUI();", true); } if (!this.IsPostBack) { // Get the record id passed as query parameter if (!string.IsNullOrEmpty(Request.QueryString["id"])) { this.RecordId = int.Parse(Request.QueryString["id"]); } // Setup the Picture1 CropConstraint and the Preview Resize constraint this.Picture1.CropConstraint = new FixedCropConstraint(300, 300); this.Picture1.CropConstraint.DefaultImageSelectionStrategy = CropConstraintImageSelectionStrategy.WholeImage; this.Picture1.PreviewFilter = null; //Use the selected image #region Load the Record if (this.RecordId != 0) { // UPDATE this.labelRecordId.Text = this.RecordId.ToString(); // Load the database data using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { using (OleDbCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = "SELECT [Title], [Picture1_PictureTrimmerValue], [Picture1_FileName_upload], [Picture1_FileName_main], [Picture1_FileName_thumbnail] FROM [Ex_A_503] WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Id", this.RecordId); using (OleDbDataReader reader = command.ExecuteReader()) { if (reader.Read()) { // Record found // Get the title this.txtTitle.Text = Convert.ToString(reader["Title"]); // Get the PictureTrimmer previous state PictureTrimmerValue picture1Value = PictureTrimmerValue.FromJSON(Convert.ToString(reader["Picture1_PictureTrimmerValue"])); // Get the picture1 file names this.Picture1FileName_upload = Convert.ToString(reader["Picture1_FileName_upload"]); this.Picture1FileName_main = Convert.ToString(reader["Picture1_FileName_main"]); this.Picture1FileName_thumbnail = Convert.ToString(reader["Picture1_FileName_thumbnail"]); if (!string.IsNullOrEmpty(this.Picture1FileName_upload)) { // Load the image into the SimpleImageUpload ASCX control string picture1FilePath_upload = System.IO.Path.Combine(Server.MapPath("~/repository/store/ex_A_503/picture1/upload/"), this.Picture1FileName_upload); this.Picture1.LoadImageFromFileSystem(picture1FilePath_upload, picture1Value); } } else { // Record not found, return to list this.ReturnToList(); return; } } } } } else { // NEW RECORD this.labelRecordId.Text = "New record"; } #endregion } // Reset some settings after every postback... this.MyUpdateProgress1.AssociatedUpdatePanelID = this.UpdatePanel1.UniqueID; }
protected void btnSave_Click(object sender, EventArgs e) { // Save the record if (!this.IsValid) { return; } #region Save the Record into the DB if (this.RecordId != 0) { // UPDATE... using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { // Update the record using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "UPDATE [Ex_A_511] SET [Title]=@Title WHERE [Id]=@Id"; command.Parameters.AddWithValue("@Title", this.txtTitle.Text); command.Parameters.AddWithValue("@Id", this.RecordId); command.ExecuteNonQuery(); } } } else { // INSERT... using (OleDbConnection connection = ExamplesHelper.GetNewOpenDbConnection()) { // Insert the new record using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "INSERT INTO [Ex_A_511] ([Title]) VALUES (@Title)"; command.Parameters.AddWithValue("@Title", this.txtTitle.Text); command.ExecuteNonQuery(); } // Get the new record id using (OleDbCommand command = connection.CreateCommand()) { command.CommandText = "SELECT @@IDENTITY"; this.RecordId = Convert.ToInt32(command.ExecuteScalar()); } } } #endregion // Save the picture 1 files // *** USE THE RECORD ID AS FILE NAME *** if (this.fuPicture1.HasFile) { // Get the source file bytes byte[] sourceFileBytes = this.fuPicture1.FileBytes; // Genereate the main image (Resize -> MaxSize: 400x250, Jpeg 92% quality) new ScaledResizeConstraint(250, 100).SaveProcessedImageToFileSystem(sourceFileBytes, string.Format("~/repository/store/ex_A_511/picture1/main/{0}.jpg", this.RecordId), new JpegFormatEncoderParams(92)); // Genereate the thumbnail image (Resize -> Fixed size: 48x48 Pixel, Jpeg 80% quality) new FixedResizeConstraint(48, 48).SaveProcessedImageToFileSystem(sourceFileBytes, string.Format("~/repository/store/ex_A_511/picture1/thumbnail/{0}.jpg", this.RecordId), new JpegFormatEncoderParams(80)); } this.ReturnToList(); }