private static void InitializeDb_SqlServer()
    {
        using (SqlConnection connection = GetNewOpenDbConnection_SqlServer())
        {
            using (SqlCommand command = connection.CreateCommand())
            {
                // *** Initialize the [Ex_A_306] TABLE ******
                command.CommandText = "INSERT INTO [Ex_A_306] ([ID], [PictureTrimmerValue], [SourceImage], [OutputImage]) VALUES (@Id, @PictureTrimmerValue, @SourceImage, @OutputImage)";

                command.Parameters.AddWithValue("@Id", 1);

                string sourceImageFilePath = HttpContext.Current.Server.MapPath("~/repository/source/trevi1.jpg");
                command.Parameters.AddWithValue("@SourceImage", File.ReadAllBytes(sourceImageFilePath));

                string pictureTrimmerValueString = "{\"imageSelection\":{\"transformation\":{\"resizeFactor\":102.4734,\"rotationAngle\":0,\"flipH\":true,\"flipV\":false},\"crop\":{\"rectangle\":{\"x\":34,\"y\":37,\"width\":320,\"height\":180},\"canvasColor\":{\"value\":{\"a\":255,\"r\":255,\"g\":255,\"b\":255},\"autoUseTransparentColor\":true}}},\"imageAdjustments\":{\"brightness\":-1.973684,\"contrast\":5.921052,\"hue\":-180,\"saturation\":-13.1579},\"imageBackColorApplyMode\":1}";
                command.Parameters.AddWithValue("@PictureTrimmerValue", pictureTrimmerValueString);

                PictureTrimmerValue value = PictureTrimmerValue.FromJSON(pictureTrimmerValueString);
                command.Parameters.AddWithValue("@OutputImage", value.SaveProcessedImageToByteArray(sourceImageFilePath, new JpegFormatEncoderParams()));

                command.ExecuteNonQuery();
                // *********
            }
        }
    }
    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 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 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();", 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:&nbsp;</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;
    }
Example #6
0
    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 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 Crop constraint and the preview filter
            this.Picture1.CropConstraint = new FixedCropConstraint(300, 300);
            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 (SqlConnection connection = ExamplesHelper.GetNewOpenDbConnection_SqlServer())
                {
                    using (SqlCommand command = connection.CreateCommand())
                    {
                        command.CommandType = CommandType.Text;
                        command.CommandText = "SELECT [Title], [Picture1_pictureTrimmerValue], [Picture1_file_upload] FROM [Ex_A_505] WHERE [Id]=@Id";
                        command.Parameters.AddWithValue("@Id", this.RecordId);

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                // Record found

                                // Get the title
                                this.txtTitle.Text = Convert.ToString(reader["Title"]);

                                // Get the picture1 PictureTrimmerValue
                                string picture1_pictureTrimmerValue = Convert.ToString(reader["Picture1_pictureTrimmerValue"]);
                                if (!string.IsNullOrEmpty(picture1_pictureTrimmerValue))
                                {
                                    PictureTrimmerValue pictureTrimmerValue = PictureTrimmerValue.FromJSON(picture1_pictureTrimmerValue);

                                    // Get the original file bytes
                                    byte[] picture1_file_upload = (byte[])(reader["Picture1_file_upload"]);
                                    if (picture1_file_upload.Length > 0)
                                    {
                                        // Load the image into the SimpleImageUpload ASCX control
                                        this.Picture1.LoadImageFromByteArray(picture1_file_upload, pictureTrimmerValue);
                                    }
                                }
                            }
                            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;
    }