diff --git a/Extras/Core/FastReport.Data/FastReport.Data.MySql/MySqlDataConnection.cs b/Extras/Core/FastReport.Data/FastReport.Data.MySql/MySqlDataConnection.cs
index bcaa1a34..8b2e3016 100644
--- a/Extras/Core/FastReport.Data/FastReport.Data.MySql/MySqlDataConnection.cs
+++ b/Extras/Core/FastReport.Data/FastReport.Data.MySql/MySqlDataConnection.cs
@@ -64,11 +64,125 @@ public override DbDataAdapter GetAdapter(string selectCommand, DbConnection conn
{
MySqlDataAdapter adapter = new MySqlDataAdapter(selectCommand, connection as MySqlConnection);
foreach (CommandParameter p in parameters)
- {
+ {
MySqlParameter parameter = adapter.SelectCommand.Parameters.Add(p.Name, (MySqlDbType)p.DataType, p.Size);
- parameter.Value = p.Value;
+
+ if (p.Value is Variant value)
+ {
+ //https://mysqlconnector.net/troubleshooting/parameter-types/
+ if (value.Type == typeof(string))
+ parameter.Value = VariantToClrType(value, (MySqlDbType)p.DataType);
+ else
+ parameter.Value = value.ToType(value.Type);
+ }
+ else
+ parameter.Value = p.Value;
}
return adapter;
}
+
+ private object VariantToClrType(Variant value, MySqlDbType type)
+ {
+ if (value.ToString() == "")
+ return null;
+
+ switch (type)
+ {
+ case MySqlDbType.Int64:
+ {
+ long val = 0;
+ long.TryParse(value.ToString(), out val);
+ return val;
+ }
+ case MySqlDbType.UInt64:
+ {
+ ulong val = 0;
+ ulong.TryParse(value.ToString(), out val);
+ return val;
+ }
+ case MySqlDbType.Bit:
+ case MySqlDbType.Bool:
+ {
+ bool val = false;
+ bool.TryParse(value.ToString(), out val);
+ if (value.ToString() == "1")
+ val = true;
+ return val;
+ }
+ case MySqlDbType.Double:
+ {
+ double val = 0;
+ double.TryParse(value.ToString(), out val);
+ return val;
+ }
+ case MySqlDbType.DateTime:
+ case MySqlDbType.Date:
+ {
+ DateTime val = DateTime.Now;
+ DateTime.TryParse(value.ToString(), out val);
+ return val;
+ }
+ case MySqlDbType.Time:
+ case MySqlDbType.Timestamp:
+ {
+ TimeSpan val = TimeSpan.Zero;
+ TimeSpan.TryParse(value.ToString(), out val);
+ return val;
+ }
+ case MySqlDbType.Decimal:
+ {
+ decimal val = 0;
+ decimal.TryParse(value.ToString(), out val);
+ return val;
+ }
+ case MySqlDbType.Float:
+ {
+ float val = 0;
+ float.TryParse(value.ToString(), out val);
+ return val;
+ }
+ case MySqlDbType.Int24:
+ case MySqlDbType.UInt24:
+ case MySqlDbType.Int32:
+ {
+ int val = 0;
+ int.TryParse(value.ToString(), out val);
+ return val;
+ }
+ case MySqlDbType.UInt32:
+ {
+ uint val = 0;
+ uint.TryParse(value.ToString(), out val);
+ return val;
+ }
+ case MySqlDbType.Guid:
+ {
+ Guid val = Guid.Empty;
+ Guid.TryParse(value.ToString(), out val);
+ return val;
+ }
+ case MySqlDbType.Int16:
+ {
+ short val = 0;
+ short.TryParse(value.ToString(), out val);
+ return val;
+ }
+ case MySqlDbType.UInt16:
+ {
+ ushort val = 0;
+ ushort.TryParse(value.ToString(), out val);
+ return val;
+ }
+ case MySqlDbType.Byte:
+ case MySqlDbType.UByte:
+ {
+ byte val = 0;
+ byte.TryParse(value.ToString(), out val);
+ return val;
+ }
+ default:
+ return value.ToString();
+ }
+ }
}
}
diff --git a/FastReport.Base/Export/Image/ImageExport.cs b/FastReport.Base/Export/Image/ImageExport.cs
index a349b232..1a875f8d 100644
--- a/FastReport.Base/Export/Image/ImageExport.cs
+++ b/FastReport.Base/Export/Image/ImageExport.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
@@ -72,6 +73,10 @@ public partial class ImageExport : ExportBase
private float zoomX;
private float zoomY;
private System.Drawing.Drawing2D.GraphicsState state;
+ private string imageExtensionFormat;
+ private string documentTitle;
+
+ private bool saveStreams;
const float DIVIDER = 0.75f;
const float PAGE_DIVIDER = 2.8346400000000003f; // mm to point
@@ -210,6 +215,16 @@ private bool IsMultiFrameTiff
{
get { return ImageFormat == ImageExportFormat.Tiff && MultiFrameTiff; }
}
+
+ ///
+ /// Enable or disable saving streams in GeneratedStreams collection.
+ ///
+ public bool SaveStreams
+ {
+ get { return saveStreams; }
+ set { saveStreams = value; }
+ }
+
#endregion
#region Private Methods
@@ -220,11 +235,24 @@ private System.Drawing.Image CreateImage(int width, int height, string suffix)
return CreateMetafile(suffix);
return new Bitmap(width, height);
}
+ private void GeneratedUpdate(string filename, Stream stream)
+ {
+ int i = GeneratedFiles.IndexOf(filename);
+ if (i == -1)
+ {
+ GeneratedFiles.Add(filename);
+ GeneratedStreams.Add(stream);
+ }
+ else
+ {
+ GeneratedStreams[i] = stream;
+ }
+ }
private System.Drawing.Image CreateMetafile(string suffix)
{
string extension = Path.GetExtension(FileName);
- string fileName = Path.ChangeExtension(FileName, suffix + extension);
+ string targetFileName = Path.ChangeExtension(FileName, suffix + extension);
System.Drawing.Image image;
using (Bitmap bmp = new Bitmap(1, 1))
@@ -235,9 +263,9 @@ private System.Drawing.Image CreateMetafile(string suffix)
image = new Metafile(Stream, hdc);
else
{
- image = new Metafile(fileName, hdc);
- if (!GeneratedFiles.Contains(fileName))
- GeneratedFiles.Add(fileName);
+ image = new Metafile(targetFileName, hdc);
+ if (!GeneratedFiles.Contains(targetFileName))
+ GeneratedFiles.Add(targetFileName);
}
g.ReleaseHdc(hdc);
}
@@ -383,17 +411,31 @@ private void SaveImage(System.Drawing.Image image, string suffix)
}
else if (ImageFormat != ImageExportFormat.Metafile)
{
- string extension = Path.GetExtension(FileName);
- string fileName = Path.ChangeExtension(FileName, suffix + extension);
+ Stream stream;
+ string targetFileName;
+ if (saveStreams)
+ {
+ targetFileName = Path.ChangeExtension(documentTitle + suffix, imageExtensionFormat);
+ stream = new MemoryStream();
+ }
+ else
+ {
+ string extension = Path.GetExtension(FileName);
+ targetFileName = Path.ChangeExtension(FileName, suffix + extension);
- // empty suffix means that we should use the Stream that was created in the ExportBase
- Stream stream = suffix == "" ? Stream : new FileStream(fileName, FileMode.Create);
+ // empty suffix means that we should use the Stream that was created in the ExportBase
+ stream = suffix == "" ? Stream : new FileStream(targetFileName, FileMode.Create);
- if (suffix != "")
- GeneratedFiles.Add(fileName);
+ if (suffix != "")
+ {
+ GeneratedFiles.Add(targetFileName);
+ }
+ }
if (ImageFormat == ImageExportFormat.Jpeg)
+ {
ExportUtils.SaveJpeg(image, stream, JpegQuality);
+ }
else if (ImageFormat == ImageExportFormat.Tiff && MonochromeTiff)
{
// handle monochrome tiff separately
@@ -426,7 +468,9 @@ private void SaveImage(System.Drawing.Image image, string suffix)
image.Save(stream, format);
}
- if (suffix != "")
+ if (saveStreams)
+ GeneratedUpdate(targetFileName, stream);
+ else if (suffix != "")
stream.Dispose();
}
@@ -450,6 +494,7 @@ protected override void Start()
//init
SeparateFiles = Stream is MemoryStream ? false : SeparateFiles;
+ GeneratedStreams = new List();
pageNumber = 0;
height = 0;
width = 0;
@@ -462,6 +507,13 @@ protected override void Start()
curOriginY = 0;
firstPage = true;
+ if (saveStreams)
+ {
+ imageExtensionFormat = ImageFormat.ToString();
+ separateFiles = true;
+ documentTitle = (!String.IsNullOrEmpty(Report.ReportInfo.Name) ?
+ Report.ReportInfo.Name : "");
+ }
if (!SeparateFiles && !IsMultiFrameTiff)
{
// create one big image. To do this, calculate max width and sum of pages height
@@ -510,7 +562,7 @@ protected override void ExportPageBegin(ReportPage page)
else
g = Graphics.FromImage(image);
- state = g.Save();
+ state = g.Save();
g.FillRegion(Brushes.Transparent, new Region(new RectangleF(0, curOriginY, width, height)));
if (bigImage != null && curOriginY + height * 2 > bigImage.Height)
@@ -663,6 +715,7 @@ public ImageExport()
Resolution = 96;
jpegQuality = 100;
monochromeTiffCompression = EncoderValue.CompressionCCITT4;
+ saveStreams = false;
}
}
}