Customizing Preview/Viewer

Stimulsoft Reports.NET discussion
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Customizing Preview/Viewer

Post by Edward »

In that case you can use the following code:

Code: Select all

StiOptions.Preview.Window.ShowBookmarksPanel = false;
report.PreviewSettings = (report.PreviewSettings & (int)(~StiPreviewSettings.Bookmarks));
           using (Stimulsoft.Report.Render.StiPreviewForm previewForm = new Stimulsoft.Report.Render.StiPreviewForm(report))
            {
                report.PreviewControl = previewForm.PreviewControl;
                previewForm.PreviewControl.ShowBookmarksPanel = false;
                report.Render();
                previewForm.ShowDialog();
            }
Another way is using the custom preview control for the report, where all these settings may be set directly for the report.

Thank you.
Dave Canto
Posts: 18
Joined: Mon Jan 22, 2007 11:51 am
Location: Belgium

Customizing Preview/Viewer

Post by Dave Canto »

Edward wrote:In that case you can use the following code:

Code: Select all

StiOptions.Preview.Window.ShowBookmarksPanel = false;
report.PreviewSettings = (report.PreviewSettings & (int)(~StiPreviewSettings.Bookmarks));
           using (Stimulsoft.Report.Render.StiPreviewForm previewForm = new Stimulsoft.Report.Render.StiPreviewForm(report))
            {
                report.PreviewControl = previewForm.PreviewControl;
                previewForm.PreviewControl.ShowBookmarksPanel = false;
                report.Render();
                previewForm.ShowDialog();
            }
Another way is using the custom preview control for the report, where all these settings may be set directly for the report.
The code above does not work. It just hides the bookmarkspanel and corresponding bookmarksbutton. What I want to achieve is hiding the bookmarkpanel when the report is shown. The user can show it manually when he/she clicks the "Show Bookmark Panel"-button.

Possible way to solve this, according to me. Extend the StiPreviewConfigService with 2 extra properties, namely:

Code: Select all

StiPreviewConfigService  config = StiConfig.Services.GetService(typeof(StiPreviewConfigService)) as StiPreviewConfigService;
            config.ToolBookmarksActive = false;
            config.ShowBookmarksPanel = true;

At the moment something analogue is already available:

Code: Select all

StiPreviewConfigService config = StiConfig.Services.GetService(typeof(StiPreviewConfigService)) as StiPreviewConfigService;
            config.ToolHandActive = true;
            config.ShowThumbsPanel = true;
Is it possible to put these extra functionalities in the next build?
Dave Canto
Posts: 18
Joined: Mon Jan 22, 2007 11:51 am
Location: Belgium

Customizing Preview/Viewer

Post by Dave Canto »

Does anyone else have this particular problem? I'm asking for a feature request for bookmarks. When the report shows, the bookmarkpanel on the left has to be hidden from the user. He / she can activate it by pressing the bookmarkbutton of the previewcontrol.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Customizing Preview/Viewer

Post by Edward »

Dave wrote:Does anyone else have this particular problem? I'm asking for a feature request for bookmarks. When the report shows, the bookmarkpanel on the left has to be hidden from the user. He / she can activate it by pressing the bookmarkbutton of the previewcontrol.
In that case the code should be a bit different:

Code: Select all

using (Stimulsoft.Report.Render.StiPreviewForm previewForm = new Stimulsoft.Report.Render.StiPreviewForm(report))
{
    report.PreviewControl = previewForm.PreviewControl;
    report.Render();
    previewForm.PreviewControl.BookmarksTreeView.Visible = false;
    (previewForm.PreviewControl.ToolBar.Controls["tbBookmarks"] as StiToolButton).Pushed = false;
    previewForm.ShowDialog();
}
This code hides the bookmarkpanel when the report is showed to the user, but "Bookmark" button remains visible, so the user may hide/show the bookmarks later if needed.

Thank you.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Customizing Preview/Viewer

Post by Edward »

We've added new properties to StiPreviewControl component. These properties allows to adjust Zoom buttons of the StiPreviewControl.
Here the list of these properties:

ShowZoom
ShowZoomIn
ShowZoomMultiplePages
ShowZoomOnePage
ShowZoomOut
ShowZoomPageWidth
ShowZoomTwoPages


fphealthcare
Posts: 33
Joined: Sun Jul 02, 2006 6:06 pm
Location: New Zealand

Customizing Preview/Viewer

Post by fphealthcare »

We want to customise the Email button so when a user clicks on it, it automatically exports the report to a PDF file, and attaches it to an email and shows the send email dialog.

We are using the following code to override the Email button.

Code: Select all

using (StiPreviewForm form = new StiPreviewForm(this.reportFile))
{
	form.PreviewControl.ClickSendEMailButton += new EventHandler(stiPreviewControl1_ClickSendEMailButton);
	this.reportFile.Render();
	form.ShowDialog();		
}

Code: Select all

private void stiPreviewControl1_ClickSendEMailButton(object sender, EventArgs e)
{
	StiPdfExportSettings settings = new StiPdfExportSettings();
	this.reportFile.ExportDocument(StiExportFormat.Pdf, "D:\\MyFile.pdf", settings);
	try
	{
		MAPI.SendEMail("Subject", "Body", "D:\\MyFile.pdf");
	}
	catch (Exception exception)
	{
		MessageBox.Show(exception.Message);
	}
}
The code works. When the user clicks on the Email button a new email is created with a PDF of the report attached. However when we try this on our work machine there is something wrong. After the new email is created, the mouse turns from an arrow to the hourglass and stays that way. The system seems to be busy doing something and is unresponsive. When you check the CPU usage, it is sitting very low (2 - 5%). This does not come right even if you leave it for a long time. However if you press the 'Windows' key on the keyboard to bring up the 'Start Menu', everything becomes fine.
There are 2 strange things about this.
1. On computers not on our network, everything seems to be working fine.
2. On our work network, using the original Email function works fine.
We use a Windows Active Directory network and MS Exchange for our emails on out network.

Is this a problem with our network? Or a problem with StimulReport?

Thanks
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Customizing Preview/Viewer

Post by Edward »

If I understand in correct way the standard code works correct on the problem machine?

Thank you.
fphealthcare
Posts: 33
Joined: Sun Jul 02, 2006 6:06 pm
Location: New Zealand

Customizing Preview/Viewer

Post by fphealthcare »

Edward wrote:If I understand in correct way the standard code works correct on the problem machine?

Thank you.
Hi.

Yes the standard code works correctly ont he problem machines on our network.

Thanks
fphealthcare
Posts: 33
Joined: Sun Jul 02, 2006 6:06 pm
Location: New Zealand

Customizing Preview/Viewer

Post by fphealthcare »

Have you got a solution for the custom email? The default email function works, but we want to override it with the custom email function.

Thanks.
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Customizing Preview/Viewer

Post by Vital »

Sorry, we don't find any difference between your code and our code in default event handler. We use following method:

Code: Select all

protected void SendEMail(string subject, string body, string filePath)
{
       try
       {
		MAPI.SendEMail(subject, body, filePath);
	}
	catch (Exception e)
	{
		StiLogService.Write(this.GetType(), "Send E-mail");
		StiLogService.Write(this.GetType(), e);

		if (!StiReport.HideMessages)MessageBox.Show(e.Message);
	}
}
I have only one recommendation, try to use our code directly. You can find full version of MAPI class above:

Code: Select all

using System;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;

namespace Stimulsoft.Report.Export
{
	#region MapiMessage
	[StructLayout(LayoutKind.Sequential)]
	public class MapiMessage
	{
		public int reserved;
		public string subject;
		public string noteText;
		public string messageType;
		public string dateReceived;
		public string conversationID;
		public int flags;
		public IntPtr originator;
		public int recipCount;
		public IntPtr recips;
		public int fileCount;
		public IntPtr files;
	}
	#endregion

	#region MapiFileDesc
	[StructLayout(LayoutKind.Sequential)]
	public class MapiFileDesc
	{
		public int reserved;
		public int flags;
		public int position;
		public string pathName;
		public string fileName;
		public IntPtr fileType;
	}
	#endregion

	[System.Security.SuppressUnmanagedCodeSecurity]
    public sealed class MAPI
    {
		#region Methods
        private static MapiMessage CreateMessage(string subject, string body, string filePath)
        {
            MapiMessage message = new MapiMessage();
            message.subject = subject;
            message.noteText = body;
            message.fileCount = 1;
            message.files = GetFileDesc(filePath);
            return message;
        }

        private static void DisposeMessage(MapiMessage msg)
        {
            if (msg.files != IntPtr.Zero)
            {
                Marshal.DestroyStructure(msg.files, typeof(MapiFileDesc));
                Marshal.FreeHGlobal(msg.files);
                msg = null;
            }
        }

        
		private static IntPtr GetFileDesc(string filePath)
        {
			if (filePath != null && filePath.Length > 0)
			{
				Type mapiType = typeof(MapiFileDesc);
				int size = Marshal.SizeOf(mapiType);

				IntPtr mapiPtr = Marshal.AllocHGlobal(size);
				MapiFileDesc mapiDesc = new MapiFileDesc();
				mapiDesc.position = -1;
				mapiDesc.fileName = Path.GetFileName(filePath);
				mapiDesc.pathName = filePath;
				Marshal.StructureToPtr(mapiDesc, mapiPtr, false);
				return mapiPtr;
			}
			return IntPtr.Zero;
        }

        
		private static void Logoff(IntPtr hwnd, ref IntPtr session)
        {
            if (session != IntPtr.Zero)
            {
                MAPI.MAPILogoff(session, hwnd, 0, 0);
                session = IntPtr.Zero;
            }
        }

        private static bool Logon(IntPtr hwnd, ref IntPtr session)
        {
            int error = MAPI.MAPILogon(hwnd, null, null, 0, 0, ref session);
            if (error != 0)
            {
                error = MAPI.MAPILogon(hwnd, null, null, MapiLogonUI, 0, ref session);
            }
            return error == 0;
        }

		#endregion

		#region Imports
		[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern int _controlfp(int n, int mask);

        [DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)]
        private static extern int MAPILogoff(IntPtr session, IntPtr hwnd, int flags, int reserved);
        
		[DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)]
        private static extern int MAPILogon(IntPtr hwnd, string profileName, string password, int flags, int reserved, ref IntPtr session);
        
		[DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)]
        private static extern int MAPISendMail(IntPtr session, IntPtr uiParam, MapiMessage message, int flags, int reserved);
		#endregion

		#region Fields
		private const int MAPI_DIALOG = 8;
		private const int MapiLogonUI = 1;
		#endregion

        public static void SendEMail(string subject, string body, string filePath)
        {
			try
			{
				IntPtr handle = IntPtr.Zero;
				IntPtr session = IntPtr.Zero;
            
				if (Logon(handle, ref session))
				{
					MapiMessage message = CreateMessage(subject, body, filePath);
					MAPI.MAPISendMail(session, handle, message, MAPI_DIALOG, 0);
					Logoff(handle, ref session);
					DisposeMessage(message);
				}				
			}
			finally
			{
				const int _MCW_EW = 0x8001F;
				const int _EM_INVALID = 0x10;

				_controlfp(_MCW_EW, _EM_INVALID);
			}
        }

		
		private MAPI()
		{
		}
    }    
}

Thank you.
Post Reply