Customizing Preview/Viewer

Stimulsoft Reports.NET discussion
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.
Dave Canto
Posts: 18
Joined: Mon Jan 22, 2007 11:51 am
Location: Belgium

Customizing Preview/Viewer

Post by Dave Canto »

Edward wrote:
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.
The code above seems to work. Thanks for your help. I noticed a little bug in the PreviewControl. When a report is shown, one can change the way the report is displayed with 3 little buttons in the bottom of the PreviewControl: SinglePage, Continuous, MultiplePages. When one of these buttons are pressed the bookmarkpanel is also automatically shown to the user. This is a strange behaviour of the PreviewControl and something a user doesn't want in my opinion.
Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

Customizing Preview/Viewer

Post by Vital »

Fixed. Patch will be available in build from 13 August.

Thank you.
Post Reply